Module: Workarea::Authorization

Extended by:
ActiveSupport::Concern
Included in:
Impersonation
Defined in:
app/controllers/workarea/authorization.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#authorized?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
# File 'app/controllers/workarea/authorization.rb', line 35

def authorized?
  current_user.admin? && Array(required_permissions).all? do |area|
    current_user.try("#{area}_access?") || current_user.try("#{area}?")
  end
end

#check_authorizationObject



28
29
30
31
32
33
# File 'app/controllers/workarea/authorization.rb', line 28

def check_authorization
  return if current_user.blank? || current_user.super_admin?
  return if required_permissions.blank?

  unauthorized_user and return false unless authorized?
end

#require_adminObject



16
17
18
19
20
21
22
# File 'app/controllers/workarea/authorization.rb', line 16

def require_admin
  unless current_user.try(:admin?)
    flash[:error] = t('workarea.admin.authorization.unauthorized_action')
    redirect_to storefront.root_path
    return false
  end
end

#required_permissionsObject



24
25
26
# File 'app/controllers/workarea/authorization.rb', line 24

def required_permissions
  self.class.required_permissions
end

#unauthorized_userObject



41
42
43
44
# File 'app/controllers/workarea/authorization.rb', line 41

def unauthorized_user
  flash[:error] = t('workarea.admin.authorization.unauthorized_area')
  redirect_back fallback_location: root_path
end