Class: Decidim::Admin::ShareTokensController
Overview
This is an abstract controller allows sharing unpublished things. Final implementation must inherit from this controller and implement the ‘resource` method.
Instance Method Summary
collapse
#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path
Instance Method Details
#create ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/controllers/decidim/admin/share_tokens_controller.rb', line 22
def create
enforce_permission_to :create, :share_token
@form = form(ShareTokenForm).from_params(params, resource:)
CreateShareToken.call(@form) do
on(:ok) do
flash[:notice] = I18n.t("share_tokens.create.success", scope: "decidim.admin")
redirect_to share_tokens_path
end
on(:invalid) do
flash.now[:alert] = I18n.t("share_tokens.create.invalid", scope: "decidim.admin")
render action: "new", status: :unprocessable_entity
end
end
end
|
#destroy ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'app/controllers/decidim/admin/share_tokens_controller.rb', line 61
def destroy
enforce_permission_to(:destroy, :share_token, share_token: current_token)
DestroyShareToken.call(current_token, current_user) do
on(:ok) do
flash[:notice] = I18n.t("share_tokens.destroy.success", scope: "decidim.admin")
end
on(:invalid) do
flash[:error] = I18n.t("share_tokens.destroy.error", scope: "decidim.admin")
end
end
redirect_to share_tokens_path
end
|
#edit ⇒ Object
39
40
41
42
|
# File 'app/controllers/decidim/admin/share_tokens_controller.rb', line 39
def edit
enforce_permission_to(:update, :share_token, share_token: current_token)
@form = form(ShareTokenForm).from_model(current_token)
end
|
#index ⇒ Object
12
13
14
15
|
# File 'app/controllers/decidim/admin/share_tokens_controller.rb', line 12
def index
enforce_permission_to :read, :share_token
@share_tokens = filtered_collection
end
|
#new ⇒ Object
17
18
19
20
|
# File 'app/controllers/decidim/admin/share_tokens_controller.rb', line 17
def new
enforce_permission_to :create, :share_token
@form = form(ShareTokenForm).instance
end
|
#update ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'app/controllers/decidim/admin/share_tokens_controller.rb', line 44
def update
enforce_permission_to(:update, :share_token, share_token: current_token)
@form = form(ShareTokenForm).from_params(params, resource:)
UpdateShareToken.call(@form, current_token) do
on(:ok) do
flash[:notice] = I18n.t("share_tokens.update.success", scope: "decidim.admin")
redirect_to share_tokens_path
end
on(:invalid) do
flash.now[:alert] = I18n.t("share_tokens.update.error", scope: "decidim.admin")
render :edit, status: :unprocessable_entity
end
end
end
|