Skip to content

Commit

Permalink
Add optional invite-link handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rambo committed Jan 31, 2019
1 parent 4c57311 commit 3c70011
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions project/config/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@
HOLVI_NOTIFICATION_INTERVAL_DAYS = env('HOLVI_NOTIFICATION_INTERVAL_DAYS', default=7)
SLACK_APIKEY = env('SLACK_APIKEY', default=None)
SLACK_API_USERNAME = env('SLACK_API_USERNAME', default=None)
SLACK_INVITE_LINK = env('SLACK_INVITE_LINK', default=None)

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
Expand Down
16 changes: 15 additions & 1 deletion project/slacksync/membersync.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import slacker
from django.conf import settings
from django.core.mail import send_mail
from members.models import Member
from requests.exceptions import RequestException
from requests.sessions import Session
Expand All @@ -30,8 +31,17 @@ def get_slack_users_simple(self, slack, exclude_api_user=True):
emails.append((member['id'], member['name'], member['profile']['email']))
return emails

def email_slack_link(self, member):
send_mail(
"Slack invite to {}".format(settings.ORGANIZATION_NAME),
"Click on the link to continue\n\n{}\n".format(settings.SLACK_INVITE_LINK),
settings.DEFAULT_FROM_EMAIL,
[member.email],
fail_silently=True
)

def sync_members(self, autodeactivate=False, resend=True):
"""Sync members, NOTE: https://github.com/ErikKalkoken/slackApiDoc/blob/master/users.admin.setInactive.md says
"""Sync members, NOTE: https://github.com/ErikKalkoken/slackApiDoc/blob/master/users.admin.setInactive.md says
deactivation via API works only on paid tiers"""
if not api_configured():
raise RuntimeError("Slack API not configured")
Expand All @@ -43,6 +53,10 @@ def sync_members(self, autodeactivate=False, resend=True):

while add_members:
member = add_members.popleft()
# If we have configured invite-link use it instead of API (which might hit the "too many invites" -error
if settings.SLACK_INVITE_LINK:
self.email_slack_link(member)
continue
try:
resp = slack.users.admin.invite(member.email, resend=resend)
if 'ok' not in resp.body or not resp.body['ok']:
Expand Down

0 comments on commit 3c70011

Please sign in to comment.