Files
astuto/app/helpers/application_helper.rb

38 lines
960 B
Ruby
Raw Normal View History

2019-08-18 14:51:37 +02:00
module ApplicationHelper
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
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')
redirect_to root_path
2022-05-01 18:00:38 +02:00
return
end
end
def authenticate_power_user
return if check_user_signed_in == false
2022-05-01 18:00:38 +02:00
unless current_user.admin? or 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?
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