approve_article.rb
3.01 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
class ApproveArticle < Task
serialize :data, Hash
validates_presence_of :requestor_id, :target_id
def article_title
article ? article.title : _('(The original text was removed)')
end
def data
self[:data] ||= {}
end
def article
Article.find_by_id data[:article_id]
end
def article= value
data[:article_id] = value.id
end
def name
data[:name].blank? ? (article ? article.name : _("Article removed.")) : data[:name]
end
def name= value
data[:name] = value
end
def closing_statment
data[:closing_statment]
end
def closing_statment= value
data[:closing_statment] = value
end
def article_parent_id= value
data[:parent_id] = value
end
def article_parent_id
data[:parent_id]
end
def article_parent
Article.find_by_id article_parent_id.to_i
end
def article_parent= value
self.article_parent_id = value.id
end
def highlighted= value
data[:highlighted] = value
end
def highlighted
data[:highlighted]
end
def abstract= value
data[:abstract] = value
end
def abstract
data[:abstract].blank? ? (article ? article.abstract : '') : data[:abstract]
end
def body= value
data[:body] = value
end
def body
data[:body].blank? ? (article ? article.body : "") : data[:body]
end
def perform
article.copy!(:name => name, :abstract => abstract, :body => body, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted, :source => article.source)
end
def title
_("New article")
end
def icon
result = {:type => :defined_image, :src => '/images/icons-app/article-minor.png', :name => name}
result.merge({:url => article.url}) if article
return result
end
def linked_subject
{:text => name, :url => article.url} if article
end
def information
if article
{:message => _('%{requestor} wants to publish the article: %{linked_subject}.')}
else
{:message => _("The article was removed.")}
end
end
def accept_details
true
end
def default_decision
if article
'skip'
else
'reject'
end
end
def accept_disabled?
article.blank?
end
def target_notification_description
_('%{requestor} wants to publish the article: %{article}.') % {:requestor => requestor.name, :article => article.name}
end
def target_notification_message
return nil if target.organization? && !target.moderated_articles?
target_notification_description + "\n\n" +
_('You need to login on %{system} in order to approve or reject this article.') % { :system => target.environment.name }
end
def task_finished_message
if !closing_statment.blank?
_("Your request for publishing the article \"%{article}\" was approved. Here is the comment left by the admin who approved your article:\n\n%{comment} ") % {:article => name, :comment => closing_statment}
else
_('Your request for publishing the article "%{article}" was approved.') % {:article => name}
end
end
end