diff --git a/controllers/mpog_software_plugin_controller.rb b/controllers/mpog_software_plugin_controller.rb index ad48f0b..e643549 100644 --- a/controllers/mpog_software_plugin_controller.rb +++ b/controllers/mpog_software_plugin_controller.rb @@ -113,17 +113,12 @@ class MpogSoftwarePluginController < ApplicationController condition = !request.xhr? || params[:query].nil? || params[:field].nil? return render :json=>{} if condition - model = case params[:field] - when "software_language" - ProgrammingLanguage - else - DatabaseDescription - end + model = get_model_by_params_field data = model.where("name ILIKE ?", "%#{params[:query]}%").select("id, name") - data = data.collect { |db| - {:id=>db.id, :label=>db.name} - } + .collect { |db| + {:id=>db.id, :label=>db.name} + } other = [model.select("id, name").last].collect { |db| {:id=>db.id, :label=>db.name} @@ -236,4 +231,13 @@ class MpogSoftwarePluginController < ApplicationController redirect_to :controller => "mpog_software_plugin", :action => "create_institution_admin" end end + + def get_model_by_params_field + case params[:field] + when "software_language" + return ProgrammingLanguage + else + return DatabaseDescription + end + end end diff --git a/controllers/mpog_software_plugin_myprofile_controller.rb b/controllers/mpog_software_plugin_myprofile_controller.rb index 79c1e70..ca34201 100644 --- a/controllers/mpog_software_plugin_myprofile_controller.rb +++ b/controllers/mpog_software_plugin_myprofile_controller.rb @@ -15,7 +15,7 @@ class MpogSoftwarePluginMyprofileController < MyProfileController def new_software set_software_as_template - + @community = Community.new(params[:community]) @community.environment = environment @software_info = SoftwareInfo.new(params[:software_info]) @@ -55,6 +55,7 @@ class MpogSoftwarePluginMyprofileController < MyProfileController session[:notice] = _('Software updated sucessefuly') end rescue ActiveRecord::RecordInvalid => invalid + session[:notice] = _('Could not update software') end end diff --git a/features/step_definitions/mpog_steps.rb b/features/step_definitions/mpog_steps.rb index 7423342..dd609e7 100644 --- a/features/step_definitions/mpog_steps.rb +++ b/features/step_definitions/mpog_steps.rb @@ -116,9 +116,9 @@ Given /^the following softwares$/ do |table| software_info.community = Community.create(:name=>item[:name]) software_info.acronym = item[:acronym] if item[:acronym] - software_info.acronym = item[:operating_platform] if item[:operating_platform] - software_info.acronym = item[:objectives] if item[:objectives] - software_info.acronym = item[:features] if item[:features] + software_info.operating_platform = item[:operating_platform] if item[:operating_platform] + software_info.objectives = item[:objectives] if item[:objectives] + software_info.features = item[:features] if item[:features] software_info.public_software = item[:public_software] == "true" if item[:public_software] if item[:software_language] diff --git a/lib/ext/communities_block.rb b/lib/ext/communities_block.rb index 717e6ec..072be4a 100644 --- a/lib/ext/communities_block.rb +++ b/lib/ext/communities_block.rb @@ -3,21 +3,13 @@ require_dependency 'communities_block' class CommunitiesBlock def profile_list - result = nil - visible_profiles = profiles.visible.includes([:image,:domains,:preferred_domain,:environment]) - if !prioritize_profiles_with_image - result = visible_profiles.all(:limit => get_limit, :order => 'profiles.updated_at DESC').sort_by{ rand } - elsif profiles.visible.with_image.count >= get_limit - result = visible_profiles.with_image.all(:limit => get_limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand } - else - result = visible_profiles.with_image.sort_by{ rand } + visible_profiles.without_image.all(:limit => get_limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand } - end + result = get_visible_profiles list_without_software_and_institution = [] - visible_profiles.each do |p| - if p.class == Community and !p.software? and !p.institution? - list_without_software_and_institution << p + result.each do |profile| + if profile.class == Community && !profile.software? && !profile.institution? + list_without_software_and_institution << profile end end @@ -30,4 +22,28 @@ class CommunitiesBlock profile_list.count end + private + + def get_visible_profiles + visible_profiles = profiles.visible.includes( + [:image,:domains,:preferred_domain,:environment] + ) + if !prioritize_profiles_with_image + return visible_profiles.all( + :limit => get_limit, + :order => 'profiles.updated_at DESC' + ).sort_by {rand} + elsif profiles.visible.with_image.count >= get_limit + return visible_profiles.with_image.all( + :limit => get_limit * 5, + :order => 'profiles.updated_at DESC' + ).sort_by {rand} + else + return visible_profiles.with_image.sort_by {rand} + + visible_profiles.without_image.all( + :limit => get_limit * 5, :order => 'profiles.updated_at DESC' + ).sort_by {rand} + end + end + end \ No newline at end of file diff --git a/lib/ext/person.rb b/lib/ext/person.rb index 1ec2681..12510c6 100644 --- a/lib/ext/person.rb +++ b/lib/ext/person.rb @@ -10,37 +10,6 @@ class Person delegate :login, :to => :user, :prefix => true - scope :search, lambda { |name="", state="", city="", email=""| - like_sql = "" - values = [] - - unless name.blank? - like_sql << "name ILIKE ? OR identifier ILIKE ? AND " - values << "%#{name}%" << "%#{name}%" - end - - unless state.blank? - like_sql << "data ILIKE ? AND " - values << "%:state: %#{state}%" - end - - unless city.blank? - like_sql << "data ILIKE ? AND " - values << "%:city: %#{city}%" - end - - unless email.blank? - like_sql << "email ILIKE ? AND " - values << "%#{email}%" - end - like_sql = like_sql[0..like_sql.length-5] - - { - :joins => :user, - :conditions=>[like_sql, *values] - } - } - def institutions institutions = [] unless self.user.institutions.nil? diff --git a/lib/ext/user.rb b/lib/ext/user.rb index 70afd05..173937c 100644 --- a/lib/ext/user.rb +++ b/lib/ext/user.rb @@ -2,6 +2,8 @@ require_dependency 'user' class User + GOV_SUFFIX = /^.*@[gov.br|jus.br|leg.br|mp.br]+$/ + has_and_belongs_to_many :institutions validate :email_different_secondary?, :email_has_already_been_used?, @@ -51,28 +53,38 @@ class User end def email_suffix_is_gov? - test = /^.*@[gov.br|jus.br|leg.br|mp.br]+$/ - primary_email_has_gov_suffix = false - secondary_email_has_gov_suffix = false + check_gov_suffix_in_secondary_email + check_gov_email_have_institution + end - if !self.email.nil? and self.email.length > 0 - primary_email_has_gov_suffix = true if test.match(self.email) - end + private - unless primary_email_has_gov_suffix - if !self.secondary_email.nil? and self.secondary_email.length > 0 - secondary_email_has_gov_suffix = !!test.match(self.secondary_email) - end + def valid_format?(value, string_format) + !value.nil? && value.length > 0 && !string_format.match(value).nil? + end + + def check_gov_suffix_in_secondary_email + unless primary_email_has_gov_suffix? self.errors.add( :base, _("The governamental email must be the primary one.") - ) if secondary_email_has_gov_suffix + ) if secondary_email_has_gov_suffix? end + end + def check_gov_email_have_institution self.errors.add( :base, _("Institution is obligatory if user has a government email.") - ) if primary_email_has_gov_suffix and self.institutions.blank? + ) if primary_email_has_gov_suffix? && self.institutions.blank? + end + + def primary_email_has_gov_suffix? + valid_format?(self.email, GOV_SUFFIX) + end + + def secondary_email_has_gov_suffix? + valid_format?(self.secondary_email, GOV_SUFFIX) end end \ No newline at end of file diff --git a/lib/juridical_nature.rb b/lib/juridical_nature.rb index 11494c1..1bb17f8 100644 --- a/lib/juridical_nature.rb +++ b/lib/juridical_nature.rb @@ -9,7 +9,7 @@ class JuridicalNature < ActiveRecord::Base def public_institutions Institution.where( :type=>"PublicInstitution", - :governmental_power_id=>self.id + :juridical_nature_id=>self.id ) end end diff --git a/lib/mpog_software_plugin.rb b/lib/mpog_software_plugin.rb index 61bc871..b0dabbc 100644 --- a/lib/mpog_software_plugin.rb +++ b/lib/mpog_software_plugin.rb @@ -42,7 +42,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin single_hash_transactions.each do |model,transaction| call_model_transaction(model,transaction) end - + end def profile_editor_controller_filters -- libgit2 0.21.2