infopark_cloud_connector 6.8.0.beta.200.621.4c8e1b0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ module RailsConnector
2
+
3
+ module PathConversion #:nodoc: all
4
+
5
+ def self.path_from_list(components)
6
+ "/#{components.join("/")}"
7
+ end
8
+
9
+ private
10
+
11
+ def path_from_list(components)
12
+ PathConversion.path_from_list(components)
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,39 @@
1
+ module RailsConnector
2
+
3
+ # The permissions assigned to an Obj.
4
+ class Permission < CmsBaseModel
5
+ # Returns the Array of the names of the user groups to which read permission has been granted.
6
+ def self.read
7
+ user_groups_for_permission_type(1)
8
+ end
9
+
10
+ # Returns the Array of the names of the user groups to which write permission has been granted
11
+ def self.write
12
+ user_groups_for_permission_type(2)
13
+ end
14
+
15
+ # Returns the Array of the names of the user groups to which root permission has been granted
16
+ def self.root
17
+ user_groups_for_permission_type(3)
18
+ end
19
+
20
+ # Returns the Array of the names of the user groups to which the children creation permission has been granted.
21
+ def self.create_children
22
+ user_groups_for_permission_type(4)
23
+ end
24
+
25
+ # Returns the Array of the names of the user groups to which live read permission has been granted.
26
+ def self.live
27
+ user_groups_for_permission_type(5)
28
+ end
29
+
30
+ private
31
+
32
+ def self.user_groups_for_permission_type(permission_type)
33
+ # Field name "user_login" is a legacy from CM tables.
34
+ # Actually the field contains the user group.
35
+ select(:user_login).where(:permission_type => permission_type).map(&:user_login)
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,6 @@
1
+ module RailsConnector
2
+ def self.rack_middlewares
3
+ ["RailsConnector::CacheMiddleware", "RailsConnector::WorkspaceSelectionMiddleware"]
4
+ end
5
+ end
6
+
@@ -0,0 +1,67 @@
1
+ module RailsConnector
2
+
3
+ class S3Blob
4
+ class << self
5
+
6
+ def s3_objects
7
+ @s3_objects ||= s3_api.buckets[bucket_name].objects
8
+ end
9
+
10
+ def s3_api
11
+ AWS::S3.new(
12
+ :access_key_id => access_key_id,
13
+ :secret_access_key => secret_access_key
14
+ )
15
+ end
16
+
17
+ def configure(spec)
18
+ @spec = spec.symbolize_keys
19
+ end
20
+
21
+ def find(id, options)
22
+ new(id)
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :spec
28
+
29
+ def bucket_name
30
+ spec[:bucket_name]
31
+ end
32
+
33
+ def access_key_id
34
+ spec[:access_key_id]
35
+ end
36
+
37
+ def secret_access_key
38
+ spec[:secret_access_key]
39
+ end
40
+
41
+ end
42
+
43
+ attr_reader :id
44
+
45
+ def initialize(id)
46
+ @id = id
47
+ end
48
+
49
+ def s3_object
50
+ @s3_object = self.class.s3_objects[id]
51
+ end
52
+
53
+ def url
54
+ s3_object.public_url.to_s
55
+ end
56
+
57
+ def content_type
58
+ s3_object.content_type
59
+ end
60
+
61
+ def length
62
+ s3_object.content_length
63
+ end
64
+
65
+ end
66
+
67
+ end # module RailsConnector
@@ -0,0 +1,39 @@
1
+ #:enddoc:
2
+ module RailsConnector
3
+
4
+ class Version
5
+ def initialize(doc)
6
+ @doc = doc
7
+ end
8
+
9
+ def obj_id
10
+ @doc["obj_id"]
11
+ end
12
+
13
+ def workspace_id
14
+ @doc["workspace_id"]
15
+ end
16
+
17
+ def diff
18
+ if @doc["content_cache_id"]
19
+ case @doc["action"]
20
+ when "D"
21
+ 0
22
+ else # "N", "E"
23
+ 1
24
+ end
25
+ else
26
+ @doc["diff"]
27
+ end
28
+ end
29
+
30
+ def obj_data(patch_diff)
31
+ data = patch_diff < 0 ? @doc["before"] : @doc["current"]
32
+ data["obj_id"] = @doc["obj_id"]
33
+ data["obj_type"] = @doc["obj_type"]
34
+
35
+ data
36
+ end
37
+ end
38
+
39
+ end # module RailsConnector
@@ -0,0 +1,139 @@
1
+ #:enddoc:
2
+ module RailsConnector
3
+
4
+ class Workspace < CmsBaseModel
5
+
6
+ self.key_prefix = "ws"
7
+
8
+ property :generation
9
+ property :base_workspace_id
10
+ property :title
11
+ property :content_cache_id
12
+
13
+ # Selects the workspace with the given id as current workspace
14
+ def self.current=(workspace)
15
+ @current = workspace
16
+ end
17
+
18
+ def self.current
19
+ @current || Workspace.default
20
+ end
21
+
22
+ def self.find_by_label(label_name)
23
+ label = WorkspaceLabel.find(label_name)
24
+ find(label.workspace_id)
25
+ end
26
+
27
+ def self.default
28
+ Workspace.find_by_label("published")
29
+ end
30
+
31
+ def find_obj_data_by(index, keys)
32
+ find_obj_data_from_cache_or_database_by(index, keys)
33
+ end
34
+
35
+ def chain
36
+ @chain ||= Chain.build_for(self, content_cache)
37
+ end
38
+
39
+ def invalidate_chain
40
+ @chain = nil
41
+ end
42
+
43
+ # returns the base workspace or nil for an initial workspace
44
+ def base_workspace
45
+ @base_workspace ||= base_workspace_id ? Workspace.find(base_workspace_id) : nil
46
+ end
47
+
48
+ # returns the content cache to be used with this workspace or nil if not available
49
+ def content_cache
50
+ if content_cache_id
51
+ if @content_cache && content_cache_id == @content_cache.id
52
+ @content_cache
53
+ else
54
+ @content_cache = ContentCache.find_by_id(content_cache_id)
55
+ end
56
+ end
57
+ end
58
+
59
+ def inspect
60
+ "<#{self.class} id=\"#{id}\" title=\"#{title}\">"
61
+ end
62
+
63
+ private
64
+
65
+ COMPOUND_KEY_INDICES = [:ppath].freeze
66
+
67
+ def find_obj_data_from_database_by(index, keys)
68
+ return [] if keys.blank?
69
+ instrumenter = ActiveSupport::Notifications.instrumenter
70
+ instrumenter.instrument(
71
+ "cms_load.rails_connector", :name => "Obj Load", :index => index, :keys => keys
72
+ ) do
73
+ keys.map do |key|
74
+ results = chain.query(index, key, COMPOUND_KEY_INDICES.include?(index))
75
+ results.values.map { |row| extract_obj_data(row) }
76
+ end
77
+ end
78
+ end
79
+
80
+ def find_obj_data_from_cache_or_database_by(index, keys)
81
+ # load results from cache
82
+ keys_from_database = []
83
+ results_from_cache = keys.map do |key|
84
+ Cache.load([:obj, index, key]).tap do |objs|
85
+ keys_from_database << key unless objs
86
+ end
87
+ end
88
+
89
+ # load cache misses from database and store them in cache
90
+ results_from_database = find_obj_data_from_database_by(index, keys_from_database)
91
+ keys_from_database.each_with_index do |key, key_number|
92
+ store_obj_data_list_in_cache(index, key, results_from_database[key_number])
93
+ end
94
+
95
+ # combine the results
96
+ results_from_cache.map do |objs_from_cache|
97
+ objs_from_cache || results_from_database.shift
98
+ end
99
+ end
100
+
101
+ UNIQUE_INDICES = [:id, :path, :permalink].freeze
102
+ OBJ_PROPERTY_VALUE_TO_RANGE_VALUE_CONVERSIONS = {
103
+ :path => PathConversion.method(:path_from_list)
104
+ }.freeze
105
+
106
+ def store_obj_data_list_in_cache(index, key, obj_data_list)
107
+ obj_data_list.each do |obj_data|
108
+ values = obj_data["values"]
109
+ UNIQUE_INDICES.each do |unique_index|
110
+ index_value = values[unique_index.to_s]
111
+ if (converter = OBJ_PROPERTY_VALUE_TO_RANGE_VALUE_CONVERSIONS[unique_index])
112
+ index_value = converter.call(index_value)
113
+ end
114
+ store_item_in_cache(unique_index, index_value, [obj_data])
115
+ end
116
+ end
117
+ unless UNIQUE_INDICES.include?(index)
118
+ store_item_in_cache(index, key, obj_data_list)
119
+ end
120
+ end
121
+
122
+ def store_item_in_cache(index, key, item)
123
+ Cache.store([:obj, index, key], item)
124
+ end
125
+
126
+ def extract_obj_data(data)
127
+ {
128
+ "values" => data["values"].merge(
129
+ "id" => data["obj_id"],
130
+ "obj_type" => data["obj_type"],
131
+ "obj_class" => data["obj_class"]["name"]
132
+ ),
133
+ "attributes" => data["attributes"]
134
+ }
135
+ end
136
+
137
+ end
138
+
139
+ end
@@ -0,0 +1,10 @@
1
+ #:enddoc:
2
+ module RailsConnector
3
+
4
+ class WorkspaceLabel < CmsBaseModel
5
+ self.key_prefix = "wsl"
6
+
7
+ property :workspace_id
8
+ end
9
+
10
+ end
@@ -0,0 +1,45 @@
1
+ #:enddoc:
2
+ module RailsConnector
3
+
4
+ class WorkspaceSelectionMiddleware
5
+ CURRENT_WORKSPACE_SESSION_KEY = "infopark_rails_connector-current_workspace_id"
6
+ CURRENT_WORKSPACE_PARAMS_KEY = "infopark_rails_connector-current_workspace_id"
7
+
8
+ def initialize(app)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ handle_workspace_parameter(env)
14
+ Workspace.current = workspace_to_show(env)
15
+
16
+ @app.call(env)
17
+ end
18
+
19
+ private
20
+
21
+ def handle_workspace_parameter(env)
22
+ workspace_id = Rack::Request.new(env).params[CURRENT_WORKSPACE_PARAMS_KEY]
23
+ return unless workspace_id
24
+ if workspace_id.present?
25
+ session(env)[CURRENT_WORKSPACE_SESSION_KEY] = workspace_id
26
+ else
27
+ session(env).delete(CURRENT_WORKSPACE_SESSION_KEY)
28
+ end
29
+ end
30
+
31
+ def workspace_to_show(env)
32
+ if preview_workspace = session(env)[CURRENT_WORKSPACE_SESSION_KEY]
33
+ Workspace.find(preview_workspace)
34
+ else
35
+ Workspace.default
36
+ end
37
+ end
38
+
39
+ def session(env)
40
+ env[Rack::Session::Abstract::ENV_SESSION_KEY]
41
+ end
42
+ end
43
+
44
+ end # module RailsConnector
45
+
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: infopark_cloud_connector
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15922107031
5
+ prerelease: 6
6
+ segments:
7
+ - 6
8
+ - 8
9
+ - 0
10
+ - beta
11
+ - 200
12
+ - 621
13
+ - 4
14
+ - c
15
+ - 8
16
+ - e
17
+ - 1
18
+ - b
19
+ - 0
20
+ version: 6.8.0.beta.200.621.4c8e1b0
21
+ platform: ruby
22
+ authors:
23
+ - Infopark AG
24
+ autorequire:
25
+ bindir: bin
26
+ cert_chain: []
27
+
28
+ date: 2012-04-18 00:00:00 +02:00
29
+ default_executable:
30
+ dependencies:
31
+ - !ruby/object:Gem::Dependency
32
+ requirement: &id001 !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ hash: 23
38
+ segments:
39
+ - 1
40
+ - 1
41
+ - 2
42
+ version: 1.1.2
43
+ prerelease: false
44
+ type: :runtime
45
+ name: couchrest
46
+ version_requirements: *id001
47
+ - !ruby/object:Gem::Dependency
48
+ requirement: &id002 !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ hash: 23
54
+ segments:
55
+ - 1
56
+ - 3
57
+ - 6
58
+ version: 1.3.6
59
+ prerelease: false
60
+ type: :runtime
61
+ name: aws-sdk
62
+ version_requirements: *id002
63
+ - !ruby/object:Gem::Dependency
64
+ requirement: &id003 !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - "="
68
+ - !ruby/object:Gem::Version
69
+ hash: 15922107031
70
+ segments:
71
+ - 6
72
+ - 8
73
+ - 0
74
+ - beta
75
+ - 200
76
+ - 621
77
+ - 4
78
+ - c
79
+ - 8
80
+ - e
81
+ - 1
82
+ - b
83
+ - 0
84
+ version: 6.8.0.beta.200.621.4c8e1b0
85
+ prerelease: false
86
+ type: :runtime
87
+ name: kvom
88
+ version_requirements: *id003
89
+ description: The Cloud Connector for Infopark CMS Fiona enables you to develop modern, dynamic Web 2.0 applications using Ruby on Rails and at the same time display CMS managed content.
90
+ email: info@infopark.de
91
+ executables: []
92
+
93
+ extensions: []
94
+
95
+ extra_rdoc_files:
96
+ - README
97
+ files:
98
+ - lib/infopark_cloud_connector.rb
99
+ - lib/rails_connector/attribute.rb
100
+ - lib/rails_connector/blob.rb
101
+ - lib/rails_connector/cache.rb
102
+ - lib/rails_connector/cache_middleware.rb
103
+ - lib/rails_connector/chain.rb
104
+ - lib/rails_connector/cms_base_model.rb
105
+ - lib/rails_connector/content_cache.rb
106
+ - lib/rails_connector/controller_runtime.rb
107
+ - lib/rails_connector/couch_blob.rb
108
+ - lib/rails_connector/couchdb_views_source_path.rb
109
+ - lib/rails_connector/date_attribute.rb
110
+ - lib/rails_connector/default_search_request.rb
111
+ - lib/rails_connector/elasticsearch_request.rb
112
+ - lib/rails_connector/errors.rb
113
+ - lib/rails_connector/link.rb
114
+ - lib/rails_connector/log_subscriber.rb
115
+ - lib/rails_connector/named_link.rb
116
+ - lib/rails_connector/obj.rb
117
+ - lib/rails_connector/obj_body.rb
118
+ - lib/rails_connector/obj_class.rb
119
+ - lib/rails_connector/path_conversion.rb
120
+ - lib/rails_connector/permission.rb
121
+ - lib/rails_connector/rack_middlewares.rb
122
+ - lib/rails_connector/s3_blob.rb
123
+ - lib/rails_connector/version.rb
124
+ - lib/rails_connector/workspace.rb
125
+ - lib/rails_connector/workspace_label.rb
126
+ - lib/rails_connector/workspace_selection_middleware.rb
127
+ - README
128
+ has_rdoc: true
129
+ homepage: http://www.infopark.de
130
+ licenses: []
131
+
132
+ post_install_message:
133
+ rdoc_options:
134
+ - --charset=UTF-8
135
+ - --title
136
+ - Infopark Cloud Connector
137
+ - --main
138
+ - README
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ hash: 3
147
+ segments:
148
+ - 0
149
+ version: "0"
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ hash: 17
156
+ segments:
157
+ - 1
158
+ - 3
159
+ - 5
160
+ version: 1.3.5
161
+ requirements: []
162
+
163
+ rubyforge_project:
164
+ rubygems_version: 1.6.2
165
+ signing_key:
166
+ specification_version: 3
167
+ summary: Infopark Cloud Connector
168
+ test_files: []
169
+