Skip to content

Commit

Permalink
Revert "Download rate limit (#6941)" (#7173)
Browse files Browse the repository at this point in the history
This reverts commit 7d36463.
  • Loading branch information
freeplant authored Dec 11, 2024
1 parent 7d36463 commit 4c231ea
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 35 deletions.
26 changes: 0 additions & 26 deletions seahub/api2/endpoints/internal_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
from seaserv import seafile_api
from seahub.utils.repo import parse_repo_perm
from seahub.views.file import send_file_access_msg
from seahub.utils.user_permissions import get_user_role
from seahub.role_permissions.settings import DEFAULT_ENABLED_ROLE_PERMISSIONS
from seahub.utils.file_size import get_quota_from_string

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -201,26 +198,3 @@ def post(self, request, repo_id):
return api_error(status.HTTP_403_FORBIDDEN, error_msg)

return Response({'user': rat.app_name})


class InternalDownloadRateLimitView(APIView):
authentication_classes = (SessionCRSFCheckFreeAuthentication, )

def post(self, request):
auth = request.META.get('HTTP_AUTHORIZATION', '').split()
is_valid = is_valid_internal_jwt(auth)
if not is_valid:
error_msg = 'Permission denied.'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)

traffic_info_dict = {}
for role, v in DEFAULT_ENABLED_ROLE_PERMISSIONS.items():
rate_limit = {}
if 'monthly_rate_limit' in v:
monthly_rate_limit = get_quota_from_string(v['monthly_rate_limit'])
rate_limit['monthly_rate_limit'] = monthly_rate_limit
if 'monthly_rate_limit_per_user' in v:
monthly_rate_limit_per_user = get_quota_from_string(v['monthly_rate_limit_per_user'])
rate_limit['monthly_rate_limit_per_user'] = monthly_rate_limit_per_user
traffic_info_dict[role] = rate_limit
return Response(traffic_info_dict)
4 changes: 0 additions & 4 deletions seahub/role_permissions/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ def merge_roles(default, custom):
'can_publish_repo': True,
'upload_rate_limit': 0,
'download_rate_limit': 0,
'monthly_rate_limit': '',
'monthly_rate_limit_per_user': ''
},
GUEST_USER: {
'can_add_repo': False,
Expand All @@ -70,8 +68,6 @@ def merge_roles(default, custom):
'can_publish_repo': False,
'upload_rate_limit': 0,
'download_rate_limit': 0,
'monthly_rate_limit': '',
'monthly_rate_limit_per_user': ''
},
}

Expand Down
3 changes: 1 addition & 2 deletions seahub/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from seahub.ai.apis import ImageCaption, GenerateSummary, ImageTags
from seahub.api2.endpoints.share_link_auth import ShareLinkUserAuthView, ShareLinkEmailAuthView
from seahub.api2.endpoints.internal_api import InternalUserListView, InternalCheckShareLinkAccess, \
InternalCheckFileOperationAccess, InternalDownloadRateLimitView
InternalCheckFileOperationAccess
from seahub.auth.views import multi_adfs_sso, login_simple_check
from seahub.views import *
from seahub.views.mobile import mobile_login
Expand Down Expand Up @@ -791,7 +791,6 @@
re_path(r'^api/v2.1/internal/user-list/$', InternalUserListView.as_view(), name="api-v2.1-internal-user-list"),
re_path(r'^api/v2.1/internal/check-share-link-access/$', InternalCheckShareLinkAccess.as_view(), name="api-v2.1-internal-share-link-info"),
re_path(r'^api/v2.1/internal/repos/(?P<repo_id>[-0-9a-f]{36})/check-access/$', InternalCheckFileOperationAccess.as_view(), name="api-v2.1-internal-check-file-op-access"),
re_path(r'^api/v2.1/internal/download-limit/$', InternalDownloadRateLimitView.as_view(), name='api-v2.1-internal-download-limit'),

### system admin ###
re_path(r'^sys/seafadmin/delete/(?P<repo_id>[-0-9a-f]{36})/$', sys_repo_delete, name='sys_repo_delete'),
Expand Down
2 changes: 0 additions & 2 deletions seahub/utils/file_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ def get_quota_from_string(quota_str):
quota = int(quota_str[:-1]) * get_file_size_unit('gb')
elif quota_str.endswith('m'):
quota = int(quota_str[:-1]) * get_file_size_unit('mb')
elif quota_str.endswith('k'):
quota = int(quota_str[:-1]) * get_file_size_unit('kb')
else:
return None

Expand Down
2 changes: 1 addition & 1 deletion tests/seahub/role_permissions/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ def test_get_available_role(self):
assert DEFAULT_USER in get_available_roles()

def test_get_enabled_role_permissions_by_role(self):
assert len(list(get_enabled_role_permissions_by_role(DEFAULT_USER).keys())) == 22
assert len(list(get_enabled_role_permissions_by_role(DEFAULT_USER).keys())) == 20

0 comments on commit 4c231ea

Please sign in to comment.