Class: Decidim::Proposals::ProposalAnswerType
- Inherits:
-
Api::Types::BaseMutation
- Object
- Api::Types::BaseMutation
- Decidim::Proposals::ProposalAnswerType
- Defined in:
- lib/decidim/api/mutations/proposal_answer_type.rb
Instance Method Summary collapse
Instance Method Details
#authorized?(attributes:) ⇒ Boolean
37 38 39 40 41 42 |
# File 'lib/decidim/api/mutations/proposal_answer_type.rb', line 37 def (attributes:) = super && allowed_to?(:create, :proposal_answer, object, context, scope: :admin) raise Decidim::Api::Errors::MutationNotAuthorizedError, I18n.t("decidim.api.errors.unauthorized_mutation") unless true end |
#current_user ⇒ Object
44 45 46 |
# File 'lib/decidim/api/mutations/proposal_answer_type.rb', line 44 def current_user context[:current_user] end |
#resolve(attributes:) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/decidim/api/mutations/proposal_answer_type.rb', line 13 def resolve(attributes:) answer_content = attributes.to_h.fetch(:answer_content, object.answer) internal_state = attributes.to_h.fetch(:state, object.internal_state) params = attributes.to_h.reverse_merge( internal_state:, answer: answer_content, cost: object.cost, cost_report: object.cost_report, execution_period: object.execution_period ) form = form(Decidim::Proposals::Admin::ProposalAnswerForm).from_params(params) Admin::AnswerProposal.call(form, object) do on(:ok) do return object end on(:invalid) do raise Decidim::Api::Errors::AttributeValidationError, form.errors end end end |