labimotion 2.0.0.rc2 → 2.0.0.rc4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/labimotion/apis/standard_api.rb +1 -2
- data/lib/labimotion/apis/standard_layer_api.rb +4 -17
- data/lib/labimotion/apis/vocabulary_api.rb +6 -20
- data/lib/labimotion/constants.rb +21 -0
- data/lib/labimotion/entities/dataset_entity.rb +0 -1
- data/lib/labimotion/entities/element_entity.rb +1 -0
- data/lib/labimotion/entities/properties_entity.rb +101 -41
- data/lib/labimotion/entities/segment_entity.rb +0 -2
- data/lib/labimotion/entities/vocabulary_entity.rb +2 -13
- data/lib/labimotion/helpers/element_helpers.rb +2 -2
- data/lib/labimotion/helpers/generic_helpers.rb +6 -1
- data/lib/labimotion/helpers/param_helpers.rb +0 -16
- data/lib/labimotion/libs/converter.rb +0 -1
- data/lib/labimotion/libs/data/mapper/Chemwiki.json +236 -0
- data/lib/labimotion/libs/data/mapper/Source.json +78 -0
- data/lib/labimotion/libs/data/vocab/System.json +1 -1
- data/lib/labimotion/libs/dataset_builder.rb +70 -0
- data/lib/labimotion/libs/export_dataset.rb +165 -66
- data/lib/labimotion/libs/nmr_mapper.rb +204 -247
- data/lib/labimotion/utils/mapper_utils.rb +169 -0
- data/lib/labimotion/utils/utils.rb +22 -0
- data/lib/labimotion/version.rb +1 -1
- data/lib/labimotion.rb +3 -3
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aab9882de072c222a6e67a54d30eabe5f81733531e36cf702fcf3383cc526981
|
4
|
+
data.tar.gz: a84933a64d143182e581afd1c69ae8bee6dec8ce462c6eec9fa90b48da64df2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59430594a0b79bf838688ffd2f3f71e928e582ee9b44f11a3dbf5cdbc0ba30e2d971dc25e2b538027357a06a04d2f61d05dfbc0a151f41e65de580633d238db6
|
7
|
+
data.tar.gz: 895e4a24ab94b5b92a2fbcafdfeb90cc1ee040d75c7fbe8b142de08293b8c503f9551f64865ee3a2980811f8344dabc7159f43992c972c80ff455661c70bfd7d
|
@@ -13,8 +13,7 @@ module Labimotion
|
|
13
13
|
use :create_std_layer_params
|
14
14
|
end
|
15
15
|
post do
|
16
|
-
|
17
|
-
# create_element_klass(current_user, params)
|
16
|
+
authenticate_admin!('standard_layers')
|
18
17
|
create_std_layer(current_user, params)
|
19
18
|
status 201
|
20
19
|
rescue ActiveRecord::RecordInvalid => e
|
@@ -7,14 +7,13 @@ module Labimotion
|
|
7
7
|
class StandardLayerAPI < Grape::API
|
8
8
|
include Grape::Kaminari
|
9
9
|
helpers Labimotion::ParamHelpers
|
10
|
+
helpers Labimotion::GenericHelpers
|
10
11
|
|
11
12
|
resource :layers do
|
12
13
|
namespace :get_all_layers do
|
13
14
|
desc 'get all standard layers for designer'
|
14
15
|
get do
|
15
16
|
list = Labimotion::StdLayer.all.sort_by { |e| e.name }
|
16
|
-
# present list, with: Labimotion::StdLayer, root: 'klass'
|
17
|
-
# data = Labimotion::StdLayer.represent(col_tree, serializable: true)
|
18
17
|
return { mc: 'ss00', data: list }
|
19
18
|
rescue StandardError => e
|
20
19
|
Labimotion.log_exception(e, current_user)
|
@@ -24,17 +23,9 @@ module Labimotion
|
|
24
23
|
|
25
24
|
namespace :get_standard_layer do
|
26
25
|
desc 'get standard layer by id'
|
27
|
-
# params do
|
28
|
-
# requires :id, type: Integer, desc: 'Layer id'
|
29
|
-
# end
|
30
26
|
route_param :id do
|
31
|
-
before do
|
32
|
-
# @element_policy = ElementPolicy.new(current_user, Labimotion::Element.find(params[:id]))
|
33
|
-
# error!('401 Unauthorized', 401) unless current_user.matrix_check_by_name('genericElement') && @element_policy.read?
|
34
|
-
# rescue ActiveRecord::RecordNotFound
|
35
|
-
# error!('404 Not Found', 404)
|
36
|
-
end
|
37
27
|
get do
|
28
|
+
authenticate_admin!('standard_layers')
|
38
29
|
entity = Labimotion::StdLayer.find(params[:id])
|
39
30
|
return { mc: 'ss00', data: entity }
|
40
31
|
rescue StandardError => e
|
@@ -50,13 +41,9 @@ module Labimotion
|
|
50
41
|
use :std_layer_save
|
51
42
|
end
|
52
43
|
before do
|
44
|
+
authenticate_admin!('standard_layers')
|
53
45
|
cur_layer = Labimotion::StdLayer.find_by(name: params[:key])
|
54
46
|
error!('Error! duplicate name', 409) if cur_layer.present?
|
55
|
-
# @element_policy = ElementPolicy.new(current_user, Labimotion::Element.find(params[:id]))
|
56
|
-
# error!('401 Unauthorized', 401) unless current_user.matrix_check_by_name('genericElement') && @element_policy.read?
|
57
|
-
# rescue ActiveRecord::RecordNotFound
|
58
|
-
# Labimotion.log_exception(e, current_user)
|
59
|
-
# error!('404 Not Found', 404)
|
60
47
|
end
|
61
48
|
post do
|
62
49
|
attributes = {
|
@@ -83,7 +70,7 @@ module Labimotion
|
|
83
70
|
end
|
84
71
|
route_param :id do
|
85
72
|
before do
|
86
|
-
|
73
|
+
authenticate_admin!('standard_layers')
|
87
74
|
end
|
88
75
|
delete do
|
89
76
|
entity = Labimotion::StdLayer.find(params[:id])
|
@@ -7,6 +7,7 @@ module Labimotion
|
|
7
7
|
class VocabularyAPI < Grape::API
|
8
8
|
include Grape::Kaminari
|
9
9
|
helpers Labimotion::ParamHelpers
|
10
|
+
helpers Labimotion::GenericHelpers
|
10
11
|
|
11
12
|
resource :vocab do
|
12
13
|
namespace :save_vocabulary do
|
@@ -15,7 +16,7 @@ module Labimotion
|
|
15
16
|
use :vocab_save
|
16
17
|
end
|
17
18
|
before do
|
18
|
-
|
19
|
+
authenticate_admin!('vocabularies')
|
19
20
|
rescue ActiveRecord::RecordNotFound
|
20
21
|
error!('404 Not Found', 404)
|
21
22
|
end
|
@@ -30,7 +31,7 @@ module Labimotion
|
|
30
31
|
source_id: params[:source_id],
|
31
32
|
layer_id: params[:layer_id],
|
32
33
|
field_id: params[:name],
|
33
|
-
identifier:
|
34
|
+
identifier: params[:source_id],
|
34
35
|
created_by: current_user.id,
|
35
36
|
properties: declared(params, include_missing: false),
|
36
37
|
}
|
@@ -46,17 +47,8 @@ module Labimotion
|
|
46
47
|
namespace :get_all_vocabularies do
|
47
48
|
desc 'get all standard layers for designer'
|
48
49
|
get do
|
49
|
-
|
50
|
-
# Dir.glob(Rails.public_path.join('generic', 'vocabularies', '*.json')).each do |file_path|
|
51
|
-
# file_content = File.read(file_path)
|
52
|
-
# json_data = JSON.parse(file_content)
|
53
|
-
# merged_data.concat(json_data)
|
54
|
-
# end
|
55
|
-
|
56
|
-
# list = Labimotion::Vocabulary.all.sort_by { |e| e.name }
|
57
|
-
# present list, with: Labimotion::StdLayer, root: 'klass'
|
50
|
+
authenticate_admin!('vocabularies')
|
58
51
|
combined_data = Labimotion::VocabularyHandler.load_all_vocabularies
|
59
|
-
# combined_data = Labimotion::VocabularyEntity.represent(vocabularies, serializable: true)
|
60
52
|
return { mc: 'ss00', data: combined_data }
|
61
53
|
rescue StandardError => e
|
62
54
|
Labimotion.log_exception(e, current_user)
|
@@ -67,15 +59,9 @@ module Labimotion
|
|
67
59
|
namespace :field_klasses do
|
68
60
|
desc 'get all field klasses for admin function'
|
69
61
|
get do
|
70
|
-
|
71
|
-
# file_content = File.read(file_path)
|
72
|
-
# json_data = JSON.parse(file_content)
|
73
|
-
# merged_data.concat(json_data)
|
74
|
-
# end
|
62
|
+
authenticate_admin!('vocabularies')
|
75
63
|
vocabularies = Labimotion::VocabularyHandler.load_app_vocabularies
|
76
64
|
merged_data = Labimotion::FieldKlassEntity.represent(vocabularies, serializable: true)
|
77
|
-
# list = Labimotion::Vocabulary.all.sort_by { |e| e.name }
|
78
|
-
# present list, with: Labimotion::VocabularyEntity, root: 'klass'
|
79
65
|
merged_data
|
80
66
|
rescue StandardError => e
|
81
67
|
Labimotion.log_exception(e, current_user)
|
@@ -90,7 +76,7 @@ module Labimotion
|
|
90
76
|
end
|
91
77
|
route_param :id do
|
92
78
|
before do
|
93
|
-
|
79
|
+
authenticate_admin!('vocabularies')
|
94
80
|
end
|
95
81
|
delete do
|
96
82
|
entity = Labimotion::Vocabulary.find(params[:id])
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Labimotion
|
4
|
+
module Constants
|
5
|
+
module DateTime
|
6
|
+
DATE_FORMAT = '%Y-%m-%d'
|
7
|
+
DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S %Z'
|
8
|
+
TIME_FORMAT = '%H:%M:%S %Z'
|
9
|
+
TIME_ZONE = 'UTC'
|
10
|
+
end
|
11
|
+
|
12
|
+
module File
|
13
|
+
ENCODING = 'UTF-8'
|
14
|
+
end
|
15
|
+
|
16
|
+
module Mapper
|
17
|
+
NMR_CONFIG = ::File.join(__dir__, 'libs', 'data', 'mapper', 'Source.json').freeze
|
18
|
+
WIKI_CONFIG = ::File.join(__dir__, 'libs', 'data', 'mapper', 'Chemwiki.json').freeze
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -12,7 +12,7 @@ module Labimotion
|
|
12
12
|
private
|
13
13
|
|
14
14
|
def process_layers
|
15
|
-
(object&.properties.is_a?(Hash) && object.properties[Labimotion::Prop::LAYERS]&.keys || []).each do |key|
|
15
|
+
(object&.properties.is_a?(Hash) && (object.properties[Labimotion::Prop::LAYERS]&.keys || [])).each do |key|
|
16
16
|
yield(key, object.properties[Labimotion::Prop::LAYERS][key])
|
17
17
|
end
|
18
18
|
end
|
@@ -25,7 +25,8 @@ module Labimotion
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def process_sample_and_molecule_fields(key, layer)
|
28
|
-
select_fields(layer,
|
28
|
+
select_fields(layer,
|
29
|
+
[Labimotion::FieldType::DRAG_SAMPLE, Labimotion::FieldType::DRAG_MOLECULE]).each do |field, idx|
|
29
30
|
update_sample_or_molecule_field(key, field, idx)
|
30
31
|
end
|
31
32
|
end
|
@@ -60,13 +61,19 @@ module Labimotion
|
|
60
61
|
return unless sid.present?
|
61
62
|
|
62
63
|
el = field['type'] == Labimotion::FieldType::DRAG_SAMPLE ? Sample.find_by(id: sid) : Molecule.find_by(id: sid)
|
63
|
-
return unless el.present? && object.properties.dig(Labimotion::Prop::LAYERS, key, Labimotion::Prop::FIELDS, idx,
|
64
|
+
return unless el.present? && object.properties.dig(Labimotion::Prop::LAYERS, key, Labimotion::Prop::FIELDS, idx,
|
65
|
+
'value').present?
|
64
66
|
|
65
67
|
update_field_value(key, idx, {
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
'el_label' => el&.short_label,
|
69
|
+
'el_tip' => el&.short_label,
|
70
|
+
'el_svg' => if field['type'] == Labimotion::FieldType::DRAG_SAMPLE
|
71
|
+
el&.get_svg_path
|
72
|
+
else
|
73
|
+
File.join('/images',
|
74
|
+
'molecules', el&.molecule_svg_file || 'nosvg')
|
75
|
+
end
|
76
|
+
})
|
70
77
|
end
|
71
78
|
|
72
79
|
def update_reaction_field(key, field, idx)
|
@@ -79,23 +86,34 @@ module Labimotion
|
|
79
86
|
return
|
80
87
|
end
|
81
88
|
|
82
|
-
return unless object.properties.dig(Labimotion::Prop::LAYERS, key, Labimotion::Prop::FIELDS, idx,
|
89
|
+
return unless object.properties.dig(Labimotion::Prop::LAYERS, key, Labimotion::Prop::FIELDS, idx,
|
90
|
+
'value').present?
|
83
91
|
|
84
92
|
update_field_value(key, idx, {
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
93
|
+
'el_label' => el.short_label,
|
94
|
+
'el_tip' => el.short_label,
|
95
|
+
'el_svg' => el.reaction_svg_file
|
96
|
+
})
|
89
97
|
end
|
90
98
|
|
91
99
|
def update_table_field(key, field, idx)
|
92
100
|
return unless field['sub_values'].present? && field[Labimotion::Prop::SUBFIELDS].present?
|
93
101
|
|
94
|
-
field_table_molecules = field[Labimotion::Prop::SUBFIELDS].select
|
95
|
-
|
102
|
+
field_table_molecules = field[Labimotion::Prop::SUBFIELDS].select do |ss|
|
103
|
+
ss['type'] == Labimotion::FieldType::DRAG_MOLECULE
|
104
|
+
end
|
105
|
+
if field_table_molecules.present?
|
106
|
+
object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx] =
|
107
|
+
set_table(field, field_table_molecules, Labimotion::Prop::MOLECULE)
|
108
|
+
end
|
109
|
+
|
110
|
+
field_table_samples = field[Labimotion::Prop::SUBFIELDS].select do |ss|
|
111
|
+
ss['type'] == Labimotion::FieldType::DRAG_SAMPLE
|
112
|
+
end
|
113
|
+
return unless field_table_samples.present?
|
96
114
|
|
97
|
-
|
98
|
-
|
115
|
+
object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx] =
|
116
|
+
set_table(field, field_table_samples, Labimotion::Prop::SAMPLE)
|
99
117
|
end
|
100
118
|
|
101
119
|
def update_voc_field(key, field, idx)
|
@@ -122,9 +140,9 @@ module Labimotion
|
|
122
140
|
end
|
123
141
|
|
124
142
|
def update_element_voc_field(key, field, idx, root_element)
|
125
|
-
|
126
|
-
|
127
|
-
|
143
|
+
return unless field['identifier'] == 'element.name'
|
144
|
+
|
145
|
+
update_field_value(key, idx, root_element&.name)
|
128
146
|
end
|
129
147
|
|
130
148
|
def update_segment_voc_field(key, field, idx, root_element)
|
@@ -132,21 +150,28 @@ module Labimotion
|
|
132
150
|
return if segs.empty? || field['layer_id'].blank? || field['field_id'].blank?
|
133
151
|
|
134
152
|
seg = segs&.first
|
135
|
-
seg_fields = seg.properties.dig(Labimotion::Prop::LAYERS, field['layer_id'],
|
153
|
+
seg_fields = seg.properties.dig(Labimotion::Prop::LAYERS, field['layer_id'],
|
154
|
+
Labimotion::Prop::FIELDS).select do |ff|
|
155
|
+
ff['field'] == field['field_id']
|
156
|
+
end
|
136
157
|
seg_field = seg_fields&.first
|
137
158
|
update_field_value(key, idx, seg_field['value'])
|
138
159
|
end
|
139
160
|
|
140
161
|
def update_dataset_voc_field(key, field, idx, root_element)
|
141
|
-
dk = DatasetKlass.find_by(identifier: field[
|
142
|
-
dk[
|
143
|
-
anas = root_element.analyses.select
|
162
|
+
dk = DatasetKlass.find_by(identifier: field['source_id'])
|
163
|
+
dk['ols_term_id']
|
164
|
+
anas = root_element.analyses.select do |ana|
|
165
|
+
ana.extended_metadata['kind'].split('|')&.first&.strip == dk['ols_term_id']
|
166
|
+
end
|
144
167
|
anas.each do |ana|
|
145
168
|
ana.children.each do |cds|
|
146
169
|
next unless cds.dataset.present?
|
147
170
|
|
148
171
|
ds_prop = cds.dataset.properties
|
149
|
-
ds_fields = ds_prop.dig(Labimotion::Prop::LAYERS, field['layer_id'], Labimotion::Prop::FIELDS).select
|
172
|
+
ds_fields = ds_prop.dig(Labimotion::Prop::LAYERS, field['layer_id'], Labimotion::Prop::FIELDS).select do |ff|
|
173
|
+
ff['field'] == field['field_id']
|
174
|
+
end
|
150
175
|
ds_field = ds_fields&.first
|
151
176
|
if object.properties[Labimotion::Prop::LAYERS][key].present? && ds_field['value'].present?
|
152
177
|
update_field_value(key, idx, ds_field['value'])
|
@@ -155,15 +180,38 @@ module Labimotion
|
|
155
180
|
end
|
156
181
|
end
|
157
182
|
|
158
|
-
def update_field_value(key, idx, value)
|
159
|
-
object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]
|
183
|
+
def update_field_value(key, idx, value, act = 'merge')
|
184
|
+
field_path = object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]
|
185
|
+
original_value = field_path['value']
|
186
|
+
|
187
|
+
field_path['value'] = merge_values(original_value, value, act)
|
188
|
+
end
|
189
|
+
|
190
|
+
def merge_by_type(original_value, new_value)
|
191
|
+
if original_value.is_a?(Hash)
|
192
|
+
merge_hash_values(original_value, new_value)
|
193
|
+
# elsif original_value.is_a?(Array)
|
194
|
+
# merge_array_values(original_value, new_value)
|
195
|
+
else
|
196
|
+
new_value
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def merge_values(original_value, new_value, act)
|
201
|
+
return new_value if act == 'overwrite'
|
202
|
+
return new_value if original_value.blank?
|
203
|
+
return original_value if new_value.blank?
|
204
|
+
|
205
|
+
merge_by_type(original_value, new_value)
|
160
206
|
end
|
161
207
|
|
162
208
|
def set_table(field, field_table_objs, obj)
|
163
209
|
col_ids = field_table_objs.map { |x| x.values[0] }
|
164
210
|
col_ids.each do |col_id|
|
165
211
|
field['sub_values'].each do |sub_value|
|
166
|
-
|
212
|
+
unless sub_value[col_id].present? && sub_value[col_id]['value'].present? && sub_value[col_id]['value']['el_id'].present?
|
213
|
+
next
|
214
|
+
end
|
167
215
|
|
168
216
|
find_obj = obj.constantize.find_by(id: sub_value[col_id]['value']['el_id'])
|
169
217
|
next if find_obj.blank?
|
@@ -181,23 +229,35 @@ module Labimotion
|
|
181
229
|
|
182
230
|
def update_molecule_sub_value(sub_value, col_id, find_obj)
|
183
231
|
sub_value[col_id]['value'].merge!({
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
232
|
+
'el_svg' => File.join('/images', 'molecules', find_obj.molecule_svg_file),
|
233
|
+
'el_inchikey' => find_obj.inchikey,
|
234
|
+
'el_smiles' => find_obj.cano_smiles,
|
235
|
+
'el_iupac' => find_obj.iupac_name,
|
236
|
+
'el_molecular_weight' => find_obj.molecular_weight
|
237
|
+
})
|
190
238
|
end
|
191
239
|
|
192
240
|
def update_sample_sub_value(sub_value, col_id, find_obj)
|
193
241
|
sub_value[col_id]['value'].merge!({
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
242
|
+
'el_svg' => find_obj.get_svg_path,
|
243
|
+
'el_label' => find_obj.short_label,
|
244
|
+
'el_short_label' => find_obj.short_label,
|
245
|
+
'el_name' => find_obj.name,
|
246
|
+
'el_external_label' => find_obj.external_label,
|
247
|
+
'el_molecular_weight' => find_obj.decoupled ? find_obj.molecular_mass : find_obj.molecule.molecular_weight
|
248
|
+
})
|
249
|
+
end
|
250
|
+
|
251
|
+
def merge_hash_values(original, new_value)
|
252
|
+
return original unless new_value.is_a?(Hash)
|
253
|
+
|
254
|
+
original.merge(new_value)
|
255
|
+
end
|
256
|
+
|
257
|
+
def merge_array_values(original, new_value)
|
258
|
+
return original unless new_value.respond_to?(:to_a)
|
259
|
+
|
260
|
+
(original + new_value.to_a).uniq
|
201
261
|
end
|
202
262
|
end
|
203
|
-
end
|
263
|
+
end
|
@@ -6,25 +6,14 @@ module Labimotion
|
|
6
6
|
class VocabularyEntity < ApplicationEntity
|
7
7
|
expose :id, :identifier, :name, :label, :field_type, :opid, :term_id,
|
8
8
|
:field_id, :properties, :source, :source_id, :layer_id
|
9
|
-
# expose :source do |obj|
|
10
|
-
# (obj[:properties] && obj[:properties]['voc'] && obj[:properties]['voc']['source']) || ''
|
11
|
-
# end
|
12
|
-
# expose :source_id do |obj|
|
13
|
-
# (obj[:properties] && obj[:properties]['voc'] && obj[:properties]['voc']['source_id']) || ''
|
14
|
-
# end
|
15
|
-
# expose :layer_id do |obj|
|
16
|
-
# (obj[:properties] && obj[:properties]['voc'] && obj[:properties]['voc']['layer_id']) || ''
|
17
|
-
# end
|
18
|
-
|
19
9
|
expose :voc do |obj|
|
20
10
|
voc = (obj[:properties] && obj[:properties]['voc']) || {}
|
21
11
|
|
22
12
|
case voc['source']
|
23
13
|
when Labimotion::Prop::ELEMENT
|
24
|
-
voc['
|
25
|
-
# if voc['identifier'] == 'element.name'
|
14
|
+
if voc['identifier'] == 'element.name'
|
26
15
|
# voc['source_name'] = ElementKlass.find_by(identifier: voc['source_id'])&.name
|
27
|
-
|
16
|
+
end
|
28
17
|
when Labimotion::Prop::SEGMENT
|
29
18
|
voc['source_name'] = SegmentKlass.find_by(identifier: voc['source_id'])&.label
|
30
19
|
when Labimotion::Prop::DATASET
|
@@ -131,8 +131,8 @@ module Labimotion
|
|
131
131
|
end
|
132
132
|
element.save_segments(segments: params[:segments], current_user_id: current_user.id)
|
133
133
|
element.reload
|
134
|
-
|
135
|
-
element.
|
134
|
+
element.properties = update_vocabularies(element.properties, current_user, element)
|
135
|
+
element.save!
|
136
136
|
element
|
137
137
|
rescue StandardError => e
|
138
138
|
Labimotion.log_exception(e, current_user)
|
@@ -9,7 +9,12 @@ module Labimotion
|
|
9
9
|
extend Grape::API::Helpers
|
10
10
|
|
11
11
|
def authenticate_admin!(type)
|
12
|
-
error!('401 Unauthorized', 401)
|
12
|
+
unauthorized = -> { error!('401 Unauthorized', 401) }
|
13
|
+
if %w[standard_layers vocabularies].include?(type)
|
14
|
+
unauthorized.call unless current_user.generic_admin.values_at('elements', 'segments', 'datasets').any?
|
15
|
+
else
|
16
|
+
unauthorized.call unless current_user.generic_admin[type]
|
17
|
+
end
|
13
18
|
end
|
14
19
|
|
15
20
|
def fetch_klass(name, id)
|
@@ -134,21 +134,5 @@ module Labimotion
|
|
134
134
|
optional :select_options, type: Hash, desc: 'selections'
|
135
135
|
optional :option_layers, type: String, desc: 'option'
|
136
136
|
end
|
137
|
-
|
138
|
-
# params :vocabulary_save do
|
139
|
-
# requires :type, type: String, desc: 'type'
|
140
|
-
# requires :field, type: String, desc: 'field'
|
141
|
-
# optional :default, type: String, desc: 'default'
|
142
|
-
# optional :description, type: String, desc: 'description'
|
143
|
-
# optional :label, type: String, desc: 'label'
|
144
|
-
# optional :position, type: Integer, desc: 'position'
|
145
|
-
# optional :ontology, type: Hash, desc: 'ontology'
|
146
|
-
# optional :required, type: Boolean, desc: 'is required?'
|
147
|
-
# optional :sub_fields, type: Array, desc: 'sub_fields'
|
148
|
-
# optional :text_sub_fields, type: Array, desc: 'text_sub_fields'
|
149
|
-
# optional :source_type, type: String, desc: 'source type'
|
150
|
-
# optional :source_id, type: String, desc: 'source id'
|
151
|
-
# optional :layer_id, type: String, desc: 'layer id'
|
152
|
-
# end
|
153
137
|
end
|
154
138
|
end
|
@@ -123,7 +123,6 @@ module Labimotion
|
|
123
123
|
tmp_file.write(response.parsed_response)
|
124
124
|
tmp_file.rewind
|
125
125
|
|
126
|
-
# name = response&.headers && response&.headers['content-disposition']&.split('=')&.last
|
127
126
|
filename = oat.filename
|
128
127
|
name = "#{File.basename(filename, '.*')}.zip"
|
129
128
|
att = Attachment.new(
|