Commit f9404f285440386c1e740c858e8bb0da405b656d
1 parent
1bd718a5
Exists in
master
and in
9 other branches
creating proposal task
Showing
2 changed files
with
193 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,189 @@ |
| 1 | +class ProposalsDiscussionPlugin::ProposalTask < Task | |
| 2 | + | |
| 3 | + validates_presence_of :requestor_id, :target_id | |
| 4 | + validates_associated :article_object | |
| 5 | + | |
| 6 | + settings_items :name, :type => String | |
| 7 | + settings_items :ip_address, :type => String | |
| 8 | + settings_items :user_agent, :type => String | |
| 9 | + settings_items :referrer, :type => String | |
| 10 | + settings_items :article, :type => Hash, :default => {} | |
| 11 | + settings_items :closing_statment, :article_parent_id | |
| 12 | + | |
| 13 | + before_create do |task| | |
| 14 | + if !task.target.nil? | |
| 15 | + organization = task.target | |
| 16 | + responsible_candidates = organization.members.by_role(organization.roles.reject {|r| !r.has_permission?('perform_task')}) | |
| 17 | + task.responsible = responsible_candidates.sample | |
| 18 | + end | |
| 19 | + end | |
| 20 | + | |
| 21 | + after_create :schedule_spam_checking | |
| 22 | + | |
| 23 | + def schedule_spam_checking | |
| 24 | + self.delay.check_for_spam | |
| 25 | + end | |
| 26 | + | |
| 27 | + def sender | |
| 28 | + requestor.name if requestor | |
| 29 | + end | |
| 30 | + | |
| 31 | + def article_parent | |
| 32 | + Article.find_by_id article_parent_id.to_i | |
| 33 | + end | |
| 34 | + | |
| 35 | + def article_object | |
| 36 | + if @article_object.nil? | |
| 37 | + @article_object = article_type.new(article.merge(target.present? ? {:profile => target} : {}).except(:type)) | |
| 38 | + @article_object.parent = article_parent | |
| 39 | + @article_object.author = requestor if requestor.present? | |
| 40 | + end | |
| 41 | + @article_object | |
| 42 | + end | |
| 43 | + | |
| 44 | + def article_type | |
| 45 | + if article[:type].present? | |
| 46 | + type = article[:type].constantize | |
| 47 | + return type if type < Article | |
| 48 | + end | |
| 49 | + TinyMceArticle | |
| 50 | + end | |
| 51 | + | |
| 52 | + def perform | |
| 53 | + article_object.save! | |
| 54 | + end | |
| 55 | + | |
| 56 | + def title | |
| 57 | + _("New proposal") | |
| 58 | + end | |
| 59 | + | |
| 60 | + def article_abstract | |
| 61 | + article[:abstract] | |
| 62 | + end | |
| 63 | + | |
| 64 | + def abstract | |
| 65 | + article_abstract | |
| 66 | + end | |
| 67 | + | |
| 68 | + | |
| 69 | + def information | |
| 70 | + {:message => _("%{requestor} wants to send the following proposal. <br/>%{abstract}"), :variables => {:abstract => abstract}} | |
| 71 | + end | |
| 72 | + | |
| 73 | + def icon | |
| 74 | + {:type => :profile_image, :profile => requestor, :url => requestor.url} | |
| 75 | + end | |
| 76 | + | |
| 77 | +# def permission | |
| 78 | +# :#manage_memberships | |
| 79 | +# end | |
| 80 | + | |
| 81 | + def target_notification_description | |
| 82 | + _('%{requestor} wants to send a proposal.') % {:requestor => requestor.name} | |
| 83 | + end | |
| 84 | + | |
| 85 | + def target_notification_message | |
| 86 | + target_notification_description + "\n\n" + | |
| 87 | + _('You will need login to %{system} in order to accept or reject the proposal sent by %{requestor}') % { :system => target.environment.name, :requestor => requestor.name} | |
| 88 | + end | |
| 89 | + | |
| 90 | +# def article_title | |
| 91 | +# article ? article.title : _('(The original text was removed)') | |
| 92 | +# end | |
| 93 | + | |
| 94 | +# def article | |
| 95 | +# Article.find_by_id data[:article_id] | |
| 96 | +# end | |
| 97 | + | |
| 98 | +# def article= value | |
| 99 | +# data[:article_id] = value.id | |
| 100 | +# end | |
| 101 | + | |
| 102 | +# def name | |
| 103 | +# data[:name].blank? ? (article ? article.name : _("Article removed.")) : data[:name] | |
| 104 | +# end | |
| 105 | +# | |
| 106 | +# def name= value | |
| 107 | +# data[:name] = value | |
| 108 | +# end | |
| 109 | + | |
| 110 | +# def article_parent | |
| 111 | +# Article.find_by_id article_parent_id.to_i | |
| 112 | +# end | |
| 113 | +# | |
| 114 | +# def article_parent= value | |
| 115 | +# self.article_parent_id = value.id | |
| 116 | +# end | |
| 117 | +# | |
| 118 | +# def abstract= value | |
| 119 | +# data[:abstract] = value | |
| 120 | +# end | |
| 121 | +# | |
| 122 | +# def abstract | |
| 123 | +# data[:abstract].blank? ? (article ? article.abstract : '') : data[:abstract] | |
| 124 | +# end | |
| 125 | +# | |
| 126 | +# def body= value | |
| 127 | +# data[:body] = value | |
| 128 | +# end | |
| 129 | +# | |
| 130 | +# def body | |
| 131 | +# data[:body].blank? ? (article ? article.body : "") : data[:body] | |
| 132 | +# end | |
| 133 | +# | |
| 134 | +# def icon | |
| 135 | +# result = {:type => :defined_image, :src => '/images/icons-app/article-minor.png', :name => name} | |
| 136 | +# result.merge({:url => article.url}) if article | |
| 137 | +# return result | |
| 138 | +# end | |
| 139 | + | |
| 140 | +# def linked_subject | |
| 141 | +#raise article.inspect | |
| 142 | +# {:text => name, :url => article.url} if article | |
| 143 | +# end | |
| 144 | + | |
| 145 | + def accept_details | |
| 146 | + true | |
| 147 | + end | |
| 148 | + | |
| 149 | + def reject_details | |
| 150 | + true | |
| 151 | + end | |
| 152 | + | |
| 153 | + def default_decision | |
| 154 | + if article | |
| 155 | + 'skip' | |
| 156 | + else | |
| 157 | + 'reject' | |
| 158 | + end | |
| 159 | + end | |
| 160 | + | |
| 161 | + def accept_disabled? | |
| 162 | + article.blank? | |
| 163 | + end | |
| 164 | + | |
| 165 | + def task_finished_message | |
| 166 | + if !closing_statment.blank? | |
| 167 | + _("Your request for publishing the proposal \"%{article}\" was approved. Here is the comment left by the admin who approved your proposal:\n\n%{comment} ") % {:article => name, :comment => closing_statment} | |
| 168 | + else | |
| 169 | + _('Your request for publishing the proposal "%{article}" was approved.') % {:article => name} | |
| 170 | + end | |
| 171 | + end | |
| 172 | + | |
| 173 | + def task_cancelled_message | |
| 174 | + message = _('Your request for publishing the proposal "%{article}" was rejected.') % {:article => name} | |
| 175 | + if !reject_explanation.blank? | |
| 176 | + message += " " + _("Here is the reject explanation left by the moderator who rejected your proposal: \n\n%{reject_explanation}") % {:reject_explanation => reject_explanation} | |
| 177 | + end | |
| 178 | + message | |
| 179 | + end | |
| 180 | + | |
| 181 | + def after_spam! | |
| 182 | + SpammerLogger.log(ip_address, self) | |
| 183 | + self.delay.marked_as_spam | |
| 184 | + end | |
| 185 | + | |
| 186 | + def after_ham! | |
| 187 | + self.delay.marked_as_ham | |
| 188 | + end | |
| 189 | +end | ... | ... |
views/tasks/proposals_discussion_plugin/_proposal_task_accept_details.html.erb
0 → 100644
| ... | ... | @@ -0,0 +1,4 @@ |
| 1 | +<%= select_profile_folder(_('Select the folder where the article must be published'), "tasks[#{task.id}][task][article_parent_id]", task.target) %> | |
| 2 | + | |
| 3 | +<%= labelled_form_field _('Comment for author'), f.text_field(:closing_statment, :style => 'width: 488px; height: 30px') %> | |
| 4 | + | ... | ... |