apidae 1.3.18 → 1.4.1

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: 404091c3c4aeea7ead657d6f94d1c87729df31a856e1e2c84926e8e9dbe19367
4
- data.tar.gz: de47d5b8f2526a44586b55207d3dd466b867590a3ab78874b78d5179a37fdf6c
3
+ metadata.gz: 7426138fffb907d9917ac5d115a954002023efcc6a2ccbe0d6e27a0ca5f4e85d
4
+ data.tar.gz: d4716809c8a3bb226d8cf538a23c07e2e926a65b1d396911f680cef4dba8cc3f
5
5
  SHA512:
6
- metadata.gz: 7dff3c671ee521d5fc73dd9d9a0061bf8d3815f6df24d121e677574d2406d2582533533b46b22505da22d4d639e206d228b66fdfbcfc6cc21bad8a956922c90a
7
- data.tar.gz: bad3ccfea997dcc9e2674b9bb0fc882581ef66391c0a11e8fbc3eed79ab599b1fedd2620e70330998d886694c54b9e2575a80497aab11cd8e976b0c676513f00
6
+ metadata.gz: a0e49d2d72be1d4f9f0036ca7da7138fb778af340a363b97b2a027062d166dfdf88dc7bc9db9ba83b4b66a186290d157767592552eb889f42c4ba8b5a4b0671d
7
+ data.tar.gz: 44d1a75ac8f9a9a14d3bc54ab31a9b9fdb1bef8bfa35f9edb7d2c19891e1637e89ed6e6f10bd1fd3131966293de66c788508988b1ac3b46cb71017dd3235bb37
@@ -130,13 +130,15 @@ module Apidae
130
130
  l.each do |locale|
131
131
  pics_data[locale] = []
132
132
  pictures_array.select { |p| p.is_a?(Hash) && !p[:traductionFichiers].blank? }.each do |pic|
133
+ pic_file = pic[:traductionFichiers][0]
133
134
  pics_data[locale] << {
134
135
  id: pic[:identifiant],
135
136
  name: localized_value(pic, :nom, locale),
136
- url: pic[:traductionFichiers][0][:url].gsub('http:', 'https:'),
137
+ url: pic_file[:url].gsub('http:', 'https:'),
137
138
  description: localized_value(pic, :legende, locale),
138
139
  credits: localized_value(pic, :copyright, locale),
139
- expiration_date: pic[:dateLimiteDePublication] || ''
140
+ expiration_date: pic[:dateLimiteDePublication] || '',
141
+ properties: {size: pic_file[:taille], width: pic_file[:largeur], height: pic_file[:height]}
140
142
  }
141
143
  end
142
144
  end
@@ -214,21 +216,22 @@ module Apidae
214
216
  def self.parse_location_data(location_hash, type_data_hash, territories)
215
217
  loc_data = {}
216
218
  unless location_hash.blank?
217
- address_hash = location_hash[:adresse]
219
+ address_hash = location_hash[:adresse] || {}
218
220
  computed_address = []
219
221
  unless address_hash.blank?
220
- computed_address << address_hash[:adresse1] unless address_hash[:adresse1].blank?
221
- computed_address << address_hash[:adresse2] unless address_hash[:adresse2].blank?
222
- computed_address << address_hash[:adresse3] unless address_hash[:adresse3].blank?
222
+ computed_address << address_hash[:adresse1]
223
+ computed_address << address_hash[:adresse2]
224
+ computed_address << address_hash[:adresse3]
223
225
  end
224
226
  loc_data.merge!({address: computed_address})
225
- loc_data.merge!({place: type_data_hash[:nomLieu]}) if type_data_hash
227
+ loc_data.merge!({place: (type_data_hash ? type_data_hash[:nomLieu] : nil) || address_hash[:nomDuLieu]})
226
228
  geoloc_details = location_hash[:geolocalisation]
227
229
  if geoloc_details && geoloc_details[:valide] && geoloc_details[:geoJson]
228
230
  loc_data[:latitude] = geoloc_details[:geoJson][:coordinates][1]
229
231
  loc_data[:longitude] = geoloc_details[:geoJson][:coordinates][0]
230
232
  end
231
233
  loc_data[:map_reference] = geoloc_details[:reperePlan]
234
+ loc_data[:valid] = geoloc_details[:valide] == true
232
235
  loc_data[:altitude] = geoloc_details[:altitude] if geoloc_details
233
236
  loc_data[:access] = node_value(geoloc_details, :complement) if geoloc_details
234
237
  loc_data[:environments] = location_hash[:environnements].map {|e| e[:id]} if location_hash[:environnements]
@@ -10,7 +10,7 @@ module Apidae
10
10
  attr_accessor :obj_versions
11
11
 
12
12
  store_accessor :title_data, :title
13
- store_accessor :owner_data, :owner_name, :owner_id
13
+ store_accessor :owner_data, :owner_name, :owner_id, :polls
14
14
  store_accessor :description_data, :short_desc, :long_desc, :theme_desc, :private_desc
15
15
  store_accessor :pictures_data, :pictures
16
16
  store_accessor :attachments_data, :attachments
@@ -28,6 +28,8 @@ module Apidae
28
28
  store_accessor :tags_data, :promo, :internal, :linked
29
29
  store_accessor :version_data, :versioned_fields
30
30
 
31
+ before_update :archive_updated_fields
32
+
31
33
  ALL_FIELDS.each do |f|
32
34
  alias_method :"get_#{f}", :"#{f}"
33
35
  alias_method :"set_#{f}", :"#{f}="
@@ -105,6 +107,10 @@ module Apidae
105
107
  @obj_versions = {}
106
108
  end
107
109
 
110
+ def self.default_scope
111
+ where(root_obj_id: nil)
112
+ end
113
+
108
114
  def root_obj
109
115
  Obj.unscoped.where(id: root_obj_id).first
110
116
  end
@@ -138,12 +144,61 @@ module Apidae
138
144
  elsif root_val.respond_to?(:dig)
139
145
  root_val.dig(*nested_keys)
140
146
  else
141
- raise ArgumentError.new('Cannot call dig with these args')
147
+ raise ArgumentError.new('Cannot call dig with these args: ' + keys.to_s)
142
148
  end
143
149
  end
144
150
 
145
- def self.default_scope
146
- where(root_obj_id: nil)
151
+ def archive_updated_fields
152
+ self.prev_data ||= {}
153
+ ignored_root_attributes = ['prev_data', 'updated_at']
154
+ changed_attributes.each_pair do |attr, prev_value|
155
+ unless ignored_root_attributes.include?(attr)
156
+ if prev_value.is_a?(Hash)
157
+ archive_hash_value(prev_value)
158
+ else
159
+ self.prev_data[attr] = {'prev' => prev_value, 'ts' => Time.current.to_i}
160
+ end
161
+ end
162
+ end
163
+ end
164
+
165
+ def archive_hash_value(prev_value, parent = nil)
166
+ ts = Time.current.to_i
167
+ ignored_sub_attributes = ['opening_days']
168
+ prev_value.each_pair do |sub_attr, prev_sub_val|
169
+ if Apidae::ALL_LOCALES.include?(sub_attr) && parent
170
+ new_val = in_locale(sub_attr).send(parent)
171
+ elsif /^\d+$/.match?(sub_attr) && parent
172
+ # Note : email / website / telephone etc... case - To be improved using changes method and a proper Hash/Array diff
173
+ new_val = in_locale(Apidae::DEFAULT_LOCALE)[parent]
174
+ else
175
+ new_val = parent ? in_locale(Apidae::DEFAULT_LOCALE).dig(parent, sub_attr) : (respond_to?(sub_attr) ? in_locale(Apidae::DEFAULT_LOCALE).send(sub_attr) : in_locale(Apidae::DEFAULT_LOCALE)[sub_attr])
176
+ end
177
+ unless ignored_sub_attributes.include?(sub_attr) || new_val == prev_sub_val
178
+ if parent
179
+ self.prev_data[parent][sub_attr] ||= {}
180
+ else
181
+ self.prev_data[sub_attr] ||= {}
182
+ end
183
+ if prev_sub_val.is_a?(Hash) && parent.nil?
184
+ archive_hash_value(prev_sub_val, sub_attr)
185
+ elsif prev_sub_val.is_a?(Array) && prev_sub_val.all? {|v| v.is_a?(Hash) && (v['id'] || v['identifiant'])}
186
+ archived_val = {'prev' => prev_sub_val.map {|v| v['id'] || v['identifiant']}, 'ts' => ts}
187
+ if parent
188
+ self.prev_data[parent][sub_attr] = archived_val
189
+ else
190
+ self.prev_data[sub_attr] = archived_val
191
+ end
192
+ else
193
+ archived_val = {'prev' => prev_sub_val, 'ts' => ts}
194
+ if parent
195
+ self.prev_data[parent][sub_attr] = archived_val
196
+ else
197
+ self.prev_data[sub_attr] = archived_val
198
+ end
199
+ end
200
+ end
201
+ end
147
202
  end
148
203
 
149
204
  def self.add_object(object_data, locales, versions)
@@ -0,0 +1,5 @@
1
+ class AddPrevDataToApidaeObjs < ActiveRecord::Migration[6.1]
2
+ def change
3
+ add_column :apidae_objs, :prev_data, :jsonb
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Apidae
2
- VERSION = "1.3.18"
2
+ VERSION = "1.4.1"
3
3
  end
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(version: 2021_06_07_214647) do
13
+ ActiveRecord::Schema.define(version: 2023_02_06_113335) do
14
14
 
15
15
  # These are extensions that must be enabled in order to support this database
16
16
  enable_extension "plpgsql"
@@ -69,6 +69,7 @@ ActiveRecord::Schema.define(version: 2021_06_07_214647) do
69
69
  t.datetime "last_update"
70
70
  t.jsonb "owner_data"
71
71
  t.jsonb "version_data"
72
+ t.jsonb "prev_data"
72
73
  t.index ["apidae_id"], name: "apidae_objs_apidae_id"
73
74
  t.index ["root_obj_id", "version"], name: "index_apidae_objs_on_root_obj_id_and_version", unique: true
74
75
  t.index ["root_obj_id"], name: "apidae_objs_root_obj_id"
@@ -19,177 +19,19 @@ callback this way:
19
19
  That block runs when the application boots, and every time there is a reload.
20
20
  For historical reasons, it may run twice, so it has to be idempotent.
21
21
 
22
- Check the "Autoloading and Reloading Constants" guide to learn more about how
23
- Rails autoloads and reloads.
24
- (called from <top (required)> at /Users/jbvilain/workspace/apidae-engine-rails/test/dummy/config/environment.rb:5)
25
- DEPRECATION WARNING: Initialization autoloaded the constants Apidae::ApidaeHelper, Apidae::ApplicationHelper, Apidae::ApiHelper, Apidae::DashboardHelper, Apidae::ExtendableHelper, Apidae::ImportHelper, Apidae::ObjectsHelper, Apidae::ReferencesHelper, Apidae::SelectionsHelper, and Apidae::ApplicationController.
26
-
27
- Being able to do this is deprecated. Autoloading during initialization is going
28
- to be an error condition in future versions of Rails.
29
-
30
- Reloading does not reboot the application, and therefore code executed during
31
- initialization does not run again. So, if you reload Apidae::ApidaeHelper, for example,
32
- the expected changes won't be reflected in that stale Module object.
33
-
34
- `config.autoloader` is set to `classic`. These autoloaded constants would have been unloaded if `config.autoloader` had been set to `:zeitwerk`.
35
-
36
- In order to autoload safely at boot time, please wrap your code in a reloader
37
- callback this way:
38
-
39
- Rails.application.reloader.to_prepare do
40
- # Autoload classes and modules needed at boot time here.
41
- end
42
-
43
- That block runs when the application boots, and every time there is a reload.
44
- For historical reasons, it may run twice, so it has to be idempotent.
45
-
46
- Check the "Autoloading and Reloading Constants" guide to learn more about how
47
- Rails autoloads and reloads.
48
- (called from <top (required)> at /Users/jbvilain/workspace/code/apidae-engine-rails/test/dummy/config/environment.rb:5)
49
- DEPRECATION WARNING: Initialization autoloaded the constants Apidae::ApidaeHelper, Apidae::ApplicationHelper, Apidae::ApiHelper, Apidae::DashboardHelper, Apidae::ExtendableHelper, Apidae::ImportHelper, Apidae::ObjectsHelper, Apidae::ReferencesHelper, Apidae::SelectionsHelper, and Apidae::ApplicationController.
50
-
51
- Being able to do this is deprecated. Autoloading during initialization is going
52
- to be an error condition in future versions of Rails.
53
-
54
- Reloading does not reboot the application, and therefore code executed during
55
- initialization does not run again. So, if you reload Apidae::ApidaeHelper, for example,
56
- the expected changes won't be reflected in that stale Module object.
57
-
58
- `config.autoloader` is set to `classic`. These autoloaded constants would have been unloaded if `config.autoloader` had been set to `:zeitwerk`.
59
-
60
- In order to autoload safely at boot time, please wrap your code in a reloader
61
- callback this way:
62
-
63
- Rails.application.reloader.to_prepare do
64
- # Autoload classes and modules needed at boot time here.
65
- end
66
-
67
- That block runs when the application boots, and every time there is a reload.
68
- For historical reasons, it may run twice, so it has to be idempotent.
69
-
70
- Check the "Autoloading and Reloading Constants" guide to learn more about how
71
- Rails autoloads and reloads.
72
- (called from <top (required)> at /Users/jbvilain/workspace/code/apidae-engine-rails/test/dummy/config/environment.rb:5)
73
- DEPRECATION WARNING: Initialization autoloaded the constants Apidae::ApidaeHelper, Apidae::ApplicationHelper, Apidae::ApiHelper, Apidae::DashboardHelper, Apidae::ExtendableHelper, Apidae::ImportHelper, Apidae::ObjectsHelper, Apidae::ReferencesHelper, Apidae::SelectionsHelper, and Apidae::ApplicationController.
74
-
75
- Being able to do this is deprecated. Autoloading during initialization is going
76
- to be an error condition in future versions of Rails.
77
-
78
- Reloading does not reboot the application, and therefore code executed during
79
- initialization does not run again. So, if you reload Apidae::ApidaeHelper, for example,
80
- the expected changes won't be reflected in that stale Module object.
81
-
82
- `config.autoloader` is set to `classic`. These autoloaded constants would have been unloaded if `config.autoloader` had been set to `:zeitwerk`.
83
-
84
- In order to autoload safely at boot time, please wrap your code in a reloader
85
- callback this way:
86
-
87
- Rails.application.reloader.to_prepare do
88
- # Autoload classes and modules needed at boot time here.
89
- end
90
-
91
- That block runs when the application boots, and every time there is a reload.
92
- For historical reasons, it may run twice, so it has to be idempotent.
93
-
94
- Check the "Autoloading and Reloading Constants" guide to learn more about how
95
- Rails autoloads and reloads.
96
- (called from <top (required)> at /Users/jbvilain/workspace/code/apidae-engine-rails/test/dummy/config/environment.rb:5)
97
- DEPRECATION WARNING: Initialization autoloaded the constants Apidae::ApidaeHelper, Apidae::ApplicationHelper, Apidae::ApiHelper, Apidae::DashboardHelper, Apidae::ExtendableHelper, Apidae::ImportHelper, Apidae::ObjectsHelper, Apidae::ReferencesHelper, Apidae::SelectionsHelper, and Apidae::ApplicationController.
98
-
99
- Being able to do this is deprecated. Autoloading during initialization is going
100
- to be an error condition in future versions of Rails.
101
-
102
- Reloading does not reboot the application, and therefore code executed during
103
- initialization does not run again. So, if you reload Apidae::ApidaeHelper, for example,
104
- the expected changes won't be reflected in that stale Module object.
105
-
106
- `config.autoloader` is set to `classic`. These autoloaded constants would have been unloaded if `config.autoloader` had been set to `:zeitwerk`.
107
-
108
- In order to autoload safely at boot time, please wrap your code in a reloader
109
- callback this way:
110
-
111
- Rails.application.reloader.to_prepare do
112
- # Autoload classes and modules needed at boot time here.
113
- end
114
-
115
- That block runs when the application boots, and every time there is a reload.
116
- For historical reasons, it may run twice, so it has to be idempotent.
117
-
118
- Check the "Autoloading and Reloading Constants" guide to learn more about how
119
- Rails autoloads and reloads.
120
- (called from <top (required)> at /Users/jbvilain/workspace/code/apidae-engine-rails/test/dummy/config/environment.rb:5)
121
- DEPRECATION WARNING: Initialization autoloaded the constants Apidae::ApidaeHelper, Apidae::ApplicationHelper, Apidae::ApiHelper, Apidae::DashboardHelper, Apidae::ExtendableHelper, Apidae::ImportHelper, Apidae::ObjectsHelper, Apidae::ReferencesHelper, Apidae::SelectionsHelper, and Apidae::ApplicationController.
122
-
123
- Being able to do this is deprecated. Autoloading during initialization is going
124
- to be an error condition in future versions of Rails.
125
-
126
- Reloading does not reboot the application, and therefore code executed during
127
- initialization does not run again. So, if you reload Apidae::ApidaeHelper, for example,
128
- the expected changes won't be reflected in that stale Module object.
129
-
130
- `config.autoloader` is set to `classic`. These autoloaded constants would have been unloaded if `config.autoloader` had been set to `:zeitwerk`.
131
-
132
- In order to autoload safely at boot time, please wrap your code in a reloader
133
- callback this way:
134
-
135
- Rails.application.reloader.to_prepare do
136
- # Autoload classes and modules needed at boot time here.
137
- end
138
-
139
- That block runs when the application boots, and every time there is a reload.
140
- For historical reasons, it may run twice, so it has to be idempotent.
141
-
142
- Check the "Autoloading and Reloading Constants" guide to learn more about how
143
- Rails autoloads and reloads.
144
- (called from <top (required)> at /Users/jbvilain/workspace/code/apidae-engine-rails/test/dummy/config/environment.rb:5)
145
- DEPRECATION WARNING: Initialization autoloaded the constants Apidae::ApidaeHelper, Apidae::ApplicationHelper, Apidae::ApiHelper, Apidae::DashboardHelper, Apidae::ExtendableHelper, Apidae::ImportHelper, Apidae::ObjectsHelper, Apidae::ReferencesHelper, Apidae::SelectionsHelper, and Apidae::ApplicationController.
146
-
147
- Being able to do this is deprecated. Autoloading during initialization is going
148
- to be an error condition in future versions of Rails.
149
-
150
- Reloading does not reboot the application, and therefore code executed during
151
- initialization does not run again. So, if you reload Apidae::ApidaeHelper, for example,
152
- the expected changes won't be reflected in that stale Module object.
153
-
154
- `config.autoloader` is set to `classic`. These autoloaded constants would have been unloaded if `config.autoloader` had been set to `:zeitwerk`.
155
-
156
- In order to autoload safely at boot time, please wrap your code in a reloader
157
- callback this way:
158
-
159
- Rails.application.reloader.to_prepare do
160
- # Autoload classes and modules needed at boot time here.
161
- end
162
-
163
- That block runs when the application boots, and every time there is a reload.
164
- For historical reasons, it may run twice, so it has to be idempotent.
165
-
166
- Check the "Autoloading and Reloading Constants" guide to learn more about how
167
- Rails autoloads and reloads.
168
- (called from <top (required)> at /Users/jbvilain/workspace/code/apidae-engine-rails/test/dummy/config/environment.rb:5)
169
- DEPRECATION WARNING: Initialization autoloaded the constants Apidae::ApidaeHelper, Apidae::ApplicationHelper, Apidae::ApiHelper, Apidae::DashboardHelper, Apidae::ExtendableHelper, Apidae::ImportHelper, Apidae::ObjectsHelper, Apidae::ReferencesHelper, Apidae::SelectionsHelper, and Apidae::ApplicationController.
170
-
171
- Being able to do this is deprecated. Autoloading during initialization is going
172
- to be an error condition in future versions of Rails.
173
-
174
- Reloading does not reboot the application, and therefore code executed during
175
- initialization does not run again. So, if you reload Apidae::ApidaeHelper, for example,
176
- the expected changes won't be reflected in that stale Module object.
177
-
178
- `config.autoloader` is set to `classic`. These autoloaded constants would have been unloaded if `config.autoloader` had been set to `:zeitwerk`.
179
-
180
- In order to autoload safely at boot time, please wrap your code in a reloader
181
- callback this way:
182
-
183
- Rails.application.reloader.to_prepare do
184
- # Autoload classes and modules needed at boot time here.
185
- end
186
-
187
- That block runs when the application boots, and every time there is a reload.
188
- For historical reasons, it may run twice, so it has to be idempotent.
189
-
190
22
  Check the "Autoloading and Reloading Constants" guide to learn more about how
191
23
  Rails autoloads and reloads.
192
24
  (called from <top (required)> at /Users/jbvilain/workspace/code/apidae-engine-rails/test/dummy/config/environment.rb:5)
25
+ Apidae::Obj Load (0.8ms) SELECT "apidae_objs".* FROM "apidae_objs" WHERE "apidae_objs"."root_obj_id" IS NULL ORDER BY "apidae_objs"."id" ASC LIMIT $1 [["LIMIT", 1]]
26
+ TRANSACTION (1.0ms) BEGIN
27
+ Apidae::Obj Create (8.3ms) INSERT INTO "apidae_objs" ("apidae_type", "created_at", "updated_at", "description_data") VALUES ($1, $2, $3, $4) RETURNING "id" [["apidae_type", "test"], ["created_at", "2023-02-16 21:12:52.351303"], ["updated_at", "2023-02-16 21:12:52.351303"], ["description_data", "{\"short_desc\":{\"\":\"test desc\"}}"]]
28
+ TRANSACTION (0.7ms) COMMIT
29
+ TRANSACTION (0.2ms) BEGIN
30
+ Apidae::Obj Update (1.3ms) UPDATE "apidae_objs" SET "updated_at" = $1, "description_data" = $2 WHERE "apidae_objs"."id" = $3 [["updated_at", "2023-02-16 21:16:00.968796"], ["description_data", "{\"short_desc\":{\"\":\"test desc\",\"fr\":\"updated desc\"}}"], ["id", 1]]
31
+ TRANSACTION (0.7ms) COMMIT
32
+ TRANSACTION (0.2ms) BEGIN
33
+ Apidae::Obj Create (0.9ms) INSERT INTO "apidae_objs" ("apidae_type", "created_at", "updated_at", "description_data") VALUES ($1, $2, $3, $4) RETURNING "id" [["apidae_type", "HOTELLERIE"], ["created_at", "2023-02-16 21:17:36.422310"], ["updated_at", "2023-02-16 21:17:36.422310"], ["description_data", "{\"short_desc\":{\"fr\":\"short desc fr\"}}"]]
34
+ TRANSACTION (1.4ms) COMMIT
193
35
  DEPRECATION WARNING: Initialization autoloaded the constants Apidae::ApidaeHelper, Apidae::ApplicationHelper, Apidae::ApiHelper, Apidae::DashboardHelper, Apidae::ExtendableHelper, Apidae::ImportHelper, Apidae::ObjectsHelper, Apidae::ReferencesHelper, Apidae::SelectionsHelper, and Apidae::ApplicationController.
194
36
 
195
37
  Being able to do this is deprecated. Autoloading during initialization is going