infopark_reactor_migrations 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +165 -0
  4. data/README +64 -0
  5. data/Rakefile +19 -0
  6. data/infopark_reactor_migrations.gemspec +27 -0
  7. data/lib/generators/cm/migration/USAGE +8 -0
  8. data/lib/generators/cm/migration/migration_generator.rb +15 -0
  9. data/lib/generators/cm/migration/templates/template.rb +7 -0
  10. data/lib/infopark_reactor_migrations.rb +29 -0
  11. data/lib/reactor/cm/attribute.rb +84 -0
  12. data/lib/reactor/cm/bridge.rb +49 -0
  13. data/lib/reactor/cm/editorial_group.rb +22 -0
  14. data/lib/reactor/cm/group.rb +270 -0
  15. data/lib/reactor/cm/language.rb +56 -0
  16. data/lib/reactor/cm/link.rb +132 -0
  17. data/lib/reactor/cm/live_group.rb +22 -0
  18. data/lib/reactor/cm/missing_credentials.rb +7 -0
  19. data/lib/reactor/cm/obj.rb +402 -0
  20. data/lib/reactor/cm/obj_class.rb +186 -0
  21. data/lib/reactor/cm/object_base.rb +164 -0
  22. data/lib/reactor/cm/user.rb +100 -0
  23. data/lib/reactor/cm/workflow.rb +40 -0
  24. data/lib/reactor/cm/xml_attribute.rb +35 -0
  25. data/lib/reactor/cm/xml_markup.rb +85 -0
  26. data/lib/reactor/cm/xml_request.rb +82 -0
  27. data/lib/reactor/cm/xml_request_error.rb +16 -0
  28. data/lib/reactor/cm/xml_response.rb +41 -0
  29. data/lib/reactor/configuration.rb +7 -0
  30. data/lib/reactor/migration.rb +82 -0
  31. data/lib/reactor/migrations/railtie.rb +10 -0
  32. data/lib/reactor/migrations/version.rb +5 -0
  33. data/lib/reactor/plans/common_attribute.rb +32 -0
  34. data/lib/reactor/plans/common_group.rb +44 -0
  35. data/lib/reactor/plans/common_obj_class.rb +69 -0
  36. data/lib/reactor/plans/create_attribute.rb +32 -0
  37. data/lib/reactor/plans/create_group.rb +34 -0
  38. data/lib/reactor/plans/create_obj.rb +48 -0
  39. data/lib/reactor/plans/create_obj_class.rb +28 -0
  40. data/lib/reactor/plans/delete_attribute.rb +23 -0
  41. data/lib/reactor/plans/delete_group.rb +28 -0
  42. data/lib/reactor/plans/delete_obj.rb +22 -0
  43. data/lib/reactor/plans/delete_obj_class.rb +22 -0
  44. data/lib/reactor/plans/prepared.rb +15 -0
  45. data/lib/reactor/plans/rename_group.rb +32 -0
  46. data/lib/reactor/plans/rename_obj_class.rb +24 -0
  47. data/lib/reactor/plans/update_attribute.rb +23 -0
  48. data/lib/reactor/plans/update_group.rb +30 -0
  49. data/lib/reactor/plans/update_obj.rb +30 -0
  50. data/lib/reactor/plans/update_obj_class.rb +26 -0
  51. data/lib/reactor/tools/migrator.rb +135 -0
  52. data/lib/reactor/tools/response_handler/base.rb +22 -0
  53. data/lib/reactor/tools/response_handler/string.rb +19 -0
  54. data/lib/reactor/tools/response_handler/xml_attribute.rb +52 -0
  55. data/lib/reactor/tools/smart_xml_logger.rb +69 -0
  56. data/lib/reactor/tools/sower.rb +89 -0
  57. data/lib/reactor/tools/uploader.rb +131 -0
  58. data/lib/reactor/tools/versioner.rb +120 -0
  59. data/lib/reactor/tools/xml_attributes.rb +70 -0
  60. data/lib/tasks/cm_migrate.rake +8 -0
  61. data/lib/tasks/cm_seeds.rake +41 -0
  62. metadata +193 -0
@@ -0,0 +1,270 @@
1
+ require 'reactor/cm/xml_request'
2
+ require 'reactor/cm/xml_response'
3
+ require 'reactor/cm/xml_request_error'
4
+ require 'reactor/tools/xml_attributes'
5
+ require 'reactor/tools/response_handler/string'
6
+
7
+ module Reactor
8
+
9
+ module Cm
10
+
11
+ # The Group class can be used to work with user groups defined or known to the content manager.
12
+ # It allows you to create, edit and delete groups, handle users and permissions and get the
13
+ # group meta data. The Group class does not respect the user management defined under
14
+ # "config/userManagement.xml", but is the basis for class like @EditorialGroup or @LiveGroup
15
+ # that respect the user management.
16
+ class Group
17
+
18
+ include XmlAttributes
19
+
20
+ class << self
21
+
22
+ # Method returns true if a group with the given +name+ exists, false otherwise.
23
+ def exists?(name)
24
+ object = new(:name => name)
25
+
26
+ begin
27
+ object.send(:get).present?
28
+ rescue XmlRequestError
29
+ false
30
+ end
31
+ end
32
+
33
+ # Returns all known group names as an array of strings.
34
+ def all(match = '')
35
+ object = new
36
+
37
+ base_name = object.send(:base_name)
38
+
39
+ request = XmlRequest.prepare do |xml|
40
+ xml.where_key_tag!(base_name, 'groupText', match)
41
+ xml.get_key_tag!(base_name, 'name')
42
+ end
43
+
44
+ begin
45
+ response = request.execute!
46
+ groups = ResponseHandler::String.new.get(response, '//group/name/text()')
47
+
48
+ groups.is_a?(Array) ? groups : [groups]
49
+ rescue XmlRequestError
50
+ []
51
+ end
52
+
53
+ end
54
+
55
+ # See @get.
56
+ def get(name)
57
+ object = new(:name => name)
58
+ object.send(:get)
59
+ object
60
+ end
61
+
62
+ # See @create.
63
+ def create(attributes = {})
64
+ object = new(attributes)
65
+ object.send(:create)
66
+ object
67
+ end
68
+
69
+ end
70
+
71
+ attribute :name, :except => [:set]
72
+ attribute :display_title, :name => :displayTitle, :only => [:get]
73
+ attribute :real_name, :name => :realName
74
+ attribute :owner
75
+ attribute :users, :type => :list
76
+ attribute :global_permissions, :name => :globalPermissions, :type => :list
77
+
78
+ primary_key :name
79
+
80
+ # Returns true, if a global permission with the given +name+ exists, false otherwise.
81
+ def global_permission?(name)
82
+ self.global_permissions.include?(name.to_s)
83
+ end
84
+
85
+ # Add the given +permissions+ to the current set of group permissions.
86
+ def grant_global_permissions!(permissions)
87
+ permissions = permissions.kind_of?(Array) ? permissions : [permissions]
88
+ permissions = self.global_permissions | permissions
89
+
90
+ set_global_permissions!(permissions)
91
+ end
92
+
93
+ # Take away the given +permissions+ from the current set of group permissions.
94
+ def revoke_global_permissions!(permissions)
95
+ permissions = permissions.kind_of?(Array) ? permissions : [permissions]
96
+ permissions = self.global_permissions - permissions
97
+
98
+ set_global_permissions(permissions)
99
+ end
100
+
101
+ # Set the group permissions to the given +permissions+.
102
+ def set_global_permissions!(permissions)
103
+ request = XmlRequest.prepare do |xml|
104
+ xml.where_key_tag!(base_name, self.class.primary_key, self.name)
105
+ xml.set_key_tag!(base_name, self.class.xml_attribute(:global_permissions).name, permissions)
106
+ end
107
+
108
+ request.execute!
109
+
110
+ self.global_permissions = permissions
111
+ end
112
+
113
+ # Returns true, if an user with the given +name+ exists, false otherwise.
114
+ def user?(name)
115
+ users.include?(name)
116
+ end
117
+
118
+ # Add the given +users+ to the current set of group users.
119
+ def add_users!(users)
120
+ users = users.kind_of?(Array) ? users : [users]
121
+ users = self.users | users
122
+
123
+ set_users(users)
124
+ end
125
+
126
+ # Remove the given +users+ from the current set of group users.
127
+ def remove_users!(users)
128
+ users = users.kind_of?(Array) ? users : [users]
129
+ users = self.users - users
130
+
131
+ set_users(users)
132
+ end
133
+
134
+ # Set the group users to the given +users+.
135
+ def set_users!(users)
136
+ request = XmlRequest.prepare do |xml|
137
+ xml.where_key_tag!(base_name, self.class.primary_key, self.name)
138
+ xml.set_key_tag!(base_name, self.class.xml_attribute(:users).name, users)
139
+ end
140
+
141
+ request.execute!
142
+
143
+ self.users = users
144
+ end
145
+
146
+ # Saves all settable instance attributes to the Content Manager.
147
+ def save!
148
+ request = XmlRequest.prepare do |xml|
149
+ xml.where_key_tag!(base_name, self.class.primary_key, self.name)
150
+ xml.set_tag!(base_name) do
151
+ self.class.attributes(:set).each do |name, xml_attribute|
152
+ value = self.send(name)
153
+
154
+ xml.value_tag!(xml_attribute.name, value)
155
+ end
156
+ end
157
+ end
158
+
159
+ response = request.execute!
160
+
161
+ response.ok?
162
+ end
163
+
164
+ # Deletes the current group instance.
165
+ def delete!
166
+ request = XmlRequest.prepare do |xml|
167
+ xml.where_key_tag!(base_name, self.class.primary_key, self.name)
168
+ xml.delete_tag!(base_name)
169
+ end
170
+
171
+ response = request.execute!
172
+
173
+ response.ok?
174
+ end
175
+
176
+ # As it is not possible to actually rename an existing group, this method creates a new group
177
+ # with the same attributes but a different name as the current instance and deletes the old
178
+ # group. The method returns the new group object.
179
+ def rename!(name)
180
+ new_attributes =
181
+ self.class.attributes.inject({}) do |hash, mapping|
182
+ key, _ = mapping
183
+
184
+ hash[key] = self.send(key)
185
+
186
+ hash
187
+ end
188
+
189
+ if self.delete!
190
+ new_attributes[:name] = name
191
+
192
+ self.class.create(new_attributes)
193
+ else
194
+ false
195
+ end
196
+ end
197
+
198
+ protected
199
+
200
+ # The group base name can either be "group", "groupProxy", or "secondaryGroupProxy". Only the
201
+ # two proxy group names take the configured user management (config/userManagement.xml) into
202
+ # account. Use +EditorialGroup+ to work on editorial groups and +LiveGroup+ to work on live
203
+ # groups.
204
+ def base_name
205
+ 'group'
206
+ end
207
+
208
+ def initialize(attributes = {})
209
+ update_attributes(attributes)
210
+ end
211
+
212
+ # Retrieves a single group matching the name set in the current instance.
213
+ def get
214
+ request = XmlRequest.prepare do |xml|
215
+ xml.where_key_tag!(base_name, self.class.primary_key, self.name)
216
+ xml.get_key_tag!(base_name, self.class.xml_attribute_names)
217
+ end
218
+
219
+ response = request.execute!
220
+
221
+ self.class.attributes(:get).each do |name, xml_attribute|
222
+ value = self.class.response_handler.get(response, xml_attribute)
223
+
224
+ set_attribute(name, value)
225
+ end
226
+
227
+ self
228
+ end
229
+
230
+ # Creates a new group and sets all attributes that are settable on create. Other attributes
231
+ # are ignored and would be overwritten by the final +get+ call.
232
+ def create
233
+ request = XmlRequest.prepare do |xml|
234
+ xml.create_tag!(base_name) do |xml|
235
+ self.class.attributes(:create).each do |name, xml_attribute|
236
+ value = self.send(name)
237
+
238
+ xml.value_tag!(xml_attribute.name, value) if value.present?
239
+ end
240
+ end
241
+ end
242
+
243
+ response = request.execute!
244
+
245
+ self.name = self.class.response_handler.get(response, self.class.xml_attribute(:name))
246
+
247
+ get
248
+ end
249
+
250
+ private
251
+
252
+ def update_attributes(attributes) # :nodoc:
253
+ self.class.attribute_names.each do |name|
254
+ value = attributes[name]
255
+
256
+ if value.present?
257
+ set_attribute(name, value)
258
+ end
259
+ end
260
+ end
261
+
262
+ def set_attribute(name, value) # :nodoc:
263
+ self.send("#{name}=", value)
264
+ end
265
+
266
+ end
267
+
268
+ end
269
+
270
+ end
@@ -0,0 +1,56 @@
1
+ module Reactor
2
+ module Cm
3
+ class Language
4
+ def self.get(username = nil)
5
+ begin
6
+ options = {}
7
+ options = {:login => username} if username
8
+ request = XmlRequest.prepare do |xml|
9
+ xml.tag!('userConfig-getTexts', options) do
10
+ xml.tag!('listitem') do
11
+ xml.text!('languages.language')
12
+ end
13
+ end
14
+ end
15
+ response = request.execute!
16
+ response.xpath('//listitem').text
17
+ rescue => e
18
+ return nil
19
+ end
20
+ end
21
+
22
+ # FIXME: broken ([011003] Die Klasse '%s' wird nicht unterstützt.)
23
+ def self.set(*args)
24
+ username = language = nil
25
+ raise ArgumentError.new('set requires one or two parameters') unless [1,2].include? args.length
26
+
27
+ username, language = *args if args.length == 2
28
+ language = *args if args.length == 1
29
+
30
+ raise ArgumentError.new('language cannot be nil') if language.nil?
31
+ options = {}
32
+ options = {:login => username} if username
33
+
34
+ begin
35
+ request = XmlRequest.prepare do |xml|
36
+ xml.tag!('userConfig.setTexts', options) do
37
+ xml.tag!('dictitem') do
38
+ xml.tag!('key') do
39
+ xml.text!('languages.language')
40
+ end
41
+ xml.tag!('value') do
42
+ xml.text!(language)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ response = request.execute!
48
+ response.ok?
49
+ rescue => e
50
+ return false
51
+ end
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,132 @@
1
+ module Reactor
2
+ module Cm
3
+ class Link
4
+ attr_reader :link_id, :dest_obj_id, :dest_url
5
+ attr_accessor :title, :target, :position
6
+
7
+ def self.exists?(id)
8
+ return !Link.get(id).nil?
9
+ rescue XmlRequestError => e
10
+ return false
11
+ end
12
+
13
+ def self.get(id)
14
+ link = Link.new
15
+ link.send(:get,id)
16
+ link
17
+ end
18
+
19
+ def self.create_inside(obj, attr, url, title=nil)
20
+ create(obj.edited_content, attr, url, title)
21
+ end
22
+
23
+ def self.create(content, attr, url, title=nil)
24
+ link = Link.new
25
+ link.send(:create, content, attr, url, title)
26
+ link
27
+ end
28
+
29
+ def is_external?
30
+ @is_external == true
31
+ end
32
+
33
+ def is_internal?
34
+ !is_external?
35
+ end
36
+
37
+ def dest_obj_id=(obj_id)
38
+ @is_external = false
39
+ @dest_url = Obj.get(obj_id).path
40
+ @dest_obj_id = obj_id
41
+ end
42
+
43
+ def dest_url=(url)
44
+ @is_external = (/^\// =~ url).nil?
45
+ @dest_obj_id = Obj.get(url).obj_id unless @is_external
46
+ @dest_url = url
47
+ end
48
+
49
+ def save!
50
+ request = XmlRequest.prepare do |xml|
51
+ xml.where_key_tag!(base_name, 'id', @link_id)
52
+ xml.set_tag!(base_name) do
53
+ xml.tag!('target', @target) if @target
54
+ xml.tag!('title', @title) if @title
55
+ xml.tag!('destinationUrl', @dest_url) if @dest_url
56
+ xml.tag!('position', @position) if @position
57
+ end
58
+ end
59
+ response = request.execute!
60
+ end
61
+
62
+ def hash
63
+ # yes, to_s.to_is is neccesary,
64
+ # because self.link_id is of type REXML::Text for the most of the time
65
+ self.link_id.to_s.to_i
66
+ end
67
+
68
+
69
+ def eql?(other)
70
+ self.link_id == other.link_id
71
+ end
72
+
73
+ def delete!
74
+ request = XmlRequest.prepare do |xml|
75
+ xml.where_key_tag!(base_name, 'id', @link_id)
76
+ xml.tag!("#{base_name}-delete")
77
+ end
78
+ response = request.execute!
79
+ end
80
+
81
+ protected
82
+ def initialize
83
+ end
84
+
85
+ def base_name
86
+ 'link'
87
+ end
88
+
89
+ def get(id)
90
+ request = XmlRequest.prepare do |xml|
91
+ xml.where_key_tag!(base_name, 'id', id)
92
+ xml.get_key_tag!(base_name, ['id', 'isExternalLink', 'target', 'title', 'destination', 'destinationUrl', 'position'])
93
+ end
94
+ response = request.execute!
95
+
96
+ @link_id = response.xpath('//id/text()')
97
+ @is_external = response.xpath('//isExternalLink/text()') == '1'
98
+ @target = response.xpath('//target/text()').presence
99
+ @title = response.xpath('//title/text()').presence
100
+ @dest_obj_id = response.xpath('//destination/text()').presence
101
+ @dest_url = response.xpath('//destinationUrl/text()').presence
102
+ @position = response.xpath('//position/text()').presence
103
+
104
+ self
105
+ end
106
+
107
+ def create(content, attr, url, title = nil)
108
+ request = XmlRequest.prepare do |xml|
109
+ xml.create_tag!(base_name) do
110
+ xml.tag!('attributeName', attr.to_s)
111
+ xml.tag!('sourceContent', content.to_s)
112
+ xml.tag!('destinationUrl', url.to_s)
113
+ end
114
+ end
115
+ response = request.execute!
116
+
117
+ id = response.xpath('//id/text()')
118
+ get(id)
119
+
120
+ if !title.nil?
121
+ request = XmlRequest.prepare do |xml|
122
+ xml.where_key_tag!(base_name, 'id', id)
123
+ xml.set_key_tag!(base_name, 'title', title)
124
+ end
125
+ response = request.execute!
126
+ end
127
+
128
+ self
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,22 @@
1
+ require 'reactor/cm/group'
2
+
3
+ module Reactor
4
+
5
+ module Cm
6
+
7
+ # The LiveGroup class respects the user management configured in the content manager and
8
+ # handles all live groups. See @Group for further details.
9
+ class LiveGroup < Group
10
+
11
+ protected
12
+
13
+ # Overwritten method from +Group+.
14
+ def base_name
15
+ 'secondaryGroupProxy'
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,7 @@
1
+ module Reactor
2
+ module Cm
3
+ class MissingCredentials < StandardError
4
+ def initialize ; super("CM access credentials are missing. Check your configuration or supplied credentials.") ; end
5
+ end
6
+ end
7
+ end