Skip to content

Commit 1859882

Browse files
authored
chore(force-release): release forest-rails 7.0.0
2 parents 9a1e63f + b49ef34 commit 1859882

File tree

73 files changed

+1714
-1045
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1714
-1045
lines changed

CHANGELOG.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,46 @@
1+
# [7.0.0-beta.6](https://github.com/ForestAdmin/forest-rails/compare/v7.0.0-beta.5...v7.0.0-beta.6) (2021-07-20)
2+
3+
4+
### Bug Fixes
5+
6+
* allow smart action endpoints to start with slashes ([d4f6a61](https://github.com/ForestAdmin/forest-rails/commit/d4f6a618aeea72364b0e7511545b67fbbfb17c99))
7+
* allow smart action endpoints to start with slashes ([cf6c6a9](https://github.com/ForestAdmin/forest-rails/commit/cf6c6a96498e6813e4b7ccaa56cacd9abefc332f))
8+
* fix time based graph when timezone is different with database ([#476](https://github.com/ForestAdmin/forest-rails/issues/476)) ([5d9fb89](https://github.com/ForestAdmin/forest-rails/commit/5d9fb8903ae53615dd1789bdebbc4d9c7d6f4576))
9+
* stats permissions should be retrieved only one time per team ([#489](https://github.com/ForestAdmin/forest-rails/issues/489)) ([c2e9104](https://github.com/ForestAdmin/forest-rails/commit/c2e9104ebf32deeb3e5676706fdcbaae5de34869))
10+
* support permissions infos with ruby < 2.7 ([#486](https://github.com/ForestAdmin/forest-rails/issues/486)) ([a611271](https://github.com/ForestAdmin/forest-rails/commit/a611271e709bb6a9ed0d3ebccfb64b6eea1d324d))
11+
12+
13+
### Features
14+
15+
* include role in the user data inside the request ([#478](https://github.com/ForestAdmin/forest-rails/issues/478)) ([0a34716](https://github.com/ForestAdmin/forest-rails/commit/0a347165897aa118e486895e55f4b29ba7fb888b))
16+
* **schema:** move some meta data under stack attribute to prevent blocking scenarios on DWO ([#469](https://github.com/ForestAdmin/forest-rails/issues/469)) ([76aa754](https://github.com/ForestAdmin/forest-rails/commit/76aa7540300f75b0ea1d00ec3b60e4976b7d800e))
17+
18+
# [7.0.0-beta.5](https://github.com/ForestAdmin/forest-rails/compare/v7.0.0-beta.4...v7.0.0-beta.5) (2021-07-09)
19+
20+
21+
### Features
22+
23+
* **scopes:** enforce scopes restrictions on a wider range of requests ([#488](https://github.com/ForestAdmin/forest-rails/issues/488)) ([66825a3](https://github.com/ForestAdmin/forest-rails/commit/66825a339fc11d03b8a1653b1877cb9d492dacfb))
24+
25+
# [7.0.0-beta.4](https://github.com/ForestAdmin/forest-rails/compare/v7.0.0-beta.3...v7.0.0-beta.4) (2021-07-06)
26+
27+
28+
### Features
29+
30+
* smart action hooks now have access to the http request ([#499](https://github.com/ForestAdmin/forest-rails/issues/499)) ([5cd4a0e](https://github.com/ForestAdmin/forest-rails/commit/5cd4a0e7b9d9e1fcc551198a2eab62e471f51d92))
31+
32+
33+
### BREAKING CHANGES
34+
35+
* record is no longer send to the hook midleware & values option on smart action is no longer supported
36+
37+
# [7.0.0-beta.3](https://github.com/ForestAdmin/forest-rails/compare/v7.0.0-beta.2...v7.0.0-beta.3) (2021-07-02)
38+
39+
40+
### Features
41+
42+
* **security:** secure segments queries ([#495](https://github.com/ForestAdmin/forest-rails/issues/495)) ([571f889](https://github.com/ForestAdmin/forest-rails/commit/571f889d85c226b8d4b78618150c75f4fa2aa9ad))
43+
144
## [6.6.2](https://github.com/ForestAdmin/forest-rails/compare/v6.6.1...v6.6.2) (2021-06-16)
245

346

@@ -27,13 +70,38 @@
2770
* allow smart action endpoints to start with slashes ([d4f6a61](https://github.com/ForestAdmin/forest-rails/commit/d4f6a618aeea72364b0e7511545b67fbbfb17c99))
2871
* allow smart action endpoints to start with slashes ([cf6c6a9](https://github.com/ForestAdmin/forest-rails/commit/cf6c6a96498e6813e4b7ccaa56cacd9abefc332f))
2972

73+
# [7.0.0-beta.2](https://github.com/ForestAdmin/forest-rails/compare/v7.0.0-beta.1...v7.0.0-beta.2) (2021-06-07)
74+
75+
76+
### Features
77+
78+
* **hooks:** developers can dynamically add or remove smart actions fields ([#465](https://github.com/ForestAdmin/forest-rails/issues/465)) ([970f3d8](https://github.com/ForestAdmin/forest-rails/commit/970f3d82806296137f2e64379c92884b04954580))
79+
80+
81+
### BREAKING CHANGES
82+
83+
* **hooks:** fields parameters on hook function is no longer a map of field, it is now an array.
84+
change hook is no longer choosen by the field name, field need to have hook defined inside it definition by addin a props hook.
85+
3086
# [6.5.0](https://github.com/ForestAdmin/forest-rails/compare/v6.4.1...v6.5.0) (2021-06-03)
3187

3288

3389
### Features
3490

3591
* **schema:** move some meta data under stack attribute to prevent blocking scenarios on DWO ([#469](https://github.com/ForestAdmin/forest-rails/issues/469)) ([76aa754](https://github.com/ForestAdmin/forest-rails/commit/76aa7540300f75b0ea1d00ec3b60e4976b7d800e))
3692

93+
# [7.0.0-beta.1](https://github.com/ForestAdmin/forest-rails/compare/v6.4.1-beta.1...v7.0.0-beta.1) (2021-06-01)
94+
95+
96+
### Bug Fixes
97+
98+
* **dependency:** now using forestadmin-jsonapi-serializers instead of the jsonapi-serializers gem ([#475](https://github.com/ForestAdmin/forest-rails/issues/475)) ([3feea36](https://github.com/ForestAdmin/forest-rails/commit/3feea36b3b578638f3ad7c16ebab8e457a68d71f))
99+
100+
101+
### BREAKING CHANGES
102+
103+
* **dependency:** Switch from jsonapi-serializers to forestadmin-jsonapi-serializers to serialize data to the JSONAPI format, mainly to avoid conflict with the jsonapi-serializer library
104+
37105
## [6.4.1](https://github.com/ForestAdmin/forest-rails/compare/v6.4.0...v6.4.1) (2021-06-01)
38106

39107

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ group :test do
2323
end
2424

2525
gem 'rails', '6.0.3.6'
26-
gem 'jsonapi-serializers', '1.0.1'
26+
gem 'forestadmin-jsonapi-serializers'
2727
gem 'rack-cors'
2828
gem 'arel-helpers', '2.11.0'
2929
gem 'groupdate', '5.2.2'

Gemfile.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
PATH
22
remote: .
33
specs:
4-
forest_liana (6.6.2)
4+
forest_liana (7.0.0-beta.6)
55
arel-helpers
66
bcrypt
7+
forestadmin-jsonapi-serializers (>= 0.14.0)
78
groupdate (>= 5.0.0)
89
httparty
910
ipaddress
1011
json
1112
json-jwt
12-
jsonapi-serializers (>= 0.14.0)
1313
jwt
1414
openid_connect
1515
rack-cors
@@ -87,6 +87,8 @@ GEM
8787
diff-lcs (1.4.4)
8888
docile (1.3.5)
8989
erubi (1.10.0)
90+
forestadmin-jsonapi-serializers (2.0.0.pre.beta.2)
91+
activesupport
9092
globalid (0.4.2)
9193
activesupport (>= 4.2.0)
9294
groupdate (5.2.2)
@@ -103,8 +105,6 @@ GEM
103105
activesupport (>= 4.2)
104106
aes_key_wrap
105107
bindata
106-
jsonapi-serializers (1.0.1)
107-
activesupport
108108
jwt (2.2.3)
109109
loofah (2.9.1)
110110
crass (~> 1.0.2)
@@ -235,12 +235,12 @@ DEPENDENCIES
235235
bcrypt
236236
byebug
237237
forest_liana!
238+
forestadmin-jsonapi-serializers
238239
groupdate (= 5.2.2)
239240
httparty (= 0.18.1)
240241
ipaddress (= 0.8.3)
241242
json
242243
json-jwt (= 1.12.0)
243-
jsonapi-serializers (= 1.0.1)
244244
jwt
245245
openid_connect (= 1.2.0)
246246
rack-cors
@@ -252,4 +252,4 @@ DEPENDENCIES
252252
useragent
253253

254254
BUNDLED WITH
255-
2.1.4
255+
2.2.3
Lines changed: 60 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
module ForestLiana
2-
class ActionsController < ForestLiana::BaseController
2+
class ActionsController < ApplicationController
33

4-
def values
5-
render serializer: nil, json: {}, status: :ok
4+
def get_smart_action_hook_request
5+
begin
6+
params[:data][:attributes]
7+
rescue => error
8+
FOREST_LOGGER.error "Smart Action hook request error: #{error}"
9+
{}
10+
end
611
end
712

813
def get_collection(collection_name)
@@ -12,49 +17,53 @@ def get_collection(collection_name)
1217
def get_action(collection_name)
1318
collection = get_collection(collection_name)
1419
begin
15-
collection.actions.find {|action| ActiveSupport::Inflector.parameterize(action.name) == params[:action_name]}
20+
collection.actions.find {|action| ActiveSupport::Inflector.parameterize(action.name) == params[:action_name]}
1621
rescue => error
1722
FOREST_LOGGER.error "Smart Action get action retrieval error: #{error}"
1823
nil
1924
end
2025
end
21-
22-
def get_record
23-
model = ForestLiana::SchemaUtils.find_model_from_collection_name(params[:collectionName])
24-
redord_getter = ForestLiana::ResourceGetter.new(model, {:id => params[:recordIds][0]})
25-
redord_getter.perform
26-
redord_getter.record
27-
end
2826

2927
def get_smart_action_load_ctx(fields)
30-
fields = fields.reduce({}) do |p, c|
31-
ForestLiana::WidgetsHelper.set_field_widget(c)
32-
p.update(c[:field] => c.merge!(value: nil))
28+
fields = fields.map do |field|
29+
ForestLiana::WidgetsHelper.set_field_widget(field)
30+
field[:value] = nil unless field[:value]
31+
field
3332
end
34-
{:record => get_record, :fields => fields}
33+
{:fields => fields, :params => params}
3534
end
3635

37-
def get_smart_action_change_ctx(fields)
38-
fields = fields.reduce({}) do |p, c|
39-
field = c.permit!.to_h.symbolize_keys
36+
def get_smart_action_change_ctx(fields, field_changed)
37+
found_field_changed = fields.find{|field| field[:field] == field_changed}
38+
fields = fields.map do |field|
39+
field = field.permit!.to_h.symbolize_keys
4040
ForestLiana::WidgetsHelper.set_field_widget(field)
41-
p.update(c[:field] => field)
41+
field
4242
end
43-
{:record => get_record, :fields => fields}
43+
{:field_changed => found_field_changed, :fields => fields, :params => params}
4444
end
4545

46-
def handle_result(result, formatted_fields, action)
47-
if result.nil? || !result.is_a?(Hash)
48-
return render status: 500, json: { error: 'Error in smart action load hook: hook must return an object' }
46+
def handle_result(result, action)
47+
if result.nil? || !result.is_a?(Array)
48+
return render status: 500, json: { error: 'Error in smart action load hook: hook must return an array of fields' }
4949
end
50-
is_same_data_structure = ForestLiana::IsSameDataStructureHelper::Analyser.new(formatted_fields, result, 1)
51-
unless is_same_data_structure.perform
52-
return render status: 500, json: { error: 'Error in smart action hook: fields must be unchanged (no addition nor deletion allowed)' }
50+
51+
# Validate that the fields are well formed.
52+
begin
53+
# action.hooks[:change] is a hashmap here
54+
# to do the validation, only the hook names are require
55+
change_hooks_name = action.hooks[:change].nil? ? nil : action.hooks[:change].keys
56+
ForestLiana::SmartActionFieldValidator.validate_smart_action_fields(result, action.name, change_hooks_name)
57+
rescue ForestLiana::Errors::SmartActionInvalidFieldError => invalid_field_error
58+
FOREST_LOGGER.warn invalid_field_error.message
59+
rescue ForestLiana::Errors::SmartActionInvalidFieldHookError => invalid_hook_error
60+
FOREST_LOGGER.error invalid_hook_error.message
61+
return render status: 500, json: { error: invalid_hook_error.message }
5362
end
5463

5564
# Apply result on fields (transform the object back to an array), preserve order.
56-
fields = action.fields.map do |field|
57-
updated_field = result[field[:field]]
65+
fields = result.map do |field|
66+
updated_field = result.find{|f| f[:field] == field[:field]}
5867

5968
# Reset `value` when not present in `enums` (which means `enums` has changed).
6069
if updated_field[:enums].is_a?(Array)
@@ -72,41 +81,49 @@ def handle_result(result, formatted_fields, action)
7281
updated_field
7382
end
7483

75-
render serializer: nil, json: { fields: fields}, status: :ok
84+
render serializer: nil, json: { fields: fields }, status: :ok
7685
end
7786

7887
def load
79-
action = get_action(params[:collectionName])
88+
load_request = get_smart_action_hook_request
89+
90+
action = get_action(load_request[:collection_name])
8091

8192
if !action
8293
render status: 500, json: {error: 'Error in smart action load hook: cannot retrieve action from collection'}
8394
else
84-
# Transform fields from array to an object to ease usage in hook, adds null value.
95+
# Get the smart action hook load context
8596
context = get_smart_action_load_ctx(action.fields)
86-
formatted_fields = context[:fields].clone # clone for following test on is_same_data_structure
8797

8898
# Call the user-defined load hook.
8999
result = action.hooks[:load].(context)
90100

91-
handle_result(result, formatted_fields, action)
101+
handle_result(result, action)
92102
end
93103
end
94104

95105
def change
96-
action = get_action(params[:collectionName])
106+
change_request = get_smart_action_hook_request
107+
108+
action = get_action(change_request[:collection_name])
97109

98110
if !action
99-
render status: 500, json: {error: 'Error in smart action change hook: cannot retrieve action from collection'}
100-
else
101-
# Transform fields from array to an object to ease usage in hook.
102-
context = get_smart_action_change_ctx(params[:fields])
103-
formatted_fields = context[:fields].clone # clone for following test on is_same_data_structure
111+
return render status: 500, json: {error: 'Error in smart action change hook: cannot retrieve action from collection'}
112+
elsif change_request[:fields].nil?
113+
return render status: 500, json: {error: 'Error in smart action change hook: fields params is mandatory'}
114+
elsif !change_request[:fields].is_a?(Array)
115+
return render status: 500, json: {error: 'Error in smart action change hook: fields params must be an array'}
116+
end
104117

105-
# Call the user-defined change hook.
106-
result = action.hooks[:change][params[:changedField]].(context)
118+
# Get the smart action hook change context
119+
context = get_smart_action_change_ctx(change_request[:fields], change_request[:changed_field])
107120

108-
handle_result(result, formatted_fields, action)
109-
end
121+
field_changed_hook = context[:field_changed][:hook]
122+
123+
# Call the user-defined change hook.
124+
result = action.hooks[:change][field_changed_hook].(context)
125+
126+
handle_result(result, action)
110127
end
111128
end
112129
end

app/controllers/forest_liana/application_controller.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ def forest_user
3434

3535
def serialize_model(record, options = {})
3636
options[:is_collection] = false
37-
json = JSONAPI::Serializer.serialize(record, options)
37+
json = ForestAdmin::JSONAPI::Serializer.serialize(record, options)
3838

3939
force_utf8_encoding(json)
4040
end
4141

4242
def serialize_models(records, options = {}, fields_searched = [])
4343
options[:is_collection] = true
44-
json = JSONAPI::Serializer.serialize(records, options)
44+
json = ForestAdmin::JSONAPI::Serializer.serialize(records, options)
4545

4646
if options[:params] && options[:params][:search]
4747
# NOTICE: Add the Smart Fields with a 'String' type.
@@ -86,15 +86,6 @@ def authenticate_user_from_jwt
8686
end
8787
end
8888

89-
def get_smart_action_context
90-
begin
91-
params[:data][:attributes].values[0].to_hash.symbolize_keys
92-
rescue => error
93-
FOREST_LOGGER.error "Smart Action context retrieval error: #{error}"
94-
{}
95-
end
96-
end
97-
9889
def internal_server_error
9990
head :internal_server_error
10091
end

app/controllers/forest_liana/associations_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class AssociationsController < ForestLiana::ApplicationController
1010

1111
def index
1212
begin
13-
getter = HasManyGetter.new(@resource, @association, params)
13+
getter = HasManyGetter.new(@resource, @association, params, forest_user)
1414
getter.perform
1515

1616
respond_to do |format|
@@ -25,7 +25,7 @@ def index
2525

2626
def count
2727
begin
28-
getter = HasManyGetter.new(@resource, @association, params)
28+
getter = HasManyGetter.new(@resource, @association, params, forest_user)
2929
getter.count
3030

3131
render serializer: nil, json: { count: getter.records_count }
@@ -41,7 +41,7 @@ def update
4141
updater.perform
4242

4343
if updater.errors
44-
render serializer: nil, json: JSONAPI::Serializer.serialize_errors(
44+
render serializer: nil, json: ForestAdmin::JSONAPI::Serializer.serialize_errors(
4545
updater.errors), status: 422
4646
else
4747
head :no_content

app/controllers/forest_liana/base_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def reject_unauthorized_ip
2424
end
2525
end
2626
rescue ForestLiana::Errors::ExpectedError => exception
27-
error_data = JSONAPI::Serializer.serialize_errors([{
27+
error_data = ForestAdmin::JSONAPI::Serializer.serialize_errors([{
2828
status: exception.error_code,
2929
detail: exception.message
3030
}])

0 commit comments

Comments
 (0)