44
55from time_tracker_api .api import common_fields , api , NullableString
66
7- faker = Faker ()
7+ from utils .azure_users import AzureConnection
8+
9+
10+ azure_connection = AzureConnection ()
811
912ns = api .namespace ('users' , description = 'Namespace of the API for users' )
1013
1720 title = 'Name' ,
1821 max_length = 50 ,
1922 description = 'Name of the user' ,
20- example = faker .word (['Marcelo' , 'Sandro' ]),
23+ example = Faker () .word (['Marcelo' , 'Sandro' ]),
2124 ),
2225 'email' : fields .String (
2326 title = "User's Email" ,
2427 max_length = 50 ,
2528 description = 'Email of the user that belongs to the tenant' ,
26- example = faker .email (),
29+ example = Faker () .email (),
2730 ),
2831 'role' : NullableString (
2932 title = "User's Role" ,
3033 max_length = 50 ,
3134 description = 'Role assigned to the user by the tenant' ,
32- example = faker .word (['time-tracker-admin' ]),
35+ example = Faker () .word (['time-tracker-admin' ]),
3336 ),
3437 },
3538)
3639
3740user_response_fields .update (common_fields )
3841
39- user_input_fields = ns .model (
40- 'UserInput ' ,
42+ user_role_input_fields = ns .model (
43+ 'UserRoleInput ' ,
4144 {
4245 'role' : NullableString (
4346 title = "User's Role" ,
4447 required = True ,
4548 max_length = 50 ,
4649 description = 'Role assigned to the user by the tenant' ,
47- example = faker .word (['time-tracker-admin' ]),
50+ example = Faker () .word (['time-tracker-admin' ]),
4851 ),
4952 },
5053)
@@ -56,26 +59,33 @@ class Users(Resource):
5659 @ns .marshal_list_with (user_response_fields )
5760 def get (self ):
5861 """List all users"""
59- from utils .azure_users import AzureConnection
60-
61- azure_connection = AzureConnection ()
6262 return azure_connection .users ()
6363
6464
6565@ns .route ('/<string:id>/roles' )
6666@ns .response (HTTPStatus .NOT_FOUND , 'User not found' )
6767@ns .response (HTTPStatus .UNPROCESSABLE_ENTITY , 'The id has an invalid format' )
6868@ns .param ('id' , 'The user identifier' )
69- class UserRole (Resource ):
70- @ns .doc ('update_user_role ' )
71- @ns .expect (user_input_fields )
69+ class UserRoles (Resource ):
70+ @ns .doc ('create_user_role ' )
71+ @ns .expect (user_role_input_fields )
7272 @ns .response (
7373 HTTPStatus .BAD_REQUEST , 'Invalid format or structure of the user'
7474 )
7575 @ns .marshal_with (user_response_fields )
76- def put (self , id ):
77- """Update user's role"""
78- from utils .azure_users import AzureConnection
79-
80- azure_connection = AzureConnection ()
76+ def post (self , id ):
77+ """Create user's role"""
8178 return azure_connection .update_user_role (id , ns .payload ['role' ])
79+
80+
81+ @ns .route ('/<string:user_id>/roles/<string:role_id>' )
82+ @ns .response (HTTPStatus .NOT_FOUND , 'User not found' )
83+ @ns .response (HTTPStatus .UNPROCESSABLE_ENTITY , 'The id has an invalid format' )
84+ @ns .param ('user_id' , 'The user identifier' )
85+ @ns .param ('role_id' , 'The role name identifier' )
86+ class UserRole (Resource ):
87+ @ns .doc ('delete_user_role' )
88+ @ns .marshal_with (user_response_fields )
89+ def delete (self , user_id , role_id ):
90+ """Delete user's role"""
91+ return azure_connection .update_user_role (user_id , role = None )
0 commit comments