Class: Decidim::ParticipatoryProcesses::Admin::ParticipatoryProcessUserRolesController

Inherits:
Admin::ApplicationController show all
Includes:
Concerns::ParticipatoryProcessAdmin
Defined in:
decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_user_roles_controller.rb

Overview

Controller that allows managing participatory process user roles.

Instance Method Summary collapse

Methods inherited from Admin::ApplicationController

#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path

Methods included from HttpCachingDisabler

#disable_http_caching

Methods included from NeedsSnippets

#snippets

Methods included from RegistersPermissions

register_permissions

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#createObject


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_user_roles_controller.rb', line 21

def create
  enforce_permission_to :create, :process_user_role
  @form = form(ParticipatoryProcessUserRoleForm).from_params(params)

  CreateParticipatoryProcessAdmin.call(@form, current_user, current_participatory_process) do
    on(:ok) do
      flash[:notice] = I18n.t("participatory_process_user_roles.create.success", scope: "decidim.admin")
      redirect_to participatory_process_user_roles_path(current_participatory_process)
    end

    on(:invalid) do
      flash[:alert] = I18n.t("participatory_process_user_roles.create.error", scope: "decidim.admin")
      render :new
    end
  end
end

#destroyObject


62
63
64
65
66
67
68
69
70
71
72
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_user_roles_controller.rb', line 62

def destroy
  @participatory_process_user_role = collection.find(params[:id])
  enforce_permission_to :destroy, :process_user_role, process_user_role: @participatory_process_user_role

  DestroyParticipatoryProcessAdmin.call(@participatory_process_user_role, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("participatory_process_user_roles.destroy.success", scope: "decidim.admin")
      redirect_to participatory_process_user_roles_path(current_participatory_process)
    end
  end
end

#editObject


38
39
40
41
42
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_user_roles_controller.rb', line 38

def edit
  @user_role = collection.find(params[:id])
  enforce_permission_to :update, :process_user_role, process_user_role: @user_role
  @form = form(ParticipatoryProcessUserRoleForm).from_model(@user_role.user)
end

#indexObject


11
12
13
14
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_user_roles_controller.rb', line 11

def index
  enforce_permission_to :read, :process_user_role
  @participatory_process_user_roles = collection
end

#newObject


16
17
18
19
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_user_roles_controller.rb', line 16

def new
  enforce_permission_to :create, :process_user_role
  @form = form(ParticipatoryProcessUserRoleForm).instance
end

#resend_invitationObject


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_user_roles_controller.rb', line 74

def resend_invitation
  @user_role = collection.find(params[:id])
  enforce_permission_to :invite, :process_user_role, process_user_role: @user_role

  InviteUserAgain.call(@user_role.user, "invite_admin") do
    on(:ok) do
      flash[:notice] = I18n.t("users.resend_invitation.success", scope: "decidim.admin")
    end

    on(:invalid) do
      flash[:alert] = I18n.t("users.resend_invitation.error", scope: "decidim.admin")
    end
  end

  redirect_to participatory_process_user_roles_path(current_participatory_process)
end

#updateObject


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_user_roles_controller.rb', line 44

def update
  @user_role = collection.find(params[:id])
  enforce_permission_to :update, :process_user_role, process_user_role: @user_role
  @form = form(ParticipatoryProcessUserRoleForm).from_params(params)

  UpdateParticipatoryProcessAdmin.call(@form, @user_role) do
    on(:ok) do
      flash[:notice] = I18n.t("participatory_process_user_roles.update.success", scope: "decidim.admin")
      redirect_to participatory_process_user_roles_path(current_participatory_process)
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("participatory_process_user_roles.update.error", scope: "decidim.admin")
      render :edit
    end
  end
end