Commit df0def9cf96457ac789da99ea58ac0805425a369
1 parent
efef1fc9
Exists in
master
and in
7 other branches
fix avoid repeated tasks
Showing
2 changed files
with
17 additions
and
8 deletions
Show diff stats
lib/proposals_discussion_plugin/api.rb
| ... | ... | @@ -23,7 +23,7 @@ class ProposalsDiscussionPlugin::API < Grape::API |
| 23 | 23 | proposal_task.requestor = current_person |
| 24 | 24 | |
| 25 | 25 | unless proposal_task.save |
| 26 | - render_api_errors!(proposal_task.article_object.errors.full_messages) | |
| 26 | + render_api_errors!(proposal_task.errors) | |
| 27 | 27 | end |
| 28 | 28 | {:success => true} |
| 29 | 29 | #present proposal_task, :with => Entities::Task, :fields => params[:fields] | ... | ... |
lib/proposals_discussion_plugin/proposal_task.rb
| 1 | 1 | class ProposalsDiscussionPlugin::ProposalTask < Task |
| 2 | - | |
| 3 | 2 | has_and_belongs_to_many :categories, |
| 4 | 3 | class_name: "ProposalsDiscussionPlugin::TaskCategory", |
| 5 | 4 | join_table: :proposals_discussion_plugin_task_categories, |
| ... | ... | @@ -10,9 +9,13 @@ class ProposalsDiscussionPlugin::ProposalTask < Task |
| 10 | 9 | |
| 11 | 10 | validates_presence_of :requestor_id, :target_id |
| 12 | 11 | validates_associated :article_object |
| 13 | - before_validation :simplify_abstract | |
| 12 | + before_save :simplify_abstract | |
| 13 | +# before_validation :simplify_abstract | |
| 14 | 14 | validate :require_category |
| 15 | - validates_uniqueness_of :proposal_discussion_plugin_simplified_abstract, :scope => ['target_id'], :message => _("Cannot create duplicate proposal") | |
| 15 | + | |
| 16 | + validate :unique_simplified_abstract? | |
| 17 | + | |
| 18 | +# validates_uniqueness_of :proposal_discussion_plugin_simplified_abstract, :scope => ['target_id'], :message => _("Cannot create duplicate proposal") | |
| 16 | 19 | |
| 17 | 20 | settings_items :name, :type => String |
| 18 | 21 | settings_items :ip_address, :type => String |
| ... | ... | @@ -22,6 +25,10 @@ class ProposalsDiscussionPlugin::ProposalTask < Task |
| 22 | 25 | settings_items :closing_statment, :article_parent_id |
| 23 | 26 | |
| 24 | 27 | |
| 28 | + def simplify_abstract | |
| 29 | + self.proposal_discussion_plugin_simplified_abstract = ProposalsDiscussionPlugin::ProposalTask.simplify(self[:data][:article]["abstract"]) | |
| 30 | + end | |
| 31 | + | |
| 25 | 32 | scope :pending_evaluated, lambda { |profile, filter_type, filter_text| |
| 26 | 33 | self |
| 27 | 34 | .to(profile) |
| ... | ... | @@ -269,14 +276,16 @@ class ProposalsDiscussionPlugin::ProposalTask < Task |
| 269 | 276 | |
| 270 | 277 | protected |
| 271 | 278 | |
| 272 | - def simplify_abstract | |
| 273 | - proposal_discussion_plugin_simplified_abstract = ProposalsDiscussionPlugin::ProposalTask.simplify(self[:data][:article]["abstract"]) | |
| 274 | - end | |
| 275 | - | |
| 276 | 279 | def require_category |
| 277 | 280 | if categories.count == 0 && flagged? |
| 278 | 281 | errors.add :categories, _('Select at least one category') |
| 279 | 282 | end |
| 280 | 283 | end |
| 281 | 284 | |
| 285 | + def unique_simplified_abstract? | |
| 286 | + sa = ProposalsDiscussionPlugin::ProposalTask.simplify(self[:data][:article]["abstract"]) | |
| 287 | + r = ProposalsDiscussionPlugin::ProposalTask.find_by_sql ["SELECT 1 AS one FROM tasks WHERE tasks.type IN ('ProposalsDiscussionPlugin::ProposalTask') AND (tasks.proposal_discussion_plugin_simplified_abstract = ? AND tasks.target_id = ?) LIMIT 1", sa, target_id] | |
| 288 | + errors.add :base, _('This proposal has been previously registered') unless r.empty? | |
| 289 | + end | |
| 290 | + | |
| 282 | 291 | end | ... | ... |