Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix : admin user can't clear their own session but can clear other user sessions [SDESK-6696]. #2398

Merged
merged 3 commits into from
Nov 16, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions apps/auth/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ def delete(self, lookup):
if error_message:
raise SuperdeskApiError.forbiddenError(message=error_message)

# Delete all the sessions
# Delete all the sessions except current session
for session in sessions:
get_resource_service("auth").delete_action({config.ID_FIELD: str(session[config.ID_FIELD])})
current_session_id = auth.get_auth().get("_id")
devketanpro marked this conversation as resolved.
Show resolved Hide resolved
if str(session[config.ID_FIELD]) != str(current_session_id):
get_resource_service("auth").delete_action({config.ID_FIELD: str(session[config.ID_FIELD])})

# Check if any orphan session_preferences exist for the user
if user.get("session_preferences"):
Expand All @@ -146,13 +148,9 @@ def __can_clear_sessions(self, user):

Operation is invalid if one of the below is True:
1. Check if the user exists.
2. Check if the user is clearing his/her own sessions.

:return: error message if invalid.
"""

if not user:
return "Invalid user to clear sessions."

if str(user[config.ID_FIELD]) == str(flask.g.user[config.ID_FIELD]):
petrjasek marked this conversation as resolved.
Show resolved Hide resolved
return "Not allowed to clear your own sessions."