infopark_reactor 1.26.0 → 1.27.0.rc9
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 +94 -270
- data/lib/reactor/attributes/date_serializer.rb +23 -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 +161 -152
- 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 +8 -9
- data/lib/reactor/link/external.rb +8 -5
- data/lib/reactor/link/internal.rb +8 -5
- data/lib/reactor/link/temporary_link.rb +18 -19
- 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 +105 -159
- 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 +76 -40
- 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,18 +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
|
-
|
37
|
+
false
|
39
38
|
end
|
40
39
|
|
41
40
|
# Removes the working version of the object,
|
42
41
|
# if it exists
|
43
42
|
# @param comment [String] comment to leave for the next user
|
44
43
|
# @return [true]
|
45
|
-
def revert(comment=nil)
|
46
|
-
|
44
|
+
def revert(comment = nil)
|
45
|
+
revert!(comment)
|
47
46
|
end
|
48
47
|
|
49
48
|
# Removes the working version of the object,
|
@@ -51,10 +50,10 @@ module Reactor
|
|
51
50
|
# @param comment [String] comment to leave for the next user
|
52
51
|
# @return [true]
|
53
52
|
# @note There is no difference between #revert and #revert!
|
54
|
-
def revert!(comment=nil)
|
53
|
+
def revert!(comment = nil)
|
55
54
|
crul_obj.revert!(comment)
|
56
55
|
reload
|
57
|
-
|
56
|
+
true
|
58
57
|
end
|
59
58
|
|
60
59
|
# Releases the object. Returns true on succes, can raise exceptions
|
@@ -62,13 +61,14 @@ module Reactor
|
|
62
61
|
# @raise [Reactor::AlreadyReleased]
|
63
62
|
# @raise [ActiveRecord::RecordInvalid] validations failed
|
64
63
|
# @raise [Reactor::NotPermitted] current user lacks required permissions
|
65
|
-
def release!(comment=nil)
|
64
|
+
def release!(comment = nil)
|
66
65
|
run_callbacks(:release) do
|
67
|
-
raise(Reactor::AlreadyReleased) unless
|
66
|
+
raise(Reactor::AlreadyReleased) unless really_edited?
|
67
|
+
|
68
68
|
crul_obj.release!(comment)
|
69
69
|
reload
|
70
70
|
end
|
71
|
-
|
71
|
+
true
|
72
72
|
end
|
73
73
|
|
74
74
|
# Makes the current user the editor of the object. Returns true when
|
@@ -78,11 +78,11 @@ module Reactor
|
|
78
78
|
# 2. the object has not beed edited
|
79
79
|
# 3. other error occured
|
80
80
|
# @param comment [String] comment to leave for the next user
|
81
|
-
def take(comment=nil)
|
81
|
+
def take(comment = nil)
|
82
82
|
take!(comment)
|
83
|
-
|
83
|
+
true
|
84
84
|
rescue Reactor::Cm::XmlRequestError, Reactor::NotPermitted, Reactor::NoWorkingVersion
|
85
|
-
|
85
|
+
false
|
86
86
|
end
|
87
87
|
|
88
88
|
# Makes the current user the editor of the object. Returns true when
|
@@ -90,13 +90,14 @@ module Reactor
|
|
90
90
|
# @param comment [String] comment to leave for the next user
|
91
91
|
# @raise [Reactor::NoWorkingVersion] there is no working version of the object
|
92
92
|
# @raise [Reactor::NotPermitted] current user lacks required permissions
|
93
|
-
def take!(comment=nil)
|
94
|
-
raise(Reactor::NoWorkingVersion) unless
|
93
|
+
def take!(comment = nil)
|
94
|
+
raise(Reactor::NoWorkingVersion) unless really_edited?
|
95
|
+
|
95
96
|
# TODO: refactor the if condition
|
96
|
-
crul_obj.take!(comment) if
|
97
|
+
crul_obj.take!(comment) if crul_obj.editor != Reactor::Configuration.xml_access[:username]
|
97
98
|
# neccessary to recalculate #editor
|
98
99
|
reload
|
99
|
-
|
100
|
+
true
|
100
101
|
end
|
101
102
|
|
102
103
|
# Creates a working version of the object. Returns true on success or when
|
@@ -104,41 +105,41 @@ module Reactor
|
|
104
105
|
# @param comment [String] comment to leave for the next user
|
105
106
|
# 1. user lacks the permissions
|
106
107
|
# 2. other error occured
|
107
|
-
def edit(comment=nil)
|
108
|
+
def edit(comment = nil)
|
108
109
|
edit!(comment)
|
109
|
-
|
110
|
+
true
|
110
111
|
rescue Reactor::Cm::XmlRequestError, Reactor::NotPermitted
|
111
|
-
|
112
|
+
false
|
112
113
|
end
|
113
114
|
|
114
115
|
# Creates a working version of the object. Returns true on success or when
|
115
116
|
# the object already has a working version. Raises exceptions
|
116
117
|
# @param comment [String] comment to leave for the next user
|
117
118
|
# @raise [Reactor::NotPermitted] current user lacks required permissions
|
118
|
-
def edit!(comment=nil)
|
119
|
-
crul_obj.edit!(comment) unless
|
119
|
+
def edit!(comment = nil)
|
120
|
+
crul_obj.edit!(comment) unless really_edited?
|
120
121
|
reload
|
121
|
-
|
122
|
+
true
|
122
123
|
end
|
123
124
|
|
124
125
|
# Returns true, if the object has any links pointing to it.
|
125
126
|
# @raise [Reactor::Cm::XmlRequestError] generic error occoured
|
126
127
|
def has_super_links?
|
127
|
-
crul_obj.get(
|
128
|
+
crul_obj.get("hasSuperLinks") == "1"
|
128
129
|
end
|
129
130
|
|
130
131
|
# Return an array of RailsConnector::AbstractObj that contain a link
|
131
132
|
# to this file.
|
132
133
|
# @raise [Reactor::Cm::XmlRequestError] generic error occoured
|
133
134
|
def super_objects
|
134
|
-
RailsConnector::AbstractObj.where(:
|
135
|
+
RailsConnector::AbstractObj.where(obj_id: crul_obj.get("superObjects")).to_a
|
135
136
|
end
|
136
137
|
|
137
138
|
# Returns true if this object hasn't been saved yet -- that is, a record
|
138
139
|
# for the object doesn't exist in the data store yet; otherwise, returns false.
|
139
140
|
def new_record?
|
140
|
-
|
141
|
-
!destroyed? && (
|
141
|
+
# !destroyed? && (self.id.nil? || !self.class.exists?(self.id))
|
142
|
+
!destroyed? && (id.nil? || path.blank?)
|
142
143
|
end
|
143
144
|
|
144
145
|
# Stolen from Rails 3.
|
@@ -172,7 +173,7 @@ module Reactor
|
|
172
173
|
# Freezes the object.
|
173
174
|
def destroy
|
174
175
|
run_callbacks(:destroy) do
|
175
|
-
|
176
|
+
delete
|
176
177
|
end
|
177
178
|
end
|
178
179
|
|
@@ -181,12 +182,12 @@ module Reactor
|
|
181
182
|
# but tries to mimmic their behaviour.
|
182
183
|
def reload(options = nil)
|
183
184
|
RailsConnector::AbstractObj.uncached do
|
184
|
-
#super # Throws RecordNotFound when changing obj_class
|
185
|
+
# super # Throws RecordNotFound when changing obj_class
|
185
186
|
# AR reload
|
186
187
|
clear_aggregation_cache
|
187
188
|
clear_association_cache
|
188
|
-
fresh_object = RailsConnector::AbstractObj.find(
|
189
|
-
@attributes = fresh_object.instance_variable_get(
|
189
|
+
fresh_object = RailsConnector::AbstractObj.find(id, options)
|
190
|
+
@attributes = fresh_object.instance_variable_get("@attributes")
|
190
191
|
@attributes_cache = {}
|
191
192
|
# RC reload
|
192
193
|
@attr_values = nil
|
@@ -207,9 +208,9 @@ module Reactor
|
|
207
208
|
# 2. generic error occoured
|
208
209
|
def resolve_refs
|
209
210
|
resolve_refs!
|
210
|
-
|
211
|
+
true
|
211
212
|
rescue Reactor::Cm::XmlRequestError, Reactor::NotPermitted
|
212
|
-
|
213
|
+
false
|
213
214
|
end
|
214
215
|
|
215
216
|
# Resolves references in any of the html fields. Returns true on success,
|
@@ -217,52 +218,39 @@ module Reactor
|
|
217
218
|
# @raise [Reactor::NotPermitted] current user lacks required permissions
|
218
219
|
def resolve_refs!
|
219
220
|
crul_obj.resolve_refs!
|
220
|
-
|
221
|
-
end
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
end
|
237
|
-
elsif Reactor.rails3_1? || Reactor.rails3_2? || Reactor.rails4_x?
|
238
|
-
# It should excactly match ActiveRecord::Base.new in it's behavior
|
239
|
-
# @see ActiveRecord::Base.new
|
240
|
-
def initialize(attributes = nil, options={}, &block)
|
241
|
-
if true || !self.class.send(:attribute_methods_overriden?) #FIXME !!!
|
242
|
-
ignored_attributes = ignore_attributes(attributes)
|
243
|
-
# supress block hijacking!
|
244
|
-
super(attributes, options) {}
|
245
|
-
load_ignored_attributes(ignored_attributes)
|
246
|
-
yield self if block_given?
|
247
|
-
else
|
248
|
-
super(attributes, options)
|
249
|
-
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)
|
250
237
|
end
|
251
|
-
else
|
252
|
-
raise RuntimeError, "Unsupported Rails version!"
|
253
238
|
end
|
254
239
|
|
255
240
|
# Equivalent to Obj#edited?
|
256
241
|
def really_edited?
|
257
|
-
|
242
|
+
# check if really edited with curl request
|
243
|
+
crul_obj.edited?
|
244
|
+
# self.edited?
|
258
245
|
end
|
259
246
|
|
260
247
|
# Returns an array of errors
|
261
248
|
def reasons_for_incomplete_state
|
262
|
-
crul_obj.get(
|
249
|
+
crul_obj.get("reasonsForIncompleteState") || []
|
263
250
|
end
|
264
251
|
|
265
252
|
protected
|
253
|
+
|
266
254
|
def prevent_resolve_refs
|
267
255
|
@prevent_resolve_refs = true
|
268
256
|
end
|
@@ -272,12 +260,10 @@ module Reactor
|
|
272
260
|
end
|
273
261
|
|
274
262
|
def sanitize_name
|
275
|
-
return unless
|
263
|
+
return unless name.present?
|
276
264
|
|
277
|
-
sanitized_name = self.class.send(:sanitize_name,
|
278
|
-
if sanitized_name !=
|
279
|
-
self.name = sanitized_name
|
280
|
-
end
|
265
|
+
sanitized_name = self.class.send(:sanitize_name, name)
|
266
|
+
self.name = sanitized_name if sanitized_name != name
|
281
267
|
end
|
282
268
|
|
283
269
|
def crul_attributes_set?
|
@@ -289,13 +275,13 @@ module Reactor
|
|
289
275
|
end
|
290
276
|
|
291
277
|
def changed_linklists
|
292
|
-
custom_attrs =
|
293
|
-
|
294
|
-
self.class.send(:instance_variable_get,
|
278
|
+
custom_attrs =
|
279
|
+
singleton_class.send(:instance_variable_get, "@_o_allowed_attrs") ||
|
280
|
+
self.class.send(:instance_variable_get, "@_o_allowed_attrs") ||
|
295
281
|
[]
|
296
282
|
|
297
283
|
custom_attrs.select do |attr|
|
298
|
-
|
284
|
+
send(:attribute_type, attr) == :linklist && send(:[], attr.to_sym).try(:changed?)
|
299
285
|
end
|
300
286
|
end
|
301
287
|
|
@@ -312,28 +298,27 @@ module Reactor
|
|
312
298
|
end
|
313
299
|
|
314
300
|
def crul_obj_save
|
315
|
-
attrs,
|
316
|
-
|
301
|
+
attrs, = crul_attributes.partition do |field, (_value, _options)|
|
302
|
+
send(:attribute_type, field) != :linklist
|
317
303
|
end
|
318
304
|
linklists = changed_linklists
|
319
305
|
|
320
306
|
new_links = {}.tap do |result|
|
321
307
|
linklists.map do |field|
|
322
308
|
result[field] = Reactor::Attributes::LinkListFromAccessor.new(self, field).call.map do |l|
|
323
|
-
{:
|
309
|
+
{ link_id: l.id, title: l.title, destination_url: (l.internal? ? l.destination_object.path : l.url), target: l.target }
|
324
310
|
end
|
325
311
|
end
|
326
312
|
end
|
327
313
|
|
328
314
|
links_modified = !linklists.empty?
|
329
315
|
|
330
|
-
crul_obj.composite_save(attrs, [], [], [], links_modified) do |
|
331
|
-
|
316
|
+
crul_obj.composite_save(attrs, [], [], [], links_modified) do |_attrs, links_to_add, links_to_remove, links_to_set|
|
332
317
|
links_to_add.clear
|
333
318
|
links_to_remove.clear
|
334
319
|
links_to_set.clear
|
335
320
|
|
336
|
-
copy = RailsConnector::
|
321
|
+
copy = RailsConnector::BasicObj.uncached { RailsConnector::BasicObj.find(id) }
|
337
322
|
|
338
323
|
linklists.each do |linklist|
|
339
324
|
original_link_ids = Reactor::Attributes::LinkListFromAttrValues.new(copy, linklist).call.map(&:id)
|
@@ -365,7 +350,6 @@ module Reactor
|
|
365
350
|
end
|
366
351
|
end
|
367
352
|
end
|
368
|
-
|
369
353
|
self.class.connection.clear_query_cache
|
370
354
|
end
|
371
355
|
|
@@ -378,66 +362,55 @@ module Reactor
|
|
378
362
|
# @param [String] new_name gives the object new name
|
379
363
|
def copy(new_parent, recursive = false, new_name = nil)
|
380
364
|
self.id = crul_obj.copy(RailsConnector::AbstractObj.path_from_anything(new_parent), recursive, new_name)
|
381
|
-
#self.reload
|
382
|
-
resolve_refs
|
383
|
-
|
365
|
+
# self.reload
|
366
|
+
resolve_refs # ?
|
367
|
+
id
|
384
368
|
end
|
385
369
|
|
386
370
|
def trim_crul_attributes
|
387
|
-
crul_attributes.delete_if {|attr,
|
371
|
+
crul_attributes.delete_if { |attr, _options| %i(name objClass).include?(attr) }
|
388
372
|
end
|
389
373
|
|
390
374
|
def crul_obj_create(name, parent, klass)
|
391
375
|
@crul_obj = Reactor::Cm::Obj.create(name, parent, klass)
|
392
376
|
end
|
393
377
|
|
378
|
+
# TODO: depends on rails version
|
394
379
|
def create
|
395
380
|
run_callbacks(:create) do
|
396
|
-
c_name
|
397
|
-
c_parent= self.class.path_from_anything(
|
398
|
-
c_objcl =
|
381
|
+
c_name = name
|
382
|
+
c_parent = self.class.path_from_anything(parent_obj_id)
|
383
|
+
c_objcl = obj_class
|
399
384
|
crul_obj_create(c_name, c_parent, c_objcl)
|
400
385
|
self.id = @crul_obj.obj_id
|
401
386
|
crul_obj_save if crul_attributes_set? || crul_links_changed?
|
402
|
-
|
403
|
-
|
387
|
+
reload # ?
|
388
|
+
changes_applied
|
389
|
+
id
|
404
390
|
end
|
405
391
|
end
|
406
392
|
|
407
|
-
|
408
|
-
if Reactor.rails4_0_ge6? || Reactor.rails4_1? || Reactor.rails4_2?
|
409
|
-
alias_method :_create_record, :create
|
410
|
-
else
|
411
|
-
alias_method :create_record, :create
|
412
|
-
end
|
413
|
-
end
|
414
|
-
|
415
|
-
def update
|
416
|
-
run_callbacks(:update) do
|
417
|
-
crul_obj_save if crul_attributes_set? || crul_links_changed?
|
418
|
-
self.reload
|
419
|
-
self.id
|
420
|
-
end
|
421
|
-
end
|
393
|
+
alias_method :_create_record, :create
|
422
394
|
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
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
|
428
401
|
end
|
429
402
|
end
|
430
403
|
|
404
|
+
alias_method :_update_record, :update
|
405
|
+
|
431
406
|
def ignore_attributes(attributes)
|
432
407
|
return {} if attributes.nil?
|
433
408
|
|
434
409
|
obj_class = attributes.delete(:obj_class)
|
435
410
|
parent = attributes.delete(:parent)
|
436
|
-
{:
|
411
|
+
{ obj_class: obj_class, parent: parent }
|
437
412
|
end
|
438
413
|
|
439
|
-
|
440
|
-
|
441
414
|
def load_ignored_attributes(attributes)
|
442
415
|
return if attributes.nil?
|
443
416
|
|
@@ -455,7 +428,6 @@ module Reactor
|
|
455
428
|
self.obj_class = obj_class
|
456
429
|
end
|
457
430
|
|
458
|
-
|
459
431
|
# disables active record transactions
|
460
432
|
def with_transaction_returning_status
|
461
433
|
yield
|
@@ -469,44 +441,17 @@ module Reactor
|
|
469
441
|
module ClassMethods
|
470
442
|
def sanitize_name(old_name)
|
471
443
|
if Reactor::Configuration.sanitize_obj_name
|
472
|
-
character_map = {
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
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
|
+
|
478
450
|
else
|
479
451
|
old_name
|
480
452
|
end
|
481
453
|
end
|
482
454
|
|
483
|
-
if Reactor.rails4_x?
|
484
|
-
# Detect the subclass from the inheritance column of attrs. If the inheritance column value
|
485
|
-
# is not self or a valid subclass, raises ActiveRecord::SubclassNotFound
|
486
|
-
# If this is a StrongParameters hash, and access to inheritance_column is not permitted,
|
487
|
-
# this will ignore the inheritance column and return nil
|
488
|
-
def subclass_from_attrs(attrs)
|
489
|
-
subclass_name = attrs.with_indifferent_access[inheritance_column]
|
490
|
-
|
491
|
-
if subclass_name.present? && subclass_name != self.name
|
492
|
-
subclass = subclass_name.safe_constantize
|
493
|
-
|
494
|
-
if subclass # this if has been added
|
495
|
-
unless descendants.include?(subclass)
|
496
|
-
raise ActiveRecord::SubclassNotFound.new("Invalid single-table inheritance type: #{subclass_name} is not a subclass of #{name}")
|
497
|
-
end
|
498
|
-
|
499
|
-
subclass
|
500
|
-
end
|
501
|
-
end
|
502
|
-
end
|
503
|
-
|
504
|
-
if Reactor.rails4_0_ge6? || Reactor.rails4_1? || Reactor.rails4_2?
|
505
|
-
alias_method :subclass_from_attributes, :subclass_from_attrs
|
506
|
-
remove_method :subclass_from_attrs
|
507
|
-
end
|
508
|
-
end
|
509
|
-
|
510
455
|
# Convenience method: it is equivalent to following call chain:
|
511
456
|
#
|
512
457
|
# i = create(attributes)
|
@@ -518,22 +463,23 @@ module Reactor
|
|
518
463
|
#
|
519
464
|
# image = Image.upload(File.open('image.jpg'), 'ext', :name => 'image', :parent => '/')
|
520
465
|
#
|
521
|
-
def upload(data_or_io, extension, attributes={})
|
466
|
+
def upload(data_or_io, extension, attributes = {})
|
522
467
|
# Try to guess the object name from filename, if it's missing
|
523
|
-
if
|
468
|
+
if data_or_io.respond_to?(:path) && !attributes.key?(:name)
|
524
469
|
attributes[:name] = sanitize_name(File.basename(data_or_io.path, File.extname(data_or_io.path)))
|
525
470
|
end
|
526
471
|
|
527
|
-
instance =
|
528
|
-
|
529
|
-
|
530
|
-
#end
|
472
|
+
instance = create!(attributes) # do |instance|
|
473
|
+
instance.upload(data_or_io, extension)
|
474
|
+
instance.save!
|
475
|
+
# end
|
531
476
|
instance
|
532
477
|
end
|
533
478
|
|
534
479
|
protected
|
480
|
+
|
535
481
|
def attribute_methods_overriden?
|
536
|
-
|
482
|
+
name != "RailsConnector::BasicObj"
|
537
483
|
end
|
538
484
|
end
|
539
485
|
end
|