Class: ForestLiana::PermissionsChecker

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

Constant Summary collapse

@@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_id: nil, smart_action_request_info: nil, collection_list_parameters: Hash.new, query_request_info: nil) ⇒ PermissionsChecker

Returns a new instance of PermissionsChecker.


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

def initialize(resource, permission_name, rendering_id, user_id: 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_id = user_id
  @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)

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

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