fix: account API output^ (#874)

This commit is contained in:
jbe-dw 2021-01-24 09:08:32 +01:00 committed by GitHub
parent 3cd98251b3
commit 8f6a800836
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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/<int:account_id>', methods=['PUT'])