Commit 5887d4b74e9ff8493ce3863aaebe9194f0ed2d94
Committed by
Álvaro Fernando Matos de Souza
1 parent
7b7bb0ac
Exists in
master
and in
5 other branches
Make only the admin see the additional fields on rate list
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
2 changed files
with
66 additions
and
19 deletions
Show diff stats
lib/software_communities_plugin.rb
@@ -85,10 +85,16 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin | @@ -85,10 +85,16 @@ class SoftwareCommunitiesPlugin < 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 |