Skip to content

Commit d9e401b

Browse files
committed
feat: TT-147 add endpoint to retrieve user
1 parent 5b0deaf commit d9e401b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

time_tracker_api/users/users_namespace.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@
4040
user_response_fields.update(common_fields)
4141

4242

43+
@ns.route('/<string:id>')
44+
@ns.param('id', 'The unique identifier of the user')
45+
class User(Resource):
46+
@ns.doc('get_user')
47+
@ns.marshal_list_with(user_response_fields)
48+
def get(self, id):
49+
"""Get an user"""
50+
return AzureConnection().get_user(id)
51+
52+
4353
@ns.route('')
4454
class Users(Resource):
4555
@ns.doc('list_users')

utils/azure_users.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ def get_token(self):
8686
error_info = f"{response['error']} {response['error_description']}"
8787
raise ValueError(error_info)
8888

89+
def get_user(self, user_id) -> AzureUser:
90+
endpoint = "{endpoint}/users/{user_id}?api-version=1.6".format(
91+
endpoint=self.config.ENDPOINT, user_id=user_id
92+
)
93+
response = requests.get(endpoint, auth=BearerAuth(self.access_token))
94+
assert 200 == response.status_code
95+
return self.to_azure_user(response.json())
96+
8997
def users(self) -> List[AzureUser]:
9098
role_fields_params = ','.join(
9199
[field_name for field_name, _ in ROLE_FIELD_VALUES.values()]

0 commit comments

Comments
 (0)