infopark_cloud_connector 6.8.0.498.46559598 → 6.8.0.515.34928522

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ resources :objs, :controller => 'rails_connector/objs', :only => [:update], :path => "__ipcms/objs"
3
+ end
@@ -0,0 +1,6 @@
1
+ module RailsConnector
2
+
3
+ class AccessDenied < StandardError
4
+ end
5
+
6
+ end
@@ -0,0 +1,12 @@
1
+ module RailsConnector
2
+
3
+ class BackendNotAvailable < StandardError
4
+ attr_reader :http_code
5
+
6
+ def initialize(message, http_code)
7
+ @http_code = http_code
8
+ super(message)
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ module RailsConnector
2
+
3
+ class ClientError < StandardError
4
+ attr_reader :http_code
5
+
6
+ def initialize(message, http_code)
7
+ @http_code = http_code
8
+ super(message)
9
+ end
10
+ end
11
+
12
+ end
@@ -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
- MultiJson.decode(RestClient::Request.execute(request_params))
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
@@ -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
@@ -54,6 +54,10 @@ class Workspace
54
54
  @workspace_data.content_cache_id = id
55
55
  end
56
56
 
57
+ def published?
58
+ self.id == 'published'
59
+ end
60
+
57
61
  end
58
62
 
59
63
  end
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: 93119979
4
+ hash: 69855207
5
5
  prerelease:
6
6
  segments:
7
7
  - 6
8
8
  - 8
9
9
  - 0
10
- - 498
11
- - 46559598
12
- version: 6.8.0.498.46559598
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-13 00:00:00 +01:00
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: 93119979
60
+ hash: 69855207
61
61
  segments:
62
62
  - 6
63
63
  - 8
64
64
  - 0
65
- - 498
66
- - 46559598
67
- version: 6.8.0.498.46559598
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