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

Feat/add flush expired tokens command to admin #721

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

tpotjj
Copy link

@tpotjj tpotjj commented Jun 29, 2023

Doing this as a cronjob might be the better way of doing it, but for a smaller project that doesn't allow setting up a cronjob or because of the lack of knowledge, it might be convenient to add this to the Admin.

@tpotjj
Copy link
Author

tpotjj commented Jul 3, 2023

@Andrew-Chen-Wang Ready for review.

@Andrew-Chen-Wang Andrew-Chen-Wang requested a review from 2ykwang July 3, 2023 10:09
@@ -67,6 +68,31 @@ class BlacklistedTokenAdmin(admin.ModelAdmin):
"token__jti",
)
ordering = ("token__user",)
actions = ["flush_expired_tokens"]

def flush_expired_tokens(self, request, queryset):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def flush_expired_tokens(self, request, queryset):
@admin.action(permissions=["change"], description = _("Flush expired tokens"))
def flush_expired_tokens(self, request, queryset):

What are your thoughts on using the @admin.action decorator?
It allows you to set the required permissions for executing an action and provides a description for it as well. Additionally, you can use gettext_lazy to provide localization support. @tpotjj

@2ykwang
Copy link
Member

2ykwang commented Jul 5, 2023

Can you please execute the 'makemessages' command to generate the 'po' file? @tpotjj

@2ykwang 2ykwang assigned 2ykwang and tpotjj and unassigned 2ykwang Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants