From 8f6a8008367c4fab853df0d03801cd349bbc2e6f Mon Sep 17 00:00:00 2001 From: jbe-dw <50663045+jbe-dw@users.noreply.github.com> Date: Sun, 24 Jan 2021 09:08:32 +0100 Subject: [PATCH] fix: account API output^ (#874) --- powerdnsadmin/routes/api.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/powerdnsadmin/routes/api.py b/powerdnsadmin/routes/api.py index 717408e..738c933 100644 --- a/powerdnsadmin/routes/api.py +++ b/powerdnsadmin/routes/api.py @@ -761,12 +761,20 @@ def api_list_accounts(account_name): Account.name == account_name).all() if not account_list: abort(404) - return jsonify(account_schema.dump(account_list)), 200 + if account_name is None: + return jsonify(account_schema.dump(account_list)), 200 + else: + return jsonify(account_schema.dump(account_list)[0]), 200 @api_bp.route('/pdnsadmin/accounts', methods=['POST']) @api_basic_auth def api_create_account(): + account_exists = [] or Account.query.filter(Account.name == account_name).all() + if len(account_exists) > 0: + msg = "Account name already exists" + current_app.logger.debug(msg) + raise AccountCreateFail(message=msg) if current_user.role.name not in ['Administrator', 'Operator']: msg = "{} role cannot create accounts".format(current_user.role.name) raise NotEnoughPrivileges(message=msg) @@ -795,7 +803,7 @@ def api_create_account(): history = History(msg='Create account {0}'.format(account.name), created_by=current_user.username) history.add() - return jsonify(account_schema.dump([account])), 201 + return jsonify(account_schema.dump([account])[0]), 201 @api_bp.route('/pdnsadmin/accounts/', methods=['PUT'])