Class: Decidim::Meetings::CloseMeetingType
- Inherits:
-
Api::Types::BaseMutation
- Object
- Api::Types::BaseMutation
- Decidim::Meetings::CloseMeetingType
- Defined in:
- lib/decidim/api/mutations/close_meeting_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
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/decidim/api/mutations/close_meeting_type.rb', line 44 def (attributes:, locale:, toggle_translations:) raise Decidim::Api::Errors::MutationNotAuthorizedError, I18n.t("decidim.api.errors.unauthorized_mutation") unless [ super, allowed_to?(:close, :meeting, object, context), object.published?, object.closed? == false, object.withdrawn? == false ].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 35 36 37 38 39 40 41 42 |
# File 'lib/decidim/api/mutations/close_meeting_type.rb', line 15 def resolve(attributes:, locale:, toggle_translations:) set_locale(locale:, toggle_translations:) closing_report = attributes.to_h.fetch(:closing_report, object.closing_report) attendees_count = attributes.to_h.fetch(:attendees_count, object.attendees_count) proposal_ids = Array(attributes.to_h.fetch(:proposal_ids, [])).map(&:to_i) closed_at = attributes.to_h.fetch(:closed_at, Time.current) params = { closing_report:, attendees_count:, proposal_ids:, closed_at:, proposals: object.sibling_scope(:proposals) } form = form(Decidim::Meetings::CloseMeetingForm).from_params(params) CloseMeeting.call(form, object) do on(:ok) do return object.reload end on(:invalid) do raise Decidim::Api::Errors::AttributeValidationError, form.errors end end end |