mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 19:27:52 +01:00
Add Site settings > General (#133)
This commit is contained in:
committed by
GitHub
parent
bdc4004e4a
commit
35831b9801
63
app/controllers/tenants_controller.rb
Normal file
63
app/controllers/tenants_controller.rb
Normal file
@@ -0,0 +1,63 @@
|
||||
class TenantsController < ApplicationController
|
||||
include ApplicationHelper
|
||||
|
||||
before_action :authenticate_admin, only: [:show, :update]
|
||||
|
||||
def new
|
||||
@page_title = t('signup.page_title')
|
||||
end
|
||||
|
||||
def show
|
||||
render json: Current.tenant_or_raise!
|
||||
end
|
||||
|
||||
def create
|
||||
@tenant = Tenant.new
|
||||
@tenant.assign_attributes(tenant_create_params)
|
||||
authorize @tenant
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
@tenant.save!
|
||||
Current.tenant = @tenant
|
||||
|
||||
@user = User.create!(
|
||||
full_name: params[:user][:full_name],
|
||||
email: params[:user][:email],
|
||||
password: params[:user][:password],
|
||||
role: "admin"
|
||||
)
|
||||
|
||||
render json: @tenant, status: :created
|
||||
|
||||
rescue ActiveRecord::RecordInvalid => exception
|
||||
render json: { error: exception }, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@tenant = Current.tenant_or_raise!
|
||||
authorize @tenant
|
||||
|
||||
if @tenant.update(tenant_update_params)
|
||||
render json: @tenant
|
||||
else
|
||||
render json: {
|
||||
error: @tenant.errors.full_messages
|
||||
}, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def tenant_create_params
|
||||
params
|
||||
.require(:tenant)
|
||||
.permit(policy(@tenant).permitted_attributes_for_create)
|
||||
end
|
||||
|
||||
def tenant_update_params
|
||||
params
|
||||
.require(:tenant)
|
||||
.permit(policy(@tenant).permitted_attributes_for_update)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user