Class: Decidim::Debates::CloseDebateType
- Inherits:
-
Api::Types::BaseMutation
- Object
- Api::Types::BaseMutation
- Decidim::Debates::CloseDebateType
- Defined in:
- lib/decidim/api/mutations/close_debate_type.rb
Instance Method Summary collapse
- #authorized?(attributes:, locale:, toggle_translations:) ⇒ Boolean
- #resolve(attributes:, locale:, toggle_translations:) ⇒ Object
Instance Method Details
#authorized?(attributes:, locale:, toggle_translations:) ⇒ Boolean
36 37 38 39 40 41 42 43 44 |
# File 'lib/decidim/api/mutations/close_debate_type.rb', line 36 def (attributes:, locale:, toggle_translations:) raise Decidim::Api::Errors::MutationNotAuthorizedError, I18n.t("decidim.api.errors.unauthorized_mutation") unless [ super, allowed_to?(:close, :debate, object, context), !object.closed? ].all? true end |
#resolve(attributes:, locale:, toggle_translations:) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/decidim/api/mutations/close_debate_type.rb', line 15 def resolve(attributes:, locale:, toggle_translations:) set_locale(locale:, toggle_translations:) params = { id: object.id, conclusions: attributes.to_h.fetch(:conclusions, "") } form = form(Decidim::Debates::CloseDebateForm).from_params(params) Decidim::Debates::CloseDebate.call(form) do on(:ok) do |debate| return debate.reload end on(:invalid) do raise Decidim::Api::Errors::AttributeValidationError, form.errors end end end |