diff --git a/plugins/organization_ratings/lib/create_organization_rating_comment.rb b/plugins/organization_ratings/lib/create_organization_rating_comment.rb index fe66ab3..42cdb50 100644 --- 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) diff --git 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 index 77c6111..659f2ca 100644 --- 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 diff --git a/plugins/organization_ratings/views/shared/_user_rating_container.html.erb b/plugins/organization_ratings/views/shared/_user_rating_container.html.erb index b1fc095..a02ba55 100644 --- 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? %>

<%= user_rate.comment.body %>

+ <% elsif user && user.is_admin? %> + <% rating_task = CreateOrganizationRatingComment.with_rating(user_rate) %> +

<%= rating_task.body %>

<% end %> <%= @plugins.dispatch(:organization_ratings_plugin_container_extra_fields, user_rate).collect { |content| instance_exec(&content) }.join("") %> -- libgit2 0.21.2