forest_liana 5.3.2 → 5.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/forest_liana/actions_controller.rb +18 -1
  3. data/app/controllers/forest_liana/resources_controller.rb +14 -17
  4. data/app/controllers/forest_liana/smart_actions_controller.rb +10 -5
  5. data/app/serializers/forest_liana/stripe_invoice_serializer.rb +5 -5
  6. data/app/services/forest_liana/permissions_checker.rb +118 -56
  7. data/app/services/forest_liana/permissions_formatter.rb +52 -0
  8. data/app/services/forest_liana/permissions_getter.rb +52 -17
  9. data/app/services/forest_liana/resource_creator.rb +1 -1
  10. data/app/services/forest_liana/resource_updater.rb +3 -3
  11. data/app/services/forest_liana/scope_validator.rb +8 -7
  12. data/app/services/forest_liana/stripe_invoice_getter.rb +1 -1
  13. data/app/services/forest_liana/stripe_invoices_getter.rb +1 -1
  14. data/app/services/forest_liana/stripe_source_getter.rb +1 -1
  15. data/app/services/forest_liana/stripe_sources_getter.rb +1 -1
  16. data/app/services/forest_liana/utils/beta_schema_utils.rb +13 -0
  17. data/lib/forest_liana/bootstrapper.rb +5 -5
  18. data/lib/forest_liana/version.rb +1 -1
  19. data/spec/dummy/app/assets/config/manifest.js +1 -0
  20. data/spec/dummy/config/application.rb +1 -1
  21. data/spec/dummy/db/migrate/20190226172951_create_user.rb +1 -1
  22. data/spec/dummy/db/migrate/20190226173051_create_isle.rb +1 -1
  23. data/spec/dummy/db/migrate/20190226174951_create_tree.rb +1 -1
  24. data/spec/dummy/db/migrate/20190716130830_add_age_to_tree.rb +1 -1
  25. data/spec/dummy/db/migrate/20190716135241_add_type_to_user.rb +1 -1
  26. data/spec/dummy/db/schema.rb +18 -20
  27. data/spec/requests/actions_controller_spec.rb +94 -11
  28. data/spec/requests/resources_spec.rb +4 -4
  29. data/spec/services/forest_liana/permissions_checker_acl_disabled_spec.rb +711 -0
  30. data/spec/services/forest_liana/permissions_checker_acl_enabled_spec.rb +831 -0
  31. data/spec/services/forest_liana/permissions_formatter_spec.rb +222 -0
  32. data/spec/services/forest_liana/permissions_getter_spec.rb +82 -0
  33. data/spec/spec_helper.rb +3 -0
  34. data/test/dummy/app/assets/config/manifest.js +1 -0
  35. data/test/dummy/config/application.rb +1 -1
  36. data/test/dummy/db/migrate/20150608130516_create_date_field.rb +1 -1
  37. data/test/dummy/db/migrate/20150608131430_create_integer_field.rb +1 -1
  38. data/test/dummy/db/migrate/20150608131603_create_decimal_field.rb +1 -1
  39. data/test/dummy/db/migrate/20150608131610_create_float_field.rb +1 -1
  40. data/test/dummy/db/migrate/20150608132159_create_boolean_field.rb +1 -1
  41. data/test/dummy/db/migrate/20150608132621_create_string_field.rb +1 -1
  42. data/test/dummy/db/migrate/20150608133038_create_belongs_to_field.rb +1 -1
  43. data/test/dummy/db/migrate/20150608133044_create_has_one_field.rb +1 -1
  44. data/test/dummy/db/migrate/20150608150016_create_has_many_field.rb +1 -1
  45. data/test/dummy/db/migrate/20150609114636_create_belongs_to_class_name_field.rb +1 -1
  46. data/test/dummy/db/migrate/20150612112520_create_has_and_belongs_to_many_field.rb +1 -1
  47. data/test/dummy/db/migrate/20150616150629_create_polymorphic_field.rb +1 -1
  48. data/test/dummy/db/migrate/20150623115554_create_has_many_class_name_field.rb +1 -1
  49. data/test/dummy/db/migrate/20150814081918_create_has_many_through_field.rb +1 -1
  50. data/test/dummy/db/migrate/20160627172810_create_owner.rb +1 -1
  51. data/test/dummy/db/migrate/20160627172951_create_tree.rb +1 -1
  52. data/test/dummy/db/migrate/20160628173505_add_timestamps.rb +1 -1
  53. data/test/dummy/db/migrate/20170614141921_create_serialize_field.rb +1 -1
  54. data/test/dummy/db/migrate/20181111162121_create_references_table.rb +1 -1
  55. data/test/services/forest_liana/resources_getter_test.rb +1 -1
  56. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ec0228713b3a5f0f943dcd9901d9d866ce2d5df36b452faaa8f163aed2b17aa
4
- data.tar.gz: 152af3bfde151e934042b8629c28c77a1fe1ea0a648fd41857fec5cbe9179e03
3
+ metadata.gz: 2709633eef3b78bd00eb543b13a9341934a727a6f4814f13744315568ce21574
4
+ data.tar.gz: 0267ca9d4be038bf7d6ecd14c3a828c4f3752bf8be537ae85e78a1b87e6129e8
5
5
  SHA512:
6
- metadata.gz: 7062153dfd912d67d91893d27d89d48f7aeba6a1de21ab442a91e1dc51d0f30369c406b700ed7b9f25fd4d69039172a118894af96f29be713e90543eadb66a18
7
- data.tar.gz: 40ed811e8dda8166ee0573377f195ba4e8ee70c2446ffcaad8c4901bf372e0442ae419252fb30e4242f65231433b3e9b7afbedb587c297dfe445c72bfdf237b3
6
+ metadata.gz: 5b31f9ebda4992c230a0eae2a8adad2f00dd260d34874da3a68bd565d628de8af01994f71390f49b55b9c4b500879092a47249f64215e5bb213b58f3fb6b95ef
7
+ data.tar.gz: 31f1bf4040e845af20501d0b34ecb9baf69c95e21a50d31fdbbbbcd4788634d815bc7009e86502c334192922ef4d4ca306d80598c06a58b4dbea22d817b87da9
@@ -53,7 +53,24 @@ module ForestLiana
53
53
  end
54
54
 
55
55
  # Apply result on fields (transform the object back to an array), preserve order.
56
- fields = action.fields.map { |field| result[field[:field]] }
56
+ fields = action.fields.map do |field|
57
+ updated_field = result[field[:field]]
58
+
59
+ # Reset `value` when not present in `enums` (which means `enums` has changed).
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
70
+ end
71
+
72
+ updated_field
73
+ end
57
74
 
58
75
  render serializer: nil, json: { fields: fields}, status: :ok
59
76
  end
@@ -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, 'export', @rendering_id)
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
- 'list',
24
+ 'browseEnabled',
28
25
  @rendering_id,
29
- nil,
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
- 'list',
59
+ 'browseEnabled',
63
60
  @rendering_id,
64
- nil,
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, 'show', @rendering_id)
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, 'create', @rendering_id)
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, 'update', @rendering_id)
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, 'delete', @rendering_id)
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, 'delete', @rendering_id)
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
- get_smart_action_permission_info(forest_user, smart_action_request)
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
- def get_smart_action_permission_info(user, smart_action_request)
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
- user_id: user['id'],
60
- action_id: smart_action_request[:smart_action_id],
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 :date
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
- @@permissions_per_rendering = Hash.new
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, smart_action_parameters = nil, collection_list_parameters = nil)
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
- @smart_action_parameters = smart_action_parameters
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
- (is_permission_expired? || !is_allowed?) ? retrieve_permissions_and_check_allowed : true
16
- end
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
- def get_permissions
21
- @@permissions_per_rendering &&
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
- def get_last_retrieve
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 smart_action_allowed?(smart_actions_permissions)
33
- if !@smart_action_parameters||
34
- !@smart_action_parameters[:user_id] ||
35
- !@smart_action_parameters[:action_id] ||
36
- !smart_actions_permissions ||
37
- !smart_actions_permissions[@smart_action_parameters[:action_id]]
38
- return false
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 collection_list_allowed?(scope_permissions)
51
- return ForestLiana::ScopeValidator.new(
52
- scope_permissions['filter'],
53
- scope_permissions['dynamicScopesValues']['users']
54
- ).is_scope_in_request?(@collection_list_parameters)
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 = get_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
- return permissions[@collection_name]['collection'][@permission_name]
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 retrieve_permissions
76
- @@permissions_per_rendering[@rendering_id] = Hash.new
77
- permissions = ForestLiana::PermissionsGetter.new(@rendering_id).perform()
78
- @@permissions_per_rendering[@rendering_id]['data'] = permissions
79
- @@permissions_per_rendering[@rendering_id]['last_retrieve'] = Time.now
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 is_permission_expired?
87
- last_retrieve = get_last_retrieve
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, last_retrieve)
150
+ elapsed_seconds = date_difference_in_seconds(Time.now, last_fetch)
92
151
  elapsed_seconds >= @@expiration_in_seconds
93
152
  end
94
153
 
95
- def retrieve_permissions_and_check_allowed
96
- retrieve_permissions
97
- is_allowed?
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