def update_workspace( self, workspace: Workspace, label: str, description: str, save_now: bool = False, agenda_enabled: bool = None, ) -> Workspace: """ Update workspace :param workspace: workspace to update :param label: new label of workspace :param description: new description :param save_now: database flush :return: updated workspace """ if not label: raise EmptyLabelNotAllowed("Workspace label cannot be empty") workspace.label = label workspace.description = description if agenda_enabled is not None: workspace.agenda_enabled = agenda_enabled if save_now: self.save(workspace) return workspace
def update_workspace( self, workspace: Workspace, label: typing.Optional[str] = None, description: typing.Optional[str] = None, save_now: bool = False, agenda_enabled: typing.Optional[bool] = None, ) -> Workspace: """ Update workspace :param workspace: workspace to update :param label: new label of workspace :param description: new description :param save_now: database flush :return: updated workspace """ if label is not None: if label == "": raise EmptyLabelNotAllowed("Workspace label cannot be empty") if (self._session.query(Workspace).filter( Workspace.label == label ).filter(Workspace.workspace_id != workspace.workspace_id).count() > 0): raise WorkspaceLabelAlreadyUsed( "A workspace with label {} already exist.".format(label)) workspace.label = label if description is not None: workspace.description = description if agenda_enabled is not None: workspace.agenda_enabled = agenda_enabled workspace.updated = datetime.utcnow() if save_now: self.save(workspace) return workspace
def create_workspace( self, label: str = "", description: str = "", agenda_enabled: bool = True, public_download_enabled: bool = True, public_upload_enabled: bool = True, access_type: WorkspaceAccessType = WorkspaceAccessType.CONFIDENTIAL, default_user_role: WorkspaceRoles = WorkspaceRoles.READER, parent: Workspace = None, save_now: bool = False, ) -> Workspace: if not self._user or not self._user_allowed_to_create_new_workspaces( self._user): raise UserNotAllowedToCreateMoreWorkspace( "User not allowed to create more workspace") if not label: raise EmptyLabelNotAllowed("Workspace label cannot be empty") if access_type not in self._config.WORKSPACE__ALLOWED_ACCESS_TYPES: raise DisallowedWorkspaceAccessType( 'Access type "{}" is not allowed for this workspace'.format( access_type.name)) workspace = Workspace() workspace.label = label workspace.description = description workspace.agenda_enabled = agenda_enabled workspace.public_download_enabled = public_download_enabled workspace.public_upload_enabled = public_upload_enabled workspace.created = datetime.utcnow() workspace.updated = datetime.utcnow() workspace.owner = self._user workspace.access_type = access_type workspace.default_user_role = default_user_role workspace.parent = parent # By default, we force the current user to be the workspace manager # And to receive email notifications role_api = RoleApi(session=self._session, current_user=self._user, config=self._config) with self._session.no_autoflush: role = role_api.create_one( self._user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, with_notif=True, flush=False, ) self._session.add(workspace) self._session.add(role) if save_now: self._session.flush() return workspace
def update_workspace( self, workspace: Workspace, label: typing.Optional[str] = None, description: typing.Optional[str] = None, save_now: bool = False, agenda_enabled: typing.Optional[bool] = None, public_upload_enabled: typing.Optional[bool] = None, public_download_enabled: typing.Optional[bool] = None, default_user_role: typing.Optional[WorkspaceRoles] = None, ) -> Workspace: """ Update workspace :param workspace: workspace to update :param label: new label of workspace :param description: new description :param save_now: database flush :return: updated workspace """ if label is not None: if label == "": raise EmptyLabelNotAllowed("Workspace label cannot be empty") workspace.label = label if description is not None: workspace.description = description if agenda_enabled is not None: workspace.agenda_enabled = agenda_enabled if public_upload_enabled is not None: workspace.public_upload_enabled = public_upload_enabled if public_download_enabled is not None: workspace.public_download_enabled = public_download_enabled if default_user_role: workspace.default_user_role = default_user_role workspace.updated = datetime.utcnow() if save_now: self.save(workspace) return workspace
def create_workspace( self, label: str = "", description: str = "", agenda_enabled: bool = True, save_now: bool = False, ) -> Workspace: if not label: raise EmptyLabelNotAllowed("Workspace label cannot be empty") if self._session.query(Workspace).filter( Workspace.label == label).count() > 0: raise WorkspaceLabelAlreadyUsed( "A workspace with label {} already exist.".format(label)) workspace = Workspace() workspace.label = label workspace.description = description workspace.agenda_enabled = agenda_enabled workspace.created = datetime.utcnow() workspace.updated = datetime.utcnow() # By default, we force the current user to be the workspace manager # And to receive email notifications role_api = RoleApi(session=self._session, current_user=self._user, config=self._config) role = role_api.create_one(self._user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, with_notif=True) self._session.add(workspace) self._session.add(role) if save_now: self._session.flush() return workspace