2024-03-24 12:54:02 +01:00
|
|
|
require 'uri'
|
|
|
|
|
|
2019-08-18 14:51:37 +02:00
|
|
|
class ApplicationController < ActionController::Base
|
2024-03-24 12:54:02 +01:00
|
|
|
include ApplicationHelper
|
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
|
2022-06-24 14:39:35 +02:00
|
|
|
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
|
2024-05-09 19:23:45 +02:00
|
|
|
# Set default locale
|
|
|
|
|
I18n.locale = I18n.default_locale
|
|
|
|
|
|
2024-03-24 12:54:02 +01:00
|
|
|
current_tenant = get_tenant_from_request(request)
|
2024-03-24 18:06:36 +01:00
|
|
|
return unless current_tenant
|
2022-07-18 10:47:54 +02:00
|
|
|
|
2024-03-24 12:54:02 +01:00
|
|
|
if current_tenant.status == "pending" and controller_name != "confirmation" and action_name != "show"
|
|
|
|
|
redirect_to pending_tenant_path; return
|
|
|
|
|
end
|
2022-07-18 10:47:54 +02:00
|
|
|
|
2024-03-24 12:54:02 +01:00
|
|
|
if current_tenant.status == "blocked"
|
|
|
|
|
redirect_to blocked_tenant_path; return
|
2022-07-18 10:47:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
Current.tenant = current_tenant
|
|
|
|
|
|
|
|
|
|
# Load tenant data
|
|
|
|
|
@tenant = Current.tenant_or_raise!
|
2023-02-04 15:43:15 +01:00
|
|
|
@tenant_setting = TenantSetting.first_or_create
|
2024-05-03 18:11:07 +02:00
|
|
|
@tenant_billing = TenantBilling.first_or_create
|
2024-04-05 18:23:31 +02:00
|
|
|
@boards = Board.select(:id, :name, :slug).order(order: :asc)
|
2022-07-18 10:47:54 +02:00
|
|
|
|
2024-05-09 19:23:45 +02:00
|
|
|
# Set tenant locale
|
2022-07-18 10:47:54 +02:00
|
|
|
I18n.locale = @tenant.locale
|
2019-08-22 17:09:13 +02:00
|
|
|
end
|
2022-06-10 12:03:33 +02:00
|
|
|
|
2022-08-05 18:15:17 +02:00
|
|
|
def load_oauths
|
2024-01-22 14:45:48 +01:00
|
|
|
@o_auths = OAuth
|
|
|
|
|
.include_defaults
|
2022-08-05 18:15:17 +02:00
|
|
|
.where(is_enabled: true)
|
|
|
|
|
.order(created_at: :asc)
|
|
|
|
|
end
|
|
|
|
|
|
2024-05-03 18:11:07 +02:00
|
|
|
def check_tenant_subscription
|
|
|
|
|
return if Current.tenant.tenant_billing.has_active_subscription?
|
|
|
|
|
|
|
|
|
|
render json: {
|
|
|
|
|
error: 'Your subscription has expired. Please renew it to continue using the service.'
|
|
|
|
|
}, status: :forbidden
|
|
|
|
|
end
|
|
|
|
|
|
2022-06-10 12:03:33 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def user_not_authorized
|
2024-02-04 16:05:41 +01:00
|
|
|
logger.error { "User not authorized: #{user_signed_in? ? current_user.inspect : 'unlogged user'}" }
|
|
|
|
|
|
2022-06-10 12:03:33 +02:00
|
|
|
render json: {
|
2022-07-23 13:32:40 +02:00
|
|
|
error: t('errors.unauthorized')
|
2022-06-10 12:03:33 +02:00
|
|
|
}, status: :unauthorized
|
|
|
|
|
end
|
2019-08-18 14:51:37 +02:00
|
|
|
end
|