예제 #1
0
파일: workspace.py 프로젝트: inkhey/tracim
 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
예제 #2
0
    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