lib/scrivito/workspace.rb in scrivito_sdk-0.16.0 vs lib/scrivito/workspace.rb in scrivito_sdk-0.17.0
- old
+ new
@@ -106,11 +106,11 @@
# Reloads this workspace to reflect any changes to it that may have happened concurrently since
# it was loaded
# @api public
def reload
@workspace_data = CmsBackend.instance.find_workspace_data_by_id(self.id)
- @revision = @base_revision = nil
+ @revision = @base_revision = @memberships = nil
end
# Updates this workspace's attributes
# @api public
# @param [Hash] attributes
@@ -160,10 +160,18 @@
# @return [String]
def title
@workspace_data.title
end
+ # @api beta
+ # Returns the members of this workspace and their roles
+ #
+ # @return [MembershipsCollection]
+ def memberships
+ @memberships ||= MembershipsCollection.new(self)
+ end
+
def data
@workspace_data
end
def published?
@@ -199,94 +207,21 @@
def assert_revertable
raise ScrivitoError, 'published workspace is not modifiable' if published?
raise ScrivitoError, 'rtc workspace may contain attribute and class changes' if rtc?
end
- # Find a {BasicObj Obj} by its id.
- # If the parameter is an Array containing ids, return a list of corresponding Objs.
- # @param [String, Integer, Array<String, Integer>]id_or_list
- # @return [Obj, Array<Obj>]
+ # {ObjsCollection} for this working copy
# @api public
- def find_obj(id_or_list)
- find_filtering_deleted(id_or_list, false)
+ # @return {ObjsCollection}
+ def objs
+ @objs ||= ObjsCollection.new(self)
end
- # Find a {BasicObj Obj} by its id.
- # If the parameter is an Array containing ids, return a list of corresponding Objs.
- # The results include deleted objects as well.
- # @param [String, Integer, Array<String, Integer>]id_or_list
- # @return [Obj, Array<Obj>]
- # @api public
- def find_obj_including_deleted(id_or_list)
- find_filtering_deleted(id_or_list, true)
- end
-
- # Find the {BasicObj Obj} with the given path.
- # Returns +nil+ if no matching Obj exists.
- # @param [String] path Path of the {BasicObj Obj}.
- # @return [Obj]
- # @api public
- def find_obj_by_path(path)
- find_objs_by(:path, [path]).first.first
- end
-
- # Returns the {BasicObj Obj} with the given permalink, or +nil+ if no matching Obj exists.
- # @param [String] permalink The permalink of the {BasicObj Obj}.
- # @return [Obj]
- # @api public
- def find_obj_by_permalink(permalink)
- find_objs_by(:permalink, [permalink]).first.first
- end
-
- def find_objs_by_parent_path(path)
- find_objs_by(:ppath, [path]).first
- end
-
- def find_obj_by_id(id)
- find_objs_by(:id, [id]).first.first
- end
-
- def find_objs_by_paths(paths)
- find_objs_by(:path, paths).map(&:first)
- end
-
def inspect
"<#{self.class} id=\"#{id}\" title=\"#{title}\">"
end
private
-
- def find_filtering_deleted(id_or_list, include_deleted)
- case id_or_list
- when Array
- find_objs_by(:id, id_or_list, include_deleted).map(&:first).compact
- else
- obj = find_objs_by(:id, [id_or_list.to_s], include_deleted).first.first
- obj or raise ResourceNotFound, "Could not find Obj with id #{id_or_list}"
- end
- end
-
- # accepts the name of an "obj_by" - view, a list of keys
- # and an "include_deleted" flag
- # returns a list of lists of Objs: a list of Objs for each given keys.
- def find_objs_by(view, keys, include_deleted = false)
- if include_deleted
- finder_method_name = :find_obj_data_including_deleted_by
- else
- finder_method_name = :find_obj_data_by
- end
-
- result = CmsBackend.instance.public_send(finder_method_name, revision, view, keys)
-
- result.map do |list|
- list.map do |obj_data|
- obj = BasicObj.instantiate(obj_data)
- obj.revision = revision
-
- obj
- end
- end
- end
def backend_url
"/workspaces/#{id}"
end