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/cm/obj_class.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require 'reactor/cm/xml_request_error'
|
1
|
+
require "reactor/cm/xml_request"
|
2
|
+
require "reactor/cm/xml_response"
|
3
|
+
require "reactor/cm/xml_request_error"
|
5
4
|
|
6
5
|
module Reactor
|
7
6
|
module Cm
|
@@ -9,15 +8,15 @@ module Reactor
|
|
9
8
|
def self.exists?(name)
|
10
9
|
klass = ObjClass.new
|
11
10
|
begin
|
12
|
-
|
13
|
-
rescue
|
14
|
-
|
11
|
+
klass.send(:get, name).ok?
|
12
|
+
rescue StandardError
|
13
|
+
false
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
18
17
|
def self.create(name, type)
|
19
18
|
klass = ObjClass.new
|
20
|
-
klass.send(:create,name, type)
|
19
|
+
klass.send(:create, name, type)
|
21
20
|
klass
|
22
21
|
end
|
23
22
|
|
@@ -29,17 +28,17 @@ module Reactor
|
|
29
28
|
|
30
29
|
def self.rename(current_name, new_name)
|
31
30
|
request = XmlRequest.prepare do |xml|
|
32
|
-
xml.tag!(
|
33
|
-
xml.tag!(
|
31
|
+
xml.tag!("objClass-where") do
|
32
|
+
xml.tag!("name", current_name)
|
34
33
|
end
|
35
|
-
xml.tag!(
|
36
|
-
xml.tag!(
|
34
|
+
xml.tag!("objClass-set") do
|
35
|
+
xml.tag!("name", new_name)
|
37
36
|
end
|
38
37
|
end
|
39
38
|
request.execute!
|
40
39
|
end
|
41
40
|
|
42
|
-
def set(key, value, options={})
|
41
|
+
def set(key, value, options = {})
|
43
42
|
@params_options[key.to_sym] = (!options.nil? && !options.empty? && options) || {}
|
44
43
|
@params[key.to_sym] = value
|
45
44
|
end
|
@@ -50,28 +49,27 @@ module Reactor
|
|
50
49
|
|
51
50
|
def preset_attributes
|
52
51
|
request = XmlRequest.prepare do |xml|
|
53
|
-
xml.where_key_tag!(base_name,
|
54
|
-
xml.get_key_tag!(base_name,
|
52
|
+
xml.where_key_tag!(base_name, "name", @name)
|
53
|
+
xml.get_key_tag!(base_name, "presetAttributes")
|
55
54
|
end
|
56
55
|
response = request.execute!
|
57
|
-
result = response.xpath(
|
58
|
-
result = [result] unless result.
|
56
|
+
result = response.xpath("//dictitem")
|
57
|
+
result = [result] unless result.is_a?(Array)
|
59
58
|
result.map do |dictitem|
|
60
|
-
key = dictitem.children.detect {|c| c.name ==
|
61
|
-
raw_value = dictitem.children.detect {|c| c.name ==
|
62
|
-
if raw_value.children.detect {|c| c.
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
{key => value}
|
59
|
+
key = dictitem.children.detect { |c| c.name == "key" }.text
|
60
|
+
raw_value = dictitem.children.detect { |c| c.name == "value" }
|
61
|
+
value = if raw_value.children.detect { |c| c.is_a?(::REXML::Text) }
|
62
|
+
raw_value.text
|
63
|
+
else
|
64
|
+
raw_value.children.map { |c| c.text }
|
65
|
+
end
|
66
|
+
{ key => value }
|
68
67
|
end.inject({}, &:merge)
|
69
68
|
end
|
70
69
|
|
71
|
-
|
72
70
|
def save!
|
73
71
|
request = XmlRequest.prepare do |xml|
|
74
|
-
xml.where_key_tag!(base_name,
|
72
|
+
xml.where_key_tag!(base_name, "name", @name)
|
75
73
|
xml.set_tag!(base_name) do
|
76
74
|
@params.each do |key, value|
|
77
75
|
if @params_options[key][:cdata]
|
@@ -83,17 +81,17 @@ module Reactor
|
|
83
81
|
end
|
84
82
|
end
|
85
83
|
unless @preset.empty?
|
86
|
-
|
87
|
-
xml.tag!(
|
84
|
+
preset_attributes.merge(@preset)
|
85
|
+
xml.tag!("presetAttributes") do
|
88
86
|
@preset.each do |key, value|
|
89
|
-
xml.tag!(
|
90
|
-
xml.tag!(
|
87
|
+
xml.tag!("dictitem") do
|
88
|
+
xml.tag!("key") do
|
91
89
|
xml.text!(key.to_s)
|
92
90
|
end
|
93
|
-
xml.tag!(
|
94
|
-
if value.
|
91
|
+
xml.tag!("value") do
|
92
|
+
if value.is_a?(Array)
|
95
93
|
value.each do |item|
|
96
|
-
xml.tag!(
|
94
|
+
xml.tag!("listitem") do
|
97
95
|
xml.text!(item.to_s)
|
98
96
|
end
|
99
97
|
end
|
@@ -107,7 +105,7 @@ module Reactor
|
|
107
105
|
end
|
108
106
|
end
|
109
107
|
end
|
110
|
-
|
108
|
+
request.execute!
|
111
109
|
end
|
112
110
|
|
113
111
|
def has_attribute?(attr_name)
|
@@ -115,35 +113,36 @@ module Reactor
|
|
115
113
|
end
|
116
114
|
|
117
115
|
def attributes
|
118
|
-
__attributes_get(
|
116
|
+
__attributes_get("attributes")
|
119
117
|
end
|
120
118
|
|
121
119
|
def attributes=(attr_arr)
|
122
|
-
__attributes_set(
|
120
|
+
__attributes_set("attributes", attr_arr)
|
123
121
|
end
|
124
122
|
|
125
123
|
def mandatory_attributes
|
126
|
-
__attributes_get(
|
124
|
+
__attributes_get("mandatoryAttributes")
|
127
125
|
end
|
128
126
|
|
129
127
|
def mandatory_attributes=(attr_arr)
|
130
|
-
__attributes_set(
|
128
|
+
__attributes_set("mandatoryAttributes", attr_arr)
|
131
129
|
end
|
132
130
|
|
133
131
|
def delete!
|
134
132
|
request = XmlRequest.prepare do |xml|
|
135
|
-
xml.where_key_tag!(base_name,
|
133
|
+
xml.where_key_tag!(base_name, "name", @name)
|
136
134
|
xml.tag!("#{base_name}-delete")
|
137
135
|
end
|
138
|
-
|
136
|
+
request.execute!
|
139
137
|
end
|
140
138
|
|
141
139
|
protected
|
140
|
+
|
142
141
|
def base_name
|
143
|
-
|
142
|
+
"objClass"
|
144
143
|
end
|
145
144
|
|
146
|
-
def initialize(name=nil)
|
145
|
+
def initialize(name = nil)
|
147
146
|
@name = name
|
148
147
|
@params = {}
|
149
148
|
@params_options = {}
|
@@ -152,8 +151,8 @@ module Reactor
|
|
152
151
|
|
153
152
|
def get(name)
|
154
153
|
request = XmlRequest.prepare do |xml|
|
155
|
-
xml.where_key_tag!(base_name,
|
156
|
-
xml.get_key_tag!(base_name,
|
154
|
+
xml.where_key_tag!(base_name, "name", name)
|
155
|
+
xml.get_key_tag!(base_name, "name")
|
157
156
|
end
|
158
157
|
response = request.execute!
|
159
158
|
@name = name
|
@@ -163,10 +162,10 @@ module Reactor
|
|
163
162
|
def create(name, type)
|
164
163
|
request = XmlRequest.prepare do |xml|
|
165
164
|
xml.create_tag!(base_name) do |xml|
|
166
|
-
xml.tag!(
|
165
|
+
xml.tag!("name") do
|
167
166
|
xml.text!(name)
|
168
167
|
end
|
169
|
-
xml.tag!(
|
168
|
+
xml.tag!("objType") do
|
170
169
|
xml.text!(type)
|
171
170
|
end
|
172
171
|
end
|
@@ -177,23 +176,25 @@ module Reactor
|
|
177
176
|
end
|
178
177
|
|
179
178
|
private
|
179
|
+
|
180
180
|
def __attributes_get(field)
|
181
181
|
request = XmlRequest.prepare do |xml|
|
182
|
-
xml.where_key_tag!(base_name,
|
182
|
+
xml.where_key_tag!(base_name, "name", @name)
|
183
183
|
xml.get_key_tag!(base_name, field)
|
184
184
|
end
|
185
185
|
response = request.execute!
|
186
186
|
items = response.xpath("//listitem/text()")
|
187
|
-
return [items.to_s] unless items.
|
187
|
+
return [items.to_s] unless items.is_a?(Array)
|
188
|
+
|
188
189
|
items.map(&:to_s)
|
189
190
|
end
|
190
191
|
|
191
192
|
def __attributes_set(field, attr_arr)
|
192
193
|
request = XmlRequest.prepare do |xml|
|
193
|
-
xml.where_key_tag!(base_name,
|
194
|
+
xml.where_key_tag!(base_name, "name", @name)
|
194
195
|
xml.set_key_tag!(base_name, field, attr_arr)
|
195
196
|
end
|
196
|
-
|
197
|
+
request.execute!
|
197
198
|
end
|
198
199
|
end
|
199
200
|
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'reactor/tools/xml_attributes'
|
1
|
+
require "reactor/tools/xml_attributes"
|
3
2
|
|
4
3
|
module Reactor
|
5
4
|
module Cm
|
@@ -12,7 +11,7 @@ module Reactor
|
|
12
11
|
|
13
12
|
# Default base_name is lowercased class name (without namespaces)
|
14
13
|
def self.base_name
|
15
|
-
|
14
|
+
name.split("::").last.downcase
|
16
15
|
end
|
17
16
|
|
18
17
|
def base_name
|
@@ -24,9 +23,9 @@ module Reactor
|
|
24
23
|
# set_base_name 'obj'
|
25
24
|
# end
|
26
25
|
def self.set_base_name(base_name_value)
|
27
|
-
|
26
|
+
# we us evaluation of a string in this case, because
|
28
27
|
# define_method cannot handle default values
|
29
|
-
|
28
|
+
class_eval <<-EOH
|
30
29
|
def self.base_name
|
31
30
|
'#{base_name_value}'
|
32
31
|
end
|
@@ -50,7 +49,7 @@ module Reactor
|
|
50
49
|
response = request.execute!
|
51
50
|
|
52
51
|
self.class.attributes.each do |attr_name, attr_def|
|
53
|
-
|
52
|
+
send(:"#{attr_name}=", self.class.response_handler.get(response, attr_def))
|
54
53
|
end
|
55
54
|
|
56
55
|
self
|
@@ -62,23 +61,24 @@ module Reactor
|
|
62
61
|
xml.where_key_tag!(base_name, primary_key, primary_key_value)
|
63
62
|
xml.set_tag!(base_name) do
|
64
63
|
self.class.attributes(:set).each do |name, xml_attribute|
|
65
|
-
value =
|
64
|
+
value = send(name)
|
66
65
|
serialize_attribute_to_xml(xml, xml_attribute, value)
|
67
66
|
end
|
68
67
|
end
|
69
68
|
end
|
70
69
|
|
71
70
|
response = request.execute!
|
72
|
-
|
73
71
|
response.ok?
|
74
72
|
end
|
75
73
|
|
76
74
|
# Alias for #save!
|
77
|
-
def save
|
75
|
+
def save
|
76
|
+
save!
|
77
|
+
end
|
78
78
|
|
79
79
|
# Proxy method. @see .delete!(login)
|
80
80
|
def delete!
|
81
|
-
self.class.delete!(
|
81
|
+
self.class.delete!(primary_key_value)
|
82
82
|
end
|
83
83
|
|
84
84
|
def serialize_attribute_to_xml(xml, xml_attribute, value)
|
@@ -99,10 +99,9 @@ module Reactor
|
|
99
99
|
|
100
100
|
response = request.execute!
|
101
101
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
return false
|
102
|
+
response.ok?
|
103
|
+
rescue XmlRequestError
|
104
|
+
false
|
106
105
|
end
|
107
106
|
|
108
107
|
# Returns an instance of the class for object with given primary key
|
@@ -122,43 +121,49 @@ module Reactor
|
|
122
121
|
xml.delete_tag!(base_name)
|
123
122
|
end
|
124
123
|
|
125
|
-
|
124
|
+
request.execute!.ok?
|
126
125
|
end
|
126
|
+
|
127
127
|
# Alias for #delete!
|
128
|
-
def delete
|
128
|
+
def delete
|
129
|
+
delete!
|
130
|
+
end
|
129
131
|
|
130
132
|
class << self
|
131
133
|
# This method should never be called directly. It should always be overriden!
|
132
134
|
# pk_value is the value of primary key, it should have its double in attributes hash
|
133
135
|
# attributes is a hash of attributes set on creation {:name => 'value'}
|
136
|
+
|
134
137
|
protected
|
138
|
+
|
135
139
|
def create(pk_value, attributes)
|
136
140
|
request = XmlRequest.prepare do |xml|
|
137
141
|
xml.create_tag!(base_name) do
|
138
142
|
attributes.each do |attr_name, attr_value|
|
139
|
-
#serialize_attribute_to_xml(xml, xml_attribute, value)
|
143
|
+
# serialize_attribute_to_xml(xml, xml_attribute, value)
|
140
144
|
xml.value_tag!(attr_name, attr_value)
|
141
145
|
end
|
142
146
|
end
|
143
147
|
end
|
144
148
|
|
145
|
-
|
149
|
+
request.execute!
|
146
150
|
|
147
|
-
|
151
|
+
get(pk_value)
|
148
152
|
end
|
149
153
|
end
|
150
154
|
|
151
155
|
protected
|
156
|
+
|
152
157
|
def primary_key
|
153
158
|
self.class.primary_key
|
154
159
|
end
|
155
160
|
|
156
161
|
def primary_key_value
|
157
|
-
instance_variable_get("@#{
|
162
|
+
instance_variable_get("@#{primary_key}")
|
158
163
|
end
|
159
164
|
|
160
165
|
def primary_key_value_set(value)
|
161
|
-
instance_variable_set("@#{
|
166
|
+
instance_variable_set("@#{primary_key}", value)
|
162
167
|
end
|
163
168
|
end
|
164
169
|
end
|
@@ -3,27 +3,27 @@ module Reactor
|
|
3
3
|
module Permissions
|
4
4
|
def self.included(base)
|
5
5
|
base.instance_eval do
|
6
|
-
attribute :global_permissions, :
|
6
|
+
attribute :global_permissions, name: :globalPermissions, type: :list
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
# Returns true, if a global permission with the given +name+ exists, false otherwise.
|
11
11
|
def global_permission?(name)
|
12
|
-
|
12
|
+
global_permissions.include?(name.to_s)
|
13
13
|
end
|
14
14
|
|
15
15
|
# Add the given +permissions+ to the current set of group permissions.
|
16
16
|
def grant_global_permissions!(permissions)
|
17
|
-
permissions = permissions.
|
18
|
-
permissions =
|
17
|
+
permissions = permissions.is_a?(Array) ? permissions : [permissions]
|
18
|
+
permissions = global_permissions | permissions
|
19
19
|
|
20
20
|
set_global_permissions!(permissions)
|
21
21
|
end
|
22
22
|
|
23
23
|
# Take away the given +permissions+ from the current set of group permissions.
|
24
24
|
def revoke_global_permissions!(permissions)
|
25
|
-
permissions = permissions.
|
26
|
-
permissions =
|
25
|
+
permissions = permissions.is_a?(Array) ? permissions : [permissions]
|
26
|
+
permissions = global_permissions - permissions
|
27
27
|
|
28
28
|
set_global_permissions(permissions)
|
29
29
|
end
|
@@ -31,7 +31,7 @@ module Reactor
|
|
31
31
|
# Set the group permissions to the given +permissions+.
|
32
32
|
def set_global_permissions!(permissions)
|
33
33
|
request = XmlRequest.prepare do |xml|
|
34
|
-
xml.where_key_tag!(base_name, self.class.primary_key,
|
34
|
+
xml.where_key_tag!(base_name, self.class.primary_key, name)
|
35
35
|
xml.set_key_tag!(base_name, self.class.xml_attribute(:global_permissions).name, permissions)
|
36
36
|
end
|
37
37
|
|
data/lib/reactor/cm/user.rb
CHANGED
@@ -1,40 +1,36 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require 'reactor/tools/where_query'
|
1
|
+
require "reactor/cm/object_base"
|
2
|
+
require "reactor/configuration"
|
3
|
+
require "reactor/cm/language"
|
4
|
+
require "reactor/tools/xml_attributes"
|
5
|
+
require "reactor/tools/where_query"
|
7
6
|
|
8
|
-
require
|
7
|
+
require "reactor/cm/permissions"
|
9
8
|
|
10
9
|
module Reactor
|
11
|
-
|
12
10
|
module Cm
|
13
|
-
|
14
11
|
class User
|
15
|
-
|
16
12
|
class Internal < Reactor::Cm::ObjectBase
|
17
|
-
set_base_name
|
13
|
+
set_base_name "user"
|
18
14
|
|
19
15
|
# Attribute definitions
|
20
|
-
attribute :login, :
|
21
|
-
attribute :super_user, :
|
22
|
-
attribute :default_group, :
|
23
|
-
attribute :groups, :
|
24
|
-
attribute :real_name, :
|
16
|
+
attribute :login, except: [:set]
|
17
|
+
attribute :super_user, except: [:set], name: :isSuperUser
|
18
|
+
attribute :default_group, name: :defaultGroup
|
19
|
+
attribute :groups, type: :list
|
20
|
+
attribute :real_name, name: :realName
|
25
21
|
attribute :email
|
26
22
|
|
27
23
|
include Permissions
|
28
24
|
|
29
25
|
def name
|
30
|
-
|
26
|
+
login
|
31
27
|
end
|
32
28
|
|
33
29
|
def change_password(new_password)
|
34
30
|
request = XmlRequest.prepare do |xml|
|
35
31
|
xml.where_key_tag!(base_name, primary_key, primary_key_value)
|
36
32
|
xml.set_tag!(base_name) do
|
37
|
-
xml.tag!(
|
33
|
+
xml.tag!("password", verifyNewPassword: new_password) do
|
38
34
|
xml.text!(new_password)
|
39
35
|
end
|
40
36
|
end
|
@@ -46,82 +42,81 @@ module Reactor
|
|
46
42
|
end
|
47
43
|
|
48
44
|
def has_password?(password)
|
49
|
-
::Reactor::Cm::User.new(
|
45
|
+
::Reactor::Cm::User.new(login).has_password?(password)
|
50
46
|
end
|
51
47
|
|
52
48
|
primary_key :login
|
53
49
|
|
54
50
|
# Returns true if user is root, false otherwise
|
55
51
|
def super_user?
|
56
|
-
super_user ==
|
52
|
+
super_user == "1"
|
57
53
|
end
|
58
54
|
|
59
55
|
# Creates a user with given login and sets its default group
|
60
56
|
# Returns instance of the class for user with given login
|
61
|
-
|
62
|
-
super(login, {:
|
63
|
-
|
64
|
-
|
57
|
+
def self.create(login, default_group)
|
58
|
+
super(login, { login: login, defaultGroup: default_group })
|
59
|
+
end
|
65
60
|
end
|
66
61
|
|
67
62
|
include XmlAttributes
|
68
63
|
extend WhereQuery
|
69
64
|
|
70
65
|
attribute :login
|
71
|
-
attribute :groups, :
|
72
|
-
attribute :global_permissions, :
|
66
|
+
attribute :groups, type: :list
|
67
|
+
attribute :global_permissions, name: :globalPermissions, type: :list
|
73
68
|
attribute :email
|
74
|
-
attribute :default_group, :
|
75
|
-
attribute :real_name, :
|
69
|
+
attribute :default_group, name: :defaultGroup
|
70
|
+
attribute :real_name, name: :realName
|
76
71
|
|
77
|
-
primary_key
|
72
|
+
primary_key "login"
|
78
73
|
|
79
74
|
def initialize(name = nil)
|
80
75
|
@login = name
|
81
76
|
end
|
82
77
|
|
83
78
|
def name
|
84
|
-
|
79
|
+
login
|
85
80
|
end
|
86
81
|
|
87
82
|
def self.all(match = nil)
|
88
|
-
|
83
|
+
where("userText", match)
|
89
84
|
end
|
90
85
|
|
91
86
|
def has_password?(password)
|
92
87
|
request = XmlRequest.prepare do |xml|
|
93
|
-
xml.where_key_tag!(base_name, self.class.primary_key,
|
88
|
+
xml.where_key_tag!(base_name, self.class.primary_key, login)
|
94
89
|
xml.get_tag!(base_name) do |xml3|
|
95
|
-
xml3.tag!(
|
90
|
+
xml3.tag!("hasPassword", password: password)
|
96
91
|
end
|
97
92
|
end
|
98
93
|
response = request.execute!
|
99
|
-
response.xpath(
|
94
|
+
response.xpath("//hasPassword/text()") == "1"
|
100
95
|
end
|
101
96
|
|
102
97
|
def is_root?
|
103
98
|
request = XmlRequest.prepare do |xml|
|
104
|
-
xml.where_key_tag!(base_name, self.class.primary_key,
|
105
|
-
xml.get_key_tag!(base_name,
|
99
|
+
xml.where_key_tag!(base_name, self.class.primary_key, login)
|
100
|
+
xml.get_key_tag!(base_name, "isSuperUser")
|
106
101
|
end
|
107
102
|
|
108
103
|
response = request.execute!
|
109
104
|
|
110
|
-
response.xpath(
|
105
|
+
response.xpath("//isSuperUser/text()") == "1"
|
111
106
|
end
|
112
107
|
|
113
108
|
def language
|
114
|
-
Reactor::Cm::Language.get(
|
109
|
+
Reactor::Cm::Language.get(login)
|
115
110
|
end
|
116
111
|
|
117
112
|
def global_permissions
|
118
|
-
val =
|
113
|
+
val = instance_variable_get(:@global_permissions)
|
119
114
|
return val unless val.nil?
|
120
115
|
|
121
116
|
xml_attribute = self.class.xml_attribute(:global_permissions)
|
122
117
|
|
123
118
|
request = XmlRequest.prepare do |xml|
|
124
|
-
xml.where_key_tag!(base_name, self.class.primary_key,
|
119
|
+
xml.where_key_tag!(base_name, self.class.primary_key, login)
|
125
120
|
xml.get_key_tag!(base_name, xml_attribute.name)
|
126
121
|
end
|
127
122
|
|
@@ -131,13 +126,13 @@ module Reactor
|
|
131
126
|
end
|
132
127
|
|
133
128
|
def groups
|
134
|
-
val =
|
129
|
+
val = instance_variable_get(:@groups)
|
135
130
|
return val unless val.nil?
|
136
131
|
|
137
132
|
xml_attribute = self.class.xml_attribute(:groups)
|
138
133
|
|
139
134
|
request = XmlRequest.prepare do |xml|
|
140
|
-
xml.where_key_tag!(base_name, self.class.primary_key,
|
135
|
+
xml.where_key_tag!(base_name, self.class.primary_key, login)
|
141
136
|
xml.get_key_tag!(base_name, xml_attribute.name)
|
142
137
|
end
|
143
138
|
|
@@ -147,13 +142,13 @@ module Reactor
|
|
147
142
|
end
|
148
143
|
|
149
144
|
def email
|
150
|
-
val =
|
145
|
+
val = instance_variable_get(:@email)
|
151
146
|
return val unless val.nil?
|
152
147
|
|
153
148
|
xml_attribute = self.class.xml_attribute(:email)
|
154
149
|
|
155
150
|
request = XmlRequest.prepare do |xml|
|
156
|
-
xml.where_key_tag!(base_name, self.class.primary_key,
|
151
|
+
xml.where_key_tag!(base_name, self.class.primary_key, login)
|
157
152
|
xml.get_key_tag!(base_name, xml_attribute.name)
|
158
153
|
end
|
159
154
|
|
@@ -163,13 +158,13 @@ module Reactor
|
|
163
158
|
end
|
164
159
|
|
165
160
|
def real_name
|
166
|
-
val =
|
161
|
+
val = instance_variable_get(:@real_name)
|
167
162
|
return val unless val.nil?
|
168
163
|
|
169
164
|
xml_attribute = self.class.xml_attribute(:real_name)
|
170
165
|
|
171
166
|
request = XmlRequest.prepare do |xml|
|
172
|
-
xml.where_key_tag!(base_name, self.class.primary_key,
|
167
|
+
xml.where_key_tag!(base_name, self.class.primary_key, login)
|
173
168
|
xml.get_key_tag!(base_name, xml_attribute.name)
|
174
169
|
end
|
175
170
|
|
@@ -179,17 +174,14 @@ module Reactor
|
|
179
174
|
end
|
180
175
|
|
181
176
|
protected
|
177
|
+
|
182
178
|
def base_name
|
183
179
|
self.class.base_name
|
184
|
-
|
185
180
|
end
|
186
181
|
|
187
182
|
def self.base_name
|
188
|
-
|
183
|
+
"userProxy"
|
189
184
|
end
|
190
|
-
|
191
185
|
end
|
192
|
-
|
193
186
|
end
|
194
|
-
|
195
187
|
end
|