Skip to content

Commit b2117c4

Browse files
committed
Fix PUT User with password change for admins without Basic Auth
1 parent 42ae9ac commit b2117c4

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

rtp_backend/apps/auth/views.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,22 @@ def user(current_user, user_id=None):
200200

201201
password = data.get("password")
202202
if "password" in data:
203-
if password.strip() != "" and request.authorization:
204-
auth_password = request.authorization.password
205-
auth_username = request.authorization.username
203+
if password.strip() != "" and (
204+
request.authorization or current_user.user_type == UserTypeEnum.admin
205+
):
206+
auth_password = ""
207+
auth_username = ""
208+
if request.authorization:
209+
auth_password = request.authorization.password
210+
auth_username = request.authorization.username
206211
if current_user.user_type == UserTypeEnum.admin or (
207-
check_password_hash(auth_password, user.password_hash)
208-
and (auth_username == user.login_name or auth_username == "")
212+
auth_password
213+
and check_password_hash(auth_password, user.password_hash)
214+
and (
215+
auth_username == user.login_name
216+
or auth_username == ""
217+
or auth_username == None
218+
)
209219
):
210220
user.password_hash = get_hash(password)
211221
else:

0 commit comments

Comments
 (0)