infopark_cloud_connector 6.8.0.498.46559598 → 6.8.0.515.34928522
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.
- data/app/controllers/rails_connector/objs_controller.rb +42 -0
- data/app/helpers/rails_connector/cms_tag_helper.rb +28 -0
- data/config/routes.rb +3 -0
- data/lib/rails_connector/access_denied.rb +6 -0
- data/lib/rails_connector/backend_not_available.rb +12 -0
- data/lib/rails_connector/client_error.rb +12 -0
- data/lib/rails_connector/cms_rest_api.rb +15 -2
- data/lib/rails_connector/obj.rb +5 -0
- data/lib/rails_connector/workspace.rb +4 -0
- metadata +15 -9
@@ -0,0 +1,42 @@
|
|
1
|
+
module RailsConnector
|
2
|
+
|
3
|
+
class ObjsController < ActionController::Base
|
4
|
+
|
5
|
+
before_filter :restrict_non_allow_access
|
6
|
+
|
7
|
+
respond_to :json
|
8
|
+
|
9
|
+
def update
|
10
|
+
raise "Required parameter 'obj' is missing." unless params[:obj].present?
|
11
|
+
raise "Parameter 'obj' is not a hash." unless params[:obj].is_a?(Hash)
|
12
|
+
|
13
|
+
begin
|
14
|
+
changed_obj = CmsRestApi.put(
|
15
|
+
"revisions/#{Workspace.current.revision_id}/objs/#{params[:id]}",
|
16
|
+
{ :obj => params[:obj] }
|
17
|
+
)
|
18
|
+
render :json => changed_obj
|
19
|
+
rescue ClientError => e
|
20
|
+
render :json => {:error => e.message}, :status => e.http_code
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def restrict_non_allow_access
|
27
|
+
unless allow_access?
|
28
|
+
render(:text => 'Forbidden', :status => 403)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Overwrite this method in your project.
|
33
|
+
# If +true+, allow access to ObjsController, else deny access.
|
34
|
+
# Default: +false+
|
35
|
+
# @return [Bool]
|
36
|
+
def allow_access?
|
37
|
+
false
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module RailsConnector
|
2
|
+
|
3
|
+
module CmsTagHelper
|
4
|
+
|
5
|
+
# A wrapper for [http://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag]
|
6
|
+
# If {cms_editor_mode?} returns true, it also renders additional data attributes, which are needed for inline editing.
|
7
|
+
# @param tag_name [String, Symbol] Name of the html tag (e.g. +:h1+ or +:div+).
|
8
|
+
# @param obj [Obj] A {Obj} from which attribute is read.
|
9
|
+
# @param attribute [String, Symbol] Which attribute should be render.
|
10
|
+
# @param options [Hash] Additional options, which are passed to +content_tag+.
|
11
|
+
def cms_tag(tag_name, obj, attribute, options = {})
|
12
|
+
options = options.merge({
|
13
|
+
'data-ip-field-id' => obj.id,
|
14
|
+
'data-ip-field-obj-class' => obj.obj_class,
|
15
|
+
'data-ip-field-name' => attribute,
|
16
|
+
'data-ip-field-type' => obj.type_of_attribute(attribute.to_s),
|
17
|
+
}) if cms_editor_mode?
|
18
|
+
|
19
|
+
content_tag(tag_name, display_value(obj[attribute]), options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def cms_editor_mode?
|
23
|
+
!Workspace.current.published?
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/config/routes.rb
ADDED
@@ -20,7 +20,6 @@ module RailsConnector
|
|
20
20
|
# @example Delete an Obj:
|
21
21
|
# RailsConnector::CmsRestApi.delete('revisions/001384beff9e5845/objs/f4123622ff07b70b')
|
22
22
|
class CmsRestApi
|
23
|
-
|
24
23
|
cattr_accessor :credentials
|
25
24
|
|
26
25
|
def self.get(resource_path, payload = nil)
|
@@ -53,7 +52,21 @@ module RailsConnector
|
|
53
52
|
request_params[:url] = url(resource_path)
|
54
53
|
request_params[:payload] = MultiJson.encode(payload) if payload.present?
|
55
54
|
|
56
|
-
|
55
|
+
begin
|
56
|
+
MultiJson.decode(RestClient::Request.execute(request_params))
|
57
|
+
rescue RestClient::ExceptionWithResponse => e
|
58
|
+
begin
|
59
|
+
if e.http_code == 403
|
60
|
+
raise AccessDenied.new(e.http_body)
|
61
|
+
elsif e.http_code.to_s.match(/4\d{2}/) &&
|
62
|
+
(specific_output = MultiJson.decode(e.http_body)['error'])
|
63
|
+
raise ClientError.new(specific_output, e.http_code)
|
64
|
+
end
|
65
|
+
rescue MultiJson::DecodeError
|
66
|
+
end
|
67
|
+
|
68
|
+
raise BackendNotAvailable.new(e.http_body, e.http_code)
|
69
|
+
end
|
57
70
|
end
|
58
71
|
|
59
72
|
def self.basic_request_params
|
data/lib/rails_connector/obj.rb
CHANGED
@@ -380,6 +380,11 @@ module RailsConnector
|
|
380
380
|
name
|
381
381
|
end
|
382
382
|
|
383
|
+
# @return [String]
|
384
|
+
def type_of_attribute(field_name)
|
385
|
+
data_from_cms.type_of(field_name.to_s)
|
386
|
+
end
|
387
|
+
|
383
388
|
# Returns an array with the names of groups that are permitted to access this Obj.
|
384
389
|
# This corresponds to the cms permission "permissionLiveServerRead".
|
385
390
|
def permitted_groups
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infopark_cloud_connector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 69855207
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 6
|
8
8
|
- 8
|
9
9
|
- 0
|
10
|
-
-
|
11
|
-
-
|
12
|
-
version: 6.8.0.
|
10
|
+
- 515
|
11
|
+
- 34928522
|
12
|
+
version: 6.8.0.515.34928522
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Infopark AG
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2012-12-
|
20
|
+
date: 2012-12-14 00:00:00 +01:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -57,14 +57,14 @@ dependencies:
|
|
57
57
|
requirements:
|
58
58
|
- - "="
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
hash:
|
60
|
+
hash: 69855207
|
61
61
|
segments:
|
62
62
|
- 6
|
63
63
|
- 8
|
64
64
|
- 0
|
65
|
-
-
|
66
|
-
-
|
67
|
-
version: 6.8.0.
|
65
|
+
- 515
|
66
|
+
- 34928522
|
67
|
+
version: 6.8.0.515.34928522
|
68
68
|
version_requirements: *id003
|
69
69
|
name: kvom
|
70
70
|
prerelease: false
|
@@ -80,12 +80,18 @@ extra_rdoc_files: []
|
|
80
80
|
files:
|
81
81
|
- .yardopts
|
82
82
|
- README
|
83
|
+
- app/controllers/rails_connector/objs_controller.rb
|
84
|
+
- app/helpers/rails_connector/cms_tag_helper.rb
|
83
85
|
- app/helpers/rails_connector/marker_helper.rb
|
86
|
+
- config/routes.rb
|
84
87
|
- lib/infopark_cloud_connector.rb
|
88
|
+
- lib/rails_connector/access_denied.rb
|
89
|
+
- lib/rails_connector/backend_not_available.rb
|
85
90
|
- lib/rails_connector/blob.rb
|
86
91
|
- lib/rails_connector/cache.rb
|
87
92
|
- lib/rails_connector/cache_middleware.rb
|
88
93
|
- lib/rails_connector/chain.rb
|
94
|
+
- lib/rails_connector/client_error.rb
|
89
95
|
- lib/rails_connector/cloud_engine.rb
|
90
96
|
- lib/rails_connector/cms_api_search_request.rb
|
91
97
|
- lib/rails_connector/cms_backend.rb
|