Add filter for disabled users to superuser user list API
Fixes https://jira.coreos.com/browse/QS-102
This commit is contained in:
parent
1d3a93efcb
commit
8e473b9779
6 changed files with 44 additions and 19 deletions
|
@ -21,7 +21,7 @@ from data.database import ServiceKeyApprovalType
|
|||
from endpoints.api import (ApiResource, nickname, resource, validate_json_request,
|
||||
internal_only, require_scope, show_if, parse_args,
|
||||
query_param, abort, require_fresh_login, path_param, verify_not_prod,
|
||||
page_support, log_action, InvalidRequest, format_date)
|
||||
page_support, log_action, InvalidRequest, format_date, truthy_bool)
|
||||
from endpoints.api.build import get_logs_or_log_url
|
||||
from endpoints.api.superuser_models_pre_oci import (pre_oci_model, ServiceKeyDoesNotExist,
|
||||
ServiceKeyAlreadyApproved,
|
||||
|
@ -275,11 +275,14 @@ class SuperUserList(ApiResource):
|
|||
@require_fresh_login
|
||||
@verify_not_prod
|
||||
@nickname('listAllUsers')
|
||||
@parse_args()
|
||||
@query_param('disabled', 'If false, only enabled users will be returned.', type=truthy_bool,
|
||||
default=True)
|
||||
@require_scope(scopes.SUPERUSER)
|
||||
def get(self):
|
||||
def get(self, parsed_args):
|
||||
""" Returns a list of all users in the system. """
|
||||
if SuperUserPermission().can():
|
||||
users = pre_oci_model.get_active_users()
|
||||
users = pre_oci_model.get_active_users(disabled=parsed_args['disabled'])
|
||||
return {
|
||||
'users': [user.to_dict() for user in users]
|
||||
}
|
||||
|
|
|
@ -198,8 +198,8 @@ class PreOCIModel(SuperuserDataInterface):
|
|||
return return_user, confirmation.code
|
||||
return return_user, ''
|
||||
|
||||
def get_active_users(self):
|
||||
users = model.user.get_active_users()
|
||||
def get_active_users(self, disabled=True):
|
||||
users = model.user.get_active_users(disabled=disabled)
|
||||
return [_create_user(user) for user in users]
|
||||
|
||||
def get_organizations(self):
|
||||
|
|
19
endpoints/api/test/test_superuser.py
Normal file
19
endpoints/api/test/test_superuser.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
import pytest
|
||||
|
||||
from endpoints.api.superuser import SuperUserList
|
||||
from endpoints.api.test.shared import conduct_api_call
|
||||
from endpoints.test.shared import client_with_identity
|
||||
from test.fixtures import *
|
||||
|
||||
@pytest.mark.parametrize('disabled', [
|
||||
(True),
|
||||
(False),
|
||||
])
|
||||
def test_list_all_users(disabled, client):
|
||||
with client_with_identity('devtable', client) as cl:
|
||||
params = {'disabled': disabled}
|
||||
result = conduct_api_call(cl, SuperUserList, 'GET', params, None, 200).json
|
||||
assert len(result['users'])
|
||||
for user in result['users']:
|
||||
if not disabled:
|
||||
assert user['enabled']
|
Reference in a new issue