Esempio n. 1
0
    def delete(self) -> None:
        """Delete this workspace."""
        doc = self.get_metadata()

        sysdb = system_db(readonly=False)
        coll = workspace_mapping_collection(readonly=False)

        sysdb.delete_database(doc["internal"])
        coll.delete(doc["_id"])

        # Invalidate the cache for things changed by this function
        workspace_mapping.cache_clear()
Esempio n. 2
0
    def save(self) -> None:
        """Save this workspace to the database."""
        doc = self.get_metadata()
        instance_dict = self.asdict()

        doc.update(instance_dict)

        coll = workspace_mapping_collection(readonly=False)
        coll.update(doc)

        # Invalidate the cache for things changed by this function
        workspace_mapping.cache_clear()
Esempio n. 3
0
    def rename(self, new_name: str) -> None:
        """Rename this workspace."""
        if Workspace.exists(new_name):
            raise AlreadyExists("Workspace", new_name)

        doc = self.get_metadata()
        doc["name"] = new_name

        coll = workspace_mapping_collection(readonly=False)
        coll.update(doc)

        self.name = new_name

        # Invalidate the cache for things changed by this function
        workspace_mapping.cache_clear()
Esempio n. 4
0
    def create(name: str, owner: User) -> Workspace:
        """Create a workspace, owned by `owner`."""
        if Workspace.exists(name):
            raise AlreadyExists("Workspace", name)

        internal = util.generate_arango_workspace_name()

        try:
            system_db(readonly=False).create_database(internal)
        except DatabaseCreateError:
            # Could only happen if there's a name collision
            raise InternalServerError("Error creating workspace")

        workspace_dict = {
            "name": name,
            "internal": internal,
            "permissions": WorkspacePermissions(owner=owner.sub).dict(),
        }

        coll = workspace_mapping_collection(readonly=False)
        coll.insert(workspace_dict, sync=True)
        workspace_mapping.cache_clear()

        return Workspace(name)
Esempio n. 5
0
 def list_public() -> Generator[str, None, None]:
     """Return a list of all public workspace names."""
     coll = workspace_mapping_collection()
     return (doc["name"] for doc in coll.find({"permissions.public": True}))
Esempio n. 6
0
 def list_all() -> Generator[str, None, None]:
     """Return a list of all workspace names."""
     coll = workspace_mapping_collection()
     return (doc["name"] for doc in coll.all())