def check_repo_owner_quota(self, isnewfile=True, contentlength=-1):
        """Check if the upload would cause the user quota be exceeded

        `contentlength` is only positive when the client does not use "transfer-encode: chunking"

        Return True if the quota would not be exceeded, otherwise return False.
        """
        # if contentlength <= 0:
        #     # When client use "transfer-encode: chunking", the content length
        #     # is not included in the request headers
        #     if isnewfile:
        #         return check_repo_quota(self.repo.id) >= 0
        #     else:
        #         return True

        # if not self.owner:
        #     self.owner = seafile_api.get_repo_owner(self.repo.id)
        # quota = seafile_api.get_user_quota(self.owner)
        # if quota == INFINITE_QUOTA:
        #     return True
        # self_usage = seafile_api.get_user_self_usage(self.owner)
        # share_usage = seafile_api.get_user_share_usage(self.owner) if CALC_SHARE_USAGE else 0

        # remain = quota - self_usage - share_usage
        # if not isnewfile:
        #     remain -= self.obj.size

        # return contentlength <= remain
        return check_repo_quota(self.repo.id) >= 0
Beispiel #2
0
    def check_repo_owner_quota(self, isnewfile=True, contentlength=-1):
        """Check if the upload would cause the user quota be exceeded

        `contentlength` is only positive when the client does not use "transfer-encode: chunking"

        Return True if the quota would not be exceeded, otherwise return False.
        """
        # if contentlength <= 0:
        #     # When client use "transfer-encode: chunking", the content length
        #     # is not included in the request headers
        #     if isnewfile:
        #         return check_repo_quota(self.repo.id) >= 0
        #     else:
        #         return True

        # if not self.owner:
        #     self.owner = seafile_api.get_repo_owner(self.repo.id)
        # quota = seafile_api.get_user_quota(self.owner)
        # if quota == INFINITE_QUOTA:
        #     return True
        # self_usage = seafile_api.get_user_self_usage(self.owner)
        # share_usage = seafile_api.get_user_share_usage(self.owner) if CALC_SHARE_USAGE else 0

        # remain = quota - self_usage - share_usage
        # if not isnewfile:
        #     remain -= self.obj.size

        # return contentlength <= remain
        return check_repo_quota(self.repo.id) >= 0
Beispiel #3
0
    def check_repo_owner_quota(self, isnewfile=True, contentlength=-1):
        """Check if the upload would cause the user quota be exceeded

        `contentlength` is only positive when the client does not use "transfer-encode: chunking"

        Return True if the quota would not be exceeded, otherwise return False.
        """
        if contentlength <= 0:
            # When client use "transfer-encode: chunking", the content length
            # is not included in the request headers
            if isnewfile:
                return check_repo_quota(self.repo.id) >= 0
            else:
                return True
        else:
            delta = contentlength - self.obj.size
            return check_repo_quota(self.repo.id, delta) >= 0
Beispiel #4
0
    def check_repo_owner_quota(self, isnewfile=True, contentlength=-1):
        """Check if the upload would cause the user quota be exceeded

        `contentlength` is only positive when the client does not use "transfer-encode: chunking"

        Return True if the quota would not be exceeded, otherwise return False.
        """
        if contentlength <= 0:
            # When client use "transfer-encode: chunking", the content length
            # is not included in the request headers
            if isnewfile:
                return check_repo_quota(self.repo.id) >= 0
            else:
                return True
        else:
            delta = contentlength - self.obj.size
            return check_repo_quota(self.repo.id, delta) >= 0
    def createEmptyResource(self, name):
        """Create an empty (length-0) resource.

        See DAVResource.createEmptyResource()
        """
        assert not "/" in name
        if self.provider.readonly:
            raise DAVError(HTTP_FORBIDDEN)

        if seafile_api.check_permission_by_path(self.repo.id, self.rel_path, self.username) != "rw":
            raise DAVError(HTTP_FORBIDDEN)

        if check_repo_quota(self.repo.id) < 0:
            raise DAVError(HTTP_FORBIDDEN, "The quota of the repo owner is exceeded")

        try:
            seafile_api.post_empty_file(self.repo.id, self.rel_path, name, self.username)
        except SearpcError, e:
            if e.msg == 'Invalid file name':
                raise DAVError(HTTP_BAD_REQUEST)
            raise
Beispiel #6
0
    def createEmptyResource(self, name):
        """Create an empty (length-0) resource.

        See DAVResource.createEmptyResource()
        """
        assert not "/" in name
        if self.provider.readonly:
            raise DAVError(HTTP_FORBIDDEN)

        if seafile_api.check_permission_by_path(self.repo.id, self.rel_path,
                                                self.username) != "rw":
            raise DAVError(HTTP_FORBIDDEN)

        if check_repo_quota(self.repo.id) < 0:
            raise DAVError(HTTP_FORBIDDEN,
                           "The quota of the repo owner is exceeded")

        try:
            seafile_api.post_empty_file(self.repo.id, self.rel_path, name,
                                        self.username)
        except SearpcError, e:
            if e.msg == 'Invalid file name':
                raise DAVError(HTTP_BAD_REQUEST)
            raise