From 8cf9b1dae4811f0bad3551f1d2505ef6dedfa331 Mon Sep 17 00:00:00 2001 From: rr- Date: Mon, 28 Mar 2016 14:27:28 +0200 Subject: [PATCH] back/users: add user retrieval --- szurubooru/api/users.py | 12 +++++++----- szurubooru/app.py | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/szurubooru/api/users.py b/szurubooru/api/users.py index f05d083..ed13502 100644 --- a/szurubooru/api/users.py +++ b/szurubooru/api/users.py @@ -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} diff --git a/szurubooru/app.py b/szurubooru/app.py index 5b1c12b..c94aed1 100644 --- a/szurubooru/app.py +++ b/szurubooru/app.py @@ -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