forest_liana 9.5.4 → 9.5.6
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5326dc27652421070200c8ad7f86863a59b6ee54750b31902e539d7891ad4825
|
4
|
+
data.tar.gz: 719a0f521b807b93eb425f51c8397e264b8db3ae2f184a76842f2c5f51865971
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d409eb403db0eba20edd180722ccd14a9eb00019cebc6b9cb04bd62f0da1ecb046ac3a351155372be316d8f08d405c4b8d393a7c1aad506ebf5d6fd2bdea502
|
7
|
+
data.tar.gz: 000bd627330daa5a934477ccb93138b94d3d6672011024c195eef9a7d40f144505010f90c3fa1ba9d09818272222b8155e39bf2f11adcee660f2f76c33dd112a
|
@@ -30,6 +30,7 @@ module ForestLiana
|
|
30
30
|
if field.try(:[], :search)
|
31
31
|
begin
|
32
32
|
@records = field[:search].call(@records, @search)
|
33
|
+
(@fields_searched << field[:field].to_s) if field[:type] == 'String'
|
33
34
|
rescue => exception
|
34
35
|
FOREST_REPORTER.report exception
|
35
36
|
FOREST_LOGGER.error "Cannot search properly on Smart Field:\n" \
|
@@ -24,11 +24,15 @@ module ForestLiana::Collection
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def action(name, opts = {})
|
27
|
+
return if model.actions.find { |action| action.name == name }
|
28
|
+
|
27
29
|
opts[:name] = name
|
28
30
|
model.actions << ForestLiana::Model::Action.new(opts)
|
29
31
|
end
|
30
32
|
|
31
33
|
def segment(name, opts = {}, &block)
|
34
|
+
return if model.segments.find { |segment| segment.name == name }
|
35
|
+
|
32
36
|
opts[:name] = name
|
33
37
|
model.segments << ForestLiana::Model::Segment.new(opts, &block)
|
34
38
|
end
|
@@ -74,12 +78,14 @@ module ForestLiana::Collection
|
|
74
78
|
opts[:validations] = [] unless opts.has_key?(:validations)
|
75
79
|
opts[:is_virtual] = true unless opts.has_key?(:polymorphic_key) && opts[:polymorphic_key]
|
76
80
|
|
77
|
-
|
81
|
+
field = opts.merge({
|
78
82
|
field: name,
|
79
83
|
is_filterable: !!opts[:is_filterable],
|
80
84
|
is_sortable: !!opts[:is_sortable],
|
81
85
|
})
|
82
86
|
|
87
|
+
add_field(field)
|
88
|
+
|
83
89
|
define_method(name) { self.data[name] } if smart_collection?
|
84
90
|
|
85
91
|
if serializer_name && ForestLiana::UserSpace.const_defined?(
|
@@ -108,13 +114,15 @@ module ForestLiana::Collection
|
|
108
114
|
end
|
109
115
|
|
110
116
|
def has_many(name, opts, &block)
|
111
|
-
|
117
|
+
field = opts.merge({
|
112
118
|
field: name,
|
113
119
|
is_virtual: true,
|
114
120
|
is_searchable: false,
|
115
121
|
type: ['String']
|
116
122
|
})
|
117
123
|
|
124
|
+
add_field(field)
|
125
|
+
|
118
126
|
define_method(name) { self.data[name] } if smart_collection?
|
119
127
|
|
120
128
|
if serializer_name && ForestLiana::UserSpace.const_defined?(
|
@@ -126,13 +134,15 @@ module ForestLiana::Collection
|
|
126
134
|
end
|
127
135
|
|
128
136
|
def belongs_to(name, opts, &block)
|
129
|
-
|
137
|
+
field = opts.merge({
|
130
138
|
field: name,
|
131
139
|
is_virtual: true,
|
132
140
|
is_searchable: false,
|
133
141
|
type: 'String'
|
134
142
|
})
|
135
143
|
|
144
|
+
add_field(field)
|
145
|
+
|
136
146
|
define_method(name) { self.data[name] } if smart_collection?
|
137
147
|
|
138
148
|
if serializer_name && ForestLiana::UserSpace.const_defined?(
|
@@ -145,6 +155,12 @@ module ForestLiana::Collection
|
|
145
155
|
|
146
156
|
private
|
147
157
|
|
158
|
+
def add_field(field)
|
159
|
+
return if model.fields.find { |field| field[:field] == name }
|
160
|
+
|
161
|
+
model.fields << field
|
162
|
+
end
|
163
|
+
|
148
164
|
def find_name(collection_name)
|
149
165
|
# TODO: Remove once lianas prior to 2.0.0 are not supported anymore.
|
150
166
|
model = ForestLiana.models.find { |collection| collection.try(:table_name) == collection_name.to_s }
|
data/lib/forest_liana/version.rb
CHANGED
@@ -8,7 +8,12 @@ class Forest::User
|
|
8
8
|
"name IS '#{capitalize_name}'"
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
search_cap_name = lambda do |query, search|
|
12
|
+
# Injects your new filter into the query.
|
13
|
+
query.or(User.where("name = '#{search}'"))
|
14
|
+
end
|
15
|
+
|
16
|
+
field :cap_name, type: 'String', filter: filter_cap_name, search: search_cap_name do
|
12
17
|
object.name.upcase
|
13
18
|
end
|
14
19
|
|
@@ -154,6 +154,100 @@ describe 'Requesting Tree resources', :type => :request do
|
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
|
+
describe 'Requesting User resources', :type => :request do
|
158
|
+
describe 'index' do
|
159
|
+
before do
|
160
|
+
User.create(name: 'John')
|
161
|
+
|
162
|
+
Rails.cache.write('forest.users', {'1' => { 'id' => 1, 'roleId' => 1, 'rendering_id' => '1' }})
|
163
|
+
Rails.cache.write('forest.has_permission', true)
|
164
|
+
Rails.cache.write(
|
165
|
+
'forest.collections',
|
166
|
+
{
|
167
|
+
'User' => {
|
168
|
+
'browse' => [1],
|
169
|
+
'read' => [1],
|
170
|
+
'edit' => [1],
|
171
|
+
'add' => [1],
|
172
|
+
'delete' => [1],
|
173
|
+
'export' => [1],
|
174
|
+
'actions' => {}
|
175
|
+
}
|
176
|
+
}
|
177
|
+
)
|
178
|
+
|
179
|
+
allow(ForestLiana::IpWhitelist).to receive(:retrieve) { true }
|
180
|
+
allow(ForestLiana::IpWhitelist).to receive(:is_ip_whitelist_retrieved) { true }
|
181
|
+
allow(ForestLiana::IpWhitelist).to receive(:is_ip_valid) { true }
|
182
|
+
allow(ForestLiana::ScopeManager).to receive(:fetch_scopes).and_return(
|
183
|
+
{'scopes' => {}, 'team' => {'id' => '1', 'name' => 'Operations'}}
|
184
|
+
)
|
185
|
+
end
|
186
|
+
|
187
|
+
after do
|
188
|
+
User.destroy_all
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'should respond the user data with meta when search apply on simple column and smart field' do
|
192
|
+
token = JWT.encode({
|
193
|
+
id: 1,
|
194
|
+
email: 'michael.kelso@that70.show',
|
195
|
+
first_name: 'Michael',
|
196
|
+
last_name: 'Kelso',
|
197
|
+
team: 'Operations',
|
198
|
+
rendering_id: 16,
|
199
|
+
exp: Time.now.to_i + 2.weeks.to_i,
|
200
|
+
permission_level: 'admin'
|
201
|
+
}, ForestLiana.auth_secret, 'HS256')
|
202
|
+
|
203
|
+
headers = {
|
204
|
+
'Accept' => 'application/json',
|
205
|
+
'Content-Type' => 'application/json',
|
206
|
+
'Authorization' => "Bearer #{token}"
|
207
|
+
}
|
208
|
+
|
209
|
+
params = {
|
210
|
+
fields: { 'User' => 'id,name,cap_name' },
|
211
|
+
page: { 'number' => '1', 'size' => '10' },
|
212
|
+
searchExtended: '0',
|
213
|
+
search: 'JOHN',
|
214
|
+
sort: '-id',
|
215
|
+
timezone: 'Europe/Paris'
|
216
|
+
}
|
217
|
+
|
218
|
+
allow(ForestAdmin::JSONAPI::Serializer).to receive(:serialize).and_return(
|
219
|
+
{ "data" => [
|
220
|
+
{
|
221
|
+
"type" => "User",
|
222
|
+
"id" => "1",
|
223
|
+
"attributes" => { "id" => 1, "name" => "John", "cap_name" => "JOHN" },
|
224
|
+
"links" => { "self" => "/forest/user/1" }
|
225
|
+
}
|
226
|
+
], "included" => [] }
|
227
|
+
)
|
228
|
+
|
229
|
+
get '/forest/User', params: params, headers: headers
|
230
|
+
|
231
|
+
expect(JSON.parse(response.body)).to include(
|
232
|
+
"data" => [
|
233
|
+
{
|
234
|
+
"type" => "User",
|
235
|
+
"id" => "1",
|
236
|
+
"attributes" => {
|
237
|
+
"id" => 1,
|
238
|
+
"name" => "John",
|
239
|
+
"cap_name" => "JOHN"
|
240
|
+
},
|
241
|
+
"links" => { "self" => "/forest/user/1" },
|
242
|
+
}
|
243
|
+
],
|
244
|
+
"included" => [],
|
245
|
+
"meta" => { 'decorators' => { '0' => { 'id' => "1", 'search' => %w[name cap_name] } } }
|
246
|
+
)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
157
251
|
describe 'Requesting Address resources', :type => :request do
|
158
252
|
let(:scope_filters) { {'scopes' => {}, 'team' => {'id' => '1', 'name' => 'Operations'}} }
|
159
253
|
before do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forest_liana
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 9.5.
|
4
|
+
version: 9.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sandro Munda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|