-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added django-hijack for only Mine & Ken's usage
- Loading branch information
1 parent
9f90b54
commit dbc4bf0
Showing
5 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,37 @@ | ||
import logging | ||
|
||
import cachetools | ||
from django.conf import settings | ||
|
||
logger = logging.getLogger(__name__) | ||
from hijack import signals | ||
|
||
|
||
@cachetools.cached(cache=cachetools.LRUCache(maxsize=4096)) | ||
def hijack_permissions_check(*, hijacker, hijacked) -> bool: | ||
"""Staff members may hijack other staff and regular users, but not superusers.""" | ||
if all( | ||
[ | ||
hijacker.id in settings.ALLOWED_HIJACKERS, | ||
hijacked.id not in settings.ALLOWED_HIJACKERS, | ||
hijacker.is_superuser, | ||
hijacked.is_active, | ||
not hijacked, | ||
] | ||
): | ||
return True | ||
return False | ||
|
||
|
||
def print_hijack_started(sender, hijacker, hijacked, request, **kwargs): | ||
print(f"{hijacker} has hijacked {hijacked}") # todo replace with logging | ||
|
||
|
||
signals.hijack_started.connect(print_hijack_started) | ||
|
||
|
||
def print_hijack_ended(sender, hijacker, hijacked, request, **kwargs): | ||
print(f"{hijacker} has released {hijacked}") | ||
|
||
|
||
signals.hijack_ended.connect(print_hijack_ended) |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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