Projet

Général

Profil

0001-api-extend-api-users-value-to-also-look-within-name-.patch

Frédéric Péters, 16 novembre 2015 15:10

Télécharger (2,41 ko)

Voir les différences:

Subject: [PATCH] api: extend /api/users/{value}/ to also look within name
 identifiers (#8994)

 tests/test_api.py |  8 ++++++++
 wcs/api.py        | 12 +++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)
tests/test_api.py
506 506
    assert [x.get('id') for x in resp.json['roles']['concerned']] == [str(role.id), str(another_role.id)]
507 507
    assert [x.get('id') for x in resp.json['roles']['actions']] == [str(role.id)]
508 508

  
509
def test_user_by_nameid(pub, local_user):
510
    resp = get_app(pub).get(sign_uri('/api/users/xyz/', user=local_user),
511
            status=404)
512
    local_user.name_identifiers = ['xyz']
513
    local_user.store()
514
    resp = get_app(pub).get(sign_uri('/api/users/xyz/', user=local_user))
515
    assert str(resp.json['id']) == str(local_user.id)
516

  
509 517
def test_user_forms(pub, local_user):
510 518
    FormDef.wipe()
511 519
    formdef = FormDef()
wcs/api.py
412 412
            raise AccessForbiddenError('no user specified')
413 413
        user_info = user.get_substitution_variables(prefix='')
414 414
        del user_info['user']
415
        user_info['id'] = user.id
415 416
        user_info['user_roles'] = [
416 417
                Role.get(x).get_json_export_dict() for x in user.roles or []]
417 418
        return json.dumps(user_info)
......
537 538
        if not (is_url_signed() or (
538 539
                get_request().user and get_request().user.can_go_in_admin())):
539 540
            raise AccessForbiddenError()
540
        return ApiUserDirectory(get_publisher().user_class.get(component))
541
        user_class = get_publisher().user_class
542
        try:
543
            int(component) # makes sure this is an id
544
            user = user_class.get(component)
545
        except (KeyError, ValueError):
546
            try:
547
                user = user_class.get_users_with_name_identifier(component)[0]
548
            except IndexError:
549
                raise TraversalError()
550
        return ApiUserDirectory(user)
541 551

  
542 552

  
543 553
class ApiDirectory(Directory):
544
-