Class: Decidim::Proposals::WithdrawProposalType

Inherits:
Api::Types::BaseMutation
  • Object
show all
Defined in:
lib/decidim/api/mutations/withdraw_proposal_type.rb

Instance Method Summary collapse

Instance Method Details

#authorized?Boolean

Returns:

  • (Boolean)

Raises:

  • (Decidim::Api::Errors::MutationNotAuthorizedError)


23
24
25
26
27
28
# File 'lib/decidim/api/mutations/withdraw_proposal_type.rb', line 23

def authorized?
  raise Decidim::Api::Errors::MutationNotAuthorizedError, I18n.t("decidim.api.errors.unauthorized_mutation") unless super && allowed_to?(:withdraw, :proposal, object,
                                                                                                                                         context)

  true
end

#resolveObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/decidim/api/mutations/withdraw_proposal_type.rb', line 11

def resolve
  WithdrawProposal.call(object, current_user) do
    on(:ok) do |proposal|
      return proposal
    end

    on(:has_votes) do
      raise Decidim::Api::Errors::ValidationError, I18n.t("proposals.withdraw.errors.has_votes", scope: "decidim")
    end
  end
end