4
4
5
5
from time_tracker_api .api import common_fields , api , NullableString
6
6
7
- faker = Faker ()
7
+ from utils .azure_users import AzureConnection
8
+
9
+
10
+ azure_connection = AzureConnection ()
8
11
9
12
ns = api .namespace ('users' , description = 'Namespace of the API for users' )
10
13
17
20
title = 'Name' ,
18
21
max_length = 50 ,
19
22
description = 'Name of the user' ,
20
- example = faker .word (['Marcelo' , 'Sandro' ]),
23
+ example = Faker () .word (['Marcelo' , 'Sandro' ]),
21
24
),
22
25
'email' : fields .String (
23
26
title = "User's Email" ,
24
27
max_length = 50 ,
25
28
description = 'Email of the user that belongs to the tenant' ,
26
- example = faker .email (),
29
+ example = Faker () .email (),
27
30
),
28
31
'role' : NullableString (
29
32
title = "User's Role" ,
30
33
max_length = 50 ,
31
34
description = 'Role assigned to the user by the tenant' ,
32
- example = faker .word (['time-tracker-admin' ]),
35
+ example = Faker () .word (['time-tracker-admin' ]),
33
36
),
34
37
},
35
38
)
36
39
37
40
user_response_fields .update (common_fields )
38
41
39
- user_input_fields = ns .model (
40
- 'UserInput ' ,
42
+ user_role_input_fields = ns .model (
43
+ 'UserRoleInput ' ,
41
44
{
42
45
'role' : NullableString (
43
46
title = "User's Role" ,
44
47
required = True ,
45
48
max_length = 50 ,
46
49
description = 'Role assigned to the user by the tenant' ,
47
- example = faker .word (['time-tracker-admin' ]),
50
+ example = Faker () .word (['time-tracker-admin' ]),
48
51
),
49
52
},
50
53
)
@@ -56,26 +59,33 @@ class Users(Resource):
56
59
@ns .marshal_list_with (user_response_fields )
57
60
def get (self ):
58
61
"""List all users"""
59
- from utils .azure_users import AzureConnection
60
-
61
- azure_connection = AzureConnection ()
62
62
return azure_connection .users ()
63
63
64
64
65
65
@ns .route ('/<string:id>/roles' )
66
66
@ns .response (HTTPStatus .NOT_FOUND , 'User not found' )
67
67
@ns .response (HTTPStatus .UNPROCESSABLE_ENTITY , 'The id has an invalid format' )
68
68
@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 )
72
72
@ns .response (
73
73
HTTPStatus .BAD_REQUEST , 'Invalid format or structure of the user'
74
74
)
75
75
@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"""
81
78
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