Exemplo n.º 1
0
    def post(self, request):
        """
        restore deleted-repo
            return:
                return True if success, otherwise api_error
        """
        post_data = request.POST
        repo_id = post_data.get('repo_id', '')
        username = request.user.username
        if not repo_id:
            error_msg = "repo_id can not be empty."
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
        owner = seafile_api.get_trash_repo_owner(repo_id)
        if owner is None:
            error_msg = "Library does not exist in trash."
            return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
        if owner != username:
            return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied.')

        try:
            seafile_api.restore_repo_from_trash(repo_id)
        except SearpcError as e:
            logger.error(e)
            error_msg = "Internal Server Error"
            return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)

        return Response({"success": True})
Exemplo n.º 2
0
    def put(self, request, repo_id, format=None):
        """ restore a deleted library

        Permission checking:
        1. only admin can perform this action.
        """

        if not seafile_api.get_trash_repo_owner(repo_id):
            error_msg = "Library does not exist in trash."
            return api_error(status.HTTP_404_NOT_FOUND, error_msg)

        try:
            seafile_api.restore_repo_from_trash(repo_id)
        except SearpcError as e:
            logger.error(e)
            error_msg = 'Internal Server Error'
            return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)

        return Response({'success': True})
Exemplo n.º 3
0
    def put(self, request, repo_id, format=None):
        """ restore a deleted library

        Permission checking:
        1. only admin can perform this action.
        """

        if not seafile_api.get_trash_repo_owner(repo_id):
            error_msg = "Library does not exist in trash."
            return api_error(status.HTTP_404_NOT_FOUND, error_msg)

        try:
            seafile_api.restore_repo_from_trash(repo_id)
            repo_restored.send(sender=None, repo_id=repo_id, operator=request.user.username)
        except SearpcError as e:
            logger.error(e)
            error_msg = 'Internal Server Error'
            return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)

        return Response({'success': True})