From 5887d4b74e9ff8493ce3863aaebe9194f0ed2d94 Mon Sep 17 00:00:00 2001 From: Fabio Teixeira Date: Tue, 28 Jul 2015 16:38:38 -0300 Subject: [PATCH] Make only the admin see the additional fields on rate list --- lib/software_communities_plugin.rb | 14 ++++++++++---- test/functional/profile_controller_test.rb | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 66 insertions(+), 19 deletions(-) diff --git a/lib/software_communities_plugin.rb b/lib/software_communities_plugin.rb index 3266906..0c95372 100644 --- a/lib/software_communities_plugin.rb +++ b/lib/software_communities_plugin.rb @@ -85,10 +85,16 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin end def communities_ratings_plugin_extra_fields_show_data user_rating - is_admin = environment.admins.include?(current_user.person) - - if is_admin and context.profile.software? - Proc::new { render :file => 'communities_ratings_extra_fields_show_data', :locals => {:user_rating => user_rating} } + if logged_in? + is_admin = environment.admins.include?(current_user.person) + is_admin ||= user_rating.community.admins.include?(current_user.person) + + if is_admin and context.profile.software? + Proc::new { + render :file => 'communities_ratings_extra_fields_show_data', + :locals => {:user_rating => user_rating} + } + end end end diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index 92ad116..b315851 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -8,19 +8,14 @@ require( class ProfileController; def rescue_action(e) raise e end; end class ProfileControllerTest < ActionController::TestCase -include SoftwareTestHelper + include SoftwareTestHelper + def setup @controller =CommunitiesRatingsPluginProfileController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new @profile = create_user('default_user').person - Environment.default.affiliate( - @profile, - [Environment::Roles.admin(Environment.default.id)] + - Profile::Roles.all_roles(Environment.default.id) - ) - LicenseInfo.create( :version=>"CC-GPL-V2", :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt" @@ -28,23 +23,23 @@ include SoftwareTestHelper @environment = Environment.default @environment.enabled_plugins = ['SoftwareCommunitiesPlugin', 'CommunitiesRatingsPlugin'] - admin = create_user("adminuser").person - admin.stubs(:has_permission?).returns("true") - login_as('adminuser') - @environment.add_admin(admin) + @admin = create_user("adminuser").person + @admin.stubs(:has_permission?).returns("true") + @environment.add_admin(@admin) @environment.save + + @software = create_software(software_fields) end should "dispach additional comment fields when a software is rated" do - @hash_list = software_fields - software = create_software(@hash_list) - - get :new_rating , profile: software.community.identifier + login_as(@admin.name) + get :new_rating , profile: @software.community.identifier assert_template :new_rating assert_match(/Additional informations/, @response.body) end should "DO NOT dispach additional comment fields when the rated community isn't a software" do + login_as(@admin.name) community = fast_create(Community) get :new_rating , profile: community.identifier @@ -52,4 +47,50 @@ include SoftwareTestHelper assert_not_match(/Additional informations/, @response.body) end + should "show additional comment fields on rate list if logged user is a environment admin" do + login_as(@admin.name) + seed_avaliations + + get :new_rating , profile: @software.community.identifier + + assert_match("People benefited : 123", @response.body) + assert_match("Saved Value : 123456.0", @response.body) + end + + should "show additional comment fields on rate list if logged user is the software admin" do + seed_avaliations + login_as(@profile.name) + @software.community.add_admin @profile + + get :new_rating , profile: @software.community.identifier + + assert_match("People benefited : 123", @response.body) + assert_match("Saved Value : 123456.0", @response.body) + end + + should "DO NOT show additional comment fields on rate list if logged user in't a admin" do + login_as(@profile.name) + seed_avaliations + + get :new_rating , profile: @software.community.identifier + + assert_not_match("People benefited : 123", @response.body) + assert_not_match("Saved Value : 123456.0", @response.body) + end + + private + + def make_avaliation software, person, rate_value, people_benefited, saved_value + comment = Comment.create! :author=>person, :body=>"simple body", :people_benefited=>people_benefited, :saved_value=>saved_value + rate = CommunityRating.new :value=>rate_value, :person=>person, :community=>software.community + + rate.comment = comment + rate.save! + rate + end + + def seed_avaliations + make_avaliation @software, @profile, 1, 123, 123456 + make_avaliation @software, @admin, 2, 456, 789456 + end end \ No newline at end of file -- libgit2 0.21.2