Class: Decidim::Admin::ParticipatorySpace::UserRoleController

Inherits:
ApplicationController show all
Includes:
Officializations::Filterable
Defined in:
app/controllers/decidim/admin/participatory_space/user_role_controller.rb

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



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/decidim/admin/participatory_space/user_role_controller.rb', line 29

def create
  enforce_permission_to :create, authorization_scope
  @form = resource_form.from_params(params)

  create_command.call(@form, current_participatory_space, event_class:, event:, role_class:) do
    on(:ok) do
      flash[:notice] = I18n.t("create.success", scope: i18n_scope)
      redirect_to space_index_path
    end

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

#destroyObject



64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/decidim/admin/participatory_space/user_role_controller.rb', line 64

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

  destroy_command.call(@user_role, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("destroy.success", scope: i18n_scope)
      redirect_to space_index_path
    end
  end
end

#editObject



23
24
25
26
27
# File 'app/controllers/decidim/admin/participatory_space/user_role_controller.rb', line 23

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

#indexObject



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

def index
  enforce_permission_to :index, authorization_scope
  @user_roles = filtered_collection
end

#newObject



18
19
20
21
# File 'app/controllers/decidim/admin/participatory_space/user_role_controller.rb', line 18

def new
  enforce_permission_to :create, authorization_scope
  @form = resource_form.instance
end

#resend_invitationObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/decidim/admin/participatory_space/user_role_controller.rb', line 76

def resend_invitation
  @user_role = collection.find(params[:id])
  enforce_permission_to :invite, authorization_scope, 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 space_index_path
end

#updateObject



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

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

  update_command.call(@form, @user_role, event_class:, event:) do
    on(:ok) do
      flash[:notice] = I18n.t("update.success", scope: i18n_scope)
      redirect_to space_index_path
    end

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