-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Upgrade to decidim 0.14.3 * Upgrade decidim to 0.15.1 * Fix seeds * Refactor user group form * Modify seeds * Clean seeds file * Refactor thanks to review * Change version
- Loading branch information
1 parent
2eb1f7b
commit 1c1b70d
Showing
14 changed files
with
497 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
# A command with all the business logic to create a user group. | ||
class CreateUserGroup < Rectify::Command | ||
# Public: Initializes the command. | ||
# | ||
# form - A form object with the params. | ||
def initialize(form) | ||
@form = form | ||
end | ||
|
||
# Executes the command. Broadcasts these events: | ||
# | ||
# - :ok when everything is valid. | ||
# - :invalid if the form wasn't valid and we couldn't proceed. | ||
# | ||
# Returns nothing. | ||
def call | ||
return broadcast(:invalid) if form.invalid? | ||
|
||
transaction do | ||
create_user_group | ||
create_membership | ||
end | ||
|
||
broadcast(:ok, @user_group) | ||
end | ||
|
||
private | ||
|
||
attr_reader :form | ||
|
||
def create_user_group | ||
@user_group = UserGroup.create!( | ||
email: form.email, | ||
name: form.name, | ||
nickname: form.nickname, | ||
organization: form.current_organization, | ||
about: form.about, | ||
avatar: form.avatar, | ||
extended_data: { | ||
phone: form.phone, | ||
document_number: form.document_number, | ||
scope_id: form.scope_id, | ||
address: form.address, | ||
url: form.url | ||
} | ||
) | ||
end | ||
|
||
def create_membership | ||
UserGroupMembership.create!( | ||
user: form.current_user, | ||
role: "creator", | ||
user_group: @user_group | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
# A command with all the business logic to update a user group profile. | ||
class UpdateUserGroup < Rectify::Command | ||
# Public: Initializes the command. | ||
# | ||
# form - A form object with the params. | ||
# user_group - The user group to update | ||
def initialize(form, user_group) | ||
@form = form | ||
@user_group = user_group | ||
end | ||
|
||
# Executes the command. Broadcasts these events: | ||
# | ||
# - :ok when everything is valid. | ||
# - :invalid if the form wasn't valid and we couldn't proceed. | ||
# | ||
# Returns nothing. | ||
def call | ||
return broadcast(:invalid) if form.invalid? | ||
|
||
update_user_group | ||
|
||
broadcast(:ok, @user_group) | ||
end | ||
|
||
private | ||
|
||
attr_reader :form, :user_group | ||
|
||
def update_user_group | ||
user_group_attributes = attributes | ||
user_group_attributes[:avatar] = form.avatar if form.avatar.present? | ||
user_group.update(user_group_attributes) | ||
end | ||
|
||
def attributes | ||
{ | ||
email: form.email, | ||
name: form.name, | ||
nickname: form.nickname, | ||
about: form.about, | ||
avatar: form.avatar, | ||
extended_data: { | ||
phone: form.phone, | ||
document_number: form.document_number, | ||
scope_id: form.scope_id, | ||
address: form.address, | ||
url: form.url | ||
} | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Admin | ||
# Controller that allows managing all admins at the admin panel. | ||
# | ||
class UsersController < Decidim::Admin::ApplicationController | ||
def index | ||
enforce_permission_to :read, :admin_user | ||
@users = collection.page(params[:page]).per(15) | ||
end | ||
|
||
def new | ||
enforce_permission_to :create, :admin_user | ||
@form = form(InviteUserForm).instance | ||
end | ||
|
||
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 | ||
|
||
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 | ||
|
||
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 | ||
|
||
private | ||
|
||
def user | ||
@user ||= collection.find(params[:id]) | ||
end | ||
|
||
def collection | ||
@collection ||= current_organization.admins.distinct.or(current_organization.users_with_any_role.distinct) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.