scrivito_sdk 0.18.1 → 0.30.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/scrivito/blobs_controller.rb +1 -2
  3. data/app/controllers/scrivito/default_cms_controller.rb +9 -75
  4. data/app/controllers/scrivito/objs_controller.rb +107 -119
  5. data/app/controllers/scrivito/tasks_controller.rb +1 -1
  6. data/app/controllers/scrivito/users_controller.rb +1 -1
  7. data/app/controllers/scrivito/webservice_controller.rb +6 -2
  8. data/app/controllers/scrivito/workspaces_controller.rb +57 -17
  9. data/app/helpers/scrivito_helper.rb +285 -0
  10. data/app/views/google_maps_widget/show.html.erb +1 -0
  11. data/app/views/scrivito/_editing_auth_warning.html.erb +43 -0
  12. data/app/views/scrivito/blobs/upload_permission.json.jbuilder +1 -0
  13. data/app/views/scrivito/objs/copy.json.jbuilder +1 -0
  14. data/app/views/scrivito/objs/copy_widget.html.erb +1 -1
  15. data/app/views/scrivito/objs/create.json.jbuilder +1 -0
  16. data/app/views/scrivito/objs/create_widget.html.erb +1 -1
  17. data/app/views/scrivito/objs/details.json.jbuilder +1 -0
  18. data/app/views/scrivito/objs/format_missing_error.json.jbuilder +1 -0
  19. data/app/views/scrivito/objs/modification.json.jbuilder +1 -0
  20. data/app/views/scrivito/objs/page_class_selection.json.jbuilder +1 -0
  21. data/app/views/scrivito/objs/search.json.jbuilder +6 -0
  22. data/app/views/scrivito/objs/search_only_size.json.jbuilder +1 -0
  23. data/app/views/scrivito/objs/update.json.jbuilder +1 -0
  24. data/app/views/scrivito/objs/widget_class_selection.json.jbuilder +1 -0
  25. data/app/views/scrivito/objs/widget_modification.json.jbuilder +1 -0
  26. data/app/views/scrivito/tasks/show.json.jbuilder +3 -0
  27. data/app/views/scrivito/users/suggest.json.jbuilder +1 -0
  28. data/app/views/scrivito/webservice/empty.json +1 -0
  29. data/app/views/scrivito/webservice/error.json.jbuilder +2 -0
  30. data/app/views/scrivito/workspaces/_workspace.json.jbuilder +5 -0
  31. data/app/views/scrivito/workspaces/check.json.jbuilder +1 -0
  32. data/app/views/scrivito/workspaces/create.json.jbuilder +1 -0
  33. data/app/views/scrivito/workspaces/index.json.jbuilder +1 -0
  34. data/app/views/scrivito/workspaces/show.json.jbuilder +1 -0
  35. data/app/views/scrivito/workspaces/task.json.jbuilder +5 -0
  36. data/config/ca-bundle.crt +259 -234
  37. data/config/cms_routes.rb +2 -2
  38. data/config/routes.rb +3 -0
  39. data/lib/assets/javascripts/{scrivito_editing.js → scrivito_sdk.js} +1662 -1180
  40. data/lib/assets/stylesheets/{scrivito_editing.css → scrivito_sdk.css} +242 -6
  41. data/lib/generators/scrivito/install/install_generator.rb +62 -0
  42. data/lib/generators/scrivito/install/templates/app/controllers/cms_controller.rb +3 -0
  43. data/lib/generators/scrivito/install/templates/app/controllers/page_controller.rb +2 -0
  44. data/lib/generators/scrivito/install/templates/app/models/headline_widget.rb +7 -0
  45. data/lib/generators/scrivito/install/templates/app/models/image.rb +5 -0
  46. data/lib/generators/scrivito/install/templates/app/models/image_widget.rb +7 -0
  47. data/lib/generators/scrivito/install/templates/app/models/obj.rb +2 -0
  48. data/lib/generators/scrivito/install/templates/app/models/page.rb +8 -0
  49. data/lib/generators/scrivito/install/templates/app/models/text_widget.rb +7 -0
  50. data/lib/generators/scrivito/install/templates/app/models/widget.rb +2 -0
  51. data/lib/generators/scrivito/install/templates/app/views/headline_widget/show.html.erb +1 -0
  52. data/lib/generators/scrivito/install/templates/app/views/headline_widget/thumbnail.html.erb +3 -0
  53. data/lib/generators/scrivito/install/templates/app/views/image_widget/show.html.erb +1 -0
  54. data/lib/generators/scrivito/install/templates/app/views/image_widget/thumbnail.html.erb +3 -0
  55. data/lib/generators/scrivito/install/templates/app/views/page/details.html.erb +1 -0
  56. data/lib/generators/scrivito/install/templates/app/views/page/index.html.erb +16 -0
  57. data/lib/generators/scrivito/install/templates/app/views/page/thumbnail.html.erb +3 -0
  58. data/lib/generators/scrivito/install/templates/app/views/text_widget/show.html.erb +1 -0
  59. data/lib/generators/scrivito/install/templates/app/views/text_widget/thumbnail.html.erb +3 -0
  60. data/lib/generators/scrivito/install/templates/config/initializers/scrivito.rb +10 -0
  61. data/lib/generators/scrivito/install/templates/scrivito/migrate/install_scrivito.rb +49 -0
  62. data/lib/generators/scrivito/migration/USAGE +9 -0
  63. data/lib/generators/{cms → scrivito}/migration/migration_generator.rb +4 -9
  64. data/lib/generators/{cms → scrivito}/migration/templates/migration.erb +3 -3
  65. data/lib/generators/{cms → scrivito}/widget/templates/details.html.erb +0 -0
  66. data/lib/generators/{cms → scrivito}/widget/templates/migration.erb +0 -0
  67. data/lib/generators/{cms → scrivito}/widget/templates/model.erb +0 -0
  68. data/lib/generators/{cms → scrivito}/widget/templates/show.html.erb +0 -0
  69. data/lib/generators/scrivito/widget/templates/thumbnail.html.erb +3 -0
  70. data/lib/generators/{cms → scrivito}/widget/widget_generator.rb +3 -2
  71. data/lib/obj.rb +17 -3
  72. data/lib/scrivito/attribute_collection.rb +7 -12
  73. data/lib/scrivito/attribute_content.rb +31 -12
  74. data/lib/scrivito/basic_obj.rb +186 -96
  75. data/lib/scrivito/basic_widget.rb +25 -10
  76. data/lib/scrivito/binary.rb +75 -0
  77. data/lib/scrivito/cache_garbage_collector.rb +19 -4
  78. data/lib/scrivito/child_list_tag.rb +108 -0
  79. data/lib/scrivito/client_config.rb +2 -1
  80. data/lib/scrivito/client_error.rb +3 -2
  81. data/lib/scrivito/cms_backend.rb +81 -16
  82. data/lib/scrivito/cms_dispatch_controller.rb +7 -0
  83. data/lib/scrivito/cms_env.rb +0 -2
  84. data/lib/scrivito/cms_field_tag.rb +44 -35
  85. data/lib/scrivito/cms_rest_api.rb +23 -6
  86. data/lib/scrivito/cms_rest_api/attribute_serializer.rb +1 -1
  87. data/lib/scrivito/cms_routing.rb +120 -0
  88. data/lib/scrivito/configuration.rb +69 -58
  89. data/lib/scrivito/connection_manager.rb +30 -1
  90. data/lib/scrivito/content_service.rb +10 -7
  91. data/lib/scrivito/controller_actions.rb +108 -0
  92. data/lib/scrivito/diff.rb +30 -15
  93. data/lib/scrivito/editing_context.rb +4 -0
  94. data/lib/scrivito/editing_context_helper.rb +19 -0
  95. data/lib/scrivito/editing_context_middleware.rb +20 -1
  96. data/lib/scrivito/image_tag_helper.rb +44 -0
  97. data/lib/scrivito/layout_tags.rb +33 -0
  98. data/lib/scrivito/link.rb +4 -2
  99. data/lib/scrivito/membership.rb +0 -8
  100. data/lib/scrivito/migrations.rb +0 -1
  101. data/lib/scrivito/migrations/installer.rb +1 -1
  102. data/lib/scrivito/migrations/migration.rb +0 -2
  103. data/lib/scrivito/migrations/migrator.rb +2 -3
  104. data/lib/scrivito/obj_class.rb +64 -16
  105. data/lib/scrivito/obj_class_data.rb +4 -0
  106. data/lib/scrivito/obj_search_enumerator.rb +1 -1
  107. data/lib/scrivito/routing_helper.rb +42 -0
  108. data/lib/scrivito/{engine.rb → sdk_engine.rb} +15 -29
  109. data/lib/scrivito/tag_renderer.rb +40 -0
  110. data/lib/scrivito/test_request.rb +40 -0
  111. data/lib/scrivito/type_computer.rb +1 -6
  112. data/lib/scrivito/user.rb +33 -15
  113. data/lib/scrivito/user_definition.rb +34 -6
  114. data/lib/scrivito/widget_tag.rb +67 -0
  115. data/lib/scrivito/workspace.rb +12 -24
  116. data/lib/scrivito_sdk.rb +17 -1
  117. data/lib/tasks/cache.rake +4 -5
  118. data/lib/tasks/migration.rake +1 -1
  119. data/lib/widget.rb +21 -3
  120. metadata +119 -70
  121. data/README +0 -6
  122. data/app/controllers/cms_controller.rb +0 -7
  123. data/app/helpers/cms_helper.rb +0 -7
  124. data/app/helpers/cms_routing_helper.rb +0 -7
  125. data/app/helpers/scrivito/cms_asset_helper.rb +0 -110
  126. data/app/helpers/scrivito/cms_tag_helper.rb +0 -232
  127. data/app/helpers/scrivito/default_cms_helper.rb +0 -21
  128. data/app/helpers/scrivito/default_cms_routing_helper.rb +0 -128
  129. data/app/helpers/scrivito/display_helper.rb +0 -64
  130. data/app/helpers/scrivito/editing_helper.rb +0 -32
  131. data/app/helpers/scrivito/layout_helper.rb +0 -21
  132. data/app/models/named_link.rb +0 -2
  133. data/app/views/cms/_index.html.erb +0 -7
  134. data/app/views/cms/index.html.erb +0 -1
  135. data/app/views/scrivito/_editing_javascript.html.erb +0 -7
  136. data/app/views/scrivito/default_cms/show_widget.html.erb +0 -1
  137. data/lib/assets/stylesheets/scrivito.css +0 -199
  138. data/lib/generators/cms/migration/USAGE +0 -9
  139. data/lib/generators/cms/widget/templates/thumbnail.html.erb +0 -2
  140. data/lib/scrivito/blob.rb +0 -48
  141. data/lib/scrivito/cms_accessible.rb +0 -30
  142. data/lib/scrivito/cms_rest_api/blob_uploader.rb +0 -18
  143. data/lib/scrivito/cms_test_request.rb +0 -23
  144. data/lib/scrivito/migrations/migration_dsl.rb +0 -180
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c030fbcf0bc0a148de95658bca6192dee2581ab
4
- data.tar.gz: 39191bc79378d57f092ea53d88169e20ea5eb307
3
+ metadata.gz: fbff45be246233cd7451a407ed46408c36322d0d
4
+ data.tar.gz: fb419781d2d22902ebf33cac737e83aab5fab40e
5
5
  SHA512:
6
- metadata.gz: 9a499b690ae3fad215f5a58772d8e80c3333e04f33db13deca5ea78d45eeb9dacf7988da7da16fbaa07ca8d020a333fa372614286c0b0092df6e8dd11e08eaa5
7
- data.tar.gz: bd110df0b0c3bd1b83c1192d8c267e662f10a096433e89a674df38c1c693dd484858ee46df4b7362aa10063057448defc7a52e0d60f1d44829fea2e694a3e2c1
6
+ metadata.gz: 688e86b1a099cc1a3dd3c53817be88772167f87fb28fb27c9f5c3aa513bcafff5170a62df30dd174a0d95d103834f6c25871d350d2c3c8d2b2c8d7276b957f4b
7
+ data.tar.gz: abcea67939882a5911bde30834f84f854397a00fe26ec123f3bba27ad276e19177e507f29d04fff5517ab3e55cdfc3f7cb73e58d60a7b7cf533a147510719246
@@ -2,8 +2,7 @@ module Scrivito
2
2
 
3
3
  class BlobsController < WebserviceController
4
4
  def upload_permission
5
- permission = CmsRestApi.task_unaware_request(:get, 'blobs/upload_permission')
6
- render json: permission
5
+ @permission = CmsRestApi.task_unaware_request(:get, 'blobs/upload_permission')
7
6
  end
8
7
  end
9
8
 
@@ -1,80 +1,14 @@
1
1
  module Scrivito
2
2
 
3
- # This controller provides some default includes ({CmsAccessible}),
4
- # before filters (+load_object+, among others), and actions to simplify
5
- # CMS object handling. It should never be used directly, but only as a
6
- # super class to {CmsController}.
7
- # @api public
8
- class DefaultCmsController < ApplicationController
9
- include CmsAccessible
10
-
11
- before_filter :load_object
12
- before_filter :authorize_editor, only: [:show_widget, :widget_details, :details_page]
13
-
14
- around_action :authorize_workspace_read, only: [:show_widget, :widget_details, :details_page]
15
-
16
- # Default Action. Delivers files directly if {BasicObj#binary?}.
17
- # Otherwise the view is rendered.
18
- # @api public
19
- def index
20
- deliver_file if @obj.binary?
21
- end
22
-
23
- def show_widget
24
- widget = load_widget
25
- render layout: false, locals: {widget: widget}
26
- end
27
-
28
- def widget_details
29
- widget = load_widget
30
- template_path = "#{widget.obj_class_name.underscore}/details"
31
- render template_path, layout: false, locals: {widget: widget}
32
- end
33
-
34
- def details_page
35
- @scrivito_resource = selected_workspace.objs.find_including_deleted(params[:resource_id])
36
- render text: '', layout: true
37
- end
38
-
39
- # This method indicates if this controller should be used automatically when an Obj is
40
- # requested via the Scrivito's standard routes. It returns true by default.
41
- #
42
- # Overwrite it to return false if you do want your controller to be excluded from Obj dispatching.
43
- #
44
- # You may also implement a method with the name {use_for_obj_dispatch?} in controllers not
45
- # descending from {DefaultCmsController} to include them in Obj dispatching.
46
- #
47
- # @see Obj#controller_name
48
- # @api public
49
- def self.use_for_obj_dispatch?
50
- true
51
- end
52
-
53
- private
54
-
55
- def authorize_editor
56
- head(:forbidden) unless editing_context.authenticated_editor?
57
- end
58
-
59
- def editing_context
60
- request.env[EditingContextMiddleware::ENVKEY] || EditingContext.new
61
- end
62
-
63
- def load_widget
64
- @obj.widget_from_pool(params[:widget_id])
65
- end
66
-
67
- def authorize_workspace_read
68
- can_user_read_workspace? ? yield : render(text: 'Forbidden', status: 403)
69
- end
70
-
71
- def can_user_read_workspace?
72
- editing_context.editor.can?(:read, selected_workspace)
73
- end
74
-
75
- def selected_workspace
76
- editing_context.selected_workspace
77
- end
3
+ class DefaultCmsController
4
+ def self.inherited(other_class)
5
+ raise %{
6
+ The controller class `Scrivito::DefaultCmsController' has been removed.
7
+ A Scrivito Cms Controllers should no longer inherit from `Scrivito::DefaultCmsController'.
8
+ Instead it should include the module `Scrivito::ControllerActions' and
9
+ inherit from the `ApplicationController' of your application.
10
+ }
78
11
  end
12
+ end
79
13
 
80
14
  end
@@ -1,58 +1,59 @@
1
1
  module Scrivito
2
-
3
2
  class ObjsController < WebserviceController
4
- around_action :authorize_selected_workspace_read,
5
- only: [:details, :page_class_selection, :widget_class_selection, :search]
6
-
7
- around_action :authorize_selected_workspace_write,
8
- only: [:create, :update, :destroy, :destroy_widget, :revert, :restore, :mark_resolved,
9
- :copy, :duplicate]
10
-
11
- before_filter :ensure_identical_selected_and_visible_workspace,
12
- only: [:create, :update, :copy, :duplicate, :page_class_selection, :widget_class_selection]
3
+ around_action :require_selected_workspace_write_authorization, only: [
4
+ :copy,
5
+ :create,
6
+ :destroy,
7
+ :destroy_widget,
8
+ :duplicate,
9
+ :mark_resolved,
10
+ :restore,
11
+ :revert,
12
+ :revert_widget,
13
+ :update,
14
+ ]
15
+
16
+ before_filter :require_identical_selected_and_visible_workspace, only: [
17
+ :copy,
18
+ :create,
19
+ :duplicate,
20
+ :page_class_selection,
21
+ :update,
22
+ :widget_class_selection,
23
+ ]
13
24
 
14
25
  def create
15
- created_obj = task_unaware_request(:post,
16
- "workspaces/#{selected_workspace.id}/objs",
17
- {obj: obj_params}
18
- )
19
- render json: created_obj
26
+ obj_params = obj_params_parser.parse(nil, params[:obj])
27
+ @obj = selected_workspace.task_unaware_api_request(:post, '/objs', obj: obj_params)
20
28
  end
21
29
 
22
30
  def details
23
- load_object
24
- render json: {markup: render_to_string(@obj.details_view_path, layout: false)}
31
+ @markup = render_to_string(current_obj.details_view_path, layout: false, formats: :html)
25
32
  end
26
33
 
27
34
  def update
28
- load_object
29
- changed_obj = task_unaware_request(:put,
30
- "workspaces/#{selected_workspace.id}/objs/#{params[:id]}",
31
- {obj: obj_params}
32
- )
33
- render json: changed_obj
35
+ obj_params = obj_params_parser.parse(current_obj, params[:obj])
36
+ @api_response = selected_workspace
37
+ .task_unaware_api_request(:put, "/objs/#{params[:id]}", obj: obj_params)
34
38
  end
35
39
 
36
40
  def destroy
37
- in_selected_workspace { load_object.destroy }
41
+ in_selected_workspace { current_obj.destroy }
38
42
  render_empty_json
39
43
  end
40
44
 
41
45
  def destroy_widget
42
- raise ScrivitoError, "no widget_id param specified" if params[:widget_id].blank?
43
- in_selected_workspace do
44
- widget = load_object.widget_from_pool(params[:widget_id])
45
- unless widget
46
- raise ScrivitoError,
47
- "widget with ID '#{params[:widget_id]}' not found in obj with ID '#{@obj.id}'"
48
- end
49
- widget.destroy
50
- end
46
+ in_selected_workspace { current_widget.destroy }
51
47
  render_empty_json
52
48
  end
53
49
 
54
50
  def revert
55
- in_selected_workspace { load_object.revert }
51
+ in_selected_workspace { current_obj.revert }
52
+ render_empty_json
53
+ end
54
+
55
+ def revert_widget
56
+ in_selected_workspace { current_widget.revert }
56
57
  render_empty_json
57
58
  end
58
59
 
@@ -62,159 +63,146 @@ module Scrivito
62
63
  end
63
64
 
64
65
  def mark_resolved
65
- in_selected_workspace { load_object.mark_resolved }
66
+ in_selected_workspace { current_obj.mark_resolved }
66
67
  render_empty_json
67
68
  end
68
69
 
69
70
  def copy
70
- render json: copy_obj(load_object, params[:parent_path])
71
+ @attributes = copy_obj(current_obj, params[:parent_path])
71
72
  end
72
73
 
73
74
  def duplicate
74
- load_object
75
-
76
- render json: copy_obj(@obj, parent_path(@obj.path))
75
+ @attributes = copy_obj(current_obj, current_obj.parent_path)
76
+ render :copy
77
77
  end
78
78
 
79
79
  def page_class_selection
80
- valid_page_classes = Obj.valid_page_classes_beneath(params[:parent_path]) ||
81
- Obj.descendants
82
- valid_page_classes.map!(&:to_s)
83
-
84
- page_class_names = valid_page_classes.map do |page_class_name|
80
+ @page_class_markup = valid_page_classes.map do |page_class_name|
85
81
  begin
86
- markup = render_to_string("#{page_class_name.underscore}/thumbnail")
82
+ markup = render_to_string("#{page_class_name.underscore}/thumbnail", formats: :html)
87
83
  {name: page_class_name, markup: markup}
88
84
  rescue ActionView::MissingTemplate
89
85
  end
90
86
  end
91
-
92
- render json: page_class_names.compact
87
+ @page_class_markup.compact!
93
88
  end
94
89
 
95
90
  def widget_class_selection
96
- load_object
97
- valid_widget_classes = @obj.valid_widget_classes_for(params[:field_name]) ||
98
- Widget.descendants
99
- valid_widget_classes.map!(&:to_s)
91
+ load_obj
100
92
 
101
- widgets_classes = valid_widget_classes.map do |widget_class_name|
93
+ @widgets_classes = valid_widget_classes.map do |widget_class_name|
102
94
  template_path = "#{widget_class_name.underscore}/thumbnail"
103
95
  markup = begin
104
- render_to_string(template_path, layout: false)
96
+ render_to_string(template_path, layout: false, formats: :html)
105
97
  rescue ActionView::MissingTemplate
106
- render_to_string('scrivito/widget_thumbnail', layout: false,
98
+ render_to_string('scrivito/widget_thumbnail', layout: false, formats: :html,
107
99
  locals: {widget_class_name: widget_class_name, template_path: template_path})
108
100
  end
109
101
  {name: widget_class_name, markup: markup}
110
102
  end
111
-
112
- render json: widgets_classes
113
103
  end
114
104
 
115
105
  def search
116
106
  in_selected_workspace do
117
- query = MultiJson.decode(params[:query]).with_indifferent_access
118
- search_builder = ObjSearchBuilder.new(query)
119
- enumerator = search_builder.build
120
- formatter = fetch_formatter(query[:format])
107
+ @query = MultiJson.decode(params[:query]).with_indifferent_access
108
+ @enumerator = ObjSearchBuilder.new(@query).build
121
109
 
122
110
  if params[:query_action] == 'size'
123
- render json: { total: enumerator.size }
124
- elsif formatter
125
- batch = enumerator.load_batch
126
-
127
- result = {
128
- total: enumerator.size,
129
- hits: batch.map { |obj| formatter.call(obj, scrivito_user) }
130
- }
131
-
132
- render json: result
111
+ render :search_only_size
112
+ elsif @formatter = fetch_formatter(@query[:format])
113
+ render :search
133
114
  else
134
- render json: { error: format_missing_message(query[:format]) }, status: :not_found
115
+ render :format_missing_error, status: :not_found
135
116
  end
136
117
  end
137
118
  end
138
119
 
139
- private
120
+ def modification
121
+ in_selected_workspace { render }
122
+ end
140
123
 
141
- def load_object
142
- @obj = Obj.find(params[:id])
124
+ def widget_modification
125
+ in_selected_workspace { render }
143
126
  end
144
127
 
145
- def ensure_identical_selected_and_visible_workspace
128
+ private
129
+
130
+ def require_identical_selected_and_visible_workspace
146
131
  if selected_workspace != editing_context.visible_workspace
147
- raise ScrivitoError, "selected and visible workspace are not identical"
132
+ raise ScrivitoError, 'selected and visible workspace are not identical'
148
133
  end
149
134
  end
150
135
 
151
- def obj_params
152
- @obj_params ||= ObjParamsParser.new(request.host, request.port).parse(@obj, params[:obj])
136
+ def require_selected_workspace_write_authorization(&block)
137
+ authorize_workspace_access(:write, selected_workspace, &block)
153
138
  end
154
139
 
155
- def copy_obj(obj, target_path)
156
- id = SecureRandom.hex(8)
157
-
158
- copied_obj = obj.copy(_id: id, _path: "#{target_path}/#{id}")
159
- dumped_last_changed = CmsRestApi::AttributeSerializer
160
- .convert_time(copied_obj[:_last_changed])
161
-
162
- {
163
- _id: copied_obj[:_id],
164
- _last_changed: dumped_last_changed,
165
- _obj_class: copied_obj[:_obj_class_name],
166
- _path: copied_obj[:_path],
167
- }
140
+ def in_selected_workspace(&block)
141
+ selected_workspace.as_current(&block)
168
142
  end
169
143
 
170
- def get_obj_attributes(id)
171
- task_unaware_request(:get, "workspaces/#{selected_workspace.id}/objs/#{id}")
144
+ def selected_workspace
145
+ editing_context.selected_workspace
172
146
  end
173
147
 
174
- def parent_path(path)
175
- path.split('/')[0..-2].join('/')
148
+ def current_obj
149
+ @obj || load_obj
176
150
  end
151
+ helper_method :current_obj
177
152
 
178
- def current_page
179
- Obj.find(params[:current_page_id]) if params[:current_page_id].present?
153
+ def load_obj
154
+ @obj = Obj.find(params[:id])
180
155
  end
181
- helper_method :current_page
182
-
183
- delegate :task_unaware_request, to: CmsRestApi
184
156
 
185
- private
157
+ def current_widget
158
+ @widget || load_widget
159
+ end
160
+ helper_method :current_widget
186
161
 
187
- def authorize_selected_workspace_read(&block)
188
- authorize_workspace_access(:read, selected_workspace, &block)
162
+ def load_widget
163
+ raise ScrivitoError, 'no widget_id param specified' if params[:widget_id].blank?
164
+ unless @widget = current_obj.widget_from_pool(params[:widget_id])
165
+ raise ScrivitoError, "widget with ID '#{params[:widget_id]}' not found"
166
+ end
167
+ @widget
189
168
  end
190
169
 
191
- def authorize_selected_workspace_write(&block)
192
- authorize_workspace_access(:write, selected_workspace, &block)
170
+ def copy_obj(obj, target_path)
171
+ id = SecureRandom.hex(8)
172
+ copied_obj = obj.copy(_id: id, _path: "#{target_path}/#{id}")
173
+ dumped_last_changed = CmsRestApi::AttributeSerializer.convert_time(copied_obj[:_last_changed])
174
+ {
175
+ _id: copied_obj[:_id],
176
+ _last_changed: dumped_last_changed,
177
+ _obj_class: copied_obj[:_obj_class_name],
178
+ _path: copied_obj[:_path],
179
+ }
193
180
  end
194
181
 
195
- def in_selected_workspace(&block)
196
- selected_workspace.as_current(&block)
182
+ def fetch_formatter(name)
183
+ name ? Configuration.obj_formats[name] : proc { |obj, _| obj.id }
197
184
  end
198
185
 
199
- def selected_workspace
200
- @selected_workspace ||= editing_context.selected_workspace
186
+ def valid_page_classes
187
+ (Obj.valid_page_classes_beneath(params[:parent_path]) || Obj.descendants).map(&:to_s)
201
188
  end
202
189
 
203
- def render_empty_json
204
- render json: {}
190
+ def valid_widget_classes
191
+ (widget_classes_from_widget || widget_classes_from_obj || Widget.descendants).map(&:to_s)
205
192
  end
206
193
 
207
- def fetch_formatter(name)
208
- if name
209
- Configuration.obj_formats[name]
210
- else
211
- proc { |obj, _| obj.id }
194
+ def widget_classes_from_widget
195
+ if params[:widget_id] && (widget = current_obj.widget_from_pool(params[:widget_id]))
196
+ widget.valid_widget_classes_for(params[:field_name])
212
197
  end
213
198
  end
214
199
 
215
- def format_missing_message(format_name)
216
- "The format with the name '#{format_name}' is not registered"
200
+ def widget_classes_from_obj
201
+ current_obj.valid_widget_classes_for(params[:field_name])
217
202
  end
218
- end
219
203
 
204
+ def obj_params_parser
205
+ ObjParamsParser.new(request.host, request.port)
206
+ end
207
+ end
220
208
  end
@@ -3,7 +3,7 @@ module Scrivito
3
3
  class TasksController < WebserviceController
4
4
 
5
5
  def show
6
- render json: CmsRestApi.task_unaware_request(:get, "tasks/#{params[:id]}")
6
+ @task = CmsRestApi.task_unaware_request(:get, "tasks/#{params[:id]}")
7
7
  end
8
8
 
9
9
  end
@@ -1,7 +1,7 @@
1
1
  module Scrivito
2
2
  class UsersController < WebserviceController
3
3
  def suggest
4
- render json: scrivito_user.suggest_users(params[:input]).first(20)
4
+ @suggested_users = scrivito_user.suggest_users(params[:input]).first(20)
5
5
  end
6
6
  end
7
7
  end