Files
astuto/app/controllers/application_controller.rb

58 lines
1.7 KiB
Ruby
Raw Normal View History

2019-08-18 14:51:37 +02:00
class ApplicationController < ActionController::Base
2022-06-10 12:03:33 +02:00
include Pundit::Authorization
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
2019-08-19 15:45:44 +02:00
before_action :configure_permitted_parameters, if: :devise_controller?
2022-07-18 10:47:54 +02:00
prepend_before_action :load_tenant_data
2019-08-19 15:45:44 +02:00
protected
def configure_permitted_parameters
additional_permitted_parameters = [:full_name, :notifications_enabled]
devise_parameter_sanitizer.permit(:sign_up, keys: additional_permitted_parameters)
devise_parameter_sanitizer.permit(:account_update, keys: additional_permitted_parameters)
2019-08-19 15:45:44 +02:00
end
2019-08-22 17:09:13 +02:00
2022-07-18 10:47:54 +02:00
def load_tenant_data
if Rails.application.multi_tenancy?
return if request.subdomain.blank? or RESERVED_SUBDOMAINS.include?(request.subdomain)
# Load the current tenant based on subdomain
current_tenant = Tenant.find_by(subdomain: request.subdomain)
if current_tenant.status == "pending" and controller_name != "confirmation" and action_name != "show"
redirect_to pending_tenant_path; return
end
if current_tenant.status == "blocked"
redirect_to blocked_tenant_path; return
end
redirect_to showcase_url unless current_tenant
else
# Load the one and only tenant
current_tenant = Tenant.first
end
return unless current_tenant
Current.tenant = current_tenant
# Load tenant data
@tenant = Current.tenant_or_raise!
@boards = Board.select(:id, :name).order(order: :asc)
2022-07-18 10:47:54 +02:00
# Setup locale
I18n.locale = @tenant.locale
2019-08-22 17:09:13 +02:00
end
2022-06-10 12:03:33 +02:00
private
def user_not_authorized
render json: {
error: t('backend.errors.unauthorized')
}, status: :unauthorized
end
2019-08-18 14:51:37 +02:00
end