ToolJet/app/controllers/organization_users_controller.rb
Unnikrishnan KP ccadcb2e9d
Rubocop fixes for controllers (#180)
* Improves ruby code in app/models/app_user.rb based on suggestions from Rubocop

* Rubocop fixes for more models

* Rubocop fixes for controllers
2021-06-01 12:39:07 +05:30

38 lines
937 B
Ruby

# frozen_string_literal: true
class OrganizationUsersController < ApplicationController
def create
authorize OrganizationUser
first_name = params[:first_name]
last_name = params[:last_name]
email = params[:email]
role = params[:role]
password = SecureRandom.uuid
org = @current_user.organization
user = User.create(
first_name: first_name,
last_name: last_name,
email: email,
password: password,
password_confirmation: password,
organization: org,
invitation_token: SecureRandom.uuid
)
org_user = OrganizationUser.new(
role: role,
user: user,
organization: org
)
UserMailer.with(user: user, sender: @current_user).invitation_email.deliver if org_user.save
end
def change_role
org_user = OrganizationUser.find params[:organization_user_id]
authorize org_user
org_user.update(role: params[:role])
end
end