Class: Decidim::Admin::UsersController

Inherits:
ApplicationController show all
Includes:
Officializations::Filterable
Defined in:
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

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/decidim/admin/users_controller.rb', line 22

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



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/decidim/admin/users_controller.rb', line 62

def destroy
  enforce_permission_to(:destroy, :admin_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



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

def index
  enforce_permission_to :read, :admin_user
  @users = filtered_collection
end

#newObject



17
18
19
20
# File 'app/controllers/decidim/admin/users_controller.rb', line 17

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

#resend_invitationObject



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

def resend_invitation
  enforce_permission_to(:invite, :admin_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