Skip to content

Commit 80625fd

Browse files
committed
fix and update demote
1 parent 3e811e5 commit 80625fd

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

labconnect/main/auth_routes.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def registerUser() -> Response:
200200
@jwt_required()
201201
def promoteUser(email: str) -> Response:
202202
json_data = request.json
203-
if not json_data or not json_data.get("promote") or not json_data.get("demote"):
203+
if not json_data or not json_data.get("change_status"):
204204
abort(400)
205205

206206
# if user accessing doesn't have the right perms then they can't assign perms
@@ -222,8 +222,7 @@ def promoteUser(email: str) -> Response:
222222

223223
if management_permissions.admin == True:
224224
management_permissions.admin = False
225-
226-
if management_permissions.admin == False:
225+
elif management_permissions.admin == False:
227226
management_permissions.admin = True
228227

229228
if management_permissions is None:

tests/test_manager_promotion.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def test_promote_user_success(test_client, setup_users, create_access_token_for_
120120
response = test_client.patch(
121121
f"/users/{users['regular_user'].email}/permissions",
122122
headers={"Authorization": f"Bearer {access_token}"},
123-
json={"promote": True},
123+
json={"change_status": True},
124124
)
125125

126126
assert response.status_code == 200
@@ -141,7 +141,7 @@ def test_demote_user_success(test_client, setup_users, create_access_token_for_u
141141
response = test_client.patch(
142142
f"/users/{users['regular_user2'].email}/permissions",
143143
headers={"Authorization": f"Bearer {access_token}"},
144-
json={"demote": True},
144+
json={"change_status": True},
145145
)
146146

147147
assert response.status_code == 200
@@ -153,7 +153,6 @@ def test_demote_user_success(test_client, setup_users, create_access_token_for_u
153153
).first()
154154
assert demoted_perms.admin is False
155155

156-
157156
def test_promote_user_no_json_data(test_client, setup_users,
158157
create_access_token_for_user):
159158
"""Test promotion fails when no JSON data is provided"""
@@ -180,7 +179,7 @@ def test_promote_user_no_super_admin_perms(test_client, setup_users,
180179
response = test_client.patch(
181180
f"/users/{users['regular_user'].email}/permissions",
182181
headers={"Authorization": f"Bearer {access_token}"},
183-
json={"promote": True}
182+
json={"change_status": True}
184183
)
185184

186185
assert response.status_code == 401
@@ -207,7 +206,7 @@ def test_promote_user_promoter_has_no_perms_record(test_client, setup_users,
207206
response = test_client.patch(
208207
f"/users/{users['regular_user'].email}/permissions",
209208
headers={"Authorization": f"Bearer {access_token}"},
210-
json={"promote": True}
209+
json={"change_status": True}
211210
)
212211

213212
assert response.status_code == 401
@@ -223,7 +222,7 @@ def test_promote_user_target_not_found(test_client, setup_users,
223222
response = test_client.patch(
224223
"/users/[email protected]/permissions",
225224
headers={"Authorization": f"Bearer {access_token}"},
226-
json={"promote": True}
225+
json={"change_status": True}
227226
)
228227

229228
assert response.status_code == 500
@@ -239,7 +238,7 @@ def test_promote_user_no_jwt_token(test_client, setup_users):
239238

240239
response = test_client.patch(
241240
f"/users/{users['regular_user'].email}/permissions",
242-
json={"promote": True}
241+
json={"change_status": True}
243242
)
244243

245244
assert response.status_code == 401

0 commit comments

Comments
 (0)