Class: Decidim::Initiatives::CommitteeRequestsController

Inherits:
ApplicationController show all
Includes:
NeedsInitiative
Defined in:
app/controllers/decidim/initiatives/committee_requests_controller.rb

Overview

Controller in charge of managing committee membership

Instance Method Summary collapse

Methods inherited from ApplicationController

#permission_class_chain, #permission_scope, #permissions_context

Instance Method Details

#approveObject

GET /initiatives/:initiative_id/committee_requests/:id/approve



44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/decidim/initiatives/committee_requests_controller.rb', line 44

def approve
  enforce_permission_to :approve, :initiative_committee_member, request: membership_request

  ApproveMembershipRequest.call(membership_request) do
    on(:ok) do
      redirect_to edit_initiative_path(current_initiative), flash: {
        notice: I18n.t("success", scope: "decidim.initiatives.committee_requests.approve")
      }
    end
  end
end

#newObject

GET /initiatives/:initiative_id/committee_requests/new



13
14
15
# File 'app/controllers/decidim/initiatives/committee_requests_controller.rb', line 13

def new
  enforce_permission_to :request_membership, :initiative, initiative: current_initiative
end

#revokeObject

DELETE /initiatives/:initiative_id/committee_requests/:id/revoke



57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/decidim/initiatives/committee_requests_controller.rb', line 57

def revoke
  enforce_permission_to :revoke, :initiative_committee_member, request: membership_request

  RevokeMembershipRequest.call(membership_request) do
    on(:ok) do
      redirect_to edit_initiative_path(current_initiative), flash: {
        notice: I18n.t("success", scope: "decidim.initiatives.committee_requests.revoke")
      }
    end
  end
end

#spawnObject

GET /initiatives/:initiative_id/committee_requests/spawn



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/decidim/initiatives/committee_requests_controller.rb', line 18

def spawn
  enforce_permission_to :request_membership, :initiative, initiative: current_initiative

  form = Decidim::Initiatives::CommitteeMemberForm
         .from_params(initiative_id: current_initiative.id, user_id: current_user.id, state: "requested")
         .with_context(current_organization: current_initiative.organization, current_user:)

  SpawnCommitteeRequest.call(form) do
    on(:ok) do
      redirect_to initiatives_path, flash: {
        notice: I18n.t(
          "success",
          scope: "decidim.initiatives.committee_requests.spawn"
        )
      }
    end

    on(:invalid) do |request|
      redirect_to initiatives_path, flash: {
        error: request.errors.full_messages.to_sentence
      }
    end
  end
end