Skip to content

Commit f0e6ad3

Browse files
Log invalid user account status to Sentry with detailed user information
1 parent cfdcc01 commit f0e6ad3

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

api/base/authentication/drf.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from osf.models import OSFUser
2222
from osf.utils.fields import ensure_str
2323
from website import settings
24+
from framework import sentry
2425

2526
SessionStore = import_module(api_settings.SESSION_ENGINE).SessionStore
2627

@@ -92,6 +93,20 @@ def check_user(user):
9293
# For all other cases, the user status is invalid. Although such status can't be reached with
9394
# normal user-facing web application flow, it is still possible as a result of direct database
9495
# access, coding bugs, database corruption, etc.
96+
extra_data = {
97+
'user_id': user.id,
98+
'user_guid': user._id,
99+
'is_active': user.is_active,
100+
'is_disabled': user.is_disabled,
101+
'is_merged': user.is_merged,
102+
'date_disabled': user.date_disabled,
103+
'is_confirmed': user.is_confirmed,
104+
'is_registered': user.is_registered,
105+
'can_login': user.has_usable_password() or (
106+
'VERIFIED' in sum([list(each.values()) for each in user.external_identity.values()], [])
107+
),
108+
}
109+
sentry.log_message(f'Invalid user account status detected: user_id={user._id}', extra_data=extra_data)
95110
raise InvalidAccountError
96111

97112

0 commit comments

Comments
 (0)