From 49284379910248160fd3c9e4d42642f3093e2739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=B0=B8=E5=BC=BA?= <11704063+s-yongqiang@user.noreply.gitee.com> Date: Mon, 4 Nov 2024 11:40:39 +0800 Subject: [PATCH] update --- seahub/api2/endpoints/admin/group_members.py | 7 +----- seahub/api2/endpoints/draft_reviewer.py | 2 +- seahub/api2/endpoints/file_comment.py | 5 ++--- seahub/api2/endpoints/file_comments.py | 2 +- seahub/api2/utils.py | 4 ++-- seahub/api2/views.py | 4 ++-- seahub/drafts/views.py | 2 +- .../management/commands/send_file_updates.py | 8 +++---- .../management/commands/send_notices.py | 8 +++---- seahub/seadoc/apis.py | 22 +++++++++---------- tests/api/endpoints/test_user_avatar.py | 8 +++---- 11 files changed, 33 insertions(+), 39 deletions(-) diff --git a/seahub/api2/endpoints/admin/group_members.py b/seahub/api2/endpoints/admin/group_members.py index 8887a9aa57e..6753f30991a 100644 --- a/seahub/api2/endpoints/admin/group_members.py +++ b/seahub/api2/endpoints/admin/group_members.py @@ -44,11 +44,6 @@ def get(self, request, group_id, format=None): error_msg = 'Group %d not found.' % group_id return api_error(status.HTTP_404_NOT_FOUND, error_msg) - try: - avatar_size = int(request.GET.get('avatar_size', AVATAR_DEFAULT_SIZE)) - except ValueError: - avatar_size = AVATAR_DEFAULT_SIZE - try: page = int(request.GET.get('page', '1')) per_page = int(request.GET.get('per_page', '100')) @@ -74,7 +69,7 @@ def get(self, request, group_id, format=None): group_members_info = [] for m in members: - member_info = get_group_member_info(request, group_id, m.user_name, avatar_size) + member_info = get_group_member_info(request, group_id, m.user_name) group_members_info.append(member_info) group_members = { diff --git a/seahub/api2/endpoints/draft_reviewer.py b/seahub/api2/endpoints/draft_reviewer.py index 44ca50e0052..b581aeac93c 100644 --- a/seahub/api2/endpoints/draft_reviewer.py +++ b/seahub/api2/endpoints/draft_reviewer.py @@ -44,7 +44,7 @@ def get(self, request, pk, format=None): # get reviewer list reviewers = [] for x in d.draftreviewer_set.all(): - reviewer = user_to_dict(x.reviewer, request=request, avatar_size=avatar_size) + reviewer = user_to_dict(x.reviewer, request=request) reviewers.append(reviewer) return Response({'reviewers': reviewers}) diff --git a/seahub/api2/endpoints/file_comment.py b/seahub/api2/endpoints/file_comment.py index 3aada19b429..ab0cb6aaba3 100644 --- a/seahub/api2/endpoints/file_comment.py +++ b/seahub/api2/endpoints/file_comment.py @@ -47,8 +47,7 @@ def get(self, request, repo_id, comment_id, format=None): avatar_size = AVATAR_DEFAULT_SIZE comment = file_comment.to_dict() - comment.update(user_to_dict(file_comment.author, request=request, - avatar_size=avatar_size)) + comment.update(user_to_dict(file_comment.author, request=request)) return Response(comment) @@ -137,6 +136,6 @@ def put(self, request, repo_id, comment_id, format=None): avatar_size = AVATAR_DEFAULT_SIZE comment = file_comment.to_dict() - comment.update(user_to_dict(file_comment.author, request=request, avatar_size=avatar_size)) + comment.update(user_to_dict(file_comment.author, request=request)) return Response(comment) diff --git a/seahub/api2/endpoints/file_comments.py b/seahub/api2/endpoints/file_comments.py index f6dc8d02e7f..e2d8416f39e 100644 --- a/seahub/api2/endpoints/file_comments.py +++ b/seahub/api2/endpoints/file_comments.py @@ -138,5 +138,5 @@ def post(self, request, repo_id, format=None): author=username) comment = file_comment.to_dict() - comment.update(user_to_dict(username, request=request, avatar_size=avatar_size)) + comment.update(user_to_dict(username, request=request)) return Response(comment, status=201) diff --git a/seahub/api2/utils.py b/seahub/api2/utils.py index eaa269373d9..13619e23d19 100644 --- a/seahub/api2/utils.py +++ b/seahub/api2/utils.py @@ -274,8 +274,8 @@ def get_user_common_info(email): "avatar_url": avatar_url } -def user_to_dict(email, request=None, avatar_size=AVATAR_DEFAULT_SIZE): - d = get_user_common_info(email, avatar_size) +def user_to_dict(email, request=None): + d = get_user_common_info(email) return { 'user_name': d['name'], 'user_email': d['email'], diff --git a/seahub/api2/views.py b/seahub/api2/views.py index cd2147e5c87..8fb54b6aff0 100644 --- a/seahub/api2/views.py +++ b/seahub/api2/views.py @@ -5058,8 +5058,8 @@ class UserAvatarView(APIView): permission_classes = (IsAuthenticated,) throttle_classes = (UserRateThrottle, ) - def get(self, request, user, format=None): - url, is_default, date_uploaded = api_avatar_url(user) + def get(self, request, user, size, format=None): + url, is_default, date_uploaded = api_avatar_url(user, int(size)) ret = { "url": url, "is_default": is_default, diff --git a/seahub/drafts/views.py b/seahub/drafts/views.py index 85b06fe1f5b..000fbe70c7d 100644 --- a/seahub/drafts/views.py +++ b/seahub/drafts/views.py @@ -43,7 +43,7 @@ def draft(request, pk): draft_file_name = os.path.basename(d.draft_file_path) - author_info = user_to_dict(d.username, avatar_size=32) + author_info = user_to_dict(d.username) return render(request, "draft.html", { "draft_id": d.id, diff --git a/seahub/notifications/management/commands/send_file_updates.py b/seahub/notifications/management/commands/send_file_updates.py index 27a0622b452..f821cf4d90c 100644 --- a/seahub/notifications/management/commands/send_file_updates.py +++ b/seahub/notifications/management/commands/send_file_updates.py @@ -71,14 +71,14 @@ def handle(self, *args, **options): logger.debug('Finish sending file updates emails.\n') self.stdout.write('[%s] Finish sending file updates emails.\n\n' % str(datetime.now())) - def get_avatar(self, username, default_size=32): - img_tag = avatar(username, default_size) + def get_avatar(self, username): + img_tag = avatar(username, 128) pattern = r'src="(.*)"' repl = r'src="%s\1"' % get_site_scheme_and_netloc() return re.sub(pattern, repl, img_tag) - def get_avatar_src(self, username, default_size=32): - avatar_img = self.get_avatar(username, default_size) + def get_avatar_src(self, username): + avatar_img = self.get_avatar(username) m = re.search('