2019-08-18 14:51:37 +02:00
|
|
|
module ApplicationHelper
|
2022-06-24 14:39:35 +02:00
|
|
|
def check_user_signed_in
|
2022-05-01 18:00:38 +02:00
|
|
|
unless user_signed_in?
|
2022-07-23 13:32:40 +02:00
|
|
|
flash[:alert] = t('errors.not_logged_in')
|
2022-05-01 18:00:38 +02:00
|
|
|
redirect_to new_user_session_path
|
2022-06-24 14:39:35 +02:00
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def authenticate_admin
|
|
|
|
|
return if check_user_signed_in == false
|
|
|
|
|
|
|
|
|
|
unless current_user.admin?
|
2022-07-23 13:32:40 +02:00
|
|
|
flash[:alert] = t('errors.not_enough_privileges')
|
2022-06-24 14:39:35 +02:00
|
|
|
redirect_to root_path
|
2022-05-01 18:00:38 +02:00
|
|
|
return
|
|
|
|
|
end
|
2022-06-24 14:39:35 +02:00
|
|
|
end
|
|
|
|
|
|
2023-01-18 21:11:27 +01:00
|
|
|
def authenticate_moderator
|
2022-06-24 14:39:35 +02:00
|
|
|
return if check_user_signed_in == false
|
2022-05-01 18:00:38 +02:00
|
|
|
|
2023-01-18 21:11:27 +01:00
|
|
|
unless current_user.moderator?
|
2022-07-23 13:32:40 +02:00
|
|
|
flash[:alert] = t('errors.not_enough_privileges')
|
2022-05-01 18:00:38 +02:00
|
|
|
redirect_to root_path
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-07-18 10:47:54 +02:00
|
|
|
|
|
|
|
|
def add_subdomain_to(url_helper, resource=nil, options={})
|
|
|
|
|
options[:subdomain] = Current.tenant_or_raise!.subdomain if Rails.application.multi_tenancy?
|
2022-08-05 18:15:17 +02:00
|
|
|
options[:host] = Rails.application.base_url
|
2022-07-18 10:47:54 +02:00
|
|
|
|
|
|
|
|
resource ? url_helper.call(resource, options) : url_helper.call(options)
|
|
|
|
|
end
|
2019-08-18 14:51:37 +02:00
|
|
|
end
|