Sha256: 49ad392c641822243f0a8c73cb072140a6f4a56f349a709b2dbde5bb4d75af9b
Contents?: true
Size: 1.7 KB
Versions: 1
Compression:
Stored size: 1.7 KB
Contents
module Dune::Api module V1 class ContributionsController < BaseController include PaginatedController before_action :require_admin! has_scope :pg_search, as: :query has_scope :by_project_id, as: :project_id has_scope :between_values, using: %i(initial final), type: :hash def index respond_with_pagination collection end def show respond_with Dune::Api::Contribution.find(params[:id]) end def update @contribution = ::Contribution.find(params[:id]) authorize @contribution respond_with ::Contribution.update(params[:id], permitted_params) end def destroy contribution = ::Contribution.find(params[:id]) authorize contribution contribution.push_to_trash! head :no_content end [:confirm, :pendent, :refund, :hide, :cancel].each do |name| define_method name do contribution = ::Contribution.find(params[:id]) authorize contribution contribution.send("#{name.to_s}!") head :no_content end end private def permitted_params params.permit(policy(@contribution || ::Contribution).permitted_attributes)[:contribution] end def collection @collection ||= begin apply_scopes( scoped_by_state(Dune::Api::Contribution) ).order('created_at desc').all end end def scoped_by_state(scope) state_scopes = params.slice(*Contribution.state_names).keys if state_scopes.any? scope.with_state(state_scopes) else scope end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dune-api-1.1.0 | app/controllers/dune/api/v1/contributions_controller.rb |