def enable_workspace_notification(self, context, request: TracimRequest, hapic_data=None): # nopep8 """ enable workspace notification """ app_config = request.registry.settings['CFG'] api = ContentApi( current_user=request.candidate_user, # User session=request.dbsession, config=app_config, ) wapi = WorkspaceApi( current_user=request.candidate_user, # User session=request.dbsession, config=app_config, ) workspace = wapi.get_one(hapic_data.path.workspace_id) wapi.enable_notifications(request.candidate_user, workspace) rapi = RoleApi( current_user=request.candidate_user, # User session=request.dbsession, config=app_config, ) role = rapi.get_one(request.candidate_user.user_id, workspace.workspace_id) wapi.save(workspace) return
def enable_account_workspace_notification(self, context, request: TracimRequest, hapic_data=None): # nopep8 """ enable workspace notification """ app_config = request.registry.settings['CFG'] api = ContentApi( current_user=request.current_user, # User session=request.dbsession, config=app_config, ) wapi = WorkspaceApi( current_user=request.current_user, # User session=request.dbsession, config=app_config, ) workspace = wapi.get_one(hapic_data.path.workspace_id) wapi.enable_notifications(request.current_user, workspace) rapi = RoleApi( current_user=request.current_user, # User session=request.dbsession, config=app_config, ) role = rapi.get_one(request.current_user.user_id, workspace.workspace_id) # nopep8 wapi.save(workspace) return
def disable_workspace_notification(self, context, request: TracimRequest, hapic_data=None): """ disable workspace notification """ app_config = request.registry.settings["CFG"] # type: CFG wapi = WorkspaceApi( current_user=request.candidate_user, # User session=request.dbsession, config=app_config, ) workspace = wapi.get_one(hapic_data.path.workspace_id) wapi.disable_notifications(request.candidate_user, workspace) wapi.save(workspace)
def disable_workspace_notification(self, context, request: TracimRequest, hapic_data=None): # nopep8 """ disable workspace notification """ app_config = request.registry.settings['CFG'] api = ContentApi( current_user=request.candidate_user, # User session=request.dbsession, config=app_config, ) wapi = WorkspaceApi( current_user=request.candidate_user, # User session=request.dbsession, config=app_config, ) workspace = wapi.get_one(hapic_data.path.workspace_id) wapi.disable_notifications(request.candidate_user, workspace) wapi.save(workspace) return
def disable_account_workspace_notification(self, context, request: TracimRequest, hapic_data=None): # nopep8 """ disable workspace notification """ app_config = request.registry.settings['CFG'] api = ContentApi( current_user=request.current_user, # User session=request.dbsession, config=app_config, ) wapi = WorkspaceApi( current_user=request.current_user, # User session=request.dbsession, config=app_config, ) workspace = wapi.get_one(hapic_data.path.workspace_id) wapi.disable_notifications(request.current_user, workspace) wapi.save(workspace) return
def enable_account_workspace_notification(self, context, request: TracimRequest, hapic_data=None): """ enable workspace notification """ app_config = request.registry.settings["CFG"] # type: CFG wapi = WorkspaceApi( current_user=request.current_user, session=request.dbsession, config=app_config # User ) workspace = wapi.get_one(hapic_data.path.workspace_id) wapi.enable_notifications(request.current_user, workspace) rapi = RoleApi( current_user=request.current_user, session=request.dbsession, config=app_config # User ) rapi.get_one(request.current_user.user_id, workspace.workspace_id) wapi.save(workspace) return
class RootResource(DAVCollection): """ RootResource ressource that represents tracim's home, which contains all workspaces """ def __init__(self, path: str, environ: dict, tracim_context: "WebdavTracimContext"): super(RootResource, self).__init__(path, environ) self.tracim_context = tracim_context self.user = tracim_context.current_user self.session = tracim_context.dbsession # TODO BS 20170221: Web interface should list all workspace to. We # disable it here for moment. When web interface will be updated to # list all workspace, change this here to. self.workspace_api = WorkspaceApi( current_user=self.user, session=self.session, force_role=True, config=tracim_context.app_config, ) def __repr__(self) -> str: return "<DAVCollection: RootResource>" @webdav_check_right(is_user) def getMemberNames(self) -> [str]: """ This method returns the names (here workspace's labels) of all its children Though for perfomance issue, we're not using this function anymore """ members_names = [] for workspace in self.workspace_api.get_all(): if webdav_convert_file_name_to_display( workspace.label) in members_names: label = "{workspace_label}~~{workspace_id}".format( workspace_label=workspace.label, workspace_id=workspace.workspace_id) else: label = workspace.label members_names.append(webdav_convert_file_name_to_display(label)) @webdav_check_right(is_user) def getMember(self, label: str) -> DAVCollection: """ This method returns the child Workspace that corresponds to a given name Though for perfomance issue, we're not using this function anymore """ try: workspace = self.workspace_api.get_one_by_label(label) # fix path workspace_path = "%s%s%s" % ( self.path, "" if self.path == "/" else "/", webdav_convert_file_name_to_display(workspace.label), ) # return item return WorkspaceResource( path=workspace_path, environ=self.environ, workspace=workspace, tracim_context=self.tracim_context, label=workspace.label, ) except AttributeError: return None @webdav_check_right(is_trusted_user) def createEmptyResource(self, name: str): """ This method is called whenever the user wants to create a DAVNonCollection resource (files in our case). There we don't allow to create files at the root; only workspaces (thus collection) can be created. """ raise DAVError(HTTP_FORBIDDEN, contextinfo="Not allowed to create new root") @webdav_check_right(is_trusted_user) def createCollection(self, name: str): """ This method is called whenever the user wants to create a DAVCollection resource as a child (in our case, we create workspaces as this is the root). [For now] we don't allow to create new workspaces through webdav client. Though if we come to allow it, deleting the error's raise will make it possible. """ # TODO : remove comment here # raise DAVError(HTTP_FORBIDDEN) workspace_name = webdav_convert_file_name_to_bdd(name) try: new_workspace = self.workspace_api.create_workspace(workspace_name) except (UserNotAllowedToCreateMoreWorkspace, EmptyLabelNotAllowed) as exc: raise DAVError(HTTP_FORBIDDEN, contextinfo=str(exc)) self.workspace_api.save(new_workspace) self.workspace_api.execute_created_workspace_actions(new_workspace) transaction.commit() # fix path workspace_path = "%s%s%s" % ( self.path, "" if self.path == "/" else "/", webdav_convert_file_name_to_display(new_workspace.label), ) # create item return WorkspaceResource( path=workspace_path, environ=self.environ, workspace=new_workspace, tracim_context=self.tracim_context, label=new_workspace.label, ) @webdav_check_right(is_user) def getMemberList(self): """ This method is called by wsgidav when requesting with a depth > 0, it will return a list of _DAVResource of all its direct children """ members = [] members_names = [] for workspace in self.workspace_api.get_all(): if webdav_convert_file_name_to_display( workspace.label) in members_names: label = "{workspace_label}~~{workspace_id}".format( workspace_label=workspace.label, workspace_id=workspace.workspace_id) else: label = workspace.label # fix path workspace_label = webdav_convert_file_name_to_display(label) path = add_trailing_slash(self.path) # return item workspace_path = "{}{}".format(path, workspace_label) members.append( WorkspaceResource( path=workspace_path, environ=self.environ, workspace=workspace, tracim_context=self.tracim_context, label=label, )) members_names.append(workspace_label) return members
class RootResource(DAVCollection): """ RootResource ressource that represents tracim's home, which contains all workspaces """ def __init__(self, path: str, environ: dict, tracim_context: 'WebdavTracimContext'): super(RootResource, self).__init__(path, environ) self.tracim_context = tracim_context self.user = tracim_context.current_user self.session = tracim_context.dbsession # TODO BS 20170221: Web interface should list all workspace to. We # disable it here for moment. When web interface will be updated to # list all workspace, change this here to. self.workspace_api = WorkspaceApi( current_user=self.user, session=self.session, force_role=True, config=tracim_context.app_config ) def __repr__(self) -> str: return '<DAVCollection: RootResource>' @webdav_check_right(is_user) def getMemberNames(self) -> [str]: """ This method returns the names (here workspace's labels) of all its children Though for perfomance issue, we're not using this function anymore """ return [ webdav_convert_file_name_to_display(workspace.label) for workspace in self.workspace_api.get_all() ] @webdav_check_right(is_user) def getMember(self, label: str) -> DAVCollection: """ This method returns the child Workspace that corresponds to a given name Though for perfomance issue, we're not using this function anymore """ try: workspace = self.workspace_api.get_one_by_label(label) # fix path workspace_path = '%s%s%s' % (self.path, '' if self.path == '/' else '/', webdav_convert_file_name_to_display(workspace.label)) # return item return WorkspaceResource( workspace_path, self.environ, workspace, tracim_context=self.tracim_context ) except AttributeError: return None @webdav_check_right(is_trusted_user) def createEmptyResource(self, name: str): """ This method is called whenever the user wants to create a DAVNonCollection resource (files in our case). There we don't allow to create files at the root; only workspaces (thus collection) can be created. """ raise DAVError(HTTP_FORBIDDEN) @webdav_check_right(is_trusted_user) def createCollection(self, name: str): """ This method is called whenever the user wants to create a DAVCollection resource as a child (in our case, we create workspaces as this is the root). [For now] we don't allow to create new workspaces through webdav client. Though if we come to allow it, deleting the error's raise will make it possible. """ # TODO : remove comment here # raise DAVError(HTTP_FORBIDDEN) workspace_name = webdav_convert_file_name_to_bdd(name) new_workspace = self.workspace_api.create_workspace(workspace_name) self.workspace_api.save(new_workspace) transaction.commit() # fix path workspace_path = '%s%s%s' % ( self.path, '' if self.path == '/' else '/', webdav_convert_file_name_to_display(new_workspace.label) ) # create item return WorkspaceResource( workspace_path, self.environ, new_workspace, tracim_context=self.tracim_context ) @webdav_check_right(is_user) def getMemberList(self): """ This method is called by wsgidav when requesting with a depth > 0, it will return a list of _DAVResource of all its direct children """ members = [] for workspace in self.workspace_api.get_all(): # fix path workspace_label = webdav_convert_file_name_to_display(workspace.label) path = add_trailing_slash(self.path) # return item workspace_path = '{}{}'.format(path, workspace_label) members.append( WorkspaceResource( path=workspace_path, environ=self.environ, workspace=workspace, tracim_context=self.tracim_context ) ) return members
class RootResource(DAVCollection): """ RootResource ressource that represents tracim's home, which contains all workspaces """ def __init__(self, path: str, environ: dict, tracim_context: 'WebdavTracimContext'): super(RootResource, self).__init__(path, environ) self.tracim_context = tracim_context self.user = tracim_context.current_user self.session = tracim_context.dbsession # TODO BS 20170221: Web interface should list all workspace to. We # disable it here for moment. When web interface will be updated to # list all workspace, change this here to. self.workspace_api = WorkspaceApi(current_user=self.user, session=self.session, force_role=True, config=tracim_context.app_config) def __repr__(self) -> str: return '<DAVCollection: RootResource>' @webdav_check_right(is_user) def getMemberNames(self) -> [str]: """ This method returns the names (here workspace's labels) of all its children Though for perfomance issue, we're not using this function anymore """ return [workspace.label for workspace in self.workspace_api.get_all()] @webdav_check_right(is_user) def getMember(self, label: str) -> DAVCollection: """ This method returns the child Workspace that corresponds to a given name Though for perfomance issue, we're not using this function anymore """ try: workspace = self.workspace_api.get_one_by_label(label) workspace_path = '%s%s%s' % ( self.path, '' if self.path == '/' else '/', webdav_convert_file_name_to_display(workspace.label)) return WorkspaceResource(workspace_path, self.environ, workspace, tracim_context=self.tracim_context) except AttributeError: return None @webdav_check_right(is_trusted_user) def createEmptyResource(self, name: str): """ This method is called whenever the user wants to create a DAVNonCollection resource (files in our case). There we don't allow to create files at the root; only workspaces (thus collection) can be created. """ raise DAVError(HTTP_FORBIDDEN) @webdav_check_right(is_trusted_user) def createCollection(self, name: str): """ This method is called whenever the user wants to create a DAVCollection resource as a child (in our case, we create workspaces as this is the root). [For now] we don't allow to create new workspaces through webdav client. Though if we come to allow it, deleting the error's raise will make it possible. """ # TODO : remove comment here # raise DAVError(HTTP_FORBIDDEN) new_workspace = self.workspace_api.create_workspace(name) self.workspace_api.save(new_workspace) workspace_path = '%s%s%s' % ( self.path, '' if self.path == '/' else '/', webdav_convert_file_name_to_display(new_workspace.label)) transaction.commit() return WorkspaceResource(workspace_path, self.environ, new_workspace, tracim_context=self.tracim_context) @webdav_check_right(is_user) def getMemberList(self): """ This method is called by wsgidav when requesting with a depth > 0, it will return a list of _DAVResource of all its direct children """ members = [] for workspace in self.workspace_api.get_all(): workspace_path = '%s%s%s' % (self.path, '' if self.path == '/' else '/', workspace.label) members.append( WorkspaceResource(path=workspace_path, environ=self.environ, workspace=workspace, tracim_context=self.tracim_context)) return members