Skip to content

Instantly share code, notes, and snippets.

@renzon
Created June 16, 2021 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renzon/898825434d352075dcb4d264bb46c4e9 to your computer and use it in GitHub Desktop.
Save renzon/898825434d352075dcb4d264bb46c4e9 to your computer and use it in GitHub Desktop.
def sync_user_on_discourse(subscription: Subscription):
"""
Synchronize user data on forum if API is configured
:param subscription
:return: returns result of hitting Discourse api
"""
can_make_api_call = bool(settings.DISCOURSE_API_KEY and settings.DISCOURSE_API_USER)
can_work_without_sync = not (settings.DISCOURSE_BASE_URL or can_make_api_call)
if can_work_without_sync:
_logger.info('Discourse Integration not available')
return
elif not can_make_api_call:
raise MissingDiscourseAPICredentials('Must define both DISCOURSE_API_KEY and DISCOURSE_API_USER configs')
# https://meta.discourse.org/t/sync-sso-user-data-with-the-sync-sso-route/84398
subscriber = subscription.subscriber
params = {
'email': subscriber.email,
'external_id': subscriber.id,
'require_activation': 'false',
'groups': ','.join(subscription.discourse_groups)
}
sso_payload, signature = discourse_facade.generate_sso_payload_and_signature(params)
# query_string = parse.urlencode()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment