-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Capture when user was last active #5630
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
Merged
+925
−0
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b5bb2d2
Add User Active Middleware class and add to server.py
5938d2c
Test useractive middleware
45e26f5
Add migration file for change to user model
3a423c2
add description to last active
f26d3e7
Adjust frequency of last active update
ab2a7d4
Grab user info from Token auths
4bdff8a
Undo add of Token auth
5f9fb1d
Add note in CHANGES on User.last_active
de77476
Include disallowed paths to static and user avatar that we don't need…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| from __future__ import absolute_import | ||
|
|
||
| import inspect | ||
| from datetime import timedelta | ||
| from django.utils import timezone | ||
|
|
||
|
|
||
| class UserActiveMiddleware(object): | ||
| disallowed_paths = ( | ||
| 'sentry.web.frontend.generic.static_media', | ||
| 'sentry.web.frontend.user_avatar', | ||
| ) | ||
|
|
||
| def process_view(self, request, view_func, view_args, view_kwargs): | ||
| view = view_func | ||
| if not inspect.isfunction(view_func): | ||
| view = view.__class__ | ||
|
|
||
| try: | ||
| path = '%s.%s' % (view.__module__, view.__name__) | ||
| except AttributeError: | ||
| return | ||
|
|
||
| if path.startswith(self.disallowed_paths): | ||
| return | ||
|
|
||
| if not request.user.is_authenticated(): | ||
| return | ||
|
|
||
| now = timezone.now() | ||
| freq = timedelta(minutes=5) | ||
| last_active = request.user.last_active | ||
|
|
||
| if last_active and freq > (now - last_active): | ||
| return | ||
|
|
||
| request.user.last_active = now | ||
|
||
| request.user.update(last_active=now) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could also do if hasattr(request, 'user') as I assume thats the issue you hit w/ the static paths