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,7 +23,7 @@ class ProposalsDiscussionPlugin::API < Grape::API | ||
| 23 | proposal_task.requestor = current_person | 23 | proposal_task.requestor = current_person |
| 24 | 24 | ||
| 25 | unless proposal_task.save | 25 | unless proposal_task.save |
| 26 | - render_api_errors!(proposal_task.article_object.errors.full_messages) | 26 | + render_api_errors!(proposal_task.errors) |
| 27 | end | 27 | end |
| 28 | {:success => true} | 28 | {:success => true} |
| 29 | #present proposal_task, :with => Entities::Task, :fields => params[:fields] | 29 | #present proposal_task, :with => Entities::Task, :fields => params[:fields] |
lib/proposals_discussion_plugin/proposal_task.rb
| 1 | class ProposalsDiscussionPlugin::ProposalTask < Task | 1 | class ProposalsDiscussionPlugin::ProposalTask < Task |
| 2 | - | ||
| 3 | has_and_belongs_to_many :categories, | 2 | has_and_belongs_to_many :categories, |
| 4 | class_name: "ProposalsDiscussionPlugin::TaskCategory", | 3 | class_name: "ProposalsDiscussionPlugin::TaskCategory", |
| 5 | join_table: :proposals_discussion_plugin_task_categories, | 4 | join_table: :proposals_discussion_plugin_task_categories, |
| @@ -10,9 +9,13 @@ class ProposalsDiscussionPlugin::ProposalTask < Task | @@ -10,9 +9,13 @@ class ProposalsDiscussionPlugin::ProposalTask < Task | ||
| 10 | 9 | ||
| 11 | validates_presence_of :requestor_id, :target_id | 10 | validates_presence_of :requestor_id, :target_id |
| 12 | validates_associated :article_object | 11 | validates_associated :article_object |
| 13 | - before_validation :simplify_abstract | 12 | + before_save :simplify_abstract |
| 13 | +# before_validation :simplify_abstract | ||
| 14 | validate :require_category | 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 | settings_items :name, :type => String | 20 | settings_items :name, :type => String |
| 18 | settings_items :ip_address, :type => String | 21 | settings_items :ip_address, :type => String |
| @@ -22,6 +25,10 @@ class ProposalsDiscussionPlugin::ProposalTask < Task | @@ -22,6 +25,10 @@ class ProposalsDiscussionPlugin::ProposalTask < Task | ||
| 22 | settings_items :closing_statment, :article_parent_id | 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 | scope :pending_evaluated, lambda { |profile, filter_type, filter_text| | 32 | scope :pending_evaluated, lambda { |profile, filter_type, filter_text| |
| 26 | self | 33 | self |
| 27 | .to(profile) | 34 | .to(profile) |
| @@ -269,14 +276,16 @@ class ProposalsDiscussionPlugin::ProposalTask < Task | @@ -269,14 +276,16 @@ class ProposalsDiscussionPlugin::ProposalTask < Task | ||
| 269 | 276 | ||
| 270 | protected | 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 | def require_category | 279 | def require_category |
| 277 | if categories.count == 0 && flagged? | 280 | if categories.count == 0 && flagged? |
| 278 | errors.add :categories, _('Select at least one category') | 281 | errors.add :categories, _('Select at least one category') |
| 279 | end | 282 | end |
| 280 | end | 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 | end | 291 | end |