[Git][noosfero/noosfero][master] 2 commits: Organization ratings: show rejected msg to admin

Joenio Costa gitlab at mg.gitlab.com
Thu Jul 14 16:10:29 BRT 2016


Joenio Costa pushed to branch master at Noosfero / noosfero


Commits:
0c447053 by Marcos Ronaldo at 2016-07-05T14:30:26-03:00
Organization ratings: show rejected msg to admin

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

- - - - -
5d45f662 by Joenio Costa at 2016-07-14T19:10:19+00:00
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 at gmail.com>
Signed-off-by: Marcos Ronaldo <marcos.rpj2 at gmail.com>

See merge request !969
- - - - -


3 changed files:

- plugins/organization_ratings/lib/create_organization_rating_comment.rb
- plugins/organization_ratings/test/functional/organization_ratings_plugin_profile_controller_test.rb
- plugins/organization_ratings/views/shared/_user_rating_container.html.erb


Changes:

=====================================
plugins/organization_ratings/lib/create_organization_rating_comment.rb
=====================================
--- a/plugins/organization_ratings/lib/create_organization_rating_comment.rb
+++ b/plugins/organization_ratings/lib/create_organization_rating_comment.rb
@@ -14,6 +14,12 @@ class CreateOrganizationRatingComment < Task
     settings_items field.to_sym
   end
 
+  scope :with_rating, -> (user_rating){
+    CreateOrganizationRatingComment.find_each do |task|
+      return task if(task.organization_rating_id == user_rating.id)
+    end
+  }
+
   def perform
     if (self.body && !self.body.blank?)
       comment = Comment.create!(:source => self.target, :body => self.body, :author => self.requestor)


=====================================
plugins/organization_ratings/test/functional/organization_ratings_plugin_profile_controller_test.rb
=====================================
--- a/plugins/organization_ratings/test/functional/organization_ratings_plugin_profile_controller_test.rb
+++ b/plugins/organization_ratings/test/functional/organization_ratings_plugin_profile_controller_test.rb
@@ -148,6 +148,39 @@ class OrganizationRatingsPluginProfileControllerTest < ActionController::TestCas
 
     get :new_rating, profile: @community.identifier
     assert_tag :tag => 'p', :content => /Report waiting for approval/, :attributes => {:class =>/moderation-msg/}
+    assert_tag :tag => 'p', :attributes => {:class =>/comment-body/}
+  end
+
+  test "display rejected comment to env admin" do
+    post :new_rating, profile: @community.identifier, :comments => {:body => "rejected comment"}, :organization_rating_value => 3
+
+    @admin = create_admin_user(@environment)
+    login_as @admin
+    @controller.stubs(:current_user).returns(Profile[@admin].user)
+
+    CreateOrganizationRatingComment.last.cancel
+
+    get :new_rating, profile: @community.identifier
+    assert_tag :tag => 'p', :attributes => {:class =>/comment-body/}, :content => /rejected comment/
+  end
+
+  test "not display rejected comment to regular user" do
+    p1 = create_user('regularUser').person
+    @community.add_member p1
+    login_as(p1.identifier)
+    @controller.stubs(:logged_in?).returns(true)
+    @controller.stubs(:current_user).returns(p1.user)
+
+    post :new_rating, profile: @community.identifier, :comments => {:body => "rejected comment"}, :organization_rating_value => 3
+    CreateOrganizationRatingComment.last.cancel
+    get :new_rating, profile: @community.identifier
+    assert_no_tag :tag => 'p', :attributes => {:class =>/comment-body/}
+  end
+
+  test "not display rejected comment to community admin" do
+    post :new_rating, profile: @community.identifier, :comments => {:body => "rejected comment"}, :organization_rating_value => 3
+    CreateOrganizationRatingComment.last.cancel
+    get :new_rating, profile: @community.identifier
     assert_no_tag :tag => 'p', :attributes => {:class =>/comment-body/}
   end
 


=====================================
plugins/organization_ratings/views/shared/_user_rating_container.html.erb
=====================================
--- a/plugins/organization_ratings/views/shared/_user_rating_container.html.erb
+++ b/plugins/organization_ratings/views/shared/_user_rating_container.html.erb
@@ -29,6 +29,9 @@
       <%= status_message_for(user, user_rate) %>
       <% if user_rate.comment.present? %>
         <p class="comment-body"> <%= user_rate.comment.body %> </p>
+      <% elsif user && user.is_admin? %>
+        <% rating_task = CreateOrganizationRatingComment.with_rating(user_rate) %>
+        <p class="comment-body"> <%= rating_task.body %> </p>
       <% end %>
     </div>
     <%= @plugins.dispatch(:organization_ratings_plugin_container_extra_fields, user_rate).collect { |content| instance_exec(&content) }.join("") %>



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/861182f04a43197d3a28483a901466d163d63f18...5d45f66269eb8cef9fd058f6a80bd8af51e7d9dd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160714/9b9f34a4/attachment-0001.html>


More information about the Noosfero-dev mailing list