Update code to support passing organization's slugs
@@ -14,6 +14,7 @@ from readthedocs.oauth.notifications import (
)
from readthedocs.oauth.services.base import SyncServiceError
from readthedocs.oauth.utils import SERVICE_MAP
+from readthedocs.organizations.models import Organization
from readthedocs.projects.models import Project
from readthedocs.sso.models import SSOIntegration
from readthedocs.worker import app
@@ -52,23 +53,40 @@ def sync_remote_repositories(user_id):
@app.task(queue='web')
-def sync_remote_repositories_organizations():
+def sync_remote_repositories_organizations(organization_slugs=None):
"""
- Re-sync users member of organizations with SSO enabled.
+ Re-sync users member of organizations.
It will trigger one `sync_remote_repositories` task per user.
+
+ :param organization_slugs: list containg organization's slugs to sync. If
+ not passed, all organizations with ALLAUTH SSO enabled will be synced
+
+ :type organization_slugs: list
"""
+ if organization_slugs:
+ query = Organization.objects.filter(slug__in=organization_slugs)
+ log.info(
+ 'Triggering SSO re-sync for organizations. slugs=%s count=%s',
+ organization_slugs,
+ query.count(),
+ )
+ else:
+ log.info(
+ 'Triggering SSO re-sync for all organizations. count=%s',
+ query.count(),
+ )
query = (
SSOIntegration.objects
.filter(provider=SSOIntegration.PROVIDER_ALLAUTH)
.values_list('organization', flat=True)
)
- log.info('Triggering scheduled SSO re-sync for all organizations. count=%s', query.count())
+
n_task = -1
for organization in query:
members = AdminPermission.members(organization)
log.info(
- 'Triggering scheduled SSO re-sync for organization. organization=%s users=%s',
+ 'Triggering SSO re-sync for organization. organization=%s users=%s',
organization.slug,
members.count(),
)
