Commit 2dd9c858225244629fbcc3d62a4a4b8cb2d70913

Authored by Victor Costa
2 parents 0bf25818 0c7ed580

Merge branch 'master' into staging_rails4

app/views/tasks/_task.html.erb
@@ -2,6 +2,10 @@ @@ -2,6 +2,10 @@
2 2
3 <%= render :partial => 'task_icon', :locals => {:task => task} %> 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 <% if !@view_only && profile.organization? && @responsible_candidates.present? %> 9 <% if !@view_only && profile.organization? && @responsible_candidates.present? %>
6 <div class="task_responsible"> 10 <div class="task_responsible">
7 <span class="label"><%= _('Assign to:') %></span> 11 <span class="label"><%= _('Assign to:') %></span>
@@ -41,9 +45,6 @@ @@ -41,9 +45,6 @@
41 <% end %> 45 <% end %>
42 </div><!-- class="task_decisions" --> 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 <div class="task_information"> 49 <div class="task_information">
49 <%= task_information(task) %> 50 <%= task_information(task) %>
plugins/organization_ratings/controllers/organization_ratings_plugin_profile_controller.rb
@@ -54,23 +54,18 @@ class OrganizationRatingsPluginProfileController &lt; ProfileController @@ -54,23 +54,18 @@ class OrganizationRatingsPluginProfileController &lt; ProfileController
54 end 54 end
55 55
56 def create_rating_comment(rating) 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 end 66 end
67 end 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 def permission 69 def permission
75 :manage_memberships 70 :manage_memberships
76 end 71 end
plugins/organization_ratings/db/migrate/20151203121430_destroy_rejected_reports.rb 0 → 100644
@@ -0,0 +1,14 @@ @@ -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,28 +9,14 @@ class CreateOrganizationRatingComment &lt; Task
9 attr_accessible :organization_rating_id, :body, :requestor 9 attr_accessible :organization_rating_id, :body, :requestor
10 attr_accessible :reject_explanation, :target 10 attr_accessible :reject_explanation, :target
11 11
12 - before_save :update_comment_body  
13 -  
14 DATA_FIELDS = ['body'] 12 DATA_FIELDS = ['body']
15 DATA_FIELDS.each do |field| 13 DATA_FIELDS.each do |field|
16 settings_items field.to_sym 14 settings_items field.to_sym
17 end 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 if (self.body && !self.body.blank?) 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 self.organization_rating_comment_id = comment.id 21 self.organization_rating_comment_id = comment.id
36 link_comment_with_its_rating(comment) 22 link_comment_with_its_rating(comment)
@@ -43,26 +29,16 @@ class CreateOrganizationRatingComment &lt; Task @@ -43,26 +29,16 @@ class CreateOrganizationRatingComment &lt; Task
43 rating.save 29 rating.save
44 end 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 def accept_details 32 def accept_details
57 true 33 true
58 end 34 end
59 35
60 def title 36 def title
61 - _("New Comment") 37 + _("New Report")
62 end 38 end
63 39
64 def information 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 {:requestor_url => url_for(self.requestor.url), :requestor => self.requestor.name, :target_class => _(self.target.class.name)} 42 {:requestor_url => url_for(self.requestor.url), :requestor => self.requestor.name, :target_class => _(self.target.class.name)}
67 43
68 {:message => message} 44 {:message => message}
@@ -87,45 +63,48 @@ class CreateOrganizationRatingComment &lt; Task @@ -87,45 +63,48 @@ class CreateOrganizationRatingComment &lt; Task
87 end 63 end
88 64
89 def target_notification_description 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 {:requestor => self.requestor.name, :target => _(self.target.class.name.downcase) } 67 {:requestor => self.requestor.name, :target => _(self.target.class.name.downcase) }
92 end 68 end
93 69
94 def target_notification_message 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 \"%{target_name}\". 72 \"%{target_name}\".
97 You have to approve or reject it through the \"Pending Validations\" 73 You have to approve or reject it through the \"Pending Validations\"
98 section in your control panel.\n") % 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 end 78 end
101 79
102 def task_created_message 80 def task_created_message
103 - _("Your request for commenting at %{target} was 81 + _("Your report at %{target_class} \"%{target}\" was
104 just sent. The administrator will receive it and will approve or 82 just sent. The administrator will receive it and will approve or
105 reject your request according to his methods and criteria. 83 reject your request according to his methods and criteria.
106 You will be notified as soon as environment administrator has a position 84 You will be notified as soon as environment administrator has a position
107 about your request.") % 85 about your request.") %
108 - { :target => self.target.name } 86 + { :target_class => _(self.target.class.name.downcase), :target => self.target.name }
109 end 87 end
110 88
111 def task_cancelled_message 89 def task_cancelled_message
112 - _("Your request for commenting at %{target} was 90 + _("Your report at %{target_class} \"%{target}\" was
113 not approved by the administrator. The following explanation 91 not approved by the administrator. The following explanation
114 was given: \n\n%{explanation}") % 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 :explanation => self.reject_explanation } 95 :explanation => self.reject_explanation }
117 end 96 end
118 97
119 def task_finished_message 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 end 102 end
124 103
125 private 104 private
126 105
127 def ratings_url 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 end 108 end
130 109
131 end 110 end
plugins/organization_ratings/lib/organization_rating.rb
@@ -13,6 +13,18 @@ class OrganizationRating &lt; ActiveRecord::Base @@ -13,6 +13,18 @@ class OrganizationRating &lt; ActiveRecord::Base
13 validates :organization_id, :person_id, 13 validates :organization_id, :person_id,
14 :presence => true 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 def self.average_rating organization_id 29 def self.average_rating organization_id
18 average = OrganizationRating.where(organization_id: organization_id).average(:value) 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,7 +22,11 @@ class OrganizationRatingsPlugin &lt; Noosfero::Plugin
22 nil 22 nil
23 end 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 nil 30 nil
27 end 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,6 +17,7 @@ class OrganizationRatingsPluginProfileControllerTest &lt; ActionController::TestCas
17 17
18 @person = create_user('testuser').person 18 @person = create_user('testuser').person
19 @community = Community.create(:name => "TestCommunity") 19 @community = Community.create(:name => "TestCommunity")
  20 + @community.add_admin @person
20 @enterprise = fast_create(Enterprise) 21 @enterprise = fast_create(Enterprise)
21 @config = OrganizationRatingsConfig.instance 22 @config = OrganizationRatingsConfig.instance
22 login_as(@person.identifier) 23 login_as(@person.identifier)
@@ -36,13 +37,13 @@ class OrganizationRatingsPluginProfileControllerTest &lt; ActionController::TestCas @@ -36,13 +37,13 @@ class OrganizationRatingsPluginProfileControllerTest &lt; ActionController::TestCas
36 assert_redirected_to @community.url 37 assert_redirected_to @community.url
37 end 38 end
38 39
39 - test "Create community_rating without comment body" do 40 + test "create community_rating without comment body" do
40 post :new_rating, profile: @community.identifier, :comments => {:body => ""}, :organization_rating_value => 2 41 post :new_rating, profile: @community.identifier, :comments => {:body => ""}, :organization_rating_value => 2
41 42
42 assert_equal "#{@community.name} successfully rated!", session[:notice] 43 assert_equal "#{@community.name} successfully rated!", session[:notice]
43 end 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 post :new_rating, profile: @community.identifier, :comments => {:body => ""}, :organization_rating_value => nil 47 post :new_rating, profile: @community.identifier, :comments => {:body => ""}, :organization_rating_value => nil
47 48
48 assert_equal "Sorry, there were problems rating this profile.", session[:notice] 49 assert_equal "Sorry, there were problems rating this profile.", session[:notice]
@@ -76,13 +77,13 @@ class OrganizationRatingsPluginProfileControllerTest &lt; ActionController::TestCas @@ -76,13 +77,13 @@ class OrganizationRatingsPluginProfileControllerTest &lt; ActionController::TestCas
76 block = StatisticsBlock.new 77 block = StatisticsBlock.new
77 enterprise = fast_create(Enterprise) 78 enterprise = fast_create(Enterprise)
78 post :new_rating, profile: enterprise.identifier, :comments => {:body => "body board"}, :organization_rating_value => 1 79 post :new_rating, profile: enterprise.identifier, :comments => {:body => "body board"}, :organization_rating_value => 1
  80 + CreateOrganizationRatingComment.last.finish
79 enterprise.reload 81 enterprise.reload
80 @environment.reload 82 @environment.reload
81 block.expects(:owner).at_least_once.returns(@environment) 83 block.expects(:owner).at_least_once.returns(@environment)
82 assert_equal 1, block.comments 84 assert_equal 1, block.comments
83 end 85 end
84 86
85 -  
86 test "should count organization ratings on statistic block when block owner = Profile" do 87 test "should count organization ratings on statistic block when block owner = Profile" do
87 @config.cooldown = 0 88 @config.cooldown = 0
88 @config.save 89 @config.save
@@ -91,13 +92,15 @@ class OrganizationRatingsPluginProfileControllerTest &lt; ActionController::TestCas @@ -91,13 +92,15 @@ class OrganizationRatingsPluginProfileControllerTest &lt; ActionController::TestCas
91 92
92 post :new_rating, profile: @community.identifier, :comments => {:body => "body board"}, :organization_rating_value => 1 93 post :new_rating, profile: @community.identifier, :comments => {:body => "body board"}, :organization_rating_value => 1
93 post :new_rating, profile: @community.identifier, :comments => {:body => "body surf"}, :organization_rating_value => 5 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 block.expects(:owner).at_least_once.returns(@community) 98 block.expects(:owner).at_least_once.returns(@community)
96 @community.reload 99 @community.reload
97 assert_equal 2, block.comments 100 assert_equal 2, block.comments
98 end 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 post :new_rating, profile: @community.identifier, :comments => {:body => ""}, :organization_rating_value => 3 104 post :new_rating, profile: @community.identifier, :comments => {:body => ""}, :organization_rating_value => 3
102 assert_no_match(/The administrators set the minimum time of/, @response.body) 105 assert_no_match(/The administrators set the minimum time of/, @response.body)
103 valid_rating = OrganizationRating.last 106 valid_rating = OrganizationRating.last
@@ -108,4 +111,81 @@ class OrganizationRatingsPluginProfileControllerTest &lt; ActionController::TestCas @@ -108,4 +111,81 @@ class OrganizationRatingsPluginProfileControllerTest &lt; ActionController::TestCas
108 111
109 assert_equal valid_rating.id, new_rating.id 112 assert_equal valid_rating.id, new_rating.id
110 end 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 end 191 end
plugins/organization_ratings/test/unit/create_organization_rating_comment_test.rb 0 → 100644
@@ -0,0 +1,44 @@ @@ -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 class OrganizationRatingTest < ActiveSupport::TestCase 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 test "The value must be between 1 and 5" do 18 test "The value must be between 1 and 5" do
5 organization_rating1 = OrganizationRating.new :value => -1 19 organization_rating1 = OrganizationRating.new :value => -1
6 organization_rating2 = OrganizationRating.new :value => 6 20 organization_rating2 = OrganizationRating.new :value => 6
@@ -21,57 +35,58 @@ class OrganizationRatingTest &lt; ActiveSupport::TestCase @@ -21,57 +35,58 @@ class OrganizationRatingTest &lt; ActiveSupport::TestCase
21 assert_equal false, organization_rating2.errors[:value].include?("must be between 1 and 5") 35 assert_equal false, organization_rating2.errors[:value].include?("must be between 1 and 5")
22 end 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 end 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 end 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 person = create_user('molly').person 90 person = create_user('molly').person
76 person.email = "person@email.com" 91 person.email = "person@email.com"
77 person.save! 92 person.save!
@@ -79,7 +94,6 @@ class OrganizationRatingTest &lt; ActiveSupport::TestCase @@ -79,7 +94,6 @@ class OrganizationRatingTest &lt; ActiveSupport::TestCase
79 community = fast_create(Community) 94 community = fast_create(Community)
80 community.add_admin(person) 95 community.add_admin(person)
81 96
82 -  
83 organization_rating = OrganizationRating.create!( 97 organization_rating = OrganizationRating.create!(
84 :value => 3, 98 :value => 3,
85 :person => person, 99 :person => person,
@@ -89,51 +103,12 @@ class OrganizationRatingTest &lt; ActiveSupport::TestCase @@ -89,51 +103,12 @@ class OrganizationRatingTest &lt; ActiveSupport::TestCase
89 create_organization_rating_comment = CreateOrganizationRatingComment.create!( 103 create_organization_rating_comment = CreateOrganizationRatingComment.create!(
90 :requestor => person, 104 :requestor => person,
91 :organization_rating_id => organization_rating.id, 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 end 110 end
135 111
136 -  
137 test "Should calculate community's rating average" do 112 test "Should calculate community's rating average" do
138 community = fast_create Community 113 community = fast_create Community
139 p1 = fast_create Person, :name=>"Person 1" 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,13 +19,12 @@
19 19
20 <% if @rating_available %> 20 <% if @rating_available %>
21 <div class="star-rate-form"> 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 <div class="star-rate-text"> 23 <div class="star-rate-text">
24 <%= @plugins.dispatch(:organization_ratings_plugin_star_message).collect { |content| instance_exec(&content) }.join("") %> 24 <%= @plugins.dispatch(:organization_ratings_plugin_star_message).collect { |content| instance_exec(&content) }.join("") %>
25 </div> 25 </div>
26 26
27 <div class="star-container" data-min-rate="<%= min_rate %>"> 27 <div class="star-container" data-min-rate="<%= min_rate %>">
28 -  
29 <% (1..5).each do |rate_number| %> 28 <% (1..5).each do |rate_number| %>
30 <% if rate_number <= default_rating %> 29 <% if rate_number <= default_rating %>
31 <div class="star-positive" data-star-rate="<%= rate_number %>"></div> 30 <div class="star-positive" data-star-rate="<%= rate_number %>"></div>
@@ -43,8 +42,8 @@ @@ -43,8 +42,8 @@
43 <div class="star-comment-container"> 42 <div class="star-comment-container">
44 <%= form_for :comments do |c| %> 43 <%= form_for :comments do |c| %>
45 <div class="formfieldline formfield type-text"> 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 </div> 47 </div>
49 48
50 <%= @plugins.dispatch(:organization_ratings_plugin_comments_extra_fields).collect { |content| instance_exec(&content) }.join("") %> 49 <%= @plugins.dispatch(:organization_ratings_plugin_comments_extra_fields).collect { |content| instance_exec(&content) }.join("") %>
@@ -57,24 +56,22 @@ @@ -57,24 +56,22 @@
57 <input type="hidden" id="minimum_stars" name="organization_rating_min_value" value="<%= min_rate %>"> 56 <input type="hidden" id="minimum_stars" name="organization_rating_min_value" value="<%= min_rate %>">
58 <% end %> 57 <% end %>
59 </div> 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 </div> 77 </div>
plugins/organization_ratings/views/shared/_user_rating_container.html.erb
@@ -25,9 +25,13 @@ @@ -25,9 +25,13 @@
25 </div> 25 </div>
26 26
27 <div class="user-testimony"> 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 </div> 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 </div> 36 </div>
33 </div> 37 </div>
plugins/organization_ratings/views/tasks/_create_organization_rating_comment_accept_details.html.erb
1 <div class="organization-rating-comment-body"> 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 </div> 19 </div>
public/stylesheets/tasks.scss
@@ -27,6 +27,7 @@ div.pending-tasks { @@ -27,6 +27,7 @@ div.pending-tasks {
27 } 27 }
28 28
29 .task_box { 29 .task_box {
  30 + overflow: hidden;
30 position: relative; 31 position: relative;
31 border: 1px solid #888; 32 border: 1px solid #888;
32 -moz-border-radius: 10px; 33 -moz-border-radius: 10px;