Commit 8c0ed2dbb38c5865475d1063bae1720d20595de8
Committed by
Thiago Ribeiro
1 parent
e42535bd
Exists in
master
and in
52 other branches
Gov User plugin rating improvements
- Adds message to warn that a rating has an institution with active ratings - Adds one hotspot to insert content on ratings task and another one to ratings container (used on ratings page and ratings block) - Adds number_to_human method to get better visualization for numbers - Makes the software tasks page closer to the prototype (changes in the divs, sizes and aligns). Signed-off-by: Dylan Guedes <djmgguedes@gmail.com> Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com> Signed-off-by: Gustavo Coelho <gust.rod.coelho@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com> Signed-off-by: Pedro de Lyra <pedrodelyra@gmail.com> Signed-off-by: Tallys Martins <tallysmartins@gmail.com> Signed-off-by: Thiago Ribeiro <thiagitosouza@gmail.com> (cherry picked from commit 15a66159b6989ce6eb154fd9deed7160b9b8af12)
Showing
10 changed files
with
113 additions
and
20 deletions
Show diff stats
src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb
@@ -111,7 +111,7 @@ class GovUserPluginController < ApplicationController | @@ -111,7 +111,7 @@ class GovUserPluginController < ApplicationController | ||
111 | params[:community] ||= {} | 111 | params[:community] ||= {} |
112 | params[:institutions] ||= {} | 112 | params[:institutions] ||= {} |
113 | 113 | ||
114 | - @show_sisp_field = environment.admins.include?(current_user.person) | 114 | + @show_sisp_field = user.is_admin? |
115 | @governmental_sphere = get_governmental_spheres() | 115 | @governmental_sphere = get_governmental_spheres() |
116 | @governmental_power = get_governmental_powers() | 116 | @governmental_power = get_governmental_powers() |
117 | @juridical_nature = get_juridical_natures() | 117 | @juridical_nature = get_juridical_natures() |
@@ -209,7 +209,7 @@ class GovUserPluginController < ApplicationController | @@ -209,7 +209,7 @@ class GovUserPluginController < ApplicationController | ||
209 | 209 | ||
210 | def add_environment_admins_to_institution institution | 210 | def add_environment_admins_to_institution institution |
211 | edit_page = params[:edit_institution_page] == false | 211 | edit_page = params[:edit_institution_page] == false |
212 | - if environment.admins.include?(current_user.person) && edit_page | 212 | + if user.is_admin? && edit_page |
213 | environment.admins.each do |adm| | 213 | environment.admins.each do |adm| |
214 | institution.community.add_admin(adm) | 214 | institution.community.add_admin(adm) |
215 | end | 215 | end |
src/noosfero-spb/gov_user/controllers/gov_user_plugin_myprofile_controller.rb
@@ -5,7 +5,7 @@ class GovUserPluginMyprofileController < MyProfileController | @@ -5,7 +5,7 @@ class GovUserPluginMyprofileController < MyProfileController | ||
5 | end | 5 | end |
6 | 6 | ||
7 | def edit_institution | 7 | def edit_institution |
8 | - @show_sisp_field = environment.admins.include?(current_user.person) | 8 | + @show_sisp_field = user.is_admin? |
9 | @state_list = NationalRegion.find( | 9 | @state_list = NationalRegion.find( |
10 | :all, | 10 | :all, |
11 | :conditions => { :national_region_type_id => 2 }, | 11 | :conditions => { :national_region_type_id => 2 }, |
src/noosfero-spb/gov_user/features/rate_community.feature
0 → 100644
@@ -0,0 +1,61 @@ | @@ -0,0 +1,61 @@ | ||
1 | +Feature: rate_community | ||
2 | + As an admin | ||
3 | + I want to see a warning in the task if a software already has a rating related to an specific institution | ||
4 | + So it will be clear when the saved value will be updated | ||
5 | + | ||
6 | + Background: | ||
7 | + Given the environment domain is "localhost" | ||
8 | + And "OrganizationRatings" plugin is enabled | ||
9 | + And "SoftwareCommunities" plugin is enabled | ||
10 | + And "GovUser" plugin is enabled | ||
11 | + And I am logged in as mpog_admin | ||
12 | + And I go to /admin/plugins | ||
13 | + And I check "Organization Ratings" | ||
14 | + And I check "GovUserPlugin" | ||
15 | + And I check "SoftwareCommunitiesPlugin" | ||
16 | + And I press "Save changes" | ||
17 | + And the following user | ||
18 | + | login | name | | ||
19 | + | joaosilva | Joao Silva | | ||
20 | + And the following softwares | ||
21 | + | name | public_software | finality | | ||
22 | + | mycommunity | true | basic software finality | | ||
23 | + | anothercommunity | true | basic software finality | | ||
24 | + And the following blocks | ||
25 | + | owner | type | | ||
26 | + | mycommunity | OrganizationRatingsBlock | | ||
27 | + And Institutions has initial default values on database | ||
28 | + And the following public institutions | ||
29 | + | name | acronym | country | state | city | cnpj | juridical_nature | governmental_power | governmental_sphere | corporate_name | | ||
30 | + | Ministerio das Cidades | MC | BR | DF | Gama | 58.745.189/0001-21 | Autarquia | Executivo | Federal | Ministerio das Cidades | | ||
31 | + | Ministerio do Planejamento | MP | BR | DF | Brasilia | 41.769.591/0001-43 | Autarquia | Judiciario | Federal | Ministerio do Planejamento | | ||
32 | + | ||
33 | + Scenario: display message on task when a rating with the same institution exists on the same software | ||
34 | + Given the following organization ratings | ||
35 | + | value | organization_name | user_login | institution_name | task_status | | ||
36 | + | 5 | mycommunity | joaosilva | Ministerio das Cidades | 3 | | ||
37 | + | 4 | mycommunity | joaosilva | Ministerio das Cidades | 1 | | ||
38 | + And I go to mycommunity's control panel | ||
39 | + And I follow "Process requests" within ".pending-tasks" | ||
40 | + And I choose "Accept" within ".task_decisions" | ||
41 | + Then I should see "This instiution already has an accepted rating" in the page | ||
42 | + | ||
43 | + Scenario: do not display message on task when a rating with the same institution does not exist on the same software | ||
44 | + Given the following organization ratings | ||
45 | + | value | organization_name | user_login | institution_name | task_status | | ||
46 | + | 5 | mycommunity | joaosilva | Ministerio das Cidades | 3 | | ||
47 | + | 4 | mycommunity | joaosilva | Ministerio do Planejamento | 1 | | ||
48 | + And I go to mycommunity's control panel | ||
49 | + And I follow "Process requests" within ".pending-tasks" | ||
50 | + And I choose "Accept" within ".task_decisions" | ||
51 | + Then I should not see "This instiution already has an accepted rating" within ".task_box" | ||
52 | + | ||
53 | + Scenario: do not display message on task when a rating with the same institution exist on different softwares | ||
54 | + Given the following organization ratings | ||
55 | + | value | organization_name | user_login | institution_name | task_status | | ||
56 | + | 5 | mycommunity | joaosilva | Ministerio das Cidades | 3 | | ||
57 | + | 4 | anothercommunity | joaosilva | Ministerio das Cidades | 1 | | ||
58 | + And I go to anothercommunity's control panel | ||
59 | + And I follow "Process requests" within ".pending-tasks" | ||
60 | + And I choose "Accept" within ".task_decisions" | ||
61 | + Then I should not see "This instiution already has an accepted rating" within ".task_box" |
src/noosfero-spb/gov_user/lib/gov_user_plugin.rb
@@ -54,9 +54,7 @@ class GovUserPlugin < Noosfero::Plugin | @@ -54,9 +54,7 @@ class GovUserPlugin < Noosfero::Plugin | ||
54 | def profile_editor_controller_filters | 54 | def profile_editor_controller_filters |
55 | block = proc do | 55 | block = proc do |
56 | if request.post? && params[:institution] | 56 | if request.post? && params[:institution] |
57 | - is_admin = environment.admins.include?(current_user.person) | ||
58 | - | ||
59 | - unless is_admin | 57 | + unless user.is_admin? |
60 | institution = profile.user.institutions | 58 | institution = profile.user.institutions |
61 | 59 | ||
62 | if !params[:institution].blank? && params[:institution].class == Hash && !params[:institution][:sisp].nil? | 60 | if !params[:institution].blank? && params[:institution].class == Hash && !params[:institution][:sisp].nil? |
@@ -241,16 +239,30 @@ class GovUserPlugin < Noosfero::Plugin | @@ -241,16 +239,30 @@ class GovUserPlugin < Noosfero::Plugin | ||
241 | Proc::new do render :file => 'ratings_extra_field' end | 239 | Proc::new do render :file => 'ratings_extra_field' end |
242 | end | 240 | end |
243 | 241 | ||
244 | - def organization_ratings_plugin_extra_fields_show_data user_rating | 242 | + def organization_ratings_plugin_task_extra_fields user_rating |
243 | + gov_user_self = self | ||
244 | + | ||
245 | + Proc::new { | ||
246 | + if logged_in? | ||
247 | + is_admin = user.is_admin? || user_rating.organization.is_admin?(user) | ||
248 | + | ||
249 | + if is_admin and gov_user_self.context.profile.software? | ||
250 | + render :file => 'organization_ratings_task_extra_fields_show_institution', | ||
251 | + :locals => {:user_rating => user_rating} | ||
252 | + end | ||
253 | + end | ||
254 | + } | ||
255 | + end | ||
256 | + | ||
257 | + def organization_ratings_plugin_container_extra_fields user_rating | ||
245 | gov_user_self = self | 258 | gov_user_self = self |
246 | 259 | ||
247 | Proc::new { | 260 | Proc::new { |
248 | if logged_in? | 261 | if logged_in? |
249 | - is_admin = environment.admins.include?(current_user.person) | ||
250 | - is_admin ||= user_rating.organization.admins.include?(current_user.person) | 262 | + is_admin = user.is_admin? || user_rating.organization.is_admin?(user) |
251 | 263 | ||
252 | if is_admin and gov_user_self.context.profile.software? | 264 | if is_admin and gov_user_self.context.profile.software? |
253 | - render :file => 'organization_ratings_extra_fields_show_institution', | 265 | + render :file => 'organization_ratings_container_extra_fields_show_institution', |
254 | :locals => {:user_rating => user_rating} | 266 | :locals => {:user_rating => user_rating} |
255 | end | 267 | end |
256 | end | 268 | end |
src/noosfero-spb/gov_user/lib/institution.rb
@@ -36,6 +36,14 @@ class Institution < ActiveRecord::Base | @@ -36,6 +36,14 @@ class Institution < ActiveRecord::Base | ||
36 | :verify_institution_type, :validate_format_cnpj | 36 | :verify_institution_type, :validate_format_cnpj |
37 | 37 | ||
38 | 38 | ||
39 | + def has_accepted_rating? user_rating | ||
40 | + rating_ids = OrganizationRating.where(institution_id: self.id, organization_id: user_rating.organization_id).map(&:id) | ||
41 | + finished_tasks = CreateOrganizationRatingComment.finished.select {|task| rating_ids.include?(task.organization_rating_id)} | ||
42 | + pending_tasks = CreateOrganizationRatingComment.pending.select{|c| c.organization_rating_id == user_rating.id} | ||
43 | + | ||
44 | + !finished_tasks.empty? && !pending_tasks.empty? | ||
45 | + end | ||
46 | + | ||
39 | protected | 47 | protected |
40 | 48 | ||
41 | def verify_institution_type | 49 | def verify_institution_type |
src/noosfero-spb/gov_user/test/functional/gov_user_plugin_controller_test.rb
@@ -230,7 +230,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | @@ -230,7 +230,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | ||
230 | fields[:edit_institution_page] = false | 230 | fields[:edit_institution_page] = false |
231 | post :new_institution, fields | 231 | post :new_institution, fields |
232 | 232 | ||
233 | - assert(Institution.last.community.admins.include?(admin2) ) | 233 | + assert(Institution.last.community.is_admin?(admin2) ) |
234 | end | 234 | end |
235 | 235 | ||
236 | end | 236 | end |
src/noosfero-spb/gov_user/test/functional/profile_editor_controller_test.rb
1 | -require File.dirname(__FILE__) + '/../../../../test/test_helper' | 1 | +require 'test_helper' |
2 | require File.dirname(__FILE__) + '/../helpers/institution_test_helper' | 2 | require File.dirname(__FILE__) + '/../helpers/institution_test_helper' |
3 | require( | 3 | require( |
4 | File.dirname(__FILE__) + | 4 | File.dirname(__FILE__) + |
src/noosfero-spb/gov_user/views/organization_ratings_container_extra_fields_show_institution.html.erb
0 → 100644
src/noosfero-spb/gov_user/views/organization_ratings_extra_fields_show_institution.html.erb
@@ -1,8 +0,0 @@ | @@ -1,8 +0,0 @@ | ||
1 | -<% if user_rating.institution %> | ||
2 | -<div class="aditional-informations"> | ||
3 | - <div class="comments-user-institution"> | ||
4 | - <span><%=_("Institution")%> :<span> <%= user_rating.institution.name unless user_rating.institution.nil? %> | ||
5 | - </div> | ||
6 | -</div> | ||
7 | -<% end %> | ||
8 | - |
src/noosfero-spb/gov_user/views/organization_ratings_task_extra_fields_show_institution.html.erb
0 → 100644
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +<% if user_rating.institution %> | ||
2 | +<div class="aditional-informations"> | ||
3 | + <div class="comments-user-institution"> | ||
4 | + <span><%=_("Institution")%> :</span> <%= user_rating.institution.name %> | ||
5 | + </div> | ||
6 | + | ||
7 | + <% if user_rating.institution.has_accepted_rating?(user_rating) %> | ||
8 | + <div class=""> | ||
9 | + <span><%=_("This instiution already has an accepted rating. Accepting it will automatically update the saved value.") %></span> | ||
10 | + </div> | ||
11 | + <% end %> | ||
12 | +</div> | ||
13 | +<% end %> |