create_community_rating_comment.rb
2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
class CreateCommunityRatingComment < Task
include Rails.application.routes.url_helpers
validates_presence_of :requestor_id, :community_rating, :target_id
attr_accessible :community_rating, :source, :body, :requestor, :reject_explanation, :organization
belongs_to :source, :class_name => 'Community', :foreign_key => :source_id
belongs_to :community_rating
alias :organization :target
alias :organization= :target=
DATA_FIELDS = ['body']
DATA_FIELDS.each do |field|
settings_items field.to_sym
end
def perform
comment = Comment.create!(:source => self.source, :body => self.body, :author => self.requestor)
self.community_rating.comment = comment
self.community_rating.save!
end
def title
_("New Comment")
end
def information
message = _("<div class=\"comment\">%{requestor} wants to create a comment in the \"%{source}\" community.<br> Comment: <br> \"%{body}\"</div>") %
{:requestor => self.requestor.name, :source => self.source.name, :body => self.body }
{:message => message}
end
def reject_details
true
end
def icon
{:type => :profile_image, :profile => requestor, :url => requestor.url}
end
# tells if this request was rejected
def rejected?
self.status == Task::Status::CANCELLED
end
# tells if this request was appoved
def approved?
self.status == Task::Status::FINISHED
end
def target_notification_description
_('%{requestor} wants to create a comment in the \"%{source}\" community') %
{:requestor => self.requestor.name, :source => self.source.name }
end
def target_notification_message
_("User \"%{user}\" just requested to create a comment in the \"%{source}\" community.
You have to approve or reject it through the \"Pending Validations\"
section in your control panel.\n") %
{ :user => self.requestor.name, :source => self.source.name }
end
def task_created_message
_("Your request for commenting at %{source} was
just sent. Environment 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.") %
{ :source => self.source.name }
end
def task_cancelled_message
_("Your request for commenting at %{source} was
not approved by the environment administrator. The following explanation
was given: \n\n%{explanation}") %
{ :source => self.source.name,
:explanation => self.reject_explanation }
end
def task_finished_message
_('Your request for commenting was approved.
You can access %{url} to see your comment.') %
{ :url => mount_url }
end
private
def mount_url
identifier = self.source.identifier
# The use of url_for doesn't allow the /social within the Public Software
# portal. That's why the url is mounted so 'hard coded'
url = "#{self.environment.top_url}/profile/#{identifier}"
end
end