Class: Decidim::Initiatives::CommitteeRequestsController

Inherits:
ApplicationController show all
Includes:
NeedsInitiative
Defined in:
decidim-initiatives/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

Methods included from RegistersPermissions

register_permissions

Methods included from UserBlockedChecker

#check_user_block_status, #check_user_not_blocked

Methods included from NeedsSnippets

#snippets

Methods included from HttpCachingDisabler

#disable_http_caching

Methods included from HasStoredPath

#skip_store_location?, #store_current_location

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#approveObject

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


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

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


15
16
17
# File 'decidim-initiatives/app/controllers/decidim/initiatives/committee_requests_controller.rb', line 15

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

#revokeObject

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


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

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


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

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")

  SpawnCommitteeRequest.call(form, current_user) do
    on(:ok) do
      redirect_to initiatives_path, flash: {
        notice: I18n.t(
          "success",
          scope: %w(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