2021-04-23 06:17:24 +00:00
|
|
|
class OrganizationUsersController < ApplicationController
|
2021-04-29 06:41:23 +00:00
|
|
|
def create
|
|
|
|
|
authorize OrganizationUser
|
2021-04-23 06:17:24 +00:00
|
|
|
|
2021-04-29 06:41:23 +00:00
|
|
|
first_name = params[:first_name]
|
|
|
|
|
last_name = params[:last_name]
|
|
|
|
|
email = params[:email]
|
|
|
|
|
role = params[:role]
|
|
|
|
|
password = SecureRandom.uuid
|
|
|
|
|
org = @current_user.organization
|
2021-04-25 14:07:13 +00:00
|
|
|
|
2021-04-29 06:41:23 +00:00
|
|
|
user = User.create(
|
|
|
|
|
first_name: first_name,
|
|
|
|
|
last_name: last_name,
|
|
|
|
|
email: email,
|
|
|
|
|
password: password,
|
|
|
|
|
password_confirmation: password,
|
|
|
|
|
organization: org,
|
|
|
|
|
invitation_token: SecureRandom.uuid
|
|
|
|
|
)
|
2021-04-23 06:17:24 +00:00
|
|
|
|
2021-04-29 06:41:23 +00:00
|
|
|
org_user = OrganizationUser.new(
|
|
|
|
|
role: role,
|
|
|
|
|
user: user,
|
|
|
|
|
organization: org
|
|
|
|
|
)
|
2021-04-23 06:17:24 +00:00
|
|
|
|
2021-04-29 06:41:23 +00:00
|
|
|
UserMailer.with(user: user, sender: @current_user).invitation_email.deliver if org_user.save
|
|
|
|
|
end
|
2021-04-23 07:36:02 +00:00
|
|
|
|
2021-04-29 06:41:23 +00:00
|
|
|
def change_role
|
|
|
|
|
org_user = OrganizationUser.find params[:organization_user_id]
|
|
|
|
|
authorize org_user
|
|
|
|
|
org_user.update(role: params[:role])
|
|
|
|
|
end
|
2021-04-23 06:17:24 +00:00
|
|
|
end
|