Commit 5d45f66269eb8cef9fd058f6a80bd8af51e7d9dd

Authored by Joenio Costa
2 parents 861182f0 0c447053

Merge branch 'task_after_cancel' into 'master'

Organization_ratings: Show rejected message to admins

Show rejected message to admins on organization_ratings plugin. Only environment admins can see the rejected message.

Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com>
Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com>

See merge request !969
plugins/organization_ratings/lib/create_organization_rating_comment.rb
... ... @@ -14,6 +14,12 @@ class CreateOrganizationRatingComment &lt; Task
14 14 settings_items field.to_sym
15 15 end
16 16  
  17 + scope :with_rating, -> (user_rating){
  18 + CreateOrganizationRatingComment.find_each do |task|
  19 + return task if(task.organization_rating_id == user_rating.id)
  20 + end
  21 + }
  22 +
17 23 def perform
18 24 if (self.body && !self.body.blank?)
19 25 comment = Comment.create!(:source => self.target, :body => self.body, :author => self.requestor)
... ...
plugins/organization_ratings/test/functional/organization_ratings_plugin_profile_controller_test.rb
... ... @@ -148,6 +148,39 @@ class OrganizationRatingsPluginProfileControllerTest &lt; ActionController::TestCas
148 148  
149 149 get :new_rating, profile: @community.identifier
150 150 assert_tag :tag => 'p', :content => /Report waiting for approval/, :attributes => {:class =>/moderation-msg/}
  151 + assert_tag :tag => 'p', :attributes => {:class =>/comment-body/}
  152 + end
  153 +
  154 + test "display rejected comment to env admin" do
  155 + post :new_rating, profile: @community.identifier, :comments => {:body => "rejected comment"}, :organization_rating_value => 3
  156 +
  157 + @admin = create_admin_user(@environment)
  158 + login_as @admin
  159 + @controller.stubs(:current_user).returns(Profile[@admin].user)
  160 +
  161 + CreateOrganizationRatingComment.last.cancel
  162 +
  163 + get :new_rating, profile: @community.identifier
  164 + assert_tag :tag => 'p', :attributes => {:class =>/comment-body/}, :content => /rejected comment/
  165 + end
  166 +
  167 + test "not display rejected comment to regular user" do
  168 + p1 = create_user('regularUser').person
  169 + @community.add_member p1
  170 + login_as(p1.identifier)
  171 + @controller.stubs(:logged_in?).returns(true)
  172 + @controller.stubs(:current_user).returns(p1.user)
  173 +
  174 + post :new_rating, profile: @community.identifier, :comments => {:body => "rejected comment"}, :organization_rating_value => 3
  175 + CreateOrganizationRatingComment.last.cancel
  176 + get :new_rating, profile: @community.identifier
  177 + assert_no_tag :tag => 'p', :attributes => {:class =>/comment-body/}
  178 + end
  179 +
  180 + test "not display rejected comment to community admin" do
  181 + post :new_rating, profile: @community.identifier, :comments => {:body => "rejected comment"}, :organization_rating_value => 3
  182 + CreateOrganizationRatingComment.last.cancel
  183 + get :new_rating, profile: @community.identifier
151 184 assert_no_tag :tag => 'p', :attributes => {:class =>/comment-body/}
152 185 end
153 186  
... ...
plugins/organization_ratings/views/shared/_user_rating_container.html.erb
... ... @@ -29,6 +29,9 @@
29 29 <%= status_message_for(user, user_rate) %>
30 30 <% if user_rate.comment.present? %>
31 31 <p class="comment-body"> <%= user_rate.comment.body %> </p>
  32 + <% elsif user && user.is_admin? %>
  33 + <% rating_task = CreateOrganizationRatingComment.with_rating(user_rate) %>
  34 + <p class="comment-body"> <%= rating_task.body %> </p>
32 35 <% end %>
33 36 </div>
34 37 <%= @plugins.dispatch(:organization_ratings_plugin_container_extra_fields, user_rate).collect { |content| instance_exec(&content) }.join("") %>
... ...