forest_liana 5.3.3 → 5.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/forest_liana/actions_controller.rb +12 -2
- data/app/controllers/forest_liana/resources_controller.rb +14 -17
- data/app/controllers/forest_liana/smart_actions_controller.rb +10 -5
- data/app/serializers/forest_liana/stripe_invoice_serializer.rb +5 -5
- data/app/services/forest_liana/permissions_checker.rb +118 -56
- data/app/services/forest_liana/permissions_formatter.rb +52 -0
- data/app/services/forest_liana/permissions_getter.rb +52 -17
- data/app/services/forest_liana/resource_creator.rb +1 -1
- data/app/services/forest_liana/resource_updater.rb +3 -3
- data/app/services/forest_liana/schema_utils.rb +8 -3
- data/app/services/forest_liana/scope_validator.rb +8 -7
- data/app/services/forest_liana/stripe_invoice_getter.rb +1 -1
- data/app/services/forest_liana/stripe_invoices_getter.rb +1 -1
- data/app/services/forest_liana/stripe_source_getter.rb +1 -1
- data/app/services/forest_liana/stripe_sources_getter.rb +1 -1
- data/app/services/forest_liana/utils/beta_schema_utils.rb +13 -0
- data/lib/forest_liana/bootstrapper.rb +5 -5
- data/lib/forest_liana/version.rb +1 -1
- data/spec/dummy/app/assets/config/manifest.js +1 -0
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/db/migrate/20190226172951_create_user.rb +1 -1
- data/spec/dummy/db/migrate/20190226173051_create_isle.rb +1 -1
- data/spec/dummy/db/migrate/20190226174951_create_tree.rb +1 -1
- data/spec/dummy/db/migrate/20190716130830_add_age_to_tree.rb +1 -1
- data/spec/dummy/db/migrate/20190716135241_add_type_to_user.rb +1 -1
- data/spec/dummy/db/schema.rb +18 -20
- data/spec/requests/actions_controller_spec.rb +59 -11
- data/spec/requests/resources_spec.rb +4 -4
- data/spec/services/forest_liana/permissions_checker_acl_disabled_spec.rb +711 -0
- data/spec/services/forest_liana/permissions_checker_acl_enabled_spec.rb +831 -0
- data/spec/services/forest_liana/permissions_formatter_spec.rb +222 -0
- data/spec/services/forest_liana/permissions_getter_spec.rb +82 -0
- data/spec/spec_helper.rb +3 -0
- data/test/dummy/app/assets/config/manifest.js +1 -0
- data/test/dummy/config/application.rb +1 -1
- data/test/dummy/db/migrate/20150608130516_create_date_field.rb +1 -1
- data/test/dummy/db/migrate/20150608131430_create_integer_field.rb +1 -1
- data/test/dummy/db/migrate/20150608131603_create_decimal_field.rb +1 -1
- data/test/dummy/db/migrate/20150608131610_create_float_field.rb +1 -1
- data/test/dummy/db/migrate/20150608132159_create_boolean_field.rb +1 -1
- data/test/dummy/db/migrate/20150608132621_create_string_field.rb +1 -1
- data/test/dummy/db/migrate/20150608133038_create_belongs_to_field.rb +1 -1
- data/test/dummy/db/migrate/20150608133044_create_has_one_field.rb +1 -1
- data/test/dummy/db/migrate/20150608150016_create_has_many_field.rb +1 -1
- data/test/dummy/db/migrate/20150609114636_create_belongs_to_class_name_field.rb +1 -1
- data/test/dummy/db/migrate/20150612112520_create_has_and_belongs_to_many_field.rb +1 -1
- data/test/dummy/db/migrate/20150616150629_create_polymorphic_field.rb +1 -1
- data/test/dummy/db/migrate/20150623115554_create_has_many_class_name_field.rb +1 -1
- data/test/dummy/db/migrate/20150814081918_create_has_many_through_field.rb +1 -1
- data/test/dummy/db/migrate/20160627172810_create_owner.rb +1 -1
- data/test/dummy/db/migrate/20160627172951_create_tree.rb +1 -1
- data/test/dummy/db/migrate/20160628173505_add_timestamps.rb +1 -1
- data/test/dummy/db/migrate/20170614141921_create_serialize_field.rb +1 -1
- data/test/dummy/db/migrate/20181111162121_create_references_table.rb +1 -1
- data/test/services/forest_liana/resources_getter_test.rb +1 -1
- metadata +119 -105
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6535dcd725511fc2509e63c4c1fb1a5ac3f412f857471a0820baaf67da7a2f86
|
4
|
+
data.tar.gz: bbbcf484b173bb2e96baffbc99b9bd42c64f3530b30801ce7179e4c2a5c69fad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9d3683defa8ed58627ce6e1c194076ae8af34ca137357ae15db8c4959811f015f9030acb207d8977485845891d92ce85ac5c55c950aded3e9d1547e432f4021
|
7
|
+
data.tar.gz: 15de6a5729539bd88d05e182f16f9329e1f36ad58e078e1598437febeb8c8b049a81f948f681e0037236089a49fce8559824255db4004bad9114878f6552539a
|
@@ -55,10 +55,20 @@ module ForestLiana
|
|
55
55
|
# Apply result on fields (transform the object back to an array), preserve order.
|
56
56
|
fields = action.fields.map do |field|
|
57
57
|
updated_field = result[field[:field]]
|
58
|
+
|
58
59
|
# Reset `value` when not present in `enums` (which means `enums` has changed).
|
59
|
-
if updated_field[:enums].is_a?(Array)
|
60
|
-
|
60
|
+
if updated_field[:enums].is_a?(Array)
|
61
|
+
# `value` can be an array if the type of fields is `[x]`
|
62
|
+
if updated_field[:type].is_a?(Array) && updated_field[:value].is_a?(Array) && !(updated_field[:value] - updated_field[:enums]).empty?
|
63
|
+
updated_field[:value] = nil
|
64
|
+
end
|
65
|
+
|
66
|
+
# `value` can be any other value
|
67
|
+
if !updated_field[:type].is_a?(Array) && !updated_field[:enums].include?(updated_field[:value])
|
68
|
+
updated_field[:value] = nil
|
69
|
+
end
|
61
70
|
end
|
71
|
+
|
62
72
|
updated_field
|
63
73
|
end
|
64
74
|
|
@@ -16,18 +16,15 @@ module ForestLiana
|
|
16
16
|
def index
|
17
17
|
begin
|
18
18
|
if request.format == 'csv'
|
19
|
-
checker = ForestLiana::PermissionsChecker.new(@resource, '
|
20
|
-
return head :forbidden unless checker.is_authorized?
|
21
|
-
elsif params.has_key?(:searchToEdit)
|
22
|
-
checker = ForestLiana::PermissionsChecker.new(@resource, 'searchToEdit', @rendering_id)
|
19
|
+
checker = ForestLiana::PermissionsChecker.new(@resource, 'exportEnabled', @rendering_id, user_id: forest_user['id'])
|
23
20
|
return head :forbidden unless checker.is_authorized?
|
24
21
|
else
|
25
22
|
checker = ForestLiana::PermissionsChecker.new(
|
26
23
|
@resource,
|
27
|
-
'
|
24
|
+
'browseEnabled',
|
28
25
|
@rendering_id,
|
29
|
-
|
30
|
-
get_collection_list_permission_info(forest_user, request)
|
26
|
+
user_id: forest_user['id'],
|
27
|
+
collection_list_parameters: get_collection_list_permission_info(forest_user, request)
|
31
28
|
)
|
32
29
|
return head :forbidden unless checker.is_authorized?
|
33
30
|
end
|
@@ -59,10 +56,10 @@ module ForestLiana
|
|
59
56
|
begin
|
60
57
|
checker = ForestLiana::PermissionsChecker.new(
|
61
58
|
@resource,
|
62
|
-
'
|
59
|
+
'browseEnabled',
|
63
60
|
@rendering_id,
|
64
|
-
|
65
|
-
get_collection_list_permission_info(forest_user, request)
|
61
|
+
user_id: forest_user['id'],
|
62
|
+
collection_list_parameters: get_collection_list_permission_info(forest_user, request)
|
66
63
|
)
|
67
64
|
return head :forbidden unless checker.is_authorized?
|
68
65
|
|
@@ -89,7 +86,7 @@ module ForestLiana
|
|
89
86
|
|
90
87
|
def show
|
91
88
|
begin
|
92
|
-
checker = ForestLiana::PermissionsChecker.new(@resource, '
|
89
|
+
checker = ForestLiana::PermissionsChecker.new(@resource, 'readEnabled', @rendering_id, user_id: forest_user['id'])
|
93
90
|
return head :forbidden unless checker.is_authorized?
|
94
91
|
|
95
92
|
getter = ForestLiana::ResourceGetter.new(@resource, params)
|
@@ -104,7 +101,7 @@ module ForestLiana
|
|
104
101
|
|
105
102
|
def create
|
106
103
|
begin
|
107
|
-
checker = ForestLiana::PermissionsChecker.new(@resource, '
|
104
|
+
checker = ForestLiana::PermissionsChecker.new(@resource, 'addEnabled', @rendering_id, user_id: forest_user['id'])
|
108
105
|
return head :forbidden unless checker.is_authorized?
|
109
106
|
|
110
107
|
creator = ForestLiana::ResourceCreator.new(@resource, params)
|
@@ -127,7 +124,7 @@ module ForestLiana
|
|
127
124
|
|
128
125
|
def update
|
129
126
|
begin
|
130
|
-
checker = ForestLiana::PermissionsChecker.new(@resource, '
|
127
|
+
checker = ForestLiana::PermissionsChecker.new(@resource, 'editEnabled', @rendering_id, user_id: forest_user['id'])
|
131
128
|
return head :forbidden unless checker.is_authorized?
|
132
129
|
|
133
130
|
updater = ForestLiana::ResourceUpdater.new(@resource, params)
|
@@ -149,7 +146,7 @@ module ForestLiana
|
|
149
146
|
end
|
150
147
|
|
151
148
|
def destroy
|
152
|
-
checker = ForestLiana::PermissionsChecker.new(@resource, '
|
149
|
+
checker = ForestLiana::PermissionsChecker.new(@resource, 'deleteEnabled', @rendering_id, user_id: forest_user['id'])
|
153
150
|
return head :forbidden unless checker.is_authorized?
|
154
151
|
|
155
152
|
@resource.destroy(params[:id]) if @resource.exists?(params[:id])
|
@@ -161,7 +158,7 @@ module ForestLiana
|
|
161
158
|
end
|
162
159
|
|
163
160
|
def destroy_bulk
|
164
|
-
checker = ForestLiana::PermissionsChecker.new(@resource, '
|
161
|
+
checker = ForestLiana::PermissionsChecker.new(@resource, 'deleteEnabled', @rendering_id, user_id: forest_user['id'])
|
165
162
|
return head :forbidden unless checker.is_authorized?
|
166
163
|
|
167
164
|
ids = ForestLiana::ResourcesGetter.get_ids_from_request(params)
|
@@ -245,8 +242,8 @@ module ForestLiana
|
|
245
242
|
@collection ||= ForestLiana.apimap.find { |collection| collection.name.to_s == collection_name }
|
246
243
|
end
|
247
244
|
|
248
|
-
# NOTICE: Return a formatted object containing the request condition filters and
|
249
|
-
# the user id used by the scope validator class to validate if scope is
|
245
|
+
# NOTICE: Return a formatted object containing the request condition filters and
|
246
|
+
# the user id used by the scope validator class to validate if scope is
|
250
247
|
# in request
|
251
248
|
def get_collection_list_permission_info(user, collection_list_request)
|
252
249
|
{
|
@@ -19,14 +19,15 @@ module ForestLiana
|
|
19
19
|
|
20
20
|
def check_permission_for_smart_route
|
21
21
|
begin
|
22
|
-
|
22
|
+
|
23
23
|
smart_action_request = get_smart_action_request
|
24
24
|
if !smart_action_request.nil? && smart_action_request.has_key?(:smart_action_id)
|
25
25
|
checker = ForestLiana::PermissionsChecker.new(
|
26
26
|
find_resource(smart_action_request[:collection_name]),
|
27
27
|
'actions',
|
28
28
|
@rendering_id,
|
29
|
-
|
29
|
+
user_id: forest_user['id'],
|
30
|
+
smart_action_request_info: get_smart_action_request_info
|
30
31
|
)
|
31
32
|
return head :forbidden unless checker.is_authorized?
|
32
33
|
else
|
@@ -54,10 +55,14 @@ module ForestLiana
|
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
57
|
-
|
58
|
+
# smart action permissions are retrieved from the action's endpoint and http_method
|
59
|
+
def get_smart_action_request_info
|
60
|
+
endpoint = request.fullpath
|
61
|
+
# Trim starting '/'
|
62
|
+
endpoint[0] = '' if endpoint[0] == '/'
|
58
63
|
{
|
59
|
-
|
60
|
-
|
64
|
+
endpoint: endpoint,
|
65
|
+
http_method: request.request_method
|
61
66
|
}
|
62
67
|
end
|
63
68
|
end
|
@@ -3,20 +3,20 @@ module ForestLiana
|
|
3
3
|
include JSONAPI::Serializer
|
4
4
|
|
5
5
|
attribute :amount_due
|
6
|
+
attribute :amount_paid
|
7
|
+
attribute :amount_remaining
|
8
|
+
attribute :application_fee_amount
|
6
9
|
attribute :attempt_count
|
7
10
|
attribute :attempted
|
8
|
-
attribute :closed
|
9
11
|
attribute :currency
|
10
|
-
attribute :
|
11
|
-
attribute :forgiven
|
12
|
+
attribute :due_date
|
12
13
|
attribute :paid
|
13
14
|
attribute :period_end
|
14
15
|
attribute :period_start
|
16
|
+
attribute :status
|
15
17
|
attribute :subtotal
|
16
18
|
attribute :total
|
17
|
-
attribute :application_fee
|
18
19
|
attribute :tax
|
19
|
-
attribute :tax_percent
|
20
20
|
|
21
21
|
has_one :customer
|
22
22
|
|
@@ -1,100 +1,162 @@
|
|
1
1
|
module ForestLiana
|
2
2
|
class PermissionsChecker
|
3
|
-
@@
|
3
|
+
@@permissions_cached = Hash.new
|
4
|
+
@@scopes_cached = Hash.new
|
5
|
+
@@roles_acl_activated = false
|
6
|
+
# TODO: handle cache scopes per rendering
|
4
7
|
@@expiration_in_seconds = (ENV['FOREST_PERMISSIONS_EXPIRATION_IN_SECONDS'] || 3600).to_i
|
5
8
|
|
6
|
-
def initialize(resource, permission_name, rendering_id,
|
9
|
+
def initialize(resource, permission_name, rendering_id, user_id:, smart_action_request_info: nil, collection_list_parameters: nil)
|
10
|
+
@user_id = user_id
|
7
11
|
@collection_name = ForestLiana.name_for(resource)
|
8
12
|
@permission_name = permission_name
|
9
13
|
@rendering_id = rendering_id
|
10
|
-
@
|
14
|
+
@smart_action_request_info = smart_action_request_info
|
11
15
|
@collection_list_parameters = collection_list_parameters
|
12
16
|
end
|
13
17
|
|
14
18
|
def is_authorized?
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
private
|
19
|
+
# User is still authorized if he already was and the permission has not expire
|
20
|
+
# if !have_permissions_expired && is_allowed
|
21
|
+
return true unless have_permissions_expired? || !is_allowed
|
19
22
|
|
20
|
-
|
21
|
-
|
22
|
-
@@permissions_per_rendering[@rendering_id] &&
|
23
|
-
@@permissions_per_rendering[@rendering_id]['data']
|
23
|
+
fetch_permissions
|
24
|
+
is_allowed
|
24
25
|
end
|
25
26
|
|
26
|
-
|
27
|
-
@@permissions_per_rendering &&
|
28
|
-
@@permissions_per_rendering[@rendering_id] &&
|
29
|
-
@@permissions_per_rendering[@rendering_id]['last_retrieve']
|
30
|
-
end
|
27
|
+
private
|
31
28
|
|
32
|
-
def
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
29
|
+
def fetch_permissions
|
30
|
+
permissions = ForestLiana::PermissionsGetter::get_permissions_for_rendering(@rendering_id)
|
31
|
+
@@roles_acl_activated = permissions['meta']['rolesACLActivated']
|
32
|
+
permissions['last_fetch'] = Time.now
|
33
|
+
if @@roles_acl_activated
|
34
|
+
@@permissions_cached = permissions
|
35
|
+
else
|
36
|
+
permissions['data'] = ForestLiana::PermissionsFormatter.convert_to_new_format(permissions['data'], @rendering_id)
|
37
|
+
@@permissions_cached[@rendering_id] = permissions
|
39
38
|
end
|
40
|
-
|
41
|
-
@user_id = @smart_action_parameters[:user_id]
|
42
|
-
@action_id = @smart_action_parameters[:action_id]
|
43
|
-
@smart_action_permissions = smart_actions_permissions[@action_id]
|
44
|
-
@allowed = @smart_action_permissions['allowed']
|
45
|
-
@users = @smart_action_permissions['users']
|
46
|
-
|
47
|
-
return @allowed && (@users.nil?|| @users.include?(@user_id.to_i));
|
39
|
+
add_scopes_to_cache(permissions)
|
48
40
|
end
|
49
41
|
|
50
|
-
def
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
42
|
+
def add_scopes_to_cache(permissions)
|
43
|
+
permissions['data']['renderings'].keys.each { |rendering_id|
|
44
|
+
@@scopes_cached[rendering_id] = permissions['data']['renderings'][rendering_id]
|
45
|
+
@@scopes_cached[rendering_id]['last_fetch'] = Time.now
|
46
|
+
} if permissions['data']['renderings']
|
55
47
|
end
|
56
48
|
|
57
|
-
def is_allowed
|
58
|
-
permissions =
|
49
|
+
def is_allowed
|
50
|
+
permissions = get_permissions_content
|
51
|
+
|
59
52
|
if permissions && permissions[@collection_name] &&
|
60
53
|
permissions[@collection_name]['collection']
|
61
54
|
if @permission_name === 'actions'
|
62
55
|
return smart_action_allowed?(permissions[@collection_name]['actions'])
|
63
|
-
# NOTICE: Permissions[@collection_name]['scope'] will either contains conditions filter and
|
64
|
-
# dynamic user values definition, or null for collection that does not use scopes
|
65
|
-
elsif @permission_name === 'list' and permissions[@collection_name]['scope']
|
66
|
-
return collection_list_allowed?(permissions[@collection_name]['scope'])
|
67
56
|
else
|
68
|
-
|
57
|
+
if @permission_name === 'browseEnabled'
|
58
|
+
refresh_scope_cache if scope_cache_expired?
|
59
|
+
scope_permissions = get_scope_in_permissions
|
60
|
+
if scope_permissions
|
61
|
+
# NOTICE: current_scope will either contains conditions filter and
|
62
|
+
# dynamic user values definition, or null for collection that does not use scopes
|
63
|
+
return false unless are_scopes_valid?(scope_permissions)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
return is_user_allowed(permissions[@collection_name]['collection'][@permission_name])
|
69
67
|
end
|
70
68
|
else
|
71
69
|
false
|
72
70
|
end
|
73
71
|
end
|
74
72
|
|
75
|
-
def
|
76
|
-
@@
|
77
|
-
|
78
|
-
@@
|
79
|
-
|
73
|
+
def get_scope_in_permissions
|
74
|
+
@@scopes_cached[@rendering_id] &&
|
75
|
+
@@scopes_cached[@rendering_id][@collection_name] &&
|
76
|
+
@@scopes_cached[@rendering_id][@collection_name]['scope']
|
77
|
+
end
|
78
|
+
|
79
|
+
def scope_cache_expired?
|
80
|
+
return true unless @@scopes_cached[@rendering_id] && @@scopes_cached[@rendering_id]['last_fetch']
|
81
|
+
|
82
|
+
elapsed_seconds = date_difference_in_seconds(Time.now, @@scopes_cached[@rendering_id]['last_fetch'])
|
83
|
+
elapsed_seconds >= @@expiration_in_seconds
|
84
|
+
end
|
85
|
+
|
86
|
+
# This will happen only on rolesACLActivated (as scope cache will always be up to date on disabled)
|
87
|
+
def refresh_scope_cache
|
88
|
+
permissions = ForestLiana::PermissionsGetter::get_permissions_for_rendering(@rendering_id, rendering_specific_only: true)
|
89
|
+
add_scopes_to_cache(permissions)
|
90
|
+
end
|
91
|
+
|
92
|
+
# When acl disabled permissions are stored and retrieved by rendering
|
93
|
+
def get_permissions
|
94
|
+
@@roles_acl_activated ? @@permissions_cached : @@permissions_cached[@rendering_id]
|
95
|
+
end
|
96
|
+
|
97
|
+
def get_permissions_content
|
98
|
+
permissions = get_permissions
|
99
|
+
permissions && permissions['data'] && permissions['data']['collections']
|
100
|
+
end
|
101
|
+
|
102
|
+
def get_last_fetch
|
103
|
+
permissions = get_permissions
|
104
|
+
permissions && permissions['last_fetch']
|
105
|
+
end
|
106
|
+
|
107
|
+
def get_smart_action_permissions(smart_actions_permissions)
|
108
|
+
endpoint = @smart_action_request_info[:endpoint]
|
109
|
+
http_method = @smart_action_request_info[:http_method]
|
110
|
+
|
111
|
+
return nil unless endpoint && http_method
|
112
|
+
|
113
|
+
schema_smart_action = ForestLiana::Utils::BetaSchemaUtils.find_action_from_endpoint(@collection_name, endpoint, http_method)
|
114
|
+
|
115
|
+
schema_smart_action &&
|
116
|
+
schema_smart_action.name &&
|
117
|
+
smart_actions_permissions &&
|
118
|
+
smart_actions_permissions[schema_smart_action.name]
|
119
|
+
end
|
120
|
+
|
121
|
+
def is_user_allowed(permission_value)
|
122
|
+
return false if permission_value.nil?
|
123
|
+
return permission_value if permission_value.in? [true, false]
|
124
|
+
permission_value.include?(@user_id.to_i)
|
125
|
+
end
|
126
|
+
|
127
|
+
def smart_action_allowed?(smart_actions_permissions)
|
128
|
+
smart_action_permissions = get_smart_action_permissions(smart_actions_permissions)
|
129
|
+
|
130
|
+
return false unless smart_action_permissions
|
131
|
+
|
132
|
+
is_user_allowed(smart_action_permissions['triggerEnabled'])
|
133
|
+
end
|
134
|
+
|
135
|
+
def are_scopes_valid?(scope_permissions)
|
136
|
+
return ForestLiana::ScopeValidator.new(
|
137
|
+
scope_permissions['filter'],
|
138
|
+
scope_permissions['dynamicScopesValues']['users']
|
139
|
+
).is_scope_in_request?(@collection_list_parameters)
|
80
140
|
end
|
81
141
|
|
82
142
|
def date_difference_in_seconds(date1, date2)
|
83
143
|
(date1 - date2).to_i
|
84
144
|
end
|
85
145
|
|
86
|
-
def
|
87
|
-
|
88
|
-
|
89
|
-
return true if last_retrieve.nil?
|
146
|
+
def have_permissions_expired?
|
147
|
+
last_fetch = get_last_fetch
|
148
|
+
return true unless last_fetch
|
90
149
|
|
91
|
-
elapsed_seconds = date_difference_in_seconds(Time.now,
|
150
|
+
elapsed_seconds = date_difference_in_seconds(Time.now, last_fetch)
|
92
151
|
elapsed_seconds >= @@expiration_in_seconds
|
93
152
|
end
|
94
153
|
|
95
|
-
|
96
|
-
|
97
|
-
|
154
|
+
# Used only for testing purpose
|
155
|
+
def self.empty_cache
|
156
|
+
@@permissions_cached = Hash.new
|
157
|
+
@@scopes_cached = Hash.new
|
158
|
+
@@roles_acl_activated = false
|
159
|
+
@@expiration_in_seconds = (ENV['FOREST_PERMISSIONS_EXPIRATION_IN_SECONDS'] || 3600).to_i
|
98
160
|
end
|
99
161
|
end
|
100
162
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module ForestLiana
|
2
|
+
class PermissionsFormatter
|
3
|
+
class << PermissionsFormatter
|
4
|
+
# Convert old format permissions to unify PermissionsGetter code
|
5
|
+
def convert_to_new_format(permissions, rendering_id)
|
6
|
+
permissions_new_format = Hash.new
|
7
|
+
permissions_new_format['collections'] = Hash.new
|
8
|
+
permissions_new_format['renderings'] = Hash.new
|
9
|
+
permissions_new_format['renderings'][rendering_id] = Hash.new
|
10
|
+
permissions.keys.each { |collection_name|
|
11
|
+
permissions_new_format['collections'][collection_name] = {
|
12
|
+
'collection' => convert_collection_permissions_to_new_format(permissions[collection_name]['collection']),
|
13
|
+
'actions' => convert_actions_permissions_to_new_format(permissions[collection_name]['actions'])
|
14
|
+
}
|
15
|
+
|
16
|
+
permissions_new_format['renderings'][rendering_id][collection_name] = { 'scope' => permissions[collection_name]['scope'] }
|
17
|
+
}
|
18
|
+
|
19
|
+
permissions_new_format
|
20
|
+
end
|
21
|
+
|
22
|
+
def convert_collection_permissions_to_new_format(collection_permissions)
|
23
|
+
{
|
24
|
+
'browseEnabled' => collection_permissions['list'] || collection_permissions['searchToEdit'],
|
25
|
+
'readEnabled' => collection_permissions['show'],
|
26
|
+
'addEnabled' => collection_permissions['create'],
|
27
|
+
'editEnabled' => collection_permissions['update'],
|
28
|
+
'deleteEnabled' => collection_permissions['delete'],
|
29
|
+
'exportEnabled' => collection_permissions['export']
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def convert_actions_permissions_to_new_format(actions_permissions)
|
34
|
+
return nil unless actions_permissions
|
35
|
+
|
36
|
+
actions_permissions_new_format = Hash.new
|
37
|
+
|
38
|
+
actions_permissions.keys.each { |action_name|
|
39
|
+
allowed = actions_permissions[action_name]['allowed']
|
40
|
+
users = actions_permissions[action_name]['users']
|
41
|
+
|
42
|
+
actions_permissions_new_format[action_name] = Hash.new
|
43
|
+
actions_permissions_new_format[action_name] = {
|
44
|
+
'triggerEnabled' => allowed && (users.nil? || users)
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
actions_permissions_new_format
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|