Class: Decidim::Admin::UsersController

Inherits:
ApplicationController show all
Defined in:
decidim-admin/app/controllers/decidim/admin/users_controller.rb

Overview

Controller that allows managing all admins at the admin panel.

Instance Method Summary collapse

Methods inherited from 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


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

def create
  enforce_permission_to :create, :admin_user

  default_params = {
    organization: current_organization,
    invitation_instructions: "invite_admin",
    invited_by: current_user
  }

  @form = form(InviteUserForm).from_params(params.merge(default_params))

  InviteAdmin.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("users.create.success", scope: "decidim.admin")
      redirect_to users_path
    end

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

#destroyObject


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'decidim-admin/app/controllers/decidim/admin/users_controller.rb', line 58

def destroy
  enforce_permission_to :destroy, :admin_user, user: user

  RemoveAdmin.call(user, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("users.destroy.success", scope: "decidim.admin")
    end

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

  redirect_to users_path
end

#indexObject


8
9
10
11
# File 'decidim-admin/app/controllers/decidim/admin/users_controller.rb', line 8

def index
  enforce_permission_to :read, :admin_user
  @users = collection.page(params[:page]).per(15)
end

#newObject


13
14
15
16
# File 'decidim-admin/app/controllers/decidim/admin/users_controller.rb', line 13

def new
  enforce_permission_to :create, :admin_user
  @form = form(InviteUserForm).instance
end

#resend_invitationObject


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'decidim-admin/app/controllers/decidim/admin/users_controller.rb', line 42

def resend_invitation
  enforce_permission_to :invite, :admin_user, user: user

  InviteUserAgain.call(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 users_path
end