forest_liana 6.0.0.pre.beta.2 → 6.0.2
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 +105 -0
- data/app/controllers/forest_liana/authentication_controller.rb +5 -5
- data/app/controllers/forest_liana/resources_controller.rb +14 -17
- data/app/controllers/forest_liana/smart_actions_controller.rb +10 -5
- data/app/helpers/forest_liana/is_same_data_structure_helper.rb +44 -0
- data/app/helpers/forest_liana/widgets_helper.rb +59 -0
- data/app/models/forest_liana/model/action.rb +2 -1
- data/app/serializers/forest_liana/stripe_invoice_serializer.rb +5 -5
- data/app/services/forest_liana/apimap_sorter.rb +1 -0
- data/app/services/forest_liana/authentication.rb +0 -2
- data/app/services/forest_liana/authorization_getter.rb +23 -21
- data/app/services/forest_liana/oidc_client_manager.rb +9 -5
- data/app/services/forest_liana/permissions_checker.rb +117 -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/resources_getter.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/config/initializers/error-messages.rb +3 -0
- data/config/initializers/errors.rb +21 -2
- data/config/routes.rb +2 -4
- data/lib/forest_liana.rb +1 -0
- data/lib/forest_liana/bootstrapper.rb +31 -5
- data/lib/forest_liana/schema_file_updater.rb +1 -0
- data/lib/forest_liana/version.rb +1 -1
- data/lib/generators/forest_liana/install_generator.rb +13 -5
- 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/helpers/forest_liana/is_same_data_structure_helper_spec.rb +87 -0
- data/spec/requests/actions_controller_spec.rb +222 -0
- data/spec/requests/authentications_spec.rb +12 -13
- data/spec/requests/resources_spec.rb +4 -4
- data/spec/services/forest_liana/apimap_sorter_spec.rb +6 -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 +83 -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/routing/route_test.rb +0 -12
- data/test/services/forest_liana/resources_getter_test.rb +1 -1
- metadata +132 -147
- data/app/controllers/forest_liana/sessions_controller.rb +0 -95
- data/app/serializers/forest_liana/session_serializer.rb +0 -33
- data/app/services/forest_liana/login_handler.rb +0 -99
- data/app/services/forest_liana/two_factor_registration_confirmer.rb +0 -36
- data/app/services/forest_liana/user_secret_creator.rb +0 -26
- data/spec/requests/sessions_spec.rb +0 -55
@@ -26,9 +26,7 @@ module ForestLiana
|
|
26
26
|
|
27
27
|
user = ForestLiana::AuthorizationGetter.authenticate(
|
28
28
|
rendering_id,
|
29
|
-
true,
|
30
29
|
{ :forest_token => access_token_instance.instance_variable_get(:@access_token) },
|
31
|
-
nil,
|
32
30
|
)
|
33
31
|
|
34
32
|
return ForestLiana::Token.create_token(user, rendering_id)
|
@@ -1,23 +1,12 @@
|
|
1
1
|
module ForestLiana
|
2
2
|
class AuthorizationGetter
|
3
|
-
def self.authenticate(rendering_id,
|
3
|
+
def self.authenticate(rendering_id, auth_data)
|
4
4
|
begin
|
5
5
|
route = "/liana/v2/renderings/#{rendering_id.to_s}/authorization"
|
6
|
-
|
7
|
-
if !use_google_authentication.nil?
|
8
|
-
headers = { 'forest-token' => auth_data[:forest_token] }
|
9
|
-
elsif !auth_data[:email].nil?
|
10
|
-
headers = { 'email' => auth_data[:email], 'password' => auth_data[:password] }
|
11
|
-
end
|
12
|
-
|
13
|
-
query_parameters = {}
|
14
|
-
|
15
|
-
unless two_factor_registration.nil?
|
16
|
-
query_parameters['two-factor-registration'] = true
|
17
|
-
end
|
6
|
+
headers = { 'forest-token' => auth_data[:forest_token] }
|
18
7
|
|
19
8
|
response = ForestLiana::ForestApiRequester
|
20
|
-
.get(route, query:
|
9
|
+
.get(route, query: {}, headers: headers)
|
21
10
|
|
22
11
|
if response.code.to_i == 200
|
23
12
|
body = JSON.parse(response.body, :symbolize_names => false)
|
@@ -25,15 +14,28 @@ module ForestLiana
|
|
25
14
|
user['id'] = body['data']['id']
|
26
15
|
user
|
27
16
|
else
|
28
|
-
|
29
|
-
raise "Cannot authorize the user using this google account. Forest API returned an #{Errors::HTTPErrorHelper.format(response)}"
|
30
|
-
else
|
31
|
-
raise "Cannot authorize the user using this email/password. Forest API returned an #{Errors::HTTPErrorHelper.format(response)}"
|
32
|
-
end
|
17
|
+
raise generate_authentication_error response
|
33
18
|
end
|
34
|
-
rescue
|
35
|
-
raise ForestLiana::Errors::HTTP401Error
|
36
19
|
end
|
37
20
|
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def self.generate_authentication_error(error)
|
24
|
+
case error[:message]
|
25
|
+
when ForestLiana::MESSAGES[:SERVER_TRANSACTION][:SECRET_AND_RENDERINGID_INCONSISTENT]
|
26
|
+
return ForestLiana::Errors::InconsistentSecretAndRenderingError.new()
|
27
|
+
when ForestLiana::MESSAGES[:SERVER_TRANSACTION][:SECRET_NOT_FOUND]
|
28
|
+
return ForestLiana::Errors::SecretNotFoundError.new()
|
29
|
+
else
|
30
|
+
end
|
31
|
+
|
32
|
+
serverError = error[:jse_cause][:response][:body][:errors][0] || nil
|
33
|
+
|
34
|
+
if !serverError.nil? && serverError[:name] == ForestLiana::MESSAGES[:SERVER_TRANSACTION][:names][:TWO_FACTOR_AUTHENTICATION_REQUIRED]
|
35
|
+
return ForestLiana::Errors::TwoFactorAuthenticationRequiredError.new()
|
36
|
+
end
|
37
|
+
|
38
|
+
return StandardError.new(error)
|
39
|
+
end
|
38
40
|
end
|
39
41
|
end
|
@@ -8,11 +8,15 @@ module ForestLiana
|
|
8
8
|
if client_data.nil?
|
9
9
|
configuration = ForestLiana::OidcConfigurationRetriever.retrieve()
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
if ForestLiana.forest_client_id.nil?
|
12
|
+
client_credentials = ForestLiana::OidcDynamicClientRegistrator.register({
|
13
|
+
token_endpoint_auth_method: 'none',
|
14
|
+
redirect_uris: [callback_url],
|
15
|
+
registration_endpoint: configuration['registration_endpoint']
|
16
|
+
})
|
17
|
+
else
|
18
|
+
client_credentials = { 'client_id' => ForestLiana.forest_client_id }
|
19
|
+
end
|
16
20
|
|
17
21
|
client_data = { :client_id => client_credentials['client_id'], :issuer => configuration['issuer'] }
|
18
22
|
Rails.cache.write(callback_url, client_data)
|
@@ -1,100 +1,161 @@
|
|
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
|
59
51
|
if permissions && permissions[@collection_name] &&
|
60
52
|
permissions[@collection_name]['collection']
|
61
53
|
if @permission_name === 'actions'
|
62
54
|
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
55
|
else
|
68
|
-
|
56
|
+
if @permission_name === 'browseEnabled'
|
57
|
+
refresh_scope_cache if scope_cache_expired?
|
58
|
+
scope_permissions = get_scope_in_permissions
|
59
|
+
if scope_permissions
|
60
|
+
# NOTICE: current_scope will either contains conditions filter and
|
61
|
+
# dynamic user values definition, or null for collection that does not use scopes
|
62
|
+
return false unless are_scopes_valid?(scope_permissions)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
return is_user_allowed(permissions[@collection_name]['collection'][@permission_name])
|
69
66
|
end
|
70
67
|
else
|
71
68
|
false
|
72
69
|
end
|
73
70
|
end
|
74
71
|
|
75
|
-
def
|
76
|
-
@@
|
77
|
-
|
78
|
-
@@
|
79
|
-
|
72
|
+
def get_scope_in_permissions
|
73
|
+
@@scopes_cached[@rendering_id] &&
|
74
|
+
@@scopes_cached[@rendering_id][@collection_name] &&
|
75
|
+
@@scopes_cached[@rendering_id][@collection_name]['scope']
|
76
|
+
end
|
77
|
+
|
78
|
+
def scope_cache_expired?
|
79
|
+
return true unless @@scopes_cached[@rendering_id] && @@scopes_cached[@rendering_id]['last_fetch']
|
80
|
+
|
81
|
+
elapsed_seconds = date_difference_in_seconds(Time.now, @@scopes_cached[@rendering_id]['last_fetch'])
|
82
|
+
elapsed_seconds >= @@expiration_in_seconds
|
83
|
+
end
|
84
|
+
|
85
|
+
# This will happen only on rolesACLActivated (as scope cache will always be up to date on disabled)
|
86
|
+
def refresh_scope_cache
|
87
|
+
permissions = ForestLiana::PermissionsGetter::get_permissions_for_rendering(@rendering_id, rendering_specific_only: true)
|
88
|
+
add_scopes_to_cache(permissions)
|
89
|
+
end
|
90
|
+
|
91
|
+
# When acl disabled permissions are stored and retrieved by rendering
|
92
|
+
def get_permissions
|
93
|
+
@@roles_acl_activated ? @@permissions_cached : @@permissions_cached[@rendering_id]
|
94
|
+
end
|
95
|
+
|
96
|
+
def get_permissions_content
|
97
|
+
permissions = get_permissions
|
98
|
+
permissions && permissions['data'] && permissions['data']['collections']
|
99
|
+
end
|
100
|
+
|
101
|
+
def get_last_fetch
|
102
|
+
permissions = get_permissions
|
103
|
+
permissions && permissions['last_fetch']
|
104
|
+
end
|
105
|
+
|
106
|
+
def get_smart_action_permissions(smart_actions_permissions)
|
107
|
+
endpoint = @smart_action_request_info[:endpoint]
|
108
|
+
http_method = @smart_action_request_info[:http_method]
|
109
|
+
|
110
|
+
return nil unless endpoint && http_method
|
111
|
+
|
112
|
+
schema_smart_action = ForestLiana::Utils::BetaSchemaUtils.find_action_from_endpoint(@collection_name, endpoint, http_method)
|
113
|
+
|
114
|
+
schema_smart_action &&
|
115
|
+
schema_smart_action.name &&
|
116
|
+
smart_actions_permissions &&
|
117
|
+
smart_actions_permissions[schema_smart_action.name]
|
118
|
+
end
|
119
|
+
|
120
|
+
def is_user_allowed(permission_value)
|
121
|
+
return false if permission_value.nil?
|
122
|
+
return permission_value if permission_value.in? [true, false]
|
123
|
+
permission_value.include?(@user_id.to_i)
|
124
|
+
end
|
125
|
+
|
126
|
+
def smart_action_allowed?(smart_actions_permissions)
|
127
|
+
smart_action_permissions = get_smart_action_permissions(smart_actions_permissions)
|
128
|
+
|
129
|
+
return false unless smart_action_permissions
|
130
|
+
|
131
|
+
is_user_allowed(smart_action_permissions['triggerEnabled'])
|
132
|
+
end
|
133
|
+
|
134
|
+
def are_scopes_valid?(scope_permissions)
|
135
|
+
return ForestLiana::ScopeValidator.new(
|
136
|
+
scope_permissions['filter'],
|
137
|
+
scope_permissions['dynamicScopesValues']['users']
|
138
|
+
).is_scope_in_request?(@collection_list_parameters)
|
80
139
|
end
|
81
140
|
|
82
141
|
def date_difference_in_seconds(date1, date2)
|
83
142
|
(date1 - date2).to_i
|
84
143
|
end
|
85
144
|
|
86
|
-
def
|
87
|
-
|
88
|
-
|
89
|
-
return true if last_retrieve.nil?
|
145
|
+
def have_permissions_expired?
|
146
|
+
last_fetch = get_last_fetch
|
147
|
+
return true unless last_fetch
|
90
148
|
|
91
|
-
elapsed_seconds = date_difference_in_seconds(Time.now,
|
149
|
+
elapsed_seconds = date_difference_in_seconds(Time.now, last_fetch)
|
92
150
|
elapsed_seconds >= @@expiration_in_seconds
|
93
151
|
end
|
94
152
|
|
95
|
-
|
96
|
-
|
97
|
-
|
153
|
+
# Used only for testing purpose
|
154
|
+
def self.empty_cache
|
155
|
+
@@permissions_cached = Hash.new
|
156
|
+
@@scopes_cached = Hash.new
|
157
|
+
@@roles_acl_activated = false
|
158
|
+
@@expiration_in_seconds = (ENV['FOREST_PERMISSIONS_EXPIRATION_IN_SECONDS'] || 3600).to_i
|
98
159
|
end
|
99
160
|
end
|
100
161
|
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
|
@@ -1,25 +1,60 @@
|
|
1
1
|
module ForestLiana
|
2
2
|
class PermissionsGetter
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
class << PermissionsGetter
|
4
|
+
def get_permissions_api_route
|
5
|
+
'/liana/v3/permissions'
|
6
|
+
end
|
7
|
+
|
8
|
+
# Permission format example:
|
9
|
+
# collections => {
|
10
|
+
# {model_name} => {
|
11
|
+
# collection => {
|
12
|
+
# browseEnabled => true,
|
13
|
+
# readEnabled => true,
|
14
|
+
# editEnabled => true,
|
15
|
+
# addEnabled => true,
|
16
|
+
# deleteEnabled => true,
|
17
|
+
# exportEnabled => true,
|
18
|
+
# },
|
19
|
+
# actions => {
|
20
|
+
# {action_name} => {
|
21
|
+
# triggerEnabled => true,
|
22
|
+
# },
|
23
|
+
# },
|
24
|
+
# },
|
25
|
+
# },
|
26
|
+
# rederings => {
|
27
|
+
# {rendering_id} => {
|
28
|
+
# {collection_id} => {
|
29
|
+
# scope => {
|
30
|
+
# dynamicScopesValues => {},
|
31
|
+
# filter => {}
|
32
|
+
# }
|
33
|
+
# }
|
34
|
+
# }
|
35
|
+
# }
|
36
|
+
# }
|
37
|
+
# With `rendering_specific_only` this returns only the permissions related data specific to the provided rendering
|
38
|
+
# For now this only includes scopes
|
39
|
+
def get_permissions_for_rendering(rendering_id, rendering_specific_only: false)
|
40
|
+
begin
|
41
|
+
query_parameters = { 'renderingId' => rendering_id }
|
42
|
+
query_parameters['renderingSpecificOnly'] = rendering_specific_only if rendering_specific_only
|
7
43
|
|
8
|
-
|
9
|
-
|
10
|
-
query_parameters = { 'renderingId' => @rendering_id }
|
11
|
-
response = ForestLiana::ForestApiRequester.get(@route, query: query_parameters)
|
44
|
+
api_route = get_permissions_api_route
|
45
|
+
response = ForestLiana::ForestApiRequester.get(api_route, query: query_parameters)
|
12
46
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
47
|
+
if response.is_a?(Net::HTTPOK)
|
48
|
+
JSON.parse(response.body)
|
49
|
+
else
|
50
|
+
raise "Forest API returned an #{ForestLiana::Errors::HTTPErrorHelper.format(response)}"
|
51
|
+
end
|
52
|
+
rescue => exception
|
53
|
+
FOREST_LOGGER.error 'Cannot retrieve the permissions from the Forest server.'
|
54
|
+
FOREST_LOGGER.error 'Which was caused by:'
|
55
|
+
ForestLiana::Errors::ExceptionHelper.recursively_print(exception, margin: ' ', is_error: true)
|
56
|
+
nil
|
17
57
|
end
|
18
|
-
rescue => exception
|
19
|
-
FOREST_LOGGER.error 'Cannot retrieve the permissions from the Forest server.'
|
20
|
-
FOREST_LOGGER.error 'Which was caused by:'
|
21
|
-
ForestLiana::Errors::ExceptionHelper.recursively_print(exception, margin: ' ', is_error: true)
|
22
|
-
nil
|
23
58
|
end
|
24
59
|
end
|
25
60
|
end
|