back/users: add user retrieval

This commit is contained in:
rr- 2016-03-28 14:27:28 +02:00
parent ff0fe077d4
commit 8cf9b1dae4
2 changed files with 9 additions and 7 deletions

View file

@ -57,16 +57,18 @@ class UserListApi(object):
class UserDetailApi(object):
''' API for individual users. '''
def __init__(self, config, auth_service):
def __init__(self, config, auth_service, user_service):
self._config = config
self._auth_service = auth_service
self._user_service = user_service
def on_get(self, request, response, user_id):
def on_get(self, request, response, user_name):
''' Retrieves an user. '''
self._auth_service.verify_privilege(request.context['user'], 'users:view')
request.context['result'] = {'message': 'Getting user ' + user_id}
user = self._user_service.get_by_name(user_name)
request.context['result'] = _serialize_user(user)
def on_put(self, request, response, user_id):
def on_put(self, request, response, user_name):
''' Updates an existing user. '''
self._auth_service.verify_privilege(request.context['user'], 'users:edit')
request.context['result'] = {'message': 'Updating user ' + user_id}
request.context['result'] = {'message': 'Updating user ' + user_name}

View file

@ -41,7 +41,7 @@ def create_app():
config, user_service, password_service)
user_list = szurubooru.api.UserListApi(config, auth_service, user_service)
user = szurubooru.api.UserDetailApi(config, auth_service)
user = szurubooru.api.UserDetailApi(config, auth_service, user_service)
app = falcon.API(middleware=[
szurubooru.middleware.RequireJson(),
@ -53,6 +53,6 @@ def create_app():
app.add_error_handler(szurubooru.services.IntegrityError, _on_integrity_error)
app.add_route('/users/', user_list)
app.add_route('/user/{user_id}', user)
app.add_route('/user/{user_name}', user)
return app