Django Action: add a request message with counts
"""Admin interface for SSO models."""
import logging
-from django.contrib import admin
+from django.contrib import admin, messages
from readthedocs.core.permissions import AdminPermission
from readthedocs.oauth.tasks import sync_remote_repositories
@@ -25,6 +25,9 @@ class SSOIntegrationAdmin(admin.ModelAdmin):
]
def resync_sso_user_accounts(self, request, queryset): # pylint: disable=no-self-use
+ users_count = 0
+ organizations_count = queryset.count()
+
for ssointegration in queryset.select_related('organization'):
members = AdminPermission.members(ssointegration.organization)
log.info(
@@ -32,9 +35,16 @@ class SSOIntegrationAdmin(admin.ModelAdmin):
ssointegration.organization.slug,
members.count(),
)
+ users_count += members.count()
for user in members:
sync_remote_repositories.delay(user.pk)
+ messages.add_message(
+ request,
+ messages.INFO,
+ f'Triggered resync for {organizations_count} organizations and {users_count} users.'
+ )
+
resync_sso_user_accounts.short_description = 'Re-sync all SSO user accounts'
