app/commands/decidim/proposals/create_proposal.rb in decidim-proposals-0.6.8 vs app/commands/decidim/proposals/create_proposal.rb in decidim-proposals-0.7.0
- old
+ new
@@ -18,10 +18,11 @@
# - :ok when everything is valid, together with the proposal.
# - :invalid if the form wasn't valid and we couldn't proceed.
#
# Returns nothing.
def call
+ return broadcast(:invalid) if proposal_limit_reached?
return broadcast(:invalid) if form.invalid?
if process_attachments?
build_attachment
return broadcast(:invalid) if attachment_invalid?
@@ -82,9 +83,20 @@
form.current_feature.settings.attachments_allowed?
end
def process_attachments?
attachments_allowed? && attachment_present?
+ end
+
+ def proposal_limit_reached?
+ proposal_limit = form.current_feature.settings.proposal_limit
+
+ return false if proposal_limit.zero?
+ current_user_proposals.count >= proposal_limit
+ end
+
+ def current_user_proposals
+ Proposal.where(author: @current_user, feature: form.current_feature)
end
end
end
end