コード例 #1
0
    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
コード例 #2
0
    def createEmptyResource(self, file_name: str):
        """
        [For now] we don't allow to create files right under workspaces.
        Though if we come to allow it, deleting the error's raise will make it possible.
        """
        # TODO : remove commentary here raise DAVError(HTTP_FORBIDDEN)
        if "/.deleted/" in self.path or "/.archived/" in self.path:
            raise DAVError(HTTP_FORBIDDEN)

        content = None

        # Note: To prevent bugs, check here again if resource already exist
        # fixed path
        fixed_file_name = webdav_convert_file_name_to_display(file_name)
        path = os.path.join(self.path, file_name)
        resource = self.provider.getResourceInst(path, self.environ)
        if resource:
            content = resource.content

        # return item
        return FakeFileStream(
            session=self.session,
            file_name=fixed_file_name,
            content_api=self.content_api,
            workspace=self.workspace,
            content=content,
            parent=self.content,
            path=self.path + "/" + fixed_file_name,
        )
コード例 #3
0
ファイル: resources.py プロジェクト: tracim/tracim
    def createCollection(self, label: str) -> 'FolderResource':
        """
        Create a new folder for the current workspace. As it's not possible for the user to choose
        which types of content are allowed in this folder, we allow allow all of them.

        This method return the DAVCollection created.
        """

        if '/.deleted/' in self.path or '/.archived/' in self.path:
            raise DAVError(HTTP_FORBIDDEN)
        folder_label = webdav_convert_file_name_to_bdd(label)
        try:
            folder = self.content_api.create(
                content_type_slug=content_type_list.Folder.slug,
                workspace=self.workspace,
                label=folder_label,
                parent=self.content
            )
        except TracimException as exc:
            raise DAVError(HTTP_FORBIDDEN) from exc

        self.content_api.save(folder)

        transaction.commit()
        # fixed_path
        folder_path = '%s/%s' % (self.path, webdav_convert_file_name_to_display(label))
        # return item
        return FolderResource(
            folder_path,
            self.environ,
            content=folder,
            tracim_context=self.tracim_context,
            workspace=self.workspace,
        )
コード例 #4
0
ファイル: resources.py プロジェクト: tracim/tracim
    def createEmptyResource(self, file_name: str):
        """
        [For now] we don't allow to create files right under workspaces.
        Though if we come to allow it, deleting the error's raise will make it possible.
        """
        # TODO : remove commentary here raise DAVError(HTTP_FORBIDDEN)
        if '/.deleted/' in self.path or '/.archived/' in self.path:
            raise DAVError(HTTP_FORBIDDEN)

        content = None

        # Note: To prevent bugs, check here again if resource already exist
        # fixed path
        fixed_file_name = webdav_convert_file_name_to_display(file_name)
        path = os.path.join(self.path, file_name)
        resource = self.provider.getResourceInst(path, self.environ)
        if resource:
            content = resource.content

        # return item
        return FakeFileStream(
            session=self.session,
            file_name=fixed_file_name,
            content_api=self.content_api,
            workspace=self.workspace,
            content=content,
            parent=self.content,
            path=self.path + '/' + fixed_file_name
        )
コード例 #5
0
    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))
コード例 #6
0
    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,
        )
コード例 #7
0
ファイル: resources.py プロジェクト: inkhey/tracim
 def createEmptyResource(self, file_name: str):
     """
     Create a new file on the current workspace/folder.
     """
     content = None
     fixed_file_name = webdav_convert_file_name_to_display(file_name)
     path = os.path.join(self.path, file_name)
     resource = self.provider.getResourceInst(path, self.environ)
     if resource:
         content = resource.content
     try:
         self.content_api.check_upload_size(
             int(self.environ["CONTENT_LENGTH"]), self.workspace)
     except (
             FileSizeOverMaxLimitation,
             FileSizeOverWorkspaceEmptySpace,
             FileSizeOverOwnerEmptySpace,
     ) as exc:
         raise DAVError(HTTP_REQUEST_ENTITY_TOO_LARGE, contextinfo=str(exc))
     # return item
     return FakeFileStream(
         session=self.session,
         file_name=fixed_file_name,
         content_api=self.content_api,
         workspace=self.workspace,
         content=content,
         parent=self.content,
         path=self.path + "/" + fixed_file_name,
     )
コード例 #8
0
ファイル: resources.py プロジェクト: inkhey/tracim
    def createCollection(self, label: str) -> "FolderResource":
        """
        Create a new folder for the current workspace/folder. As it's not possible for the user to choose
        which types of content are allowed in this folder, we allow allow all of them.

        This method return the DAVCollection created.
        """
        folder_label = webdav_convert_file_name_to_bdd(label)
        try:
            folder = self.content_api.create(
                content_type_slug=content_type_list.Folder.slug,
                workspace=self.workspace,
                label=folder_label,
                parent=self.content,
            )
            self.content_api.execute_created_content_actions(folder)
        except TracimException as exc:
            raise DAVError(HTTP_FORBIDDEN, contextinfo=str(exc)) from exc

        self.content_api.save(folder)

        transaction.commit()
        # fixed_path
        folder_path = "%s/%s" % (self.path,
                                 webdav_convert_file_name_to_display(label))
        # return item
        return FolderResource(
            folder_path,
            self.environ,
            content=folder,
            tracim_context=self.tracim_context,
            workspace=self.workspace,
        )
コード例 #9
0
ファイル: resources.py プロジェクト: tracim/tracim
    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
        )
コード例 #10
0
    def getMemberList(self) -> [_DAVResource]:
        members = []

        children = self.content_api.get_all(False, content_type_list.Any_SLUG,
                                            self.workspace)

        for content in children:
            content_path = '%s/%s' % (self.path,
                                      webdav_convert_file_name_to_display(
                                          content.file_name))

            if content.type == content_type_list.Folder.slug:
                members.append(
                    FolderResource(path=content_path,
                                   environ=self.environ,
                                   workspace=self.workspace,
                                   content=content,
                                   tracim_context=self.tracim_context))
            elif content.type == content_type_list.File.slug:
                self._file_count += 1
                members.append(
                    FileResource(path=content_path,
                                 environ=self.environ,
                                 content=content,
                                 tracim_context=self.tracim_context))
            else:
                self._file_count += 1
                members.append(
                    OtherFileResource(content_path,
                                      self.environ,
                                      content,
                                      tracim_context=self.tracim_context))
        return members
コード例 #11
0
    def createCollection(self, label: str) -> 'FolderResource':
        """
        Create a new folder for the current workspace. As it's not possible for the user to choose
        which types of content are allowed in this folder, we allow allow all of them.

        This method return the DAVCollection created.
        """

        if '/.deleted/' in self.path or '/.archived/' in self.path:
            raise DAVError(HTTP_FORBIDDEN)

        try:
            folder = self.content_api.create(
                content_type_slug=content_type_list.Folder.slug,
                workspace=self.workspace,
                label=label,
                parent=self.content)
        except TracimException as exc:
            raise DAVError(HTTP_FORBIDDEN) from exc

        self.content_api.save(folder)

        transaction.commit()

        return FolderResource(
            '%s/%s' % (self.path, webdav_convert_file_name_to_display(label)),
            self.environ,
            content=folder,
            tracim_context=self.tracim_context,
            workspace=self.workspace,
        )
コード例 #12
0
ファイル: resources.py プロジェクト: inkhey/tracim
 def getMember(self, label: str) -> _DAVResource:
     """
     Access to a specific members
     """
     return self.provider.getResourceInst(
         "%s/%s" % (self.path, webdav_convert_file_name_to_display(label)),
         self.environ)
コード例 #13
0
ファイル: resources.py プロジェクト: tracim/tracim
    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()
        ]
コード例 #14
0
    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()
        ]
コード例 #15
0
ファイル: resources.py プロジェクト: inkhey/tracim
 def getMemberNames(self) -> [str]:
     """
     Access to the list of content names for current workspace/folder
     """
     # INFO - G.M - 2020-14-10 - Unclear if this method is really used by wsgidav
     retlist = []
     for content in self._get_members():
         retlist.append(
             webdav_convert_file_name_to_display(content.file_name))
     return retlist
コード例 #16
0
ファイル: resources.py プロジェクト: inkhey/tracim
 def getMemberNames(self) -> List[str]:
     """
     This method returns the names (here workspace's labels) of all its children
     """
     # INFO - G.M - 2020-14-10 - Unclear if this method is really used by wsgidav
     members_names = []  # type: List[str]
     for workspace in self._get_members():
         members_names.append(
             webdav_convert_file_name_to_display(
                 workspace.filemanager_filename))
     return members_names
コード例 #17
0
ファイル: resources.py プロジェクト: inkhey/tracim
 def _generate_child_content_resource(
         self, parent_path: str, child_content: Content) -> _DAVResource:
     content_path = "%s/%s" % (
         self.path,
         webdav_convert_file_name_to_display(child_content.file_name),
     )
     return get_content_resource(
         path=content_path,
         environ=self.environ,
         workspace=self.workspace,
         content=child_content,
         tracim_context=self.tracim_context,
     )
コード例 #18
0
    def getMemberList(self) -> [_DAVResource]:
        members = []
        content_api = ContentApi(
            current_user=self.user,
            config=self.provider.app_config,
            session=self.session,
            namespaces_filter=[self.content.content_namespace],
        )
        visible_children = content_api.get_all([self.content.content_id],
                                               content_type_list.Any_SLUG,
                                               self.workspace)

        for content in visible_children:
            content_path = "%s/%s" % (
                self.path,
                webdav_convert_file_name_to_display(content.file_name),
            )

            try:
                if content.type == content_type_list.Folder.slug:
                    members.append(
                        FolderResource(
                            path=content_path,
                            environ=self.environ,
                            workspace=self.workspace,
                            content=content,
                            tracim_context=self.tracim_context,
                        ))
                elif content.type == content_type_list.File.slug:
                    self._file_count += 1
                    members.append(
                        FileResource(
                            path=content_path,
                            environ=self.environ,
                            content=content,
                            tracim_context=self.tracim_context,
                        ))
                else:
                    self._file_count += 1
                    members.append(
                        OtherFileResource(
                            path=content_path,
                            environ=self.environ,
                            content=content,
                            tracim_context=self.tracim_context,
                        ))
            except NotImplementedError:
                pass

        return members
コード例 #19
0
ファイル: resources.py プロジェクト: inkhey/tracim
 def _generate_child_workspace_resource(
         self, parent_path: str,
         child_workspace: Workspace) -> "WorkspaceResource":
     workspace_label = webdav_convert_file_name_to_display(
         child_workspace.filemanager_filename)
     path = add_trailing_slash(parent_path)
     workspace_path = "{}{}".format(path, workspace_label)
     return get_workspace_resource(
         path=workspace_path,
         environ=self.environ,
         workspace=child_workspace,
         tracim_context=self.tracim_context,
         label=workspace_label,
     )
コード例 #20
0
ファイル: resources.py プロジェクト: tracim/tracim
    def getMemberList(self) -> [_DAVResource]:
        members = []
        content_api = ContentApi(
            current_user=self.user,
            config=self.provider.app_config,
            session=self.session,
        )
        visible_children = content_api.get_all(
            [self.content.content_id],
            content_type_list.Any_SLUG,
            self.workspace,
        )

        for content in visible_children:
            content_path = '%s/%s' % (self.path, webdav_convert_file_name_to_display(content.file_name))

            try:
                if content.type == content_type_list.Folder.slug:
                    members.append(
                        FolderResource(
                            path=content_path,
                            environ=self.environ,
                            workspace=self.workspace,
                            content=content,
                            tracim_context=self.tracim_context
                        )
                    )
                elif content.type == content_type_list.File.slug:
                    self._file_count += 1
                    members.append(
                        FileResource(
                            path=content_path,
                            environ=self.environ,
                            content=content,
                            tracim_context=self.tracim_context
                        ))
                else:
                    self._file_count += 1
                    members.append(
                        OtherFileResource(
                            path=content_path,
                            environ=self.environ,
                            content=content,
                            tracim_context=self.tracim_context
                        ))
            except NotImplementedError as exc:
                pass

        return members
コード例 #21
0
ファイル: resources.py プロジェクト: tracim/tracim
    def getMemberNames(self) -> [str]:
        retlist = []

        children = self.content_api.get_all(
            parent_ids=[self.content.id] if self.content is not None else None,
            workspace=self.workspace
        )

        for content in children:
            # the purpose is to display .history only if there's at least one content's type that has a history
            if content.type != content_type_list.Folder.slug:
                self._file_count += 1
            retlist.append(webdav_convert_file_name_to_display(content.file_name))

        return retlist
コード例 #22
0
    def getMemberNames(self) -> [str]:
        retlist = []

        children = self.content_api.get_all(
            parent_ids=[self.content.id] if self.content is not None else None,
            workspace=self.workspace,
        )

        for content in children:
            # the purpose is to display .history only if there's at least one content's type that has a history
            if content.type != content_type_list.Folder.slug:
                self._file_count += 1
            retlist.append(
                webdav_convert_file_name_to_display(content.file_name))

        return retlist
コード例 #23
0
    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
コード例 #24
0
ファイル: resources.py プロジェクト: tracim/tracim
    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
コード例 #25
0
ファイル: resources.py プロジェクト: tracim/tracim
    def getMemberList(self) -> [_DAVResource]:
        members = []

        children = self.content_api.get_all(False, content_type_list.Any_SLUG, self.workspace)

        for content in children:
            content_path = '%s/%s' % (self.path, webdav_convert_file_name_to_display(content.file_name))

            if content.type == content_type_list.Folder.slug:
                members.append(
                    FolderResource(
                        path=content_path,
                        environ=self.environ,
                        workspace=self.workspace,
                        content=content,
                        tracim_context=self.tracim_context
                    )
                )
            elif content.type == content_type_list.File.slug:
                self._file_count += 1
                members.append(
                    FileResource(
                        path=content_path,
                        environ=self.environ,
                        content=content,
                        tracim_context=self.tracim_context
                    )
                )
            else:
                self._file_count += 1
                members.append(
                    OtherFileResource(
                        content_path,
                        self.environ,
                        content,
                        tracim_context=self.tracim_context
                    ))
        return members
コード例 #26
0
ファイル: resources.py プロジェクト: tracim/tracim
    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
コード例 #27
0
    def createEmptyResource(self, file_name: str):
        """
        [For now] we don't allow to create files right under workspaces.
        Though if we come to allow it, deleting the error's raise will make it possible.
        """
        # TODO : remove commentary here raise DAVError(HTTP_FORBIDDEN)
        if "/.deleted/" in self.path or "/.archived/" in self.path:
            raise DAVError(HTTP_FORBIDDEN)

        content = None

        # Note: To prevent bugs, check here again if resource already exist
        # fixed path
        fixed_file_name = webdav_convert_file_name_to_display(file_name)
        path = os.path.join(self.path, file_name)
        resource = self.provider.getResourceInst(path, self.environ)
        if resource:
            content = resource.content
        try:
            self.content_api.check_upload_size(
                int(self.environ["CONTENT_LENGTH"]), self.workspace)
        except (
                FileSizeOverMaxLimitation,
                FileSizeOverWorkspaceEmptySpace,
                FileSizeOverOwnerEmptySpace,
        ) as exc:
            raise DAVError(HTTP_REQUEST_ENTITY_TOO_LARGE, contextinfo=str(exc))
        # return item
        return FakeFileStream(
            session=self.session,
            file_name=fixed_file_name,
            content_api=self.content_api,
            workspace=self.workspace,
            content=content,
            parent=self.content,
            path=self.path + "/" + fixed_file_name,
        )
コード例 #28
0
    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
コード例 #29
0
    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)
コード例 #30
0
ファイル: resources.py プロジェクト: tracim/tracim
 def getDisplayName(self) -> str:
     return webdav_convert_file_name_to_display(self.workspace.label)
コード例 #31
0
ファイル: resources.py プロジェクト: tracim/tracim
    def getMember(self, content_label: str) -> _DAVResource:

        return self.provider.getResourceInst(
            '%s/%s' % (self.path, webdav_convert_file_name_to_display(content_label)),
            self.environ
        )
コード例 #32
0
    def getMember(self, content_label: str) -> _DAVResource:

        return self.provider.getResourceInst(
            "%s/%s" %
            (self.path, webdav_convert_file_name_to_display(content_label)),
            self.environ)
コード例 #33
0
ファイル: resources.py プロジェクト: tracim/tracim
 def getDisplayName(self) -> str:
     return webdav_convert_file_name_to_display(self.content.file_name)
コード例 #34
0
ファイル: resources.py プロジェクト: inkhey/tracim
 def getDisplayName(self) -> str:
     return webdav_convert_file_name_to_display(self.content.file_name)
コード例 #35
0
 def getDisplayName(self) -> str:
     return webdav_convert_file_name_to_display(self.workspace.label)