Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
孙永强 committed Nov 6, 2024
1 parent d973cc4 commit 4928437
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 39 deletions.
7 changes: 1 addition & 6 deletions seahub/api2/endpoints/admin/group_members.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion seahub/api2/endpoints/draft_reviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
5 changes: 2 additions & 3 deletions seahub/api2/endpoints/file_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion seahub/api2/endpoints/file_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions seahub/api2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
4 changes: 2 additions & 2 deletions seahub/api2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion seahub/drafts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions seahub/notifications/management/commands/send_file_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('<img src="(.*?)".*', avatar_img)
if m:
return m.group(1)
Expand Down
8 changes: 4 additions & 4 deletions seahub/notifications/management/commands/send_notices.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ def handle(self, *args, **options):
self.do_action()
logger.debug('Finish sending user notices.\n')

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('<img src="(.*?)".*', avatar_img)
if m:
return m.group(1)
Expand Down
22 changes: 11 additions & 11 deletions seahub/seadoc/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ def get(self, request, file_uuid):
for notification in notifications_query:
data = notification.to_dict()
data.update(
user_to_dict(notification.username, request=request, avatar_size=avatar_size))
user_to_dict(notification.username, request=request))
notifications.append(data)

result = {'notifications': notifications}
Expand Down Expand Up @@ -983,7 +983,7 @@ def get(self, request, file_uuid):

for file_comment in file_comments:
comment = file_comment.to_dict(reply_queryset)
comment.update(user_to_dict(file_comment.author, request=request, avatar_size=avatar_size))
comment.update(user_to_dict(file_comment.author, request=request))
comments.append(comment)

result = {'comments': comments, 'total_count': total_count}
Expand Down Expand Up @@ -1016,7 +1016,7 @@ def post(self, request, file_uuid):
file_comment = FileComment.objects.add_by_file_uuid(
file_uuid, username, comment, detail)
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))

# notification
to_users = set()
Expand All @@ -1033,7 +1033,7 @@ def post(self, request, file_uuid):
'created_at': datetime_to_isoformat_timestr(file_comment.created_at),
'updated_at': datetime_to_isoformat_timestr(file_comment.updated_at),
}
detail.update(user_to_dict(username, request=request, avatar_size=avatar_size))
detail.update(user_to_dict(username, request=request))

new_notifications = []
for to_user in to_users:
Expand Down Expand Up @@ -1084,7 +1084,7 @@ def get(self, request, file_uuid, comment_id):

comment = file_comment.to_dict()
comment.update(user_to_dict(
file_comment.author, request=request, avatar_size=avatar_size))
file_comment.author, request=request))
return Response(comment)

def delete(self, request, file_uuid, comment_id):
Expand Down Expand Up @@ -1153,7 +1153,7 @@ def put(self, request, file_uuid, comment_id):
file_comment.save()

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)


Expand Down Expand Up @@ -1198,7 +1198,7 @@ def get(self, request, file_uuid, comment_id):
for reply in reply_queryset:
data = reply.to_dict()
data.update(
user_to_dict(reply.author, request=request, avatar_size=avatar_size))
user_to_dict(reply.author, request=request))
replies.append(data)

result = {'replies': replies, 'total_count': total_count}
Expand Down Expand Up @@ -1242,7 +1242,7 @@ def post(self, request, file_uuid, comment_id):
)
data = reply.to_dict()
data.update(
user_to_dict(reply.author, request=request, avatar_size=avatar_size))
user_to_dict(reply.author, request=request))

# notification
to_users = set()
Expand All @@ -1260,7 +1260,7 @@ def post(self, request, file_uuid, comment_id):
'created_at': datetime_to_isoformat_timestr(reply.created_at),
'updated_at': datetime_to_isoformat_timestr(reply.updated_at),
}
detail.update(user_to_dict(username, request=request, avatar_size=avatar_size))
detail.update(user_to_dict(username, request=request))

new_notifications = []
for to_user in to_users:
Expand Down Expand Up @@ -1314,7 +1314,7 @@ def get(self, request, file_uuid, comment_id, reply_id):

data = reply.to_dict()
data.update(
user_to_dict(reply.author, request=request, avatar_size=avatar_size))
user_to_dict(reply.author, request=request))
return Response(data)

def delete(self, request, file_uuid, comment_id, reply_id):
Expand Down Expand Up @@ -1373,7 +1373,7 @@ def put(self, request, file_uuid, comment_id, reply_id):

data = reply.to_dict()
data.update(
user_to_dict(reply.author, request=request, avatar_size=avatar_size))
user_to_dict(reply.author, request=request))
return Response(data)


Expand Down
8 changes: 4 additions & 4 deletions tests/api/endpoints/test_user_avatar.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def test_create_user_avatar(self):
avatar_url = urljoin(BASE_URL, avatar_url)
avatar_file = os.path.join(os.getcwd(), 'media/img/seafile-logo.png')

random_avatar_size = random.randint(12, 128)
random_avatar_size = 256

with open(avatar_file, 'rb') as f:
json_resp = self.post(avatar_url, files={'avatar': f}, data={'avatar_size': random_avatar_size}).json()
json_resp = self.post(avatar_url, files={'avatar': f}, data={'avatar_size': 256}).json()

assert 'avatar_url' in json_resp
response_url = json_resp['avatar_url']
Expand All @@ -28,5 +28,5 @@ def test_create_user_avatar(self):
# assert is NOT default avatar
avatar_url = urljoin(AVATAR_BASE_URL, 'user', self.username, '/resized/80/')
info = self.get(avatar_url).json()
assert 'resized' in info['url']
assert info['is_default'] == False
assert 'resized' not in info['url']
assert info['is_default'] == True

0 comments on commit 4928437

Please sign in to comment.