[Git][noosfero/noosfero][master] Organization Ratings plugin improvements

Daniela Feitosa gitlab at mg.gitlab.com
Fri Dec 4 02:39:43 BRST 2015


Daniela Feitosa pushed to branch master at Noosfero / noosfero


Commits:
0c7ed580 by Gabriel Silva at 2015-12-04T01:35:00Z
Organization Ratings plugin improvements

- Adds hostspot in Organization Rating task details
- Improvements on task and organization ratings layout
- Added one hotspot for task contents and another for ratings container content
- Rejected rating comments are only displayed to env admins and comment owners
- All task messages now refers to "a Report" instead of Comment:
  i.g. "Report waiting for approval" instead of "Comment waiting for approval"
- Also added css style to auto expand task div

Signed-off-by: Gabriel Silva <gabriel93.silva at gmail.com>
Signed-off-by: Gustavo Coelho <gust.rod.coelho at gmail.com>
Signed-off-by: Tallys Martins <tallysmartins at gmail.com>
Signed-off-by: Thiago Ribeiro <thiagitosouza at gmail.com>
Signed-off-by: Dylan Guedes <djmgguedes at gmail.com>
Signed-off-by: Daniela Soares Feitosa <danielafeitosa at colivre.coop.br>

See merge request !737

- - - - -


13 changed files:

- app/views/tasks/_task.html.erb
- plugins/organization_ratings/controllers/organization_ratings_plugin_profile_controller.rb
- + plugins/organization_ratings/db/migrate/20151203121430_destroy_rejected_reports.rb
- plugins/organization_ratings/lib/create_organization_rating_comment.rb
- plugins/organization_ratings/lib/organization_rating.rb
- plugins/organization_ratings/lib/organization_ratings_plugin.rb
- plugins/organization_ratings/test/functional/organization_ratings_plugin_profile_controller_test.rb
- + plugins/organization_ratings/test/unit/create_organization_rating_comment_test.rb
- plugins/organization_ratings/test/unit/organization_rating_test.rb
- plugins/organization_ratings/views/organization_ratings_plugin_profile/_new_rating_fields.html.erb
- plugins/organization_ratings/views/shared/_user_rating_container.html.erb
- plugins/organization_ratings/views/tasks/_create_organization_rating_comment_accept_details.html.erb
- public/stylesheets/tasks.scss


Changes:

=====================================
app/views/tasks/_task.html.erb
=====================================
--- a/app/views/tasks/_task.html.erb
+++ b/app/views/tasks/_task.html.erb
@@ -2,6 +2,10 @@
 
   <%= render :partial => 'task_icon', :locals => {:task => task} %>
 
+  <div class="task_date"><%= show_time(task.created_at) %></div>
+
+  <%= render :partial => 'task_title', :locals => {:task => task} %>
+
   <% if !@view_only && profile.organization? && @responsible_candidates.present? %>
     <div class="task_responsible">
       <span class="label"><%= _('Assign to:') %></span>
@@ -41,9 +45,6 @@
     <% end %>
   </div><!-- class="task_decisions" -->
 
-  <div class="task_date"><%= show_time(task.created_at) %></div>
-
-  <%= render :partial => 'task_title', :locals => {:task => task} %>
 
   <div class="task_information">
     <%= task_information(task) %>


=====================================
plugins/organization_ratings/controllers/organization_ratings_plugin_profile_controller.rb
=====================================
--- a/plugins/organization_ratings/controllers/organization_ratings_plugin_profile_controller.rb
+++ b/plugins/organization_ratings/controllers/organization_ratings_plugin_profile_controller.rb
@@ -54,23 +54,18 @@ class OrganizationRatingsPluginProfileController < ProfileController
   end
 
   def create_rating_comment(rating)
-    if params[:comments]
-        comment_task = CreateOrganizationRatingComment.create!(
-          params[:comments].merge(
-            :requestor => rating.person,
-            :organization_rating_id => rating.id,
-            :target => rating.organization
-          )
+    if params[:comments].present? && params[:comments][:body].present?
+      comment_task = CreateOrganizationRatingComment.create!(
+        params[:comments].merge(
+          :requestor => rating.person,
+          :organization_rating_id => rating.id,
+          :target => rating.organization
         )
-        comment_task.finish if can_perform?(params)
+      )
+      comment_task.finish unless env_organization_ratings_config.are_moderated
     end
   end
 
-  def can_perform? (params)
-    (params[:comments][:body].blank? ||
-    !env_organization_ratings_config.are_moderated)
-  end
-
   def permission
     :manage_memberships
   end


=====================================
plugins/organization_ratings/db/migrate/20151203121430_destroy_rejected_reports.rb
=====================================
--- /dev/null
+++ b/plugins/organization_ratings/db/migrate/20151203121430_destroy_rejected_reports.rb
@@ -0,0 +1,14 @@
+class DestroyRejectedReports < ActiveRecord::Migration
+  def up
+    comments = []
+    select_all("SELECT data FROM tasks WHERE type = 'CreateOrganizationRatingComment' AND status = 2").each do |task|
+      settings = YAML.load(task['data'])
+      comments << settings[:organization_rating_comment_id]
+    end
+    execute("DELETE FROM comments WHERE id IN (#{comments.join(',')})")
+  end
+
+  def down
+    say "This migration can't be reverted"
+  end
+end


=====================================
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
@@ -9,28 +9,14 @@ class CreateOrganizationRatingComment < Task
   attr_accessible :organization_rating_id, :body, :requestor
   attr_accessible :reject_explanation, :target
 
-  before_save :update_comment_body
-
   DATA_FIELDS = ['body']
   DATA_FIELDS.each do |field|
     settings_items field.to_sym
   end
 
-  def update_comment_body
-    if self.organization_rating_comment_id.nil?
-      create_comment
-    else
-      comment = Comment.find_by_id(self.organization_rating_comment_id)
-      comment.body = get_comment_message
-      comment.save
-    end
-  end
-
-  def create_comment
+  def perform
     if (self.body && !self.body.blank?)
-      comment_body = _("Comment waiting for approval")
-      comment = Comment.create!(:source => self.target, :body => comment_body, :author => self.requestor)
-
+      comment = Comment.create!(:source => self.target, :body => self.body, :author => self.requestor)
 
       self.organization_rating_comment_id = comment.id
       link_comment_with_its_rating(comment)
@@ -43,26 +29,16 @@ class CreateOrganizationRatingComment < Task
     rating.save
   end
 
-  def get_comment_message
-    if self.status == Status::CANCELLED
-      _("Comment rejected")
-    elsif self.status == Status::FINISHED
-      self.body
-    else
-      _("No comment")
-    end
-  end
-
   def accept_details
     true
   end
 
   def title
-    _("New Comment")
+    _("New Report")
   end
 
   def information
-    message = _("<a href=%{requestor_url}>%{requestor}</a> wants to create a comment in this %{target_class}") %
+    message = _("<a href=%{requestor_url}>%{requestor}</a> wants to leave a report about this %{target_class}") %
     {:requestor_url => url_for(self.requestor.url), :requestor => self.requestor.name, :target_class => _(self.target.class.name)}
 
     {:message => message}
@@ -87,45 +63,48 @@ class CreateOrganizationRatingComment < Task
   end
 
   def target_notification_description
-    _("%{requestor} wants to create a comment in this \"%{target}\"") %
+    _("%{requestor} wants to leave a report about this \"%{target}\"") %
     {:requestor => self.requestor.name, :target => _(self.target.class.name.downcase) }
   end
 
   def target_notification_message
-    _("User \"%{user}\" requested to create a comment in the %{target_class}
+    _("User \"%{user}\" just made a report at %{target_class}
       \"%{target_name}\".
       You have to approve or reject it through the \"Pending Validations\"
       section in your control panel.\n") %
-    { :user => self.requestor.name, :target_class => _(self.target.class.name.downcase), :target_name => self.target.name }
+    { :user => self.requestor.name,
+      :target_class => _(self.target.class.name.downcase),
+      :target_name => self.target.name }
   end
 
   def task_created_message
-    _("Your request for commenting at %{target} was
+    _("Your report at %{target_class} \"%{target}\" was
       just sent. The administrator will receive it and will approve or
       reject your request according to his methods and criteria.
       You will be notified as soon as environment administrator has a position
       about your request.") %
-    { :target => self.target.name }
+    { :target_class => _(self.target.class.name.downcase), :target => self.target.name }
   end
 
   def task_cancelled_message
-    _("Your request for commenting at %{target} was
+    _("Your report at %{target_class} \"%{target}\" was
       not approved by the administrator. The following explanation
       was given: \n\n%{explanation}") %
-    { :target => self.target.name,
+    { :target_class => _(self.target.class.name.downcase),
+      :target => self.target.name,
       :explanation => self.reject_explanation }
   end
 
   def task_finished_message
-    _('Your request for commenting at %{target} was approved.
-      You can access %{url} to see your comment.') %
-    { :target => self.target.name, :url => ratings_url }
+    _("Your report at %{target_class} \"%{target}\" was approved.
+      You can access %{url} to see your comment.") %
+    { :target_class => _(self.target.class.name.downcase), :target => self.target.name, :url => ratings_url }
   end
 
   private
 
   def ratings_url
-    url = url_for(self.target.public_profile_url) + "/plugin/organization_ratings/new_rating"
+    url_for(self.target.public_profile_url) + "/plugin/organization_ratings/new_rating"
   end
 
 end


=====================================
plugins/organization_ratings/lib/organization_rating.rb
=====================================
--- a/plugins/organization_ratings/lib/organization_rating.rb
+++ b/plugins/organization_ratings/lib/organization_rating.rb
@@ -13,6 +13,18 @@ class OrganizationRating < ActiveRecord::Base
   validates :organization_id, :person_id,
             :presence => true
 
+  def display_moderation_message person
+    if person.present?
+      task_active? && (person.is_admin? || person == self.person ||
+      self.organization.is_admin?(person))
+    end
+  end
+
+  def task_active?
+    tasks = CreateOrganizationRatingComment.where(:target_id => self.organization.id,
+                                                  :status => Task::Status::ACTIVE)
+    tasks.detect {|t| t.organization_rating_id == self.id}.present?
+  end
 
   def self.average_rating organization_id
     average = OrganizationRating.where(organization_id: organization_id).average(:value)


=====================================
plugins/organization_ratings/lib/organization_ratings_plugin.rb
=====================================
--- a/plugins/organization_ratings/lib/organization_ratings_plugin.rb
+++ b/plugins/organization_ratings/lib/organization_ratings_plugin.rb
@@ -22,7 +22,11 @@ class OrganizationRatingsPlugin < Noosfero::Plugin
       nil
     end
 
-    def organization_ratings_plugin_extra_fields_show_data user_rating
+    def organization_ratings_plugin_task_extra_fields user_rating
+      nil
+    end
+
+    def organization_ratings_plugin_container_extra_fields user_rating
       nil
     end
 


=====================================
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
@@ -17,6 +17,7 @@ class OrganizationRatingsPluginProfileControllerTest < ActionController::TestCas
 
     @person = create_user('testuser').person
     @community = Community.create(:name => "TestCommunity")
+    @community.add_admin @person
     @enterprise = fast_create(Enterprise)
     @config = OrganizationRatingsConfig.instance
     login_as(@person.identifier)
@@ -36,13 +37,13 @@ class OrganizationRatingsPluginProfileControllerTest < ActionController::TestCas
     assert_redirected_to @community.url
   end
 
-  test "Create community_rating without comment body" do
+  test "create community_rating without comment body" do
     post :new_rating, profile: @community.identifier, :comments => {:body => ""}, :organization_rating_value => 2
 
     assert_equal "#{@community.name} successfully rated!", session[:notice]
   end
 
-  test "Do not create community_rating without a rate value" do
+  test "do not create community_rating without a rate value" do
     post :new_rating, profile: @community.identifier, :comments => {:body => ""}, :organization_rating_value => nil
 
     assert_equal "Sorry, there were problems rating this profile.", session[:notice]
@@ -76,13 +77,13 @@ class OrganizationRatingsPluginProfileControllerTest < ActionController::TestCas
     block = StatisticsBlock.new
     enterprise = fast_create(Enterprise)
     post :new_rating, profile: enterprise.identifier, :comments => {:body => "body board"}, :organization_rating_value => 1
+    CreateOrganizationRatingComment.last.finish
     enterprise.reload
     @environment.reload
     block.expects(:owner).at_least_once.returns(@environment)
     assert_equal 1, block.comments
   end
 
-
   test "should count organization ratings on statistic block when block owner = Profile" do
     @config.cooldown = 0
     @config.save
@@ -91,13 +92,15 @@ class OrganizationRatingsPluginProfileControllerTest < ActionController::TestCas
 
     post :new_rating, profile: @community.identifier, :comments => {:body => "body board"}, :organization_rating_value => 1
     post :new_rating, profile: @community.identifier, :comments => {:body => "body surf"}, :organization_rating_value => 5
-
+    CreateOrganizationRatingComment.all.each do |s|
+      s.finish
+    end
     block.expects(:owner).at_least_once.returns(@community)
     @community.reload
     assert_equal 2, block.comments
   end
 
-  test "Display unavailable rating message for users that must wait the rating cooldown time" do
+  test "display unavailable rating message for users that must wait the rating cooldown time" do
     post :new_rating, profile: @community.identifier, :comments => {:body => ""}, :organization_rating_value => 3
     assert_no_match(/The administrators set the minimum time of/, @response.body)
     valid_rating = OrganizationRating.last
@@ -108,4 +111,81 @@ class OrganizationRatingsPluginProfileControllerTest < ActionController::TestCas
 
     assert_equal valid_rating.id, new_rating.id
   end
+
+  test "display moderation report message body to community admin" do
+    @member = create_user('member')
+    @community.add_member @member.person
+    login_as 'member'
+    @controller.stubs(:current_user).returns(@member)
+
+    post :new_rating, profile: @community.identifier, :comments => {:body => "comment"}, :organization_rating_value => 3
+
+    login_as 'testuser'
+    @controller.stubs(:current_user).returns(@person.user)
+    get :new_rating, profile: @community.identifier
+    assert_tag :tag => 'p', :content => /Report waiting for approval/, :attributes => {:class =>/moderation-msg/}
+    assert_no_tag :tag => 'p', :attributes => {:class =>/comment-body/}
+  end
+
+  test "display moderation report message to owner" do
+    @member = create_user('member')
+    @community.add_member @member.person
+    login_as 'member'
+    @controller.stubs(:current_user).returns(@member)
+
+    post :new_rating, profile: @community.identifier, :comments => {:body => "comment"}, :organization_rating_value => 3
+    get :new_rating, profile: @community.identifier
+    assert_tag :tag => 'p', :content => /Report waiting for approval/, :attributes => {:class =>/moderation-msg/}
+    assert_no_tag :tag => 'p', :attributes => {:class =>/comment-body/}
+  end
+
+  test "display moderation report message comment to env admin" do
+    post :new_rating, profile: @community.identifier, :comments => {:body => "comment"}, :organization_rating_value => 3
+
+    @admin = create_admin_user(@environment)
+    login_as @admin
+    @controller.stubs(:current_user).returns(Profile[@admin].user)
+
+    get :new_rating, profile: @community.identifier
+    assert_tag :tag => 'p', :content => /Report waiting for approval/, :attributes => {:class =>/moderation-msg/}
+    assert_no_tag :tag => 'p', :attributes => {:class =>/comment-body/}
+  end
+
+  test "not display moderation report message to regular user" do
+    post :new_rating, profile: @community.identifier, :comments => {:body => "comment"}, :organization_rating_value => 3
+    rating_task = CreateOrganizationRatingComment.last
+    rating_task.cancel
+
+    @member = create_user('member')
+    @community.add_member @member.person
+    login_as 'member'
+    @controller.stubs(:current_user).returns(@member)
+
+    get :new_rating, profile: @community.identifier
+    assert_no_tag :tag => 'p', :content => /Report waiting for approval/, :attributes => {:class =>/moderation-msg/}
+    assert_no_tag :tag => 'p', :attributes => {:class =>/comment-body/}
+  end
+
+  test "not display rejected comment message to not logged user" do
+    post :new_rating, profile: @community.identifier, :comments => {:body => "comment"}, :organization_rating_value => 3
+    rating_task = CreateOrganizationRatingComment.last
+    rating_task.cancel
+
+    logout
+    @controller.stubs(:logged_in?).returns(false)
+
+    get :new_rating, profile: @community.identifier
+    assert_no_tag :tag => 'p', :content => /Report waiting for approval/, :attributes => {:class =>/comment-rejected-msg/}
+    assert_no_tag :tag => 'p', :attributes => {:class =>/comment-body/}
+  end
+
+  test "display report when Task accepted" do
+    post :new_rating, profile: @community.identifier, :comments => {:body => "comment accepted"}, :organization_rating_value => 3
+    rating_task = CreateOrganizationRatingComment.last
+    rating_task.finish
+
+    get :new_rating, profile: @community.identifier
+    assert_no_tag :tag => 'p', :content => /Report waiting for approva/, :attributes => {:class =>/comment-rejected-msg/}
+    assert_tag :tag => 'p', :content => /comment accepted/, :attributes => {:class =>/comment-body/}
+  end
 end


=====================================
plugins/organization_ratings/test/unit/create_organization_rating_comment_test.rb
=====================================
--- /dev/null
+++ b/plugins/organization_ratings/test/unit/create_organization_rating_comment_test.rb
@@ -0,0 +1,44 @@
+require 'test_helper'
+class CreateOrganizationRatingCommentTest < ActiveSupport::TestCase
+
+  def setup
+    @person = create_user('Mario').person
+    @person.email = "person at email.com"
+    @person.save
+    @community = fast_create(Community)
+    @adminuser = Person[create_admin_user(Environment.default)]
+    @rating = fast_create(OrganizationRating, {:value => 1,
+                                               :person_id => @person.id,
+                                               :organization_id => @community.id,
+                                               :created_at => DateTime.now,
+                                               :updated_at => DateTime.now,
+                                              })
+  end
+
+  test "create comment when finish TASK" do
+    create_organization_rating_comment = CreateOrganizationRatingComment.create!(
+      :requestor => @person,
+      :organization_rating_id => @rating.id,
+      :target => @community,
+      :body => "sample comment"
+    )
+    assert_equal Task::Status::ACTIVE, create_organization_rating_comment.status
+    assert_difference 'Comment.count' do
+      create_organization_rating_comment.finish
+    end
+  end
+
+  test "do not create comment when cancel TASK" do
+    create_organization_rating_comment = CreateOrganizationRatingComment.create!(
+      :requestor => @person,
+      :organization_rating_id => @rating.id,
+      :target => @community,
+      :body => "sample comment"
+    )
+    assert_equal Task::Status::ACTIVE, create_organization_rating_comment.status
+    assert_no_difference 'Comment.count' do
+      create_organization_rating_comment.cancel
+    end
+  end
+
+end


=====================================
plugins/organization_ratings/test/unit/organization_rating_test.rb
=====================================
--- a/plugins/organization_ratings/test/unit/organization_rating_test.rb
+++ b/plugins/organization_ratings/test/unit/organization_rating_test.rb
@@ -1,6 +1,20 @@
-require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper'
-
+require 'test_helper'
 class OrganizationRatingTest < ActiveSupport::TestCase
+
+  def setup
+    @person = create_user('Mario').person
+    @person.email = "person at email.com"
+    @person.save
+    @community = fast_create(Community)
+    @adminuser = Person[create_admin_user(Environment.default)]
+    @rating = fast_create(OrganizationRating, {:value => 1,
+                                               :person_id => @person.id,
+                                               :organization_id => @community.id,
+                                               :created_at => DateTime.now,
+                                               :updated_at => DateTime.now,
+                                              })
+  end
+
   test "The value must be between 1 and 5" do
     organization_rating1 = OrganizationRating.new :value => -1
     organization_rating2 = OrganizationRating.new :value => 6
@@ -21,57 +35,58 @@ class OrganizationRatingTest < ActiveSupport::TestCase
     assert_equal false, organization_rating2.errors[:value].include?("must be between 1 and 5")
   end
 
-  test "Create task for create a rating comment" do
-    person = create_user('molly').person
-    person.email = "person at email.com"
-    person.save!
+  test "false return when no active tasks for an Organization Rating" do
+    assert_not @rating.task_active?
+  end
 
-    community = fast_create(Community)
-    community.add_admin(person)
+  test "true return when an active task exists for an Organization Rating" do
+    CreateOrganizationRatingComment.create!(
+                      :organization_rating_id => @rating.id,
+                      :target => @community,
+                      :requestor => @person)
 
-    organization_rating = OrganizationRating.create!(
-        :value => 3,
-        :person => person,
-        :organization => community
-    )
-
-    create_organization_rating_comment = CreateOrganizationRatingComment.create!(
-      :requestor => person,
-      :organization_rating_id => organization_rating.id,
-      :target => community
-    )
+    assert_equal Task::Status::ACTIVE, CreateOrganizationRatingComment.last.status
+    assert @rating.task_active?
+  end
 
-    assert community.tasks.include?(create_organization_rating_comment)
+  test "return false when an cancelled task exists for an Organization Rating" do
+    CreateOrganizationRatingComment.create!(
+                      :organization_rating_id => @rating.id,
+                      :target => @community,
+                      :requestor => @person)
+    CreateOrganizationRatingComment.last.cancel
+    assert_not @rating.task_active?
   end
 
-    test "Check comment message when Task status = ACTIVE" do
-    person = create_user('molly').person
-    person.email = "person at email.com"
-    person.save!
+  test "display report moderation message to community admin" do
+    moderator = create_user('moderator')
+    @community.add_admin(moderator.person)
+    @rating.stubs(:task_active?).returns(true)
+    assert @rating.display_moderation_message(@adminuser)
+  end
 
-    community = fast_create(Community)
-    community.add_admin(person)
+  test "display report moderation message to owner" do
+    @rating.stubs(:task_active?).returns(true)
+    assert @rating.display_moderation_message(@person)
+  end
 
+  test "do not display report moderation message to regular user" do
+    regular_person = fast_create(Person)
+    @rating.stubs(:task_active?).returns(true)
+    assert_not @rating.display_moderation_message(regular_person)
+  end
 
-    organization_rating = OrganizationRating.create!(
-        :value => 3,
-        :person => person,
-        :organization => community
-    )
+  test "do not display report moderation message to not logged user" do
+    @rating.stubs(:task_active?).returns(true)
+    assert_not @rating.display_moderation_message(nil)
+  end
 
-    create_organization_rating_comment = CreateOrganizationRatingComment.create!(
-      :requestor => person,
-      :organization_rating_id => organization_rating.id,
-      :target => community,
-      :body => "sample comment"
-    )
-    assert_equal 1, create_organization_rating_comment.status
-    message = "Comment waiting for approval"
-    comment = Comment.find_by_id(create_organization_rating_comment.organization_rating_comment_id)
-    assert_equal message, comment.body
+  test "do not display report moderation message no active task exists" do
+    @rating.stubs(:task_active?).returns(false)
+    assert_not @rating.display_moderation_message(@person)
   end
 
-  test "Check comment message when Task status = CANCELLED" do
+  test "Create task for create a rating comment" do
     person = create_user('molly').person
     person.email = "person at email.com"
     person.save!
@@ -79,7 +94,6 @@ class OrganizationRatingTest < ActiveSupport::TestCase
     community = fast_create(Community)
     community.add_admin(person)
 
-
     organization_rating = OrganizationRating.create!(
         :value => 3,
         :person => person,
@@ -89,51 +103,12 @@ class OrganizationRatingTest < ActiveSupport::TestCase
     create_organization_rating_comment = CreateOrganizationRatingComment.create!(
       :requestor => person,
       :organization_rating_id => organization_rating.id,
-      :target => community,
-      :body => "sample comment"
-    )
-    create_organization_rating_comment.cancel
-    assert_equal 2, create_organization_rating_comment.status
-    message = "Comment rejected"
-    comment = Comment.find_by_id(create_organization_rating_comment.organization_rating_comment_id)
-    assert_equal message, comment.body
-  end
-
-  test "Check comment message when Task status = FINISHED" do
-    person = create_user('molly').person
-    person.email = "person at email.com"
-    person.save!
-
-    community = fast_create(Community)
-    community.add_admin(person)
-
-    comment = Comment.create!(source: community,
-                                                 body: "regular comment",
-                                                 author: person)
-
-    organization_rating = OrganizationRating.create!(
-        :value => 3,
-        :person => person,
-        :organization => community,
-        :comment => comment
+      :target => community
     )
 
-    create_organization_rating_comment = CreateOrganizationRatingComment.create!(
-          :body => comment.body,
-          :requestor => organization_rating.person,
-          :organization_rating_id => organization_rating.id,
-          :target => organization_rating.organization,
-          :body => "sample comment"
-      )
-
-    create_organization_rating_comment.finish
-    assert_equal 3, create_organization_rating_comment.status
-    message = "sample comment"
-    comment = Comment.find_by_id(create_organization_rating_comment.organization_rating_comment_id)
-    assert_equal message, comment.body
+    assert community.tasks.include?(create_organization_rating_comment)
   end
 
-
   test "Should calculate community's rating average" do
     community = fast_create Community
     p1 = fast_create Person, :name=>"Person 1"


=====================================
plugins/organization_ratings/views/organization_ratings_plugin_profile/_new_rating_fields.html.erb
=====================================
--- a/plugins/organization_ratings/views/organization_ratings_plugin_profile/_new_rating_fields.html.erb
+++ b/plugins/organization_ratings/views/organization_ratings_plugin_profile/_new_rating_fields.html.erb
@@ -19,13 +19,12 @@
 
   <% if @rating_available %>
     <div class="star-rate-form">
-      <div data-rate-url=<%= url_for controller: "organization_ratings_plugin_profile", :action => "rate" %>>
+      <div data-rate-url='<%= url_for controller: "organization_ratings_plugin_profile", :action => "rate" %>'>
         <div class="star-rate-text">
           <%= @plugins.dispatch(:organization_ratings_plugin_star_message).collect { |content| instance_exec(&content) }.join("") %>
         </div>
 
         <div class="star-container" data-min-rate="<%= min_rate %>">
-
           <% (1..5).each do |rate_number| %>
             <% if rate_number <= default_rating %>
               <div class="star-positive" data-star-rate="<%= rate_number %>"></div>
@@ -43,8 +42,8 @@
       <div class="star-comment-container">
         <%= form_for :comments do |c| %>
           <div class="formfieldline formfield type-text">
-              <%= c.label :body, _('Comment (Optional):'), :class => "formlabel" %>
-              <%= c.text_area :body %>
+            <%= c.label :body, _('Comment (Optional):'), :class => "formlabel" %>
+            <%= c.text_area :body %>
           </div>
 
           <%= @plugins.dispatch(:organization_ratings_plugin_comments_extra_fields).collect { |content| instance_exec(&content) }.join("") %>
@@ -57,24 +56,22 @@
           <input type="hidden" id="minimum_stars" name="organization_rating_min_value" value="<%= min_rate %>">
         <% end %>
       </div>
+    </div>
+  <% elsif env_organization_ratings_config.vote_once %>
+    <div class="star-rate-form rating-vote-once">
+      <%= _("Hi, %s! The administrators set that you can vote") % current_user.name %>
+      <strong><%= _("only once") %></strong>
+      <%= _("for this %s.") % profile.class.name.downcase %>
+      <%= render :partial => 'shared/rating_button', :locals => { :disabled => true } %>
+    </div>
+  <% else %>
+    <div class="star-rate-form rating-cooldown">
+      <%= _("Hi, %s! The administrators set the minimum time of") % current_user.name %>
+      <strong><%= _("%d hour(s)") % env_organization_ratings_config.cooldown %></strong>
+      <%= _("between each evaluation.") %>
 
-    <% elsif env_organization_ratings_config.vote_once %>
-      <div class="star-rate-form rating-vote-once">
-        <%= _("Hi, %s! The administrators set that you can vote") % current_user.name %>
-        <strong><%= _("only once") %></strong>
-        <%= _("for this %s.") % profile.class.name.downcase %>
-        <%= render :partial => 'shared/rating_button', :locals => { :disabled => true } %>
-      </div>
-    <% else %>
-      <div class="star-rate-form rating-cooldown">
-        <%= _("Hi, %s! The administrators set the minimum time of") % current_user.name %>
-        <strong><%= _("%d hour(s)") % env_organization_ratings_config.cooldown %></strong>
-        <%= _("between each evaluation.") %>
-
-        <%= render :partial => 'shared/rating_button', :locals => { :disabled => true } %>
-      </div>
-    <% end %>
-
+      <%= render :partial => 'shared/rating_button', :locals => { :disabled => true } %>
+    </div>
+  <% end %>
 
-  </div>
 </div>


=====================================
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
@@ -25,9 +25,13 @@
     </div>
 
     <div class="user-testimony">
-      <%= user_rate.comment.nil? ? _("No comment") : user_rate.comment.body %>
+      <% if user_rate.display_moderation_message(user) %>
+        <p class="moderation-msg"><%= _("Report waiting for approval") %></p>
+      <% end %>
+      <% if user_rate.comment.present? %>
+        <p class="comment-body"> <%= user_rate.comment.body %> </p>
+      <% end %>
     </div>
-
-    <%= @plugins.dispatch(:organization_ratings_plugin_extra_fields_show_data, user_rate).collect { |content| instance_exec(&content) }.join("") %>
+    <%= @plugins.dispatch(:organization_ratings_plugin_container_extra_fields, user_rate).collect { |content| instance_exec(&content) }.join("") %>
   </div>
 </div>


=====================================
plugins/organization_ratings/views/tasks/_create_organization_rating_comment_accept_details.html.erb
=====================================
--- a/plugins/organization_ratings/views/tasks/_create_organization_rating_comment_accept_details.html.erb
+++ b/plugins/organization_ratings/views/tasks/_create_organization_rating_comment_accept_details.html.erb
@@ -1,4 +1,19 @@
 <div class="organization-rating-comment-body">
-  <%= _("Comment:")%>
-  <%= "\"#{task.body}\""%>
+  <% rating = OrganizationRating.find(task.organization_rating_id) %>
+  <%= @plugins.dispatch(:organization_ratings_plugin_task_extra_fields, rating).collect{ |content| instance_exec(&content) }.join("") %>
+  <div class="task-comment">
+    <span><%= _("Description:")%></span>
+    <p><%= "\"#{task.body}\""%></p>
+  </div>
+
+  <span class="rating-notice"><%= _("* The rating score is not moderated.")%></span>
+  <div class="task-star-container">
+    <% (1..5).each do |star_number| %>
+      <% if star_number <= rating.value %>
+        <div class="medium-star-positive"></div>
+      <% else %>
+        <div class="medium-star-negative"></div>
+      <% end %>
+    <% end %>
+  </div>
 </div>


=====================================
public/stylesheets/tasks.scss
=====================================
--- a/public/stylesheets/tasks.scss
+++ b/public/stylesheets/tasks.scss
@@ -27,6 +27,7 @@ div.pending-tasks {
 }
 
 .task_box {
+  overflow: hidden;
   position: relative;
   border: 1px solid #888;
   -moz-border-radius: 10px;



View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/0c7ed580c795934949ed7ea330294d3dbd7c0853
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20151204/30787198/attachment-0001.html>


More information about the Noosfero-dev mailing list