app/controllers/scrivito/objs_controller.rb in scrivito_sdk-0.16.0 vs app/controllers/scrivito/objs_controller.rb in scrivito_sdk-0.17.0

- old
+ new

@@ -29,10 +29,23 @@ def destroy in_selected_workspace { load_object.destroy } render_empty_json end + def destroy_widget + raise ScrivitoError, "no widget_id param specified" if params[:widget_id].blank? + in_selected_workspace do + widget = load_object.widget_from_pool(params[:widget_id]) + unless widget + raise ScrivitoError, + "widget with ID '#{params[:widget_id]}' not found in obj with ID '#{@obj.id}'" + end + widget.destroy + end + render_empty_json + end + def revert in_selected_workspace { load_object.revert } render_empty_json end @@ -130,14 +143,16 @@ def obj_params @obj_params ||= ObjParamsParser.new(request.host, request.port).parse(@obj, params[:obj]) end def copy_obj(attributes, target_path=nil) - copied_attributes = attributes.except!('id', '_id', '_permalink') - copied_attributes['_path'] = "#{target_path}/#{SecureRandom.hex(6)}" + attributes = attributes.except('_permalink') + id = SecureRandom.hex(8) + attributes['_id'] = id + attributes['_path'] = "#{target_path}/#{id}" - task_unaware_request(:post, "workspaces/#{Workspace.current.id}/objs", obj: copied_attributes) + task_unaware_request(:post, "workspaces/#{Workspace.current.id}/objs", obj: attributes) end def get_obj_attributes(id) task_unaware_request(:get, "workspaces/#{Workspace.current.id}/objs/#{id}") end @@ -152,13 +167,9 @@ helper_method :current_page delegate :task_unaware_request, to: CmsRestApi private - - def editing_context - request.env[EditingContextMiddleware::ENVKEY] || EditingContext.new - end def in_selected_workspace editing_context.selected_workspace.as_current do yield end