mirror of
https://github.com/rr-/szurubooru.git
synced 2025-07-17 08:26:24 +00:00
client/users: add user view prototype
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
from szurubooru import errors, search
|
||||
import hashlib
|
||||
from szurubooru import config, errors, search
|
||||
from szurubooru.util import auth, users
|
||||
from szurubooru.api.base_api import BaseApi
|
||||
|
||||
@ -7,12 +8,23 @@ def _serialize_user(authenticated_user, user):
|
||||
'id': user.user_id,
|
||||
'name': user.name,
|
||||
'rank': user.rank,
|
||||
'rankName': config.config['rank_names'].get(user.rank, 'Unknown'),
|
||||
'creationTime': user.creation_time,
|
||||
'lastLoginTime': user.last_login_time,
|
||||
'avatarStyle': user.avatar_style
|
||||
}
|
||||
|
||||
if user.avatar_style == user.AVATAR_GRAVATAR:
|
||||
md5 = hashlib.md5()
|
||||
md5.update((user.email or user.name).lower().encode('utf-8'))
|
||||
digest = md5.hexdigest()
|
||||
ret['avatarUrl'] = 'http://gravatar.com/avatar/%s?s=%d' % (
|
||||
digest, config.config['avatar_thumbnail_size'])
|
||||
# TODO: else construct a link
|
||||
|
||||
if authenticated_user.user_id == user.user_id:
|
||||
ret['email'] = user.email
|
||||
|
||||
return ret
|
||||
|
||||
class UserListApi(BaseApi):
|
||||
|
@ -13,7 +13,9 @@ class TestRetrievingUsers(DatabaseTestCase):
|
||||
'users:view': 'regular_user',
|
||||
'users:create': 'regular_user',
|
||||
},
|
||||
'avatar_thumbnail_size': 200,
|
||||
'ranks': ['anonymous', 'regular_user', 'mod', 'admin'],
|
||||
'rank_names': {},
|
||||
})
|
||||
util.mock_context(self)
|
||||
|
||||
@ -71,7 +73,9 @@ class TestCreatingUser(DatabaseTestCase):
|
||||
'user_name_regex': '.{3,}',
|
||||
'password_regex': '.{3,}',
|
||||
'default_rank': 'regular_user',
|
||||
'avatar_thumbnail_size': 200,
|
||||
'ranks': ['anonymous', 'regular_user', 'mod', 'admin'],
|
||||
'rank_names': {},
|
||||
'privileges': {
|
||||
'users:create': 'anonymous',
|
||||
},
|
||||
@ -130,7 +134,9 @@ class TestUpdatingUser(DatabaseTestCase):
|
||||
'secret': '',
|
||||
'user_name_regex': '.{3,}',
|
||||
'password_regex': '.{3,}',
|
||||
'avatar_thumbnail_size': 200,
|
||||
'ranks': ['anonymous', 'regular_user', 'mod', 'admin'],
|
||||
'rank_names': {},
|
||||
'privileges': {
|
||||
'users:edit:self:name': 'regular_user',
|
||||
'users:edit:self:pass': 'regular_user',
|
||||
|
Reference in New Issue
Block a user