Project

General

Profile

0001-WIP-include-roles-in-users-api-25645.patch

Paul Marillonnet, 30 Aug 2018 02:53 PM

Download (2.32 KB)

View differences:

Subject: [PATCH] WIP include roles in users api (#25645)

 src/authentic2/api_views.py | 6 +++++-
 tests/test_api.py           | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)
src/authentic2/api_views.py
322 322
                                     default=CreateOnlyDefault(utils.generate_password),
323 323
                                     required=False)
324 324
    force_password_reset = serializers.BooleanField(write_only=True, required=False, default=False)
325
    roles = serializers.SlugRelatedField(
326
        queryset=get_role_model().objects.all(), slug_field='slug',
327
        required=False, many=True)
325 328

  
326 329
    def __init__(self, *args, **kwargs):
327 330
        super(BaseUserSerializer, self).__init__(*args, **kwargs)
......
537 540

  
538 541

  
539 542
class UsersAPI(HookMixin, ExceptionHandlerMixin, ModelViewSet):
540
    ordering_fields = ['username', 'first_name', 'last_name', 'modified', 'date_joined']
543
    ordering_fields = ['username', 'first_name', 'last_name', 'modified',
544
        'date_joined', 'roles']
541 545
    lookup_field = 'uuid'
542 546
    serializer_class = BaseUserSerializer
543 547
    filter_class = UsersFilter
tests/test_api.py
231 231
    if api_user.is_superuser or api_user.roles.exists():
232 232
        assert set(['ou', 'id', 'uuid', 'is_staff', 'is_superuser', 'first_name', 'last_name',
233 233
                    'date_joined', 'last_login', 'username', 'password', 'email', 'is_active',
234
                    'title', 'modified', 'email_verified']) == set(resp.json.keys())
234
                    'title', 'modified', 'email_verified', 'roles']) == set(resp.json.keys())
235 235
        assert resp.json['first_name'] == payload['first_name']
236 236
        assert resp.json['last_name'] == payload['last_name']
237 237
        assert resp.json['email'] == payload['email']
238
-