diff --git a/src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb b/src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb index 8d97824..cda91d5 100644 --- a/src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb +++ b/src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb @@ -111,7 +111,7 @@ class GovUserPluginController < ApplicationController params[:community] ||= {} params[:institutions] ||= {} - @show_sisp_field = environment.admins.include?(current_user.person) + @show_sisp_field = user.is_admin? @governmental_sphere = get_governmental_spheres() @governmental_power = get_governmental_powers() @juridical_nature = get_juridical_natures() @@ -209,7 +209,7 @@ class GovUserPluginController < ApplicationController def add_environment_admins_to_institution institution edit_page = params[:edit_institution_page] == false - if environment.admins.include?(current_user.person) && edit_page + if user.is_admin? && edit_page environment.admins.each do |adm| institution.community.add_admin(adm) end diff --git a/src/noosfero-spb/gov_user/controllers/gov_user_plugin_myprofile_controller.rb b/src/noosfero-spb/gov_user/controllers/gov_user_plugin_myprofile_controller.rb index 6b4d03e..1571c77 100644 --- a/src/noosfero-spb/gov_user/controllers/gov_user_plugin_myprofile_controller.rb +++ b/src/noosfero-spb/gov_user/controllers/gov_user_plugin_myprofile_controller.rb @@ -5,7 +5,7 @@ class GovUserPluginMyprofileController < MyProfileController end def edit_institution - @show_sisp_field = environment.admins.include?(current_user.person) + @show_sisp_field = user.is_admin? @state_list = NationalRegion.find( :all, :conditions => { :national_region_type_id => 2 }, diff --git a/src/noosfero-spb/gov_user/features/rate_community.feature b/src/noosfero-spb/gov_user/features/rate_community.feature new file mode 100644 index 0000000..d5d3d87 --- /dev/null +++ b/src/noosfero-spb/gov_user/features/rate_community.feature @@ -0,0 +1,61 @@ +Feature: rate_community + As an admin + I want to see a warning in the task if a software already has a rating related to an specific institution + So it will be clear when the saved value will be updated + + Background: + Given the environment domain is "localhost" + And "OrganizationRatings" plugin is enabled + And "SoftwareCommunities" plugin is enabled + And "GovUser" plugin is enabled + And I am logged in as mpog_admin + And I go to /admin/plugins + And I check "Organization Ratings" + And I check "GovUserPlugin" + And I check "SoftwareCommunitiesPlugin" + And I press "Save changes" + And the following user + | login | name | + | joaosilva | Joao Silva | + And the following softwares + | name | public_software | finality | + | mycommunity | true | basic software finality | + | anothercommunity | true | basic software finality | + And the following blocks + | owner | type | + | mycommunity | OrganizationRatingsBlock | + And Institutions has initial default values on database + And the following public institutions + | name | acronym | country | state | city | cnpj | juridical_nature | governmental_power | governmental_sphere | corporate_name | + | Ministerio das Cidades | MC | BR | DF | Gama | 58.745.189/0001-21 | Autarquia | Executivo | Federal | Ministerio das Cidades | + | Ministerio do Planejamento | MP | BR | DF | Brasilia | 41.769.591/0001-43 | Autarquia | Judiciario | Federal | Ministerio do Planejamento | + + Scenario: display message on task when a rating with the same institution exists on the same software + Given the following organization ratings + | value | organization_name | user_login | institution_name | task_status | + | 5 | mycommunity | joaosilva | Ministerio das Cidades | 3 | + | 4 | mycommunity | joaosilva | Ministerio das Cidades | 1 | + And I go to mycommunity's control panel + And I follow "Process requests" within ".pending-tasks" + And I choose "Accept" within ".task_decisions" + Then I should see "This instiution already has an accepted rating" in the page + + Scenario: do not display message on task when a rating with the same institution does not exist on the same software + Given the following organization ratings + | value | organization_name | user_login | institution_name | task_status | + | 5 | mycommunity | joaosilva | Ministerio das Cidades | 3 | + | 4 | mycommunity | joaosilva | Ministerio do Planejamento | 1 | + And I go to mycommunity's control panel + And I follow "Process requests" within ".pending-tasks" + And I choose "Accept" within ".task_decisions" + Then I should not see "This instiution already has an accepted rating" within ".task_box" + + Scenario: do not display message on task when a rating with the same institution exist on different softwares + Given the following organization ratings + | value | organization_name | user_login | institution_name | task_status | + | 5 | mycommunity | joaosilva | Ministerio das Cidades | 3 | + | 4 | anothercommunity | joaosilva | Ministerio das Cidades | 1 | + And I go to anothercommunity's control panel + And I follow "Process requests" within ".pending-tasks" + And I choose "Accept" within ".task_decisions" + Then I should not see "This instiution already has an accepted rating" within ".task_box" diff --git a/src/noosfero-spb/gov_user/lib/gov_user_plugin.rb b/src/noosfero-spb/gov_user/lib/gov_user_plugin.rb index 7af0be3..25b2006 100644 --- a/src/noosfero-spb/gov_user/lib/gov_user_plugin.rb +++ b/src/noosfero-spb/gov_user/lib/gov_user_plugin.rb @@ -54,9 +54,7 @@ class GovUserPlugin < Noosfero::Plugin def profile_editor_controller_filters block = proc do if request.post? && params[:institution] - is_admin = environment.admins.include?(current_user.person) - - unless is_admin + unless user.is_admin? institution = profile.user.institutions if !params[:institution].blank? && params[:institution].class == Hash && !params[:institution][:sisp].nil? @@ -241,16 +239,30 @@ class GovUserPlugin < Noosfero::Plugin Proc::new do render :file => 'ratings_extra_field' end end - def organization_ratings_plugin_extra_fields_show_data user_rating + def organization_ratings_plugin_task_extra_fields user_rating + gov_user_self = self + + Proc::new { + if logged_in? + is_admin = user.is_admin? || user_rating.organization.is_admin?(user) + + if is_admin and gov_user_self.context.profile.software? + render :file => 'organization_ratings_task_extra_fields_show_institution', + :locals => {:user_rating => user_rating} + end + end + } + end + + def organization_ratings_plugin_container_extra_fields user_rating gov_user_self = self Proc::new { if logged_in? - is_admin = environment.admins.include?(current_user.person) - is_admin ||= user_rating.organization.admins.include?(current_user.person) + is_admin = user.is_admin? || user_rating.organization.is_admin?(user) if is_admin and gov_user_self.context.profile.software? - render :file => 'organization_ratings_extra_fields_show_institution', + render :file => 'organization_ratings_container_extra_fields_show_institution', :locals => {:user_rating => user_rating} end end diff --git a/src/noosfero-spb/gov_user/lib/institution.rb b/src/noosfero-spb/gov_user/lib/institution.rb index ee5e870..1f5df5c 100644 --- a/src/noosfero-spb/gov_user/lib/institution.rb +++ b/src/noosfero-spb/gov_user/lib/institution.rb @@ -36,6 +36,14 @@ class Institution < ActiveRecord::Base :verify_institution_type, :validate_format_cnpj + def has_accepted_rating? user_rating + rating_ids = OrganizationRating.where(institution_id: self.id, organization_id: user_rating.organization_id).map(&:id) + finished_tasks = CreateOrganizationRatingComment.finished.select {|task| rating_ids.include?(task.organization_rating_id)} + pending_tasks = CreateOrganizationRatingComment.pending.select{|c| c.organization_rating_id == user_rating.id} + + !finished_tasks.empty? && !pending_tasks.empty? + end + protected def verify_institution_type diff --git a/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_controller_test.rb b/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_controller_test.rb index 48b4fc4..0829b08 100644 --- a/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_controller_test.rb +++ b/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_controller_test.rb @@ -230,7 +230,7 @@ class GovUserPluginControllerTest < ActionController::TestCase fields[:edit_institution_page] = false post :new_institution, fields - assert(Institution.last.community.admins.include?(admin2) ) + assert(Institution.last.community.is_admin?(admin2) ) end end diff --git a/src/noosfero-spb/gov_user/test/functional/profile_editor_controller_test.rb b/src/noosfero-spb/gov_user/test/functional/profile_editor_controller_test.rb index 52de533..5241483 100644 --- a/src/noosfero-spb/gov_user/test/functional/profile_editor_controller_test.rb +++ b/src/noosfero-spb/gov_user/test/functional/profile_editor_controller_test.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../../../test/test_helper' +require 'test_helper' require File.dirname(__FILE__) + '/../helpers/institution_test_helper' require( File.dirname(__FILE__) + diff --git a/src/noosfero-spb/gov_user/views/organization_ratings_container_extra_fields_show_institution.html.erb b/src/noosfero-spb/gov_user/views/organization_ratings_container_extra_fields_show_institution.html.erb new file mode 100644 index 0000000..b11c44c --- /dev/null +++ b/src/noosfero-spb/gov_user/views/organization_ratings_container_extra_fields_show_institution.html.erb @@ -0,0 +1,7 @@ +<% if user_rating.institution %> +