require 'fiona7/workspace' require 'fiona7/assert' module Fiona7 module Controllers module RestAPI class WorkspaceController def fetch(id) id = id.to_sym Assert.exists( id == :published || id == :rtc, "Could not find Scrivito::Workspace with id #{id}" ) w = Workspace.new(id) return ::JSON.parse(::ActiveSupport::JSON.encode(w)) end def changes(id) id = id.to_sym Assert.exists( id == :published || id == :rtc, "Could not find Scrivito::Workspace with id #{id}" ) w = Workspace.new(id) w_json = ::JSON.parse(::ActiveSupport::JSON.encode(w)) { "workspace" => w_json, "current" => w.content_state_id, "objs" => "*" } end def publish(id) raise "Unexpected workspace_id: #{id}" unless id.to_s == "rtc" WriteObj.where(is_edited: 1).order('path DESC').each do |obj| begin obj.take obj.release! ::Fiona7.run_callbacks(:release_obj, obj.id) unless obj.path =~ /\/_widgets\// rescue => e raise "Release impossible of: #{obj.path} because: #{e.message}" end end {'task' => {'id' => '1', 'status' => 'success', 'result' => '1'}} end def delete(id) Assert.contraint(false, "Workspaces cannot be deleted") end def update(id) # DUMMY NO OP {} end def create(values) id = (values[:workspace][:id] || values[:workspace]["id"]) id = (id || :no_id_provided).to_sym Assert.constraint( id == :rtc, "Only rtc workspace can be created" ) w = Workspace.rtc # NOTE: this "creates" a rtc workspace # and breaks publish checker spec ... #WriteObj.root.take ; WriteObj.root.edit ::JSON.parse(::ActiveSupport::JSON.encode(w)) end def all results = [Workspace.published, Workspace.rtc] w = {'results' => results} ::JSON.parse(::ActiveSupport::JSON.encode(w)) end end end end end