Class: ForestLiana::PermissionsChecker

Inherits:
Object
  • Object
show all
Defined in:
app/services/forest_liana/permissions_checker.rb

Constant Summary collapse

ALLOWED_PERMISSION_LEVELS =
%w[admin editor developer]
@@permissions_cached =
Hash.new
@@renderings_cached =
Hash.new
@@roles_acl_activated =
false
@@expiration_in_seconds =
(ENV['FOREST_PERMISSIONS_EXPIRATION_IN_SECONDS'] || 3600).to_i

Instance Method Summary collapse

Constructor Details

#initialize(resource, permission_name, rendering_id, user: nil, smart_action_request_info: nil, collection_list_parameters: Hash.new, query_request_info: nil) ⇒ PermissionsChecker

Returns a new instance of PermissionsChecker.



11
12
13
14
15
16
17
18
19
20
# File 'app/services/forest_liana/permissions_checker.rb', line 11

def initialize(resource, permission_name, rendering_id, user: nil, smart_action_request_info: nil, collection_list_parameters: Hash.new, query_request_info: nil)
  @collection_name = resource.present? ? ForestLiana.name_for(resource) : nil
  @permission_name = permission_name
  @rendering_id = rendering_id

  @user = user
  @smart_action_request_info = smart_action_request_info
  @collection_list_parameters = collection_list_parameters
  @query_request_info = query_request_info
end

Instance Method Details

#is_authorized?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
# File 'app/services/forest_liana/permissions_checker.rb', line 22

def is_authorized?
  # User is still authorized if he already was and the permission has not expire
  # if !have_permissions_expired && is_allowed
  return true unless have_permissions_expired? || !is_allowed

  fetch_permissions
  is_allowed
end