server/general: cosmetic changes
This commit is contained in:
parent
5053598a13
commit
2af8c9c1a4
4 changed files with 3 additions and 18 deletions
|
@ -30,14 +30,11 @@ def _serialize_user(authenticated_user, user):
|
|||
return ret
|
||||
|
||||
class UserListApi(BaseApi):
|
||||
''' API for lists of users. '''
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self._search_executor = search.SearchExecutor(search.UserSearchConfig())
|
||||
|
||||
def get(self, context):
|
||||
''' Retrieve a list of users. '''
|
||||
auth.verify_privilege(context.user, 'users:list')
|
||||
query = context.get_param_as_string('query')
|
||||
page = context.get_param_as_int('page', 1)
|
||||
|
@ -51,7 +48,6 @@ class UserListApi(BaseApi):
|
|||
}
|
||||
|
||||
def post(self, context):
|
||||
''' Create a new user. '''
|
||||
auth.verify_privilege(context.user, 'users:create')
|
||||
|
||||
try:
|
||||
|
@ -69,10 +65,7 @@ class UserListApi(BaseApi):
|
|||
return {'user': _serialize_user(context.user, user)}
|
||||
|
||||
class UserDetailApi(BaseApi):
|
||||
''' API for individual users. '''
|
||||
|
||||
def get(self, context, user_name):
|
||||
''' Retrieve an user. '''
|
||||
auth.verify_privilege(context.user, 'users:view')
|
||||
user = users.get_by_name(context.session, user_name)
|
||||
if not user:
|
||||
|
@ -80,7 +73,6 @@ class UserDetailApi(BaseApi):
|
|||
return {'user': _serialize_user(context.user, user)}
|
||||
|
||||
def put(self, context, user_name):
|
||||
''' Update an existing user. '''
|
||||
user = users.get_by_name(context.session, user_name)
|
||||
if not user:
|
||||
raise errors.NotFoundError('User %r not found.' % user_name)
|
||||
|
@ -120,7 +112,6 @@ class UserDetailApi(BaseApi):
|
|||
return {'user': _serialize_user(context.user, user)}
|
||||
|
||||
def delete(self, context, user_name):
|
||||
''' Delete an existing user. '''
|
||||
user = users.get_by_name(context.session, user_name)
|
||||
if not user:
|
||||
raise errors.NotFoundError('User %r not found.' % user_name)
|
||||
|
|
|
@ -1,4 +1,2 @@
|
|||
''' Base model for every database resource. '''
|
||||
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
Base = declarative_base() # pylint: disable=invalid-name
|
||||
|
|
|
@ -3,7 +3,7 @@ import datetime
|
|||
import json
|
||||
import falcon
|
||||
|
||||
def json_serial(obj):
|
||||
def json_serializer(obj):
|
||||
''' JSON serializer for objects not serializable by default JSON code '''
|
||||
if isinstance(obj, datetime.datetime):
|
||||
serial = obj.isoformat()
|
||||
|
@ -52,4 +52,4 @@ class JsonTranslator(object):
|
|||
if 'result' not in request.context:
|
||||
return
|
||||
response.body = json.dumps(
|
||||
request.context.result, default=json_serial, indent=2)
|
||||
request.context.result, default=json_serializer, indent=2)
|
||||
|
|
|
@ -20,7 +20,6 @@ def get_legacy_password_hash(salt, password):
|
|||
return digest.hexdigest()
|
||||
|
||||
def create_password():
|
||||
''' Create an easy-to-remember password. '''
|
||||
alphabet = {
|
||||
'c': list('bcdfghijklmnpqrstvwxyz'),
|
||||
'v': list('aeiou'),
|
||||
|
@ -30,7 +29,6 @@ def create_password():
|
|||
return ''.join(random.choice(alphabet[l]) for l in list(pattern))
|
||||
|
||||
def is_valid_password(user, password):
|
||||
''' Return whether the given password for a given user is valid. '''
|
||||
salt, valid_hash = user.password_salt, user.password_hash
|
||||
possible_hashes = [
|
||||
get_password_hash(salt, password),
|
||||
|
@ -39,9 +37,7 @@ def is_valid_password(user, password):
|
|||
return valid_hash in possible_hashes
|
||||
|
||||
def verify_privilege(user, privilege_name):
|
||||
'''
|
||||
Throw an AuthError if the given user doesn't have given privilege.
|
||||
'''
|
||||
''' Throw an AuthError if the given user doesn't have given privilege. '''
|
||||
all_ranks = config.config['ranks']
|
||||
|
||||
assert privilege_name in config.config['privileges']
|
||||
|
|
Loading…
Reference in a new issue