Commit 8ac18ed968996418903549ce03b2848156e50271

Authored by Gabriel Silva
Committed by Tallys Martins
1 parent 6988bf6f

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@gmail.com>
Signed-off-by: Gustavo Coelho <gust.rod.coelho@gmail.com>
Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
Signed-off-by: Thiago Ribeiro <thiagitosouza@gmail.com>
Signed-off-by: Dylan Guedes <djmgguedes@gmail.com>
Signed-off-by: Daniela Soares Feitosa <danielafeitosa@colivre.coop.br>

See merge request !737
app/views/tasks/_task.html.erb
... ... @@ -2,6 +2,10 @@
2 2  
3 3 <%= render :partial => 'task_icon', :locals => {:task => task} %>
4 4  
  5 + <div class="task_date"><%= show_time(task.created_at) %></div>
  6 +
  7 + <%= render :partial => 'task_title', :locals => {:task => task} %>
  8 +
5 9 <% if !@view_only && profile.organization? && @responsible_candidates.present? %>
6 10 <div class="task_responsible">
7 11 <span class="label"><%= _('Assign to:') %></span>
... ... @@ -41,9 +45,6 @@
41 45 <% end %>
42 46 </div><!-- class="task_decisions" -->
43 47  
44   - <div class="task_date"><%= show_time(task.created_at) %></div>
45   -
46   - <%= render :partial => 'task_title', :locals => {:task => task} %>
47 48  
48 49 <div class="task_information">
49 50 <%= task_information(task) %>
... ...
plugins/organization_ratings/controllers/organization_ratings_plugin_profile_controller.rb
... ... @@ -54,23 +54,18 @@ class OrganizationRatingsPluginProfileController &lt; ProfileController
54 54 end
55 55  
56 56 def create_rating_comment(rating)
57   - if params[:comments]
58   - comment_task = CreateOrganizationRatingComment.create!(
59   - params[:comments].merge(
60   - :requestor => rating.person,
61   - :organization_rating_id => rating.id,
62   - :target => rating.organization
63   - )
  57 + if params[:comments].present? && params[:comments][:body].present?
  58 + comment_task = CreateOrganizationRatingComment.create!(
  59 + params[:comments].merge(
  60 + :requestor => rating.person,
  61 + :organization_rating_id => rating.id,
  62 + :target => rating.organization
64 63 )
65   - comment_task.finish if can_perform?(params)
  64 + )
  65 + comment_task.finish unless env_organization_ratings_config.are_moderated
66 66 end
67 67 end
68 68  
69   - def can_perform? (params)
70   - (params[:comments][:body].blank? ||
71   - !env_organization_ratings_config.are_moderated)
72   - end
73   -
74 69 def permission
75 70 :manage_memberships
76 71 end
... ...
plugins/organization_ratings/db/migrate/20151203121430_destroy_rejected_reports.rb 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +class DestroyRejectedReports < ActiveRecord::Migration
  2 + def up
  3 + comments = []
  4 + select_all("SELECT data FROM tasks WHERE type = 'CreateOrganizationRatingComment' AND status = 2").each do |task|
  5 + settings = YAML.load(task['data'])
  6 + comments << settings[:organization_rating_comment_id]
  7 + end
  8 + execute("DELETE FROM comments WHERE id IN (#{comments.join(',')})")
  9 + end
  10 +
  11 + def down
  12 + say "This migration can't be reverted"
  13 + end
  14 +end
... ...
plugins/organization_ratings/lib/create_organization_rating_comment.rb
... ... @@ -9,28 +9,14 @@ class CreateOrganizationRatingComment &lt; Task
9 9 attr_accessible :organization_rating_id, :body, :requestor
10 10 attr_accessible :reject_explanation, :target
11 11  
12   - before_save :update_comment_body
13   -
14 12 DATA_FIELDS = ['body']
15 13 DATA_FIELDS.each do |field|
16 14 settings_items field.to_sym
17 15 end
18 16  
19   - def update_comment_body
20   - if self.organization_rating_comment_id.nil?
21   - create_comment
22   - else
23   - comment = Comment.find_by_id(self.organization_rating_comment_id)
24   - comment.body = get_comment_message
25   - comment.save
26   - end
27   - end
28   -
29   - def create_comment
  17 + def perform
30 18 if (self.body && !self.body.blank?)
31   - comment_body = _("Comment waiting for approval")
32   - comment = Comment.create!(:source => self.target, :body => comment_body, :author => self.requestor)
33   -
  19 + comment = Comment.create!(:source => self.target, :body => self.body, :author => self.requestor)
34 20  
35 21 self.organization_rating_comment_id = comment.id
36 22 link_comment_with_its_rating(comment)
... ... @@ -43,26 +29,16 @@ class CreateOrganizationRatingComment &lt; Task
43 29 rating.save
44 30 end
45 31  
46   - def get_comment_message
47   - if self.status == Status::CANCELLED
48   - _("Comment rejected")
49   - elsif self.status == Status::FINISHED
50   - self.body
51   - else
52   - _("No comment")
53   - end
54   - end
55   -
56 32 def accept_details
57 33 true
58 34 end
59 35  
60 36 def title
61   - _("New Comment")
  37 + _("New Report")
62 38 end
63 39  
64 40 def information
65   - message = _("<a href=%{requestor_url}>%{requestor}</a> wants to create a comment in this %{target_class}") %
  41 + message = _("<a href=%{requestor_url}>%{requestor}</a> wants to leave a report about this %{target_class}") %
66 42 {:requestor_url => url_for(self.requestor.url), :requestor => self.requestor.name, :target_class => _(self.target.class.name)}
67 43  
68 44 {:message => message}
... ... @@ -87,45 +63,48 @@ class CreateOrganizationRatingComment &lt; Task
87 63 end
88 64  
89 65 def target_notification_description
90   - _("%{requestor} wants to create a comment in this \"%{target}\"") %
  66 + _("%{requestor} wants to leave a report about this \"%{target}\"") %
91 67 {:requestor => self.requestor.name, :target => _(self.target.class.name.downcase) }
92 68 end
93 69  
94 70 def target_notification_message
95   - _("User \"%{user}\" requested to create a comment in the %{target_class}
  71 + _("User \"%{user}\" just made a report at %{target_class}
96 72 \"%{target_name}\".
97 73 You have to approve or reject it through the \"Pending Validations\"
98 74 section in your control panel.\n") %
99   - { :user => self.requestor.name, :target_class => _(self.target.class.name.downcase), :target_name => self.target.name }
  75 + { :user => self.requestor.name,
  76 + :target_class => _(self.target.class.name.downcase),
  77 + :target_name => self.target.name }
100 78 end
101 79  
102 80 def task_created_message
103   - _("Your request for commenting at %{target} was
  81 + _("Your report at %{target_class} \"%{target}\" was
104 82 just sent. The administrator will receive it and will approve or
105 83 reject your request according to his methods and criteria.
106 84 You will be notified as soon as environment administrator has a position
107 85 about your request.") %
108   - { :target => self.target.name }
  86 + { :target_class => _(self.target.class.name.downcase), :target => self.target.name }
109 87 end
110 88  
111 89 def task_cancelled_message
112   - _("Your request for commenting at %{target} was
  90 + _("Your report at %{target_class} \"%{target}\" was
113 91 not approved by the administrator. The following explanation
114 92 was given: \n\n%{explanation}") %
115   - { :target => self.target.name,
  93 + { :target_class => _(self.target.class.name.downcase),
  94 + :target => self.target.name,
116 95 :explanation => self.reject_explanation }
117 96 end
118 97  
119 98 def task_finished_message
120   - _('Your request for commenting at %{target} was approved.
121   - You can access %{url} to see your comment.') %
122   - { :target => self.target.name, :url => ratings_url }
  99 + _("Your report at %{target_class} \"%{target}\" was approved.
  100 + You can access %{url} to see your comment.") %
  101 + { :target_class => _(self.target.class.name.downcase), :target => self.target.name, :url => ratings_url }
123 102 end
124 103  
125 104 private
126 105  
127 106 def ratings_url
128   - url = url_for(self.target.public_profile_url) + "/plugin/organization_ratings/new_rating"
  107 + url_for(self.target.public_profile_url) + "/plugin/organization_ratings/new_rating"
129 108 end
130 109  
131 110 end
... ...
plugins/organization_ratings/lib/organization_rating.rb
... ... @@ -13,6 +13,18 @@ class OrganizationRating &lt; ActiveRecord::Base
13 13 validates :organization_id, :person_id,
14 14 :presence => true
15 15  
  16 + def display_moderation_message person
  17 + if person.present?
  18 + task_active? && (person.is_admin? || person == self.person ||
  19 + self.organization.is_admin?(person))
  20 + end
  21 + end
  22 +
  23 + def task_active?
  24 + tasks = CreateOrganizationRatingComment.where(:target_id => self.organization.id,
  25 + :status => Task::Status::ACTIVE)
  26 + tasks.detect {|t| t.organization_rating_id == self.id}.present?
  27 + end
16 28  
17 29 def self.average_rating organization_id
18 30 average = OrganizationRating.where(organization_id: organization_id).average(:value)
... ...
plugins/organization_ratings/lib/organization_ratings_plugin.rb
... ... @@ -22,7 +22,11 @@ class OrganizationRatingsPlugin &lt; Noosfero::Plugin
22 22 nil
23 23 end
24 24  
25   - def organization_ratings_plugin_extra_fields_show_data user_rating
  25 + def organization_ratings_plugin_task_extra_fields user_rating
  26 + nil
  27 + end
  28 +
  29 + def organization_ratings_plugin_container_extra_fields user_rating
26 30 nil
27 31 end
28 32  
... ...
plugins/organization_ratings/test/functional/organization_ratings_plugin_profile_controller_test.rb
... ... @@ -17,6 +17,7 @@ class OrganizationRatingsPluginProfileControllerTest &lt; ActionController::TestCas
17 17  
18 18 @person = create_user('testuser').person
19 19 @community = Community.create(:name => "TestCommunity")
  20 + @community.add_admin @person
20 21 @enterprise = fast_create(Enterprise)
21 22 @config = OrganizationRatingsConfig.instance
22 23 login_as(@person.identifier)
... ... @@ -36,13 +37,13 @@ class OrganizationRatingsPluginProfileControllerTest &lt; ActionController::TestCas
36 37 assert_redirected_to @community.url
37 38 end
38 39  
39   - test "Create community_rating without comment body" do
  40 + test "create community_rating without comment body" do
40 41 post :new_rating, profile: @community.identifier, :comments => {:body => ""}, :organization_rating_value => 2
41 42  
42 43 assert_equal "#{@community.name} successfully rated!", session[:notice]
43 44 end
44 45  
45   - test "Do not create community_rating without a rate value" do
  46 + test "do not create community_rating without a rate value" do
46 47 post :new_rating, profile: @community.identifier, :comments => {:body => ""}, :organization_rating_value => nil
47 48  
48 49 assert_equal "Sorry, there were problems rating this profile.", session[:notice]
... ... @@ -76,13 +77,13 @@ class OrganizationRatingsPluginProfileControllerTest &lt; ActionController::TestCas
76 77 block = StatisticsBlock.new
77 78 enterprise = fast_create(Enterprise)
78 79 post :new_rating, profile: enterprise.identifier, :comments => {:body => "body board"}, :organization_rating_value => 1
  80 + CreateOrganizationRatingComment.last.finish
79 81 enterprise.reload
80 82 @environment.reload
81 83 block.expects(:owner).at_least_once.returns(@environment)
82 84 assert_equal 1, block.comments
83 85 end
84 86  
85   -
86 87 test "should count organization ratings on statistic block when block owner = Profile" do
87 88 @config.cooldown = 0
88 89 @config.save
... ... @@ -91,13 +92,15 @@ class OrganizationRatingsPluginProfileControllerTest &lt; ActionController::TestCas
91 92  
92 93 post :new_rating, profile: @community.identifier, :comments => {:body => "body board"}, :organization_rating_value => 1
93 94 post :new_rating, profile: @community.identifier, :comments => {:body => "body surf"}, :organization_rating_value => 5
94   -
  95 + CreateOrganizationRatingComment.all.each do |s|
  96 + s.finish
  97 + end
95 98 block.expects(:owner).at_least_once.returns(@community)
96 99 @community.reload
97 100 assert_equal 2, block.comments
98 101 end
99 102  
100   - test "Display unavailable rating message for users that must wait the rating cooldown time" do
  103 + test "display unavailable rating message for users that must wait the rating cooldown time" do
101 104 post :new_rating, profile: @community.identifier, :comments => {:body => ""}, :organization_rating_value => 3
102 105 assert_not_match(/The administrators set the minimum time of/, @response.body)
103 106 valid_rating = OrganizationRating.last
... ... @@ -108,4 +111,81 @@ class OrganizationRatingsPluginProfileControllerTest &lt; ActionController::TestCas
108 111  
109 112 assert_equal valid_rating.id, new_rating.id
110 113 end
  114 +
  115 + test "display moderation report message body to community admin" do
  116 + @member = create_user('member')
  117 + @community.add_member @member.person
  118 + login_as 'member'
  119 + @controller.stubs(:current_user).returns(@member)
  120 +
  121 + post :new_rating, profile: @community.identifier, :comments => {:body => "comment"}, :organization_rating_value => 3
  122 +
  123 + login_as 'testuser'
  124 + @controller.stubs(:current_user).returns(@person.user)
  125 + get :new_rating, profile: @community.identifier
  126 + assert_tag :tag => 'p', :content => /Report waiting for approval/, :attributes => {:class =>/moderation-msg/}
  127 + assert_no_tag :tag => 'p', :attributes => {:class =>/comment-body/}
  128 + end
  129 +
  130 + test "display moderation report message to owner" do
  131 + @member = create_user('member')
  132 + @community.add_member @member.person
  133 + login_as 'member'
  134 + @controller.stubs(:current_user).returns(@member)
  135 +
  136 + post :new_rating, profile: @community.identifier, :comments => {:body => "comment"}, :organization_rating_value => 3
  137 + get :new_rating, profile: @community.identifier
  138 + assert_tag :tag => 'p', :content => /Report waiting for approval/, :attributes => {:class =>/moderation-msg/}
  139 + assert_no_tag :tag => 'p', :attributes => {:class =>/comment-body/}
  140 + end
  141 +
  142 + test "display moderation report message comment to env admin" do
  143 + post :new_rating, profile: @community.identifier, :comments => {:body => "comment"}, :organization_rating_value => 3
  144 +
  145 + @admin = create_admin_user(@environment)
  146 + login_as @admin
  147 + @controller.stubs(:current_user).returns(Profile[@admin].user)
  148 +
  149 + get :new_rating, profile: @community.identifier
  150 + assert_tag :tag => 'p', :content => /Report waiting for approval/, :attributes => {:class =>/moderation-msg/}
  151 + assert_no_tag :tag => 'p', :attributes => {:class =>/comment-body/}
  152 + end
  153 +
  154 + test "not display moderation report message to regular user" do
  155 + post :new_rating, profile: @community.identifier, :comments => {:body => "comment"}, :organization_rating_value => 3
  156 + rating_task = CreateOrganizationRatingComment.last
  157 + rating_task.cancel
  158 +
  159 + @member = create_user('member')
  160 + @community.add_member @member.person
  161 + login_as 'member'
  162 + @controller.stubs(:current_user).returns(@member)
  163 +
  164 + get :new_rating, profile: @community.identifier
  165 + assert_no_tag :tag => 'p', :content => /Report waiting for approval/, :attributes => {:class =>/moderation-msg/}
  166 + assert_no_tag :tag => 'p', :attributes => {:class =>/comment-body/}
  167 + end
  168 +
  169 + test "not display rejected comment message to not logged user" do
  170 + post :new_rating, profile: @community.identifier, :comments => {:body => "comment"}, :organization_rating_value => 3
  171 + rating_task = CreateOrganizationRatingComment.last
  172 + rating_task.cancel
  173 +
  174 + logout
  175 + @controller.stubs(:logged_in?).returns(false)
  176 +
  177 + get :new_rating, profile: @community.identifier
  178 + assert_no_tag :tag => 'p', :content => /Report waiting for approval/, :attributes => {:class =>/comment-rejected-msg/}
  179 + assert_no_tag :tag => 'p', :attributes => {:class =>/comment-body/}
  180 + end
  181 +
  182 + test "display report when Task accepted" do
  183 + post :new_rating, profile: @community.identifier, :comments => {:body => "comment accepted"}, :organization_rating_value => 3
  184 + rating_task = CreateOrganizationRatingComment.last
  185 + rating_task.finish
  186 +
  187 + get :new_rating, profile: @community.identifier
  188 + assert_no_tag :tag => 'p', :content => /Report waiting for approva/, :attributes => {:class =>/comment-rejected-msg/}
  189 + assert_tag :tag => 'p', :content => /comment accepted/, :attributes => {:class =>/comment-body/}
  190 + end
111 191 end
... ...
plugins/organization_ratings/test/unit/create_organization_rating_comment_test.rb 0 → 100644
... ... @@ -0,0 +1,44 @@
  1 +require 'test_helper'
  2 +class CreateOrganizationRatingCommentTest < ActiveSupport::TestCase
  3 +
  4 + def setup
  5 + @person = create_user('Mario').person
  6 + @person.email = "person@email.com"
  7 + @person.save
  8 + @community = fast_create(Community)
  9 + @adminuser = Person[create_admin_user(Environment.default)]
  10 + @rating = fast_create(OrganizationRating, {:value => 1,
  11 + :person_id => @person.id,
  12 + :organization_id => @community.id,
  13 + :created_at => DateTime.now,
  14 + :updated_at => DateTime.now,
  15 + })
  16 + end
  17 +
  18 + test "create comment when finish TASK" do
  19 + create_organization_rating_comment = CreateOrganizationRatingComment.create!(
  20 + :requestor => @person,
  21 + :organization_rating_id => @rating.id,
  22 + :target => @community,
  23 + :body => "sample comment"
  24 + )
  25 + assert_equal Task::Status::ACTIVE, create_organization_rating_comment.status
  26 + assert_difference 'Comment.count' do
  27 + create_organization_rating_comment.finish
  28 + end
  29 + end
  30 +
  31 + test "do not create comment when cancel TASK" do
  32 + create_organization_rating_comment = CreateOrganizationRatingComment.create!(
  33 + :requestor => @person,
  34 + :organization_rating_id => @rating.id,
  35 + :target => @community,
  36 + :body => "sample comment"
  37 + )
  38 + assert_equal Task::Status::ACTIVE, create_organization_rating_comment.status
  39 + assert_no_difference 'Comment.count' do
  40 + create_organization_rating_comment.cancel
  41 + end
  42 + end
  43 +
  44 +end
... ...
plugins/organization_ratings/test/unit/organization_rating_test.rb
1   -require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper'
2   -
  1 +require 'test_helper'
3 2 class OrganizationRatingTest < ActiveSupport::TestCase
  3 +
  4 + def setup
  5 + @person = create_user('Mario').person
  6 + @person.email = "person@email.com"
  7 + @person.save
  8 + @community = fast_create(Community)
  9 + @adminuser = Person[create_admin_user(Environment.default)]
  10 + @rating = fast_create(OrganizationRating, {:value => 1,
  11 + :person_id => @person.id,
  12 + :organization_id => @community.id,
  13 + :created_at => DateTime.now,
  14 + :updated_at => DateTime.now,
  15 + })
  16 + end
  17 +
4 18 test "The value must be between 1 and 5" do
5 19 organization_rating1 = OrganizationRating.new :value => -1
6 20 organization_rating2 = OrganizationRating.new :value => 6
... ... @@ -21,57 +35,58 @@ class OrganizationRatingTest &lt; ActiveSupport::TestCase
21 35 assert_equal false, organization_rating2.errors[:value].include?("must be between 1 and 5")
22 36 end
23 37  
24   - test "Create task for create a rating comment" do
25   - person = create_user('molly').person
26   - person.email = "person@email.com"
27   - person.save!
  38 + test "false return when no active tasks for an Organization Rating" do
  39 + assert_not @rating.task_active?
  40 + end
28 41  
29   - community = fast_create(Community)
30   - community.add_admin(person)
  42 + test "true return when an active task exists for an Organization Rating" do
  43 + CreateOrganizationRatingComment.create!(
  44 + :organization_rating_id => @rating.id,
  45 + :target => @community,
  46 + :requestor => @person)
31 47  
32   - organization_rating = OrganizationRating.create!(
33   - :value => 3,
34   - :person => person,
35   - :organization => community
36   - )
37   -
38   - create_organization_rating_comment = CreateOrganizationRatingComment.create!(
39   - :requestor => person,
40   - :organization_rating_id => organization_rating.id,
41   - :target => community
42   - )
  48 + assert_equal Task::Status::ACTIVE, CreateOrganizationRatingComment.last.status
  49 + assert @rating.task_active?
  50 + end
43 51  
44   - assert community.tasks.include?(create_organization_rating_comment)
  52 + test "return false when an cancelled task exists for an Organization Rating" do
  53 + CreateOrganizationRatingComment.create!(
  54 + :organization_rating_id => @rating.id,
  55 + :target => @community,
  56 + :requestor => @person)
  57 + CreateOrganizationRatingComment.last.cancel
  58 + assert_not @rating.task_active?
45 59 end
46 60  
47   - test "Check comment message when Task status = ACTIVE" do
48   - person = create_user('molly').person
49   - person.email = "person@email.com"
50   - person.save!
  61 + test "display report moderation message to community admin" do
  62 + moderator = create_user('moderator')
  63 + @community.add_admin(moderator.person)
  64 + @rating.stubs(:task_active?).returns(true)
  65 + assert @rating.display_moderation_message(@adminuser)
  66 + end
51 67  
52   - community = fast_create(Community)
53   - community.add_admin(person)
  68 + test "display report moderation message to owner" do
  69 + @rating.stubs(:task_active?).returns(true)
  70 + assert @rating.display_moderation_message(@person)
  71 + end
54 72  
  73 + test "do not display report moderation message to regular user" do
  74 + regular_person = fast_create(Person)
  75 + @rating.stubs(:task_active?).returns(true)
  76 + assert_not @rating.display_moderation_message(regular_person)
  77 + end
55 78  
56   - organization_rating = OrganizationRating.create!(
57   - :value => 3,
58   - :person => person,
59   - :organization => community
60   - )
  79 + test "do not display report moderation message to not logged user" do
  80 + @rating.stubs(:task_active?).returns(true)
  81 + assert_not @rating.display_moderation_message(nil)
  82 + end
61 83  
62   - create_organization_rating_comment = CreateOrganizationRatingComment.create!(
63   - :requestor => person,
64   - :organization_rating_id => organization_rating.id,
65   - :target => community,
66   - :body => "sample comment"
67   - )
68   - assert_equal 1, create_organization_rating_comment.status
69   - message = "Comment waiting for approval"
70   - comment = Comment.find_by_id(create_organization_rating_comment.organization_rating_comment_id)
71   - assert_equal message, comment.body
  84 + test "do not display report moderation message no active task exists" do
  85 + @rating.stubs(:task_active?).returns(false)
  86 + assert_not @rating.display_moderation_message(@person)
72 87 end
73 88  
74   - test "Check comment message when Task status = CANCELLED" do
  89 + test "Create task for create a rating comment" do
75 90 person = create_user('molly').person
76 91 person.email = "person@email.com"
77 92 person.save!
... ... @@ -79,7 +94,6 @@ class OrganizationRatingTest &lt; ActiveSupport::TestCase
79 94 community = fast_create(Community)
80 95 community.add_admin(person)
81 96  
82   -
83 97 organization_rating = OrganizationRating.create!(
84 98 :value => 3,
85 99 :person => person,
... ... @@ -89,51 +103,12 @@ class OrganizationRatingTest &lt; ActiveSupport::TestCase
89 103 create_organization_rating_comment = CreateOrganizationRatingComment.create!(
90 104 :requestor => person,
91 105 :organization_rating_id => organization_rating.id,
92   - :target => community,
93   - :body => "sample comment"
94   - )
95   - create_organization_rating_comment.cancel
96   - assert_equal 2, create_organization_rating_comment.status
97   - message = "Comment rejected"
98   - comment = Comment.find_by_id(create_organization_rating_comment.organization_rating_comment_id)
99   - assert_equal message, comment.body
100   - end
101   -
102   - test "Check comment message when Task status = FINISHED" do
103   - person = create_user('molly').person
104   - person.email = "person@email.com"
105   - person.save!
106   -
107   - community = fast_create(Community)
108   - community.add_admin(person)
109   -
110   - comment = Comment.create!(source: community,
111   - body: "regular comment",
112   - author: person)
113   -
114   - organization_rating = OrganizationRating.create!(
115   - :value => 3,
116   - :person => person,
117   - :organization => community,
118   - :comment => comment
  106 + :target => community
119 107 )
120 108  
121   - create_organization_rating_comment = CreateOrganizationRatingComment.create!(
122   - :body => comment.body,
123   - :requestor => organization_rating.person,
124   - :organization_rating_id => organization_rating.id,
125   - :target => organization_rating.organization,
126   - :body => "sample comment"
127   - )
128   -
129   - create_organization_rating_comment.finish
130   - assert_equal 3, create_organization_rating_comment.status
131   - message = "sample comment"
132   - comment = Comment.find_by_id(create_organization_rating_comment.organization_rating_comment_id)
133   - assert_equal message, comment.body
  109 + assert community.tasks.include?(create_organization_rating_comment)
134 110 end
135 111  
136   -
137 112 test "Should calculate community's rating average" do
138 113 community = fast_create Community
139 114 p1 = fast_create Person, :name=>"Person 1"
... ...
plugins/organization_ratings/views/organization_ratings_plugin_profile/_new_rating_fields.html.erb
... ... @@ -19,13 +19,12 @@
19 19  
20 20 <% if @rating_available %>
21 21 <div class="star-rate-form">
22   - <div data-rate-url=<%= url_for controller: "organization_ratings_plugin_profile", :action => "rate" %>>
  22 + <div data-rate-url='<%= url_for controller: "organization_ratings_plugin_profile", :action => "rate" %>'>
23 23 <div class="star-rate-text">
24 24 <%= @plugins.dispatch(:organization_ratings_plugin_star_message).collect { |content| instance_exec(&content) }.join("") %>
25 25 </div>
26 26  
27 27 <div class="star-container" data-min-rate="<%= min_rate %>">
28   -
29 28 <% (1..5).each do |rate_number| %>
30 29 <% if rate_number <= default_rating %>
31 30 <div class="star-positive" data-star-rate="<%= rate_number %>"></div>
... ... @@ -43,8 +42,8 @@
43 42 <div class="star-comment-container">
44 43 <%= form_for :comments do |c| %>
45 44 <div class="formfieldline formfield type-text">
46   - <%= c.label :body, _('Comment (Optional):'), :class => "formlabel" %>
47   - <%= c.text_area :body %>
  45 + <%= c.label :body, _('Comment (Optional):'), :class => "formlabel" %>
  46 + <%= c.text_area :body %>
48 47 </div>
49 48  
50 49 <%= @plugins.dispatch(:organization_ratings_plugin_comments_extra_fields).collect { |content| instance_exec(&content) }.join("") %>
... ... @@ -57,24 +56,22 @@
57 56 <input type="hidden" id="minimum_stars" name="organization_rating_min_value" value="<%= min_rate %>">
58 57 <% end %>
59 58 </div>
  59 + </div>
  60 + <% elsif env_organization_ratings_config.vote_once %>
  61 + <div class="star-rate-form rating-vote-once">
  62 + <%= _("Hi, %s! The administrators set that you can vote") % current_user.name %>
  63 + <strong><%= _("only once") %></strong>
  64 + <%= _("for this %s.") % profile.class.name.downcase %>
  65 + <%= render :partial => 'shared/rating_button', :locals => { :disabled => true } %>
  66 + </div>
  67 + <% else %>
  68 + <div class="star-rate-form rating-cooldown">
  69 + <%= _("Hi, %s! The administrators set the minimum time of") % current_user.name %>
  70 + <strong><%= _("%d hour(s)") % env_organization_ratings_config.cooldown %></strong>
  71 + <%= _("between each evaluation.") %>
60 72  
61   - <% elsif env_organization_ratings_config.vote_once %>
62   - <div class="star-rate-form rating-vote-once">
63   - <%= _("Hi, %s! The administrators set that you can vote") % current_user.name %>
64   - <strong><%= _("only once") %></strong>
65   - <%= _("for this %s.") % profile.class.name.downcase %>
66   - <%= render :partial => 'shared/rating_button', :locals => { :disabled => true } %>
67   - </div>
68   - <% else %>
69   - <div class="star-rate-form rating-cooldown">
70   - <%= _("Hi, %s! The administrators set the minimum time of") % current_user.name %>
71   - <strong><%= _("%d hour(s)") % env_organization_ratings_config.cooldown %></strong>
72   - <%= _("between each evaluation.") %>
73   -
74   - <%= render :partial => 'shared/rating_button', :locals => { :disabled => true } %>
75   - </div>
76   - <% end %>
77   -
  73 + <%= render :partial => 'shared/rating_button', :locals => { :disabled => true } %>
  74 + </div>
  75 + <% end %>
78 76  
79   - </div>
80 77 </div>
... ...
plugins/organization_ratings/views/shared/_user_rating_container.html.erb
... ... @@ -25,9 +25,13 @@
25 25 </div>
26 26  
27 27 <div class="user-testimony">
28   - <%= user_rate.comment.nil? ? _("No comment") : user_rate.comment.body %>
  28 + <% if user_rate.display_moderation_message(user) %>
  29 + <p class="moderation-msg"><%= _("Report waiting for approval") %></p>
  30 + <% end %>
  31 + <% if user_rate.comment.present? %>
  32 + <p class="comment-body"> <%= user_rate.comment.body %> </p>
  33 + <% end %>
29 34 </div>
30   -
31   - <%= @plugins.dispatch(:organization_ratings_plugin_extra_fields_show_data, user_rate).collect { |content| instance_exec(&content) }.join("") %>
  35 + <%= @plugins.dispatch(:organization_ratings_plugin_container_extra_fields, user_rate).collect { |content| instance_exec(&content) }.join("") %>
32 36 </div>
33 37 </div>
... ...
plugins/organization_ratings/views/tasks/_create_organization_rating_comment_accept_details.html.erb
1 1 <div class="organization-rating-comment-body">
2   - <%= _("Comment:")%>
3   - <%= "\"#{task.body}\""%>
  2 + <% rating = OrganizationRating.find(task.organization_rating_id) %>
  3 + <%= @plugins.dispatch(:organization_ratings_plugin_task_extra_fields, rating).collect{ |content| instance_exec(&content) }.join("") %>
  4 + <div class="task-comment">
  5 + <span><%= _("Description:")%></span>
  6 + <p><%= "\"#{task.body}\""%></p>
  7 + </div>
  8 +
  9 + <span class="rating-notice"><%= _("* The rating score is not moderated.")%></span>
  10 + <div class="task-star-container">
  11 + <% (1..5).each do |star_number| %>
  12 + <% if star_number <= rating.value %>
  13 + <div class="medium-star-positive"></div>
  14 + <% else %>
  15 + <div class="medium-star-negative"></div>
  16 + <% end %>
  17 + <% end %>
  18 + </div>
4 19 </div>
... ...
public/stylesheets/tasks.scss
... ... @@ -27,6 +27,7 @@ div.pending-tasks {
27 27 }
28 28  
29 29 .task_box {
  30 + overflow: hidden;
30 31 position: relative;
31 32 border: 1px solid #888;
32 33 -moz-border-radius: 10px;
... ...