Commit 5887d4b74e9ff8493ce3863aaebe9194f0ed2d94

Authored by Fabio Teixeira
Committed by Álvaro Fernando Matos de Souza
1 parent 7b7bb0ac
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

Make only the admin see the additional fields on rate list

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
lib/software_communities_plugin.rb
@@ -85,10 +85,16 @@ class SoftwareCommunitiesPlugin &lt; Noosfero::Plugin @@ -85,10 +85,16 @@ class SoftwareCommunitiesPlugin &lt; Noosfero::Plugin
85 end 85 end
86 86
87 def communities_ratings_plugin_extra_fields_show_data user_rating 87 def communities_ratings_plugin_extra_fields_show_data user_rating
88 - is_admin = environment.admins.include?(current_user.person)  
89 -  
90 - if is_admin and context.profile.software?  
91 - Proc::new { render :file => 'communities_ratings_extra_fields_show_data', :locals => {:user_rating => user_rating} } 88 + if logged_in?
  89 + is_admin = environment.admins.include?(current_user.person)
  90 + is_admin ||= user_rating.community.admins.include?(current_user.person)
  91 +
  92 + if is_admin and context.profile.software?
  93 + Proc::new {
  94 + render :file => 'communities_ratings_extra_fields_show_data',
  95 + :locals => {:user_rating => user_rating}
  96 + }
  97 + end
92 end 98 end
93 end 99 end
94 100
test/functional/profile_controller_test.rb
@@ -8,19 +8,14 @@ require( @@ -8,19 +8,14 @@ require(
8 class ProfileController; def rescue_action(e) raise e end; end 8 class ProfileController; def rescue_action(e) raise e end; end
9 9
10 class ProfileControllerTest < ActionController::TestCase 10 class ProfileControllerTest < ActionController::TestCase
11 -include SoftwareTestHelper 11 + include SoftwareTestHelper
  12 +
12 def setup 13 def setup
13 @controller =CommunitiesRatingsPluginProfileController.new 14 @controller =CommunitiesRatingsPluginProfileController.new
14 @request = ActionController::TestRequest.new 15 @request = ActionController::TestRequest.new
15 @response = ActionController::TestResponse.new 16 @response = ActionController::TestResponse.new
16 @profile = create_user('default_user').person 17 @profile = create_user('default_user').person
17 18
18 - Environment.default.affiliate(  
19 - @profile,  
20 - [Environment::Roles.admin(Environment.default.id)] +  
21 - Profile::Roles.all_roles(Environment.default.id)  
22 - )  
23 -  
24 LicenseInfo.create( 19 LicenseInfo.create(
25 :version=>"CC-GPL-V2", 20 :version=>"CC-GPL-V2",
26 :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt" 21 :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt"
@@ -28,23 +23,23 @@ include SoftwareTestHelper @@ -28,23 +23,23 @@ include SoftwareTestHelper
28 23
29 @environment = Environment.default 24 @environment = Environment.default
30 @environment.enabled_plugins = ['SoftwareCommunitiesPlugin', 'CommunitiesRatingsPlugin'] 25 @environment.enabled_plugins = ['SoftwareCommunitiesPlugin', 'CommunitiesRatingsPlugin']
31 - admin = create_user("adminuser").person  
32 - admin.stubs(:has_permission?).returns("true")  
33 - login_as('adminuser')  
34 - @environment.add_admin(admin) 26 + @admin = create_user("adminuser").person
  27 + @admin.stubs(:has_permission?).returns("true")
  28 + @environment.add_admin(@admin)
35 @environment.save 29 @environment.save
  30 +
  31 + @software = create_software(software_fields)
36 end 32 end
37 33
38 should "dispach additional comment fields when a software is rated" do 34 should "dispach additional comment fields when a software is rated" do
39 - @hash_list = software_fields  
40 - software = create_software(@hash_list)  
41 -  
42 - get :new_rating , profile: software.community.identifier 35 + login_as(@admin.name)
  36 + get :new_rating , profile: @software.community.identifier
43 assert_template :new_rating 37 assert_template :new_rating
44 assert_match(/Additional informations/, @response.body) 38 assert_match(/Additional informations/, @response.body)
45 end 39 end
46 40
47 should "DO NOT dispach additional comment fields when the rated community isn't a software" do 41 should "DO NOT dispach additional comment fields when the rated community isn't a software" do
  42 + login_as(@admin.name)
48 community = fast_create(Community) 43 community = fast_create(Community)
49 44
50 get :new_rating , profile: community.identifier 45 get :new_rating , profile: community.identifier
@@ -52,4 +47,50 @@ include SoftwareTestHelper @@ -52,4 +47,50 @@ include SoftwareTestHelper
52 assert_not_match(/Additional informations/, @response.body) 47 assert_not_match(/Additional informations/, @response.body)
53 end 48 end
54 49
  50 + should "show additional comment fields on rate list if logged user is a environment admin" do
  51 + login_as(@admin.name)
  52 + seed_avaliations
  53 +
  54 + get :new_rating , profile: @software.community.identifier
  55 +
  56 + assert_match("<span>People benefited :</span> 123", @response.body)
  57 + assert_match("<span>Saved Value :</span> 123456.0", @response.body)
  58 + end
  59 +
  60 + should "show additional comment fields on rate list if logged user is the software admin" do
  61 + seed_avaliations
  62 + login_as(@profile.name)
  63 + @software.community.add_admin @profile
  64 +
  65 + get :new_rating , profile: @software.community.identifier
  66 +
  67 + assert_match("<span>People benefited :</span> 123", @response.body)
  68 + assert_match("<span>Saved Value :</span> 123456.0", @response.body)
  69 + end
  70 +
  71 + should "DO NOT show additional comment fields on rate list if logged user in't a admin" do
  72 + login_as(@profile.name)
  73 + seed_avaliations
  74 +
  75 + get :new_rating , profile: @software.community.identifier
  76 +
  77 + assert_not_match("<span>People benefited :</span> 123", @response.body)
  78 + assert_not_match("<span>Saved Value :</span> 123456.0", @response.body)
  79 + end
  80 +
  81 + private
  82 +
  83 + def make_avaliation software, person, rate_value, people_benefited, saved_value
  84 + comment = Comment.create! :author=>person, :body=>"simple body", :people_benefited=>people_benefited, :saved_value=>saved_value
  85 + rate = CommunityRating.new :value=>rate_value, :person=>person, :community=>software.community
  86 +
  87 + rate.comment = comment
  88 + rate.save!
  89 + rate
  90 + end
  91 +
  92 + def seed_avaliations
  93 + make_avaliation @software, @profile, 1, 123, 123456
  94 + make_avaliation @software, @admin, 2, 456, 789456
  95 + end
55 end 96 end
56 \ No newline at end of file 97 \ No newline at end of file