infopark_reactor 1.26.1 → 1.27.0.rc4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +25 -0
- data/.rubocop_todo.yml +363 -0
- data/Rakefile +10 -13
- data/app/models/rails_connector/abstract_obj.rb +2 -1
- data/config/routes.rb +0 -1
- data/infopark_reactor.gemspec +16 -15
- data/lib/generators/cm/migration/migration_generator.rb +4 -8
- data/lib/infopark_reactor.rb +43 -69
- data/lib/reactor/already_released.rb +1 -2
- data/lib/reactor/attributes.rb +92 -268
- data/lib/reactor/attributes/date_serializer.rb +20 -16
- data/lib/reactor/attributes/html_serializer.rb +6 -5
- data/lib/reactor/attributes/link_list_extender.rb +10 -8
- data/lib/reactor/attributes/link_list_from_accessor.rb +2 -1
- data/lib/reactor/attributes/link_list_from_attr_values.rb +2 -1
- data/lib/reactor/attributes/link_list_serializer.rb +8 -7
- data/lib/reactor/attributes_handlers.rb +164 -0
- data/lib/reactor/cache/permission.rb +6 -9
- data/lib/reactor/cache/user.rb +3 -6
- data/lib/reactor/cm/attribute.rb +16 -16
- data/lib/reactor/cm/attribute_group.rb +18 -21
- data/lib/reactor/cm/blob_too_small_error.rb +2 -2
- data/lib/reactor/cm/bridge.rb +6 -9
- data/lib/reactor/cm/channel.rb +3 -4
- data/lib/reactor/cm/editorial_group.rb +2 -9
- data/lib/reactor/cm/group.rb +30 -43
- data/lib/reactor/cm/job.rb +23 -25
- data/lib/reactor/cm/language.rb +21 -22
- data/lib/reactor/cm/link.rb +38 -40
- data/lib/reactor/cm/live_group.rb +2 -9
- data/lib/reactor/cm/log_entry.rb +22 -21
- data/lib/reactor/cm/missing_credentials.rb +3 -2
- data/lib/reactor/cm/multi_xml_request.rb +22 -25
- data/lib/reactor/cm/obj.rb +159 -154
- data/lib/reactor/cm/obj_class.rb +52 -51
- data/lib/reactor/cm/object_base.rb +26 -21
- data/lib/reactor/cm/permissions.rb +7 -7
- data/lib/reactor/cm/user.rb +43 -51
- data/lib/reactor/cm/workflow.rb +11 -12
- data/lib/reactor/cm/xml_attribute.rb +10 -19
- data/lib/reactor/cm/xml_markup.rb +7 -10
- data/lib/reactor/cm/xml_multi_request_error.rb +1 -3
- data/lib/reactor/cm/xml_request.rb +21 -29
- data/lib/reactor/cm/xml_request_error.rb +1 -3
- data/lib/reactor/cm/xml_response.rb +8 -16
- data/lib/reactor/cm/xml_single_request_error.rb +3 -5
- data/lib/reactor/configuration.rb +1 -3
- data/lib/reactor/engine.rb +5 -10
- data/lib/reactor/legacy.rb +6 -7
- data/lib/reactor/link/external.rb +8 -5
- data/lib/reactor/link/internal.rb +8 -5
- data/lib/reactor/link/temporary_link.rb +16 -17
- data/lib/reactor/main.rb +11 -15
- data/lib/reactor/migration.rb +52 -53
- data/lib/reactor/no_working_version.rb +1 -2
- data/lib/reactor/not_permitted.rb +1 -2
- data/lib/reactor/permission.rb +36 -38
- data/lib/reactor/persistence.rb +104 -178
- data/lib/reactor/plans/common_attribute.rb +7 -7
- data/lib/reactor/plans/common_attribute_group.rb +6 -6
- data/lib/reactor/plans/common_channel.rb +6 -6
- data/lib/reactor/plans/common_group.rb +7 -14
- data/lib/reactor/plans/common_job.rb +6 -6
- data/lib/reactor/plans/common_obj_class.rb +11 -11
- data/lib/reactor/plans/create_attribute.rb +1 -3
- data/lib/reactor/plans/create_attribute_group.rb +1 -3
- data/lib/reactor/plans/create_channel.rb +2 -3
- data/lib/reactor/plans/create_group.rb +3 -10
- data/lib/reactor/plans/create_job.rb +3 -4
- data/lib/reactor/plans/create_obj.rb +12 -14
- data/lib/reactor/plans/create_obj_class.rb +1 -2
- data/lib/reactor/plans/delete_attribute.rb +1 -3
- data/lib/reactor/plans/delete_attribute_group.rb +2 -4
- data/lib/reactor/plans/delete_channel.rb +3 -6
- data/lib/reactor/plans/delete_group.rb +2 -9
- data/lib/reactor/plans/delete_job.rb +3 -5
- data/lib/reactor/plans/delete_obj.rb +3 -4
- data/lib/reactor/plans/delete_obj_class.rb +1 -2
- data/lib/reactor/plans/prepared.rb +3 -4
- data/lib/reactor/plans/rename_group.rb +4 -11
- data/lib/reactor/plans/rename_obj_class.rb +1 -2
- data/lib/reactor/plans/update_attribute.rb +1 -3
- data/lib/reactor/plans/update_attribute_group.rb +2 -4
- data/lib/reactor/plans/update_group.rb +2 -9
- data/lib/reactor/plans/update_job.rb +4 -8
- data/lib/reactor/plans/update_obj.rb +6 -7
- data/lib/reactor/plans/update_obj_class.rb +0 -2
- data/lib/reactor/rc_independent.rb +0 -1
- data/lib/reactor/session.rb +27 -31
- data/lib/reactor/session/observers.rb +3 -5
- data/lib/reactor/session/user.rb +6 -7
- data/lib/reactor/session_helper/auth_filter.rb +9 -0
- data/lib/reactor/session_helper/auth_helper.rb +24 -0
- data/lib/reactor/session_helper/rsession_helper.rb +16 -0
- data/lib/reactor/session_helper/session_state.rb +31 -0
- data/lib/reactor/streaming_upload.rb +0 -1
- data/lib/reactor/sudo.rb +2 -3
- data/lib/reactor/support/link_matcher.rb +8 -7
- data/lib/reactor/tools/migrator.rb +30 -35
- data/lib/reactor/tools/response_handler/xml_attribute.rb +27 -33
- data/lib/reactor/tools/smart_xml_logger.rb +20 -22
- data/lib/reactor/tools/sower.rb +22 -23
- data/lib/reactor/tools/uploader.rb +12 -17
- data/lib/reactor/tools/versioner.rb +29 -30
- data/lib/reactor/tools/where_query.rb +11 -14
- data/lib/reactor/tools/workflow_generator.rb +26 -28
- data/lib/reactor/tools/xml_attributes.rb +7 -14
- data/lib/reactor/tools/xpath_extractor.rb +2 -1
- data/lib/reactor/validations.rb +20 -16
- data/lib/reactor/version.rb +1 -2
- data/lib/reactor/workflow.rb +10 -33
- data/lib/reactor/workflow/comment.rb +28 -0
- data/lib/reactor/workflow/empty.rb +0 -1
- data/lib/reactor/workflow/standard.rb +4 -3
- data/lib/tasks/cm_migrate.rake +3 -3
- data/lib/tasks/cm_seeds.rake +9 -16
- metadata +64 -28
- data/app/models/rails_connector/abstract_model.rb +0 -7
- data/app/models/rails_connector/attribute.rb +0 -94
- data/app/models/rails_connector/blob_mapping.rb +0 -16
- data/app/models/rails_connector/channel.rb +0 -41
- data/app/models/rails_connector/content.rb +0 -12
- data/app/models/rails_connector/job.rb +0 -14
- data/app/models/rails_connector/obj_class.rb +0 -158
- data/app/models/rails_connector/obj_class_attr.rb +0 -5
- data/app/models/rails_connector/object_with_meta_data.rb +0 -18
- data/lib/rails_connector/meta/eager_loader.rb +0 -91
- data/lib/reactor/rails_connector_meta.rb +0 -149
- data/lib/reactor/session_helper.rb +0 -72
data/lib/reactor/persistence.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require 'reactor/attributes/link_list_from_attr_values'
|
1
|
+
require "reactor/attributes/link_list_from_accessor"
|
2
|
+
require "reactor/attributes/link_list_from_attr_values"
|
4
3
|
|
5
4
|
module Reactor
|
6
5
|
module Persistence
|
@@ -32,30 +31,18 @@ module Reactor
|
|
32
31
|
# 3. object is invalid
|
33
32
|
# 4. other error occoured
|
34
33
|
# @param comment [String] comment to leave for the next user
|
35
|
-
def release(comment=nil)
|
36
|
-
|
34
|
+
def release(comment = nil)
|
35
|
+
release!(comment)
|
37
36
|
rescue Reactor::Cm::XmlRequestError, ActiveRecord::RecordInvalid, Reactor::NotPermitted, Reactor::AlreadyReleased
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
# Unreleases the object. Returns true on success,
|
42
|
-
# false when one of the following occurs:
|
43
|
-
# 1. user lacks the permissions
|
44
|
-
# 2. the object is not released
|
45
|
-
# 3. object is invalid
|
46
|
-
# 4. other error occoured
|
47
|
-
def unrelease(comment=nil)
|
48
|
-
return unrelease!(comment)
|
49
|
-
rescue Reactor::Cm::XmlRequestError, ActiveRecord::RecordInvalid, Reactor::NotPermitted
|
50
|
-
return false
|
37
|
+
false
|
51
38
|
end
|
52
39
|
|
53
40
|
# Removes the working version of the object,
|
54
41
|
# if it exists
|
55
42
|
# @param comment [String] comment to leave for the next user
|
56
43
|
# @return [true]
|
57
|
-
def revert(comment=nil)
|
58
|
-
|
44
|
+
def revert(comment = nil)
|
45
|
+
revert!(comment)
|
59
46
|
end
|
60
47
|
|
61
48
|
# Removes the working version of the object,
|
@@ -63,10 +50,10 @@ module Reactor
|
|
63
50
|
# @param comment [String] comment to leave for the next user
|
64
51
|
# @return [true]
|
65
52
|
# @note There is no difference between #revert and #revert!
|
66
|
-
def revert!(comment=nil)
|
53
|
+
def revert!(comment = nil)
|
67
54
|
crul_obj.revert!(comment)
|
68
55
|
reload
|
69
|
-
|
56
|
+
true
|
70
57
|
end
|
71
58
|
|
72
59
|
# Releases the object. Returns true on succes, can raise exceptions
|
@@ -74,21 +61,14 @@ module Reactor
|
|
74
61
|
# @raise [Reactor::AlreadyReleased]
|
75
62
|
# @raise [ActiveRecord::RecordInvalid] validations failed
|
76
63
|
# @raise [Reactor::NotPermitted] current user lacks required permissions
|
77
|
-
def release!(comment=nil)
|
64
|
+
def release!(comment = nil)
|
78
65
|
run_callbacks(:release) do
|
79
|
-
raise(Reactor::AlreadyReleased) unless
|
66
|
+
raise(Reactor::AlreadyReleased) unless really_edited?
|
67
|
+
|
80
68
|
crul_obj.release!(comment)
|
81
69
|
reload
|
82
70
|
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
# Unreleases the object. Returns true on succes, can raise exceptions
|
87
|
-
# @param comment [String] comment to leave for the next user
|
88
|
-
def unrelease!(comment=nil)
|
89
|
-
crul_obj.unrelease!(comment)
|
90
|
-
reload
|
91
|
-
return true
|
71
|
+
true
|
92
72
|
end
|
93
73
|
|
94
74
|
# Makes the current user the editor of the object. Returns true when
|
@@ -98,11 +78,11 @@ module Reactor
|
|
98
78
|
# 2. the object has not beed edited
|
99
79
|
# 3. other error occured
|
100
80
|
# @param comment [String] comment to leave for the next user
|
101
|
-
def take(comment=nil)
|
81
|
+
def take(comment = nil)
|
102
82
|
take!(comment)
|
103
|
-
|
83
|
+
true
|
104
84
|
rescue Reactor::Cm::XmlRequestError, Reactor::NotPermitted, Reactor::NoWorkingVersion
|
105
|
-
|
85
|
+
false
|
106
86
|
end
|
107
87
|
|
108
88
|
# Makes the current user the editor of the object. Returns true when
|
@@ -110,13 +90,14 @@ module Reactor
|
|
110
90
|
# @param comment [String] comment to leave for the next user
|
111
91
|
# @raise [Reactor::NoWorkingVersion] there is no working version of the object
|
112
92
|
# @raise [Reactor::NotPermitted] current user lacks required permissions
|
113
|
-
def take!(comment=nil)
|
114
|
-
raise(Reactor::NoWorkingVersion) unless
|
93
|
+
def take!(comment = nil)
|
94
|
+
raise(Reactor::NoWorkingVersion) unless really_edited?
|
95
|
+
|
115
96
|
# TODO: refactor the if condition
|
116
|
-
crul_obj.take!(comment) if
|
97
|
+
crul_obj.take!(comment) if crul_obj.editor != Reactor::Configuration.xml_access[:username]
|
117
98
|
# neccessary to recalculate #editor
|
118
99
|
reload
|
119
|
-
|
100
|
+
true
|
120
101
|
end
|
121
102
|
|
122
103
|
# Creates a working version of the object. Returns true on success or when
|
@@ -124,41 +105,41 @@ module Reactor
|
|
124
105
|
# @param comment [String] comment to leave for the next user
|
125
106
|
# 1. user lacks the permissions
|
126
107
|
# 2. other error occured
|
127
|
-
def edit(comment=nil)
|
108
|
+
def edit(comment = nil)
|
128
109
|
edit!(comment)
|
129
|
-
|
110
|
+
true
|
130
111
|
rescue Reactor::Cm::XmlRequestError, Reactor::NotPermitted
|
131
|
-
|
112
|
+
false
|
132
113
|
end
|
133
114
|
|
134
115
|
# Creates a working version of the object. Returns true on success or when
|
135
116
|
# the object already has a working version. Raises exceptions
|
136
117
|
# @param comment [String] comment to leave for the next user
|
137
118
|
# @raise [Reactor::NotPermitted] current user lacks required permissions
|
138
|
-
def edit!(comment=nil)
|
139
|
-
crul_obj.edit!(comment) unless
|
119
|
+
def edit!(comment = nil)
|
120
|
+
crul_obj.edit!(comment) unless really_edited?
|
140
121
|
reload
|
141
|
-
|
122
|
+
true
|
142
123
|
end
|
143
124
|
|
144
125
|
# Returns true, if the object has any links pointing to it.
|
145
126
|
# @raise [Reactor::Cm::XmlRequestError] generic error occoured
|
146
127
|
def has_super_links?
|
147
|
-
crul_obj.get(
|
128
|
+
crul_obj.get("hasSuperLinks") == "1"
|
148
129
|
end
|
149
130
|
|
150
131
|
# Return an array of RailsConnector::AbstractObj that contain a link
|
151
132
|
# to this file.
|
152
133
|
# @raise [Reactor::Cm::XmlRequestError] generic error occoured
|
153
134
|
def super_objects
|
154
|
-
RailsConnector::AbstractObj.where(:
|
135
|
+
RailsConnector::AbstractObj.where(obj_id: crul_obj.get("superObjects")).to_a
|
155
136
|
end
|
156
137
|
|
157
138
|
# Returns true if this object hasn't been saved yet -- that is, a record
|
158
139
|
# for the object doesn't exist in the data store yet; otherwise, returns false.
|
159
140
|
def new_record?
|
160
|
-
|
161
|
-
!destroyed? && (
|
141
|
+
# !destroyed? && (self.id.nil? || !self.class.exists?(self.id))
|
142
|
+
!destroyed? && (id.nil? || path.blank?)
|
162
143
|
end
|
163
144
|
|
164
145
|
# Stolen from Rails 3.
|
@@ -192,7 +173,7 @@ module Reactor
|
|
192
173
|
# Freezes the object.
|
193
174
|
def destroy
|
194
175
|
run_callbacks(:destroy) do
|
195
|
-
|
176
|
+
delete
|
196
177
|
end
|
197
178
|
end
|
198
179
|
|
@@ -201,12 +182,12 @@ module Reactor
|
|
201
182
|
# but tries to mimmic their behaviour.
|
202
183
|
def reload(options = nil)
|
203
184
|
RailsConnector::AbstractObj.uncached do
|
204
|
-
#super # Throws RecordNotFound when changing obj_class
|
185
|
+
# super # Throws RecordNotFound when changing obj_class
|
205
186
|
# AR reload
|
206
187
|
clear_aggregation_cache
|
207
188
|
clear_association_cache
|
208
|
-
fresh_object = RailsConnector::AbstractObj.find(
|
209
|
-
@attributes = fresh_object.instance_variable_get(
|
189
|
+
fresh_object = RailsConnector::AbstractObj.find(id, options)
|
190
|
+
@attributes = fresh_object.instance_variable_get("@attributes")
|
210
191
|
@attributes_cache = {}
|
211
192
|
# RC reload
|
212
193
|
@attr_values = nil
|
@@ -227,9 +208,9 @@ module Reactor
|
|
227
208
|
# 2. generic error occoured
|
228
209
|
def resolve_refs
|
229
210
|
resolve_refs!
|
230
|
-
|
211
|
+
true
|
231
212
|
rescue Reactor::Cm::XmlRequestError, Reactor::NotPermitted
|
232
|
-
|
213
|
+
false
|
233
214
|
end
|
234
215
|
|
235
216
|
# Resolves references in any of the html fields. Returns true on success,
|
@@ -237,52 +218,39 @@ module Reactor
|
|
237
218
|
# @raise [Reactor::NotPermitted] current user lacks required permissions
|
238
219
|
def resolve_refs!
|
239
220
|
crul_obj.resolve_refs!
|
240
|
-
|
241
|
-
end
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
end
|
257
|
-
elsif Reactor.rails3_1? || Reactor.rails3_2? || Reactor.rails4_x?
|
258
|
-
# It should excactly match ActiveRecord::Base.new in it's behavior
|
259
|
-
# @see ActiveRecord::Base.new
|
260
|
-
def initialize(attributes = nil, options={}, &block)
|
261
|
-
if true || !self.class.send(:attribute_methods_overriden?) #FIXME !!!
|
262
|
-
ignored_attributes = ignore_attributes(attributes)
|
263
|
-
# supress block hijacking!
|
264
|
-
super(attributes, options) {}
|
265
|
-
load_ignored_attributes(ignored_attributes)
|
266
|
-
yield self if block_given?
|
267
|
-
else
|
268
|
-
super(attributes, options)
|
269
|
-
end
|
221
|
+
true
|
222
|
+
end
|
223
|
+
|
224
|
+
# It should excactly match ActiveRecord::Base.new in it's behavior
|
225
|
+
# @see ActiveRecord::Base.new
|
226
|
+
def initialize(attributes = nil, _options = {})
|
227
|
+
if true || !self.class.send(:attribute_methods_overriden?)
|
228
|
+
ignored_attributes = ignore_attributes(attributes)
|
229
|
+
# supress block hijacking!
|
230
|
+
super(attributes) {}
|
231
|
+
load_ignored_attributes(ignored_attributes)
|
232
|
+
yield self if block_given?
|
233
|
+
else
|
234
|
+
# TODO
|
235
|
+
# here we get 'ActiveRecord::AssociationTypeMismatch'
|
236
|
+
super(attributes)
|
270
237
|
end
|
271
|
-
else
|
272
|
-
raise RuntimeError, "Unsupported Rails version!"
|
273
238
|
end
|
274
239
|
|
275
240
|
# Equivalent to Obj#edited?
|
276
241
|
def really_edited?
|
277
|
-
|
242
|
+
# check if really edited with curl request
|
243
|
+
crul_obj.edited?
|
244
|
+
# self.edited?
|
278
245
|
end
|
279
246
|
|
280
247
|
# Returns an array of errors
|
281
248
|
def reasons_for_incomplete_state
|
282
|
-
crul_obj.get(
|
249
|
+
crul_obj.get("reasonsForIncompleteState") || []
|
283
250
|
end
|
284
251
|
|
285
252
|
protected
|
253
|
+
|
286
254
|
def prevent_resolve_refs
|
287
255
|
@prevent_resolve_refs = true
|
288
256
|
end
|
@@ -292,12 +260,10 @@ module Reactor
|
|
292
260
|
end
|
293
261
|
|
294
262
|
def sanitize_name
|
295
|
-
return unless
|
263
|
+
return unless name.present?
|
296
264
|
|
297
|
-
sanitized_name = self.class.send(:sanitize_name,
|
298
|
-
if sanitized_name !=
|
299
|
-
self.name = sanitized_name
|
300
|
-
end
|
265
|
+
sanitized_name = self.class.send(:sanitize_name, name)
|
266
|
+
self.name = sanitized_name if sanitized_name != name
|
301
267
|
end
|
302
268
|
|
303
269
|
def crul_attributes_set?
|
@@ -310,12 +276,12 @@ module Reactor
|
|
310
276
|
|
311
277
|
def changed_linklists
|
312
278
|
custom_attrs =
|
313
|
-
|
314
|
-
self.class.send(:instance_variable_get,
|
279
|
+
singleton_class.send(:instance_variable_get, "@_o_allowed_attrs") ||
|
280
|
+
self.class.send(:instance_variable_get, "@_o_allowed_attrs") ||
|
315
281
|
[]
|
316
282
|
|
317
283
|
custom_attrs.select do |attr|
|
318
|
-
|
284
|
+
send(:attribute_type, attr) == :linklist && send(:[], attr.to_sym).try(:changed?)
|
319
285
|
end
|
320
286
|
end
|
321
287
|
|
@@ -332,28 +298,27 @@ module Reactor
|
|
332
298
|
end
|
333
299
|
|
334
300
|
def crul_obj_save
|
335
|
-
attrs,
|
336
|
-
|
301
|
+
attrs, = crul_attributes.partition do |field, (_value, _options)|
|
302
|
+
send(:attribute_type, field) != :linklist
|
337
303
|
end
|
338
304
|
linklists = changed_linklists
|
339
305
|
|
340
306
|
new_links = {}.tap do |result|
|
341
307
|
linklists.map do |field|
|
342
308
|
result[field] = Reactor::Attributes::LinkListFromAccessor.new(self, field).call.map do |l|
|
343
|
-
{:
|
309
|
+
{ link_id: l.id, title: l.title, destination_url: (l.internal? ? l.destination_object.path : l.url), target: l.target }
|
344
310
|
end
|
345
311
|
end
|
346
312
|
end
|
347
313
|
|
348
314
|
links_modified = !linklists.empty?
|
349
315
|
|
350
|
-
crul_obj.composite_save(attrs, [], [], [], links_modified) do |
|
351
|
-
|
316
|
+
crul_obj.composite_save(attrs, [], [], [], links_modified) do |_attrs, links_to_add, links_to_remove, links_to_set|
|
352
317
|
links_to_add.clear
|
353
318
|
links_to_remove.clear
|
354
319
|
links_to_set.clear
|
355
320
|
|
356
|
-
copy = RailsConnector::
|
321
|
+
copy = RailsConnector::BasicObj.uncached { RailsConnector::BasicObj.find(id) }
|
357
322
|
|
358
323
|
linklists.each do |linklist|
|
359
324
|
original_link_ids = Reactor::Attributes::LinkListFromAttrValues.new(copy, linklist).call.map(&:id)
|
@@ -385,7 +350,6 @@ module Reactor
|
|
385
350
|
end
|
386
351
|
end
|
387
352
|
end
|
388
|
-
|
389
353
|
self.class.connection.clear_query_cache
|
390
354
|
end
|
391
355
|
|
@@ -398,66 +362,55 @@ module Reactor
|
|
398
362
|
# @param [String] new_name gives the object new name
|
399
363
|
def copy(new_parent, recursive = false, new_name = nil)
|
400
364
|
self.id = crul_obj.copy(RailsConnector::AbstractObj.path_from_anything(new_parent), recursive, new_name)
|
401
|
-
#self.reload
|
402
|
-
resolve_refs
|
403
|
-
|
365
|
+
# self.reload
|
366
|
+
resolve_refs # ?
|
367
|
+
id
|
404
368
|
end
|
405
369
|
|
406
370
|
def trim_crul_attributes
|
407
|
-
crul_attributes.delete_if {|attr,
|
371
|
+
crul_attributes.delete_if { |attr, _options| %i(name objClass).include?(attr) }
|
408
372
|
end
|
409
373
|
|
410
374
|
def crul_obj_create(name, parent, klass)
|
411
375
|
@crul_obj = Reactor::Cm::Obj.create(name, parent, klass)
|
412
376
|
end
|
413
377
|
|
378
|
+
# TODO: depends on rails version
|
414
379
|
def create
|
415
380
|
run_callbacks(:create) do
|
416
|
-
c_name
|
417
|
-
c_parent= self.class.path_from_anything(
|
418
|
-
c_objcl =
|
381
|
+
c_name = name
|
382
|
+
c_parent = self.class.path_from_anything(parent_obj_id)
|
383
|
+
c_objcl = obj_class
|
419
384
|
crul_obj_create(c_name, c_parent, c_objcl)
|
420
385
|
self.id = @crul_obj.obj_id
|
421
386
|
crul_obj_save if crul_attributes_set? || crul_links_changed?
|
422
|
-
|
423
|
-
|
387
|
+
reload # ?
|
388
|
+
changes_applied
|
389
|
+
id
|
424
390
|
end
|
425
391
|
end
|
426
392
|
|
427
|
-
|
428
|
-
if Reactor.rails4_0_ge6? || Reactor.rails4_1? || Reactor.rails4_2?
|
429
|
-
alias_method :_create_record, :create
|
430
|
-
else
|
431
|
-
alias_method :create_record, :create
|
432
|
-
end
|
433
|
-
end
|
393
|
+
alias_method :_create_record, :create
|
434
394
|
|
435
|
-
def update
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
end
|
442
|
-
|
443
|
-
if Reactor.rails4_x?
|
444
|
-
if Reactor.rails4_0_ge6? || Reactor.rails4_1? || Reactor.rails4_2?
|
445
|
-
alias_method :_update_record, :update
|
446
|
-
else
|
447
|
-
alias_method :update_record, :update
|
395
|
+
def update(_attribute_names = attribute_names)
|
396
|
+
run_callbacks(:update) do
|
397
|
+
crul_obj_save if crul_attributes_set? || crul_links_changed?
|
398
|
+
reload
|
399
|
+
changes_applied
|
400
|
+
id
|
448
401
|
end
|
449
402
|
end
|
450
403
|
|
404
|
+
alias_method :_update_record, :update
|
405
|
+
|
451
406
|
def ignore_attributes(attributes)
|
452
407
|
return {} if attributes.nil?
|
453
408
|
|
454
409
|
obj_class = attributes.delete(:obj_class)
|
455
410
|
parent = attributes.delete(:parent)
|
456
|
-
{:
|
411
|
+
{ obj_class: obj_class, parent: parent }
|
457
412
|
end
|
458
413
|
|
459
|
-
|
460
|
-
|
461
414
|
def load_ignored_attributes(attributes)
|
462
415
|
return if attributes.nil?
|
463
416
|
|
@@ -475,7 +428,6 @@ module Reactor
|
|
475
428
|
self.obj_class = obj_class
|
476
429
|
end
|
477
430
|
|
478
|
-
|
479
431
|
# disables active record transactions
|
480
432
|
def with_transaction_returning_status
|
481
433
|
yield
|
@@ -489,44 +441,17 @@ module Reactor
|
|
489
441
|
module ClassMethods
|
490
442
|
def sanitize_name(old_name)
|
491
443
|
if Reactor::Configuration.sanitize_obj_name
|
492
|
-
character_map = {
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
444
|
+
character_map = { "ä" => "ae", "ö" => "oe", "ü" => "ue", "ß" => "ss", "Ä" => "Ae", "Ö" => "Oe", "Ü" => "Ue" }
|
445
|
+
old_name.gsub(/[^-$a-zA-Z0-9]/) { |char| character_map[char] || "_" }
|
446
|
+
.gsub(/__+/, "_")
|
447
|
+
.gsub(/^_+/, "")
|
448
|
+
.gsub(/_+$/, "")
|
449
|
+
|
498
450
|
else
|
499
451
|
old_name
|
500
452
|
end
|
501
453
|
end
|
502
454
|
|
503
|
-
if Reactor.rails4_x?
|
504
|
-
# Detect the subclass from the inheritance column of attrs. If the inheritance column value
|
505
|
-
# is not self or a valid subclass, raises ActiveRecord::SubclassNotFound
|
506
|
-
# If this is a StrongParameters hash, and access to inheritance_column is not permitted,
|
507
|
-
# this will ignore the inheritance column and return nil
|
508
|
-
def subclass_from_attrs(attrs)
|
509
|
-
subclass_name = attrs.with_indifferent_access[inheritance_column]
|
510
|
-
|
511
|
-
if subclass_name.present? && subclass_name != self.name
|
512
|
-
subclass = subclass_name.safe_constantize
|
513
|
-
|
514
|
-
if subclass # this if has been added
|
515
|
-
unless descendants.include?(subclass)
|
516
|
-
raise ActiveRecord::SubclassNotFound.new("Invalid single-table inheritance type: #{subclass_name} is not a subclass of #{name}")
|
517
|
-
end
|
518
|
-
|
519
|
-
subclass
|
520
|
-
end
|
521
|
-
end
|
522
|
-
end
|
523
|
-
|
524
|
-
if Reactor.rails4_0_ge6? || Reactor.rails4_1? || Reactor.rails4_2?
|
525
|
-
alias_method :subclass_from_attributes, :subclass_from_attrs
|
526
|
-
remove_method :subclass_from_attrs
|
527
|
-
end
|
528
|
-
end
|
529
|
-
|
530
455
|
# Convenience method: it is equivalent to following call chain:
|
531
456
|
#
|
532
457
|
# i = create(attributes)
|
@@ -538,22 +463,23 @@ module Reactor
|
|
538
463
|
#
|
539
464
|
# image = Image.upload(File.open('image.jpg'), 'ext', :name => 'image', :parent => '/')
|
540
465
|
#
|
541
|
-
def upload(data_or_io, extension, attributes={})
|
466
|
+
def upload(data_or_io, extension, attributes = {})
|
542
467
|
# Try to guess the object name from filename, if it's missing
|
543
|
-
if
|
468
|
+
if data_or_io.respond_to?(:path) && !attributes.key?(:name)
|
544
469
|
attributes[:name] = sanitize_name(File.basename(data_or_io.path, File.extname(data_or_io.path)))
|
545
470
|
end
|
546
471
|
|
547
|
-
instance =
|
548
|
-
|
549
|
-
|
550
|
-
#end
|
472
|
+
instance = create!(attributes) # do |instance|
|
473
|
+
instance.upload(data_or_io, extension)
|
474
|
+
instance.save!
|
475
|
+
# end
|
551
476
|
instance
|
552
477
|
end
|
553
478
|
|
554
479
|
protected
|
480
|
+
|
555
481
|
def attribute_methods_overriden?
|
556
|
-
|
482
|
+
name != "RailsConnector::BasicObj"
|
557
483
|
end
|
558
484
|
end
|
559
485
|
end
|