def moveRecursive(self, destpath): # INFO - G.M - 2018-12-11 - We only allow renaming if dirname(normpath( destpath)) == self.environ["http_authenticator.realm"]: # FIXME - G.M - 2018-12-11 - For an unknown reason current_workspace # of tracim_context is here invalid. self.tracim_context._current_workspace = self.workspace try: can_modify_workspace.check(self.tracim_context) except TracimException as exc: raise DAVError(HTTP_FORBIDDEN, contextinfo=str(exc)) try: workspace_api = WorkspaceApi(current_user=self.user, session=self.session, config=self.provider.app_config) workspace_api.update_workspace( workspace=self.workspace, label=webdav_convert_file_name_to_bdd( basename(normpath(destpath))), description=self.workspace.description, ) self.session.add(self.workspace) self.session.flush() workspace_api.execute_update_workspace_actions(self.workspace) transaction.commit() except TracimException as exc: raise DAVError(HTTP_FORBIDDEN, contextinfo=str(exc))
def update_workspace(self, context, request: TracimRequest, hapic_data=None): """ Update a workspace. This route is for trusted users and administrators. Note : a trusted user can only update spaces on which he/she is space manager """ app_config = request.registry.settings["CFG"] # type: CFG wapi = WorkspaceApi( current_user=request.current_user, session=request.dbsession, config=app_config # User ) wapi.update_workspace( request.current_workspace, label=hapic_data.body.label, description=hapic_data.body.description, agenda_enabled=hapic_data.body.agenda_enabled, public_download_enabled=hapic_data.body.public_download_enabled, public_upload_enabled=hapic_data.body.public_upload_enabled, default_user_role=hapic_data.body.default_user_role, save_now=True, ) wapi.execute_update_workspace_actions(request.current_workspace) return wapi.get_workspace_with_context(request.current_workspace)
def test_unit__rename_workspace_same_name_other_workspace__ok__same_workspace_name_allowed( self, session, admin_user, app_config ): wapi = WorkspaceApi(session=session, current_user=admin_user, config=app_config) wapi.create_workspace(label="business", save_now=True) workspace2 = wapi.create_workspace(label="meeting", save_now=True) wapi.update_workspace(workspace=workspace2, label="business", save_now=True, description="")
def test_unit__rename_workspace_same_workspace_same_name__ok__nominal_case( self, admin_user, session, app_config ): wapi = WorkspaceApi(session=session, current_user=admin_user, config=app_config) workspace1 = wapi.create_workspace(label="business", save_now=True) modified_datetime = workspace1.updated wapi.update_workspace(workspace=workspace1, label="business", description="") assert workspace1.updated != modified_datetime
def test_unit__rename_workspace_same_name_other_workspace__err__same_workspace_name_unallowed( self): admin = self.session.query(User).filter( User.email == "*****@*****.**").one() wapi = WorkspaceApi(session=self.session, current_user=admin, config=self.app_config) wapi.create_workspace(label="business", save_now=True) workspace2 = wapi.create_workspace(label="meeting", save_now=True) with pytest.raises(WorkspaceLabelAlreadyUsed): wapi.update_workspace(workspace=workspace2, label="business", save_now=True, description="")
def test_unit__rename_workspace_same_wworkspace_same_name__ok__nominal_case( self): admin = self.session.query(User).filter( User.email == "*****@*****.**").one() wapi = WorkspaceApi(session=self.session, current_user=admin, config=self.app_config) workspace1 = wapi.create_workspace(label="business", save_now=True) modified_datetime = workspace1.updated try: wapi.update_workspace(workspace=workspace1, label="business", description="") except WorkspaceLabelAlreadyUsed: pytest.fail("Unexpected WorkspaceLabelAlreadyUsed..") assert workspace1.updated != modified_datetime
def update_workspace(self, context, request: TracimRequest, hapic_data=None): # nopep8 """ Update a workspace. This route is for trusted users and administrators. Note : a trusted user can only update spaces on which he/she is space manager """ app_config = request.registry.settings['CFG'] wapi = WorkspaceApi( current_user=request.current_user, # User session=request.dbsession, config=app_config, ) wapi.update_workspace( request.current_workspace, label=hapic_data.body.label, description=hapic_data.body.description, save_now=True, ) return wapi.get_workspace_with_context(request.current_workspace)