Copy the main tenant administrator login credentials into the new tenant

Co-Authored-By: Senén Rodero <senenrodero@gmail.com>
This commit is contained in:
taitus
2022-12-15 14:35:07 +01:00
committed by Senén Rodero Rodríguez
parent 171cf4e634
commit 951eec7d08
7 changed files with 51 additions and 1 deletions

View File

@@ -13,6 +13,7 @@ class Admin::TenantsController < Admin::BaseController
def create
if @tenant.save
update_default_tenant_administrator
redirect_to admin_tenants_path, notice: t("admin.tenants.create.notice")
else
render :new
@@ -50,4 +51,19 @@ class Admin::TenantsController < Admin::BaseController
def tenant_params
params.require(:tenant).permit(:name, :schema, :schema_type)
end
def update_default_tenant_administrator
tenant_administrator_credentials = {
email: current_user.email,
username: current_user.username,
encrypted_password: current_user.encrypted_password
}
Tenant.switch(@tenant.schema) do
default_admin_account = User.administrators.first
default_admin_account.skip_confirmation_notification!
default_admin_account.update!(tenant_administrator_credentials)
default_admin_account.confirm
end
end
end