Class: Decidim::GroupsController
Overview
The controller to handle user groups creation
Instance Method Summary
collapse
Methods included from UserGroups
#enforce_user_groups_enabled
#check_user_block_status, #check_user_not_blocked
#snippets
#disable_http_caching
#skip_store_location?, #store_current_location
#default_locale?
register_permissions
enhance_controller, extended, included
Instance Method Details
#create ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'app/controllers/decidim/groups_controller.rb', line 18
def create
enforce_permission_to(:create, :user_group, current_user:)
@form = form(UserGroupForm).from_params(params)
CreateUserGroup.call(@form) do
on(:ok) do |user_group|
flash[:notice] = t("groups.create.success", scope: "decidim")
redirect_to profile_path(user_group.nickname)
end
on(:invalid) do
flash[:alert] = t("groups.create.error", scope: "decidim")
render action: :new
end
end
end
|
#edit ⇒ Object
36
37
38
39
|
# File 'app/controllers/decidim/groups_controller.rb', line 36
def edit
enforce_permission_to(:manage, :user_group, current_user:, user_group:)
@form = form(UserGroupForm).from_model(user_group)
end
|
#leave ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'app/controllers/decidim/groups_controller.rb', line 59
def leave
enforce_permission_to :leave, :user_group, user_group: accepted_user_group
LeaveUserGroup.call(current_user, accepted_user_group) do
on(:ok) do
flash[:notice] = t("groups.leave.success", scope: "decidim")
redirect_back fallback_location: profile_path(accepted_user_group.nickname)
end
on(:last_admin) do
flash[:alert] = t("groups.leave.last_admin", scope: "decidim")
redirect_back fallback_location: profile_path(accepted_user_group.nickname)
end
on(:invalid) do
flash[:alert] = t("groups.leave.error", scope: "decidim")
redirect_back fallback_location: profile_path(accepted_user_group.nickname)
end
end
end
|
#new ⇒ Object
13
14
15
16
|
# File 'app/controllers/decidim/groups_controller.rb', line 13
def new
enforce_permission_to(:create, :user_group, current_user:)
@form = form(UserGroupForm).instance
end
|
#update ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'app/controllers/decidim/groups_controller.rb', line 41
def update
enforce_permission_to(:manage, :user_group, current_user:, user_group:)
@form = form(UserGroupForm).from_params(user_group_params)
UpdateUserGroup.call(@form, user_group) do
on(:ok) do |user_group|
flash[:notice] = t("groups.update.success", scope: "decidim")
redirect_to profile_path(user_group.nickname)
end
on(:invalid) do
flash[:alert] = t("groups.update.error", scope: "decidim")
render action: :edit
end
end
end
|