Ejemplo n.º 1
0
 def sized_preview_jpg_revision(self,
                                context,
                                request: TracimRequest,
                                hapic_data=None):  # nopep8
     """
     Obtain resized jpg preview of a specific revision of content.
     """
     app_config = request.registry.settings['CFG']
     api = ContentApi(
         current_user=request.current_user,
         session=request.dbsession,
         config=app_config,
     )
     content = api.get_one(hapic_data.path.content_id,
                           content_type=ContentType.Any)
     revision = api.get_one_revision(
         revision_id=hapic_data.path.revision_id, content=content)
     jpg_preview_path = api.get_jpg_preview_path(
         content_id=content.content_id,
         revision_id=revision.revision_id,
         page=hapic_data.query.page,
         height=hapic_data.path.height,
         width=hapic_data.path.width,
     )
     return FileResponse(jpg_preview_path)
Ejemplo n.º 2
0
    def exists(self, path, environ) -> bool:
        """
        Called by wsgidav to check if a certain path is linked to a _DAVResource
        """

        path = normpath(path)
        working_path = self.reduce_path(path)
        root_path = environ['http_authenticator.realm']
        parent_path = dirname(working_path)
        user = environ['tracim_user']
        session = environ['tracim_dbsession']
        if path == root_path:
            return True

        workspace = self.get_workspace_from_path(
            path,
            WorkspaceApi(
                current_user=user,
                session=session,
                config=self.app_config,
            )
        )

        if parent_path == root_path or workspace is None:
            return workspace is not None

        # TODO bastien: Arnaud avait mis a True, verif le comportement
        # lorsque l'on explore les dossiers archive et deleted
        content_api = ContentApi(
            current_user=user,
            session=session,
            config=self.app_config,
            show_archived=False,
            show_deleted=False
        )

        revision_id = re.search(r'/\.history/[^/]+/\((\d+) - [a-zA-Z]+\) ([^/].+)$', path)

        is_archived = self.is_path_archive(path)

        is_deleted = self.is_path_delete(path)

        if revision_id:
            revision_id = revision_id.group(1)
            content = content_api.get_one_revision(revision_id)
        else:
            content = self.get_content_from_path(working_path, content_api, workspace)

        return content is not None \
            and content.is_deleted == is_deleted \
            and content.is_archived == is_archived
Ejemplo n.º 3
0
 def preview_pdf_revision(self,
                          context,
                          request: TracimRequest,
                          hapic_data=None):  # nopep8
     """
     Obtain a specific page pdf preview of a specific revision of content.
     """
     app_config = request.registry.settings['CFG']
     api = ContentApi(
         current_user=request.current_user,
         session=request.dbsession,
         config=app_config,
     )
     content = api.get_one(hapic_data.path.content_id,
                           content_type=ContentType.Any)
     revision = api.get_one_revision(
         revision_id=hapic_data.path.revision_id, content=content)
     pdf_preview_path = api.get_pdf_preview_path(revision.content_id,
                                                 revision.revision_id,
                                                 page=hapic_data.query.page)
     return FileResponse(pdf_preview_path)
Ejemplo n.º 4
0
 def download_revisions_file(self,
                             context,
                             request: TracimRequest,
                             hapic_data=None):  # nopep8
     """
     Download raw file for specific revision of content.
     """
     app_config = request.registry.settings['CFG']
     api = ContentApi(
         current_user=request.current_user,
         session=request.dbsession,
         config=app_config,
     )
     content = api.get_one(hapic_data.path.content_id,
                           content_type=ContentType.Any)
     revision = api.get_one_revision(
         revision_id=hapic_data.path.revision_id, content=content)
     file = DepotManager.get().get(revision.depot_file)
     response = request.response
     response.content_type = file.content_type
     response.app_iter = FileIter(file)
     return response
Ejemplo n.º 5
0
    def getResourceInst(self, path: str, environ: dict):
        """
        Called by wsgidav whenever a request is called to get the _DAVResource corresponding to the path
        """
        user = environ['tracim_user']
        session = environ['tracim_dbsession']
        if not self.exists(path, environ):
            return None
        path = normpath(path)
        root_path = environ['http_authenticator.realm']

        # If the requested path is the root, then we return a RootResource resource
        if path == root_path:
            return resources.RootResource(
                path=path,
                environ=environ,
                user=user,
                session=session
            )

        workspace_api = WorkspaceApi(
            current_user=user,
            session=session,
            config=self.app_config,
        )
        workspace = self.get_workspace_from_path(path, workspace_api)

        # If the request path is in the form root/name, then we return a WorkspaceResource resource
        parent_path = dirname(path)
        if parent_path == root_path:
            if not workspace:
                return None
            return resources.WorkspaceResource(
                path=path,
                environ=environ,
                workspace=workspace,
                user=user,
                session=session,
            )

        # And now we'll work on the path to establish which type or resource is requested

        content_api = ContentApi(
            current_user=user,
            session=session,
            config=self.app_config,
            show_archived=False,  # self._show_archive,
            show_deleted=False,  # self._show_delete
        )

        content = self.get_content_from_path(
            path=path,
            content_api=content_api,
            workspace=workspace
        )


        # Easy cases : path either end with /.deleted, /.archived or /.history, then we return corresponding resources
        if path.endswith(SpecialFolderExtension.Archived) and self._show_archive:
            return resources.ArchivedFolderResource(
                path=path,
                environ=environ,
                workspace=workspace,
                user=user,
                content=content,
                session=session,
            )

        if path.endswith(SpecialFolderExtension.Deleted) and self._show_delete:
            return resources.DeletedFolderResource(
                path=path,
                environ=environ,
                workspace=workspace,
                user=user,
                content=content,
                session=session,
            )

        if path.endswith(SpecialFolderExtension.History) and self._show_history:
            is_deleted_folder = re.search(r'/\.deleted/\.history$', path) is not None
            is_archived_folder = re.search(r'/\.archived/\.history$', path) is not None

            type = HistoryType.Deleted if is_deleted_folder \
                else HistoryType.Archived if is_archived_folder \
                else HistoryType.Standard

            return resources.HistoryFolderResource(
                path=path,
                environ=environ,
                workspace=workspace,
                user=user,
                content=content,
                session=session,
                type=type
            )

        # Now that's more complicated, we're trying to find out if the path end with /.history/file_name
        is_history_file_folder = re.search(r'/\.history/([^/]+)$', path) is not None

        if is_history_file_folder and self._show_history:
            return resources.HistoryFileFolderResource(
                path=path,
                environ=environ,
                user=user,
                content=content,
                session=session,
            )
        # And here next step :
        is_history_file = re.search(r'/\.history/[^/]+/\((\d+) - [a-zA-Z]+\) .+', path) is not None

        if self._show_history and is_history_file:

            revision_id = re.search(r'/\.history/[^/]+/\((\d+) - [a-zA-Z]+\) ([^/].+)$', path).group(1)

            content_revision = content_api.get_one_revision(revision_id)
            content = self.get_content_from_revision(content_revision, content_api)

            if content.type == ContentType.File:
                return resources.HistoryFileResource(
                    path=path,
                    environ=environ,
                    user=user,
                    content=content,
                    content_revision=content_revision,
                    session=session,
                )
            else:
                return resources.HistoryOtherFile(
                    path=path,
                    environ=environ,
                    user=user,
                    content=content,
                    content_revision=content_revision,
                    session=session,
                )

        # And if we're still going, the client is asking for a standard Folder/File/Page/Thread so we check the type7
        # and return the corresponding resource

        if content is None:
            return None
        if content.type == ContentType.Folder:
            return resources.FolderResource(
                path=path,
                environ=environ,
                workspace=content.workspace,
                content=content,
                session=session,
                user=user,
            )
        elif content.type == ContentType.File:
            return resources.FileResource(
                path=path,
                environ=environ,
                content=content,
                session=session,
                user=user
            )
        else:
            return resources.OtherFileResource(
                path=path,
                environ=environ,
                content=content,
                session=session,
                user=user,
            )