Exemple #1
0
def slack(request, username):
    user = get_object_or_404(User, username=username)
    if not user == request.user:
        if not request.user.is_staff:
            return HttpResponseRedirect(
                reverse('member:profile:view',
                        kwargs={'username': request.user.username}))

    if request.method == 'POST':
        try:
            slack_api = SlackAPI()
            slack_api.invite_user(user)
            messages.add_message(
                request, messages.INFO,
                "Slack Invitation Sent.  Check your email for further instructions."
            )
        except Exception as e:
            messages.add_message(request, messages.ERROR,
                                 "Failed to send invitation: %s" % e)

    context = {
        'user': user,
        'team_url': settings.SLACK_TEAM_URL,
        'settings': settings
    }
    return render(request, 'members/connect/slack.html', context)
Exemple #2
0
def slack(request, username):
    user = get_object_or_404(User, username=username)
    if not user == request.user:
        if not request.user.is_staff:
            return HttpResponseRedirect(reverse('members.views.user', kwargs={'username': request.user.username}))

    if request.method == 'POST':
        try:
            slack_api = SlackAPI()
            slack_api.invite_user(user)
            messages.add_message(request, messages.INFO, "Slack Invitation Sent.  Check your email for further instructions.")
        except Exception as e:
            messages.add_message(request, messages.ERROR, "Failed to send invitation: %s" % e)

    return render_to_response('members/slack.html', {'user': user, 'team_url':settings.SLACK_TEAM_URL}, context_instance=RequestContext(request))
Exemple #3
0
def send_manual(user, message):
    message = message.lower()
    if not message in valid_message_keys():
        return False
    if message == "introduction" or message == "all":
        send_introduction(user)
    if message == "newsletter" or message == "all":
        subscribe_to_newsletter(user)
    if message == "new_member" or message == "all":
        send_new_membership(user)
    if message == "first_day_checkin" or message == "all":
        send_first_day_checkin(user)
    if message == "exit_survey" or message == "all":
        send_exit_survey(user)
    if message == "member_survey" or message == "all":
        send_member_survey(user)
    if message == "no_return_checkin" or message == "all":
        send_no_return_checkin(user)
    if message == "invalid_billing" or message == "all":
        send_invalid_billing(user)
    if message == "no_signin" or message == "all":
        send_no_signin(user)
    if message == "no_device" or message == "all":
        send_no_device(user)
    if message == "new_key" or message == "all":
        send_new_key(user)
    if message == "edit_profile" or message == "all":
        send_edit_profile(user)
    if message == "slack_invite":
        SlackAPI().invite_user(user)
    return True
Exemple #4
0
def slack_bots(request):
    # Stupid chat bot
    try:
        text = request.POST.get("text")[7:]
        SlackAPI().post_message(text)
    except Exception as e:
        return JsonResponse({'text': str(e)})
    return JsonResponse({})
Exemple #5
0
 def expired_slack_users(self):
     expired_users = []
     active_emails = self.active_member_emails()
     slack_users = SlackAPI().users.list()
     for u in slack_users.body['members']:
         if 'profile' in u and 'real_name' in u and 'email' in u['profile']:
             email = u['profile']['email']
             if email and email not in active_emails and 'nadine' not in email:
                 expired_users.append({'email':email, 'real_name':u['real_name']})
     return expired_users
Exemple #6
0
def slack_users(request):
    expired_users = User.helper.expired_slack_users()
    slack_emails = []
    slack_users = SlackAPI().users.list().body['members']
    for u in slack_users:
        if 'profile' in u and 'email' in u['profile'] and u['profile']['email']:
            slack_emails.append(u['profile']['email'])
    non_slack_users = User.helper.active_members().exclude(email__in=slack_emails)
    context = {'expired_users':expired_users, 'slack_users':slack_users,
         'non_slack_users':non_slack_users, 'slack_url':settings.SLACK_TEAM_URL}
    return render(request, 'staff/members/slack_users.html', context)
Exemple #7
0
def slack_users(request):
    expired_users = Member.objects.expired_slack_users()
    slack_emails = []
    slack_users = SlackAPI().users.list().body['members']
    for u in slack_users:
        if 'profile' in u and 'email' in u['profile'] and u['profile']['email']:
            slack_emails.append(u['profile']['email'])
    non_slack_users = Member.objects.active_members().exclude(user__email__in=slack_emails)
    return render_to_response('staff/slack_users.html', {'expired_users':expired_users,
                                                         'slack_users':slack_users,
                                                         'non_slack_users':non_slack_users,
                                                         'slack_url':settings.SLACK_TEAM_URL}, context_instance=RequestContext(request))
Exemple #8
0
    def trigger_new_membership(self, user):
        logger.debug("trigger_new_membership: %s" % user)

        # Pull a bunch of data so we don't keep hitting the database
        open_alerts = user.profile.alerts_by_key(include_resolved=False)
        all_alerts = user.profile.alerts_by_key(include_resolved=True)
        existing_files = user.profile.files_by_type()

        # Send New Member email
        try:
            email.send_new_membership(user)
            email.announce_new_membership(user)
        except Exception as e:
            logger.error("Could not send New Member notification", e)

        # Member Information
        if not FileUpload.MEMBER_INFO in existing_files:
            if not MemberAlert.PAPERWORK in open_alerts:
                MemberAlert.objects.create(user=user,
                                           key=MemberAlert.PAPERWORK)
            if not MemberAlert.MEMBER_INFO in open_alerts:
                MemberAlert.objects.create(user=user,
                                           key=MemberAlert.MEMBER_INFO)

        # Membership Agreement
        if not FileUpload.MEMBER_AGMT in existing_files:
            if not MemberAlert.MEMBER_AGREEMENT in open_alerts:
                MemberAlert.objects.create(user=user,
                                           key=MemberAlert.MEMBER_AGREEMENT)

        # User Photo
        if not user.profile.photo:
            if not MemberAlert.TAKE_PHOTO in open_alerts:
                MemberAlert.objects.create(user=user,
                                           key=MemberAlert.TAKE_PHOTO)
            if not MemberAlert.UPLOAD_PHOTO in open_alerts:
                MemberAlert.objects.create(user=user,
                                           key=MemberAlert.UPLOAD_PHOTO)
        if not MemberAlert.POST_PHOTO in open_alerts:
            MemberAlert.objects.create(user=user, key=MemberAlert.POST_PHOTO)

        # New Member Orientation
        if not MemberAlert.ORIENTATION in all_alerts:
            MemberAlert.objects.create(user=user, key=MemberAlert.ORIENTATION)

        # Subscribe them to all the opt_out mailing lists
        for mailing_list in MailingList.objects.filter(is_opt_out=True):
            mailing_list.subscribers.add(user)

        # Invite them to slack
        if hasattr(settings, 'SLACK_API_TOKEN'):
            SlackAPI().invite_user_quiet(user)
Exemple #9
0
def notify_new_membership(sender, **kwargs):
    user = kwargs['user']

    # Notify the user
    try:
        email.send_new_membership(user)
    except Exception as e:
        logger.error(f"Could not send New Member notification for '{user}'", e)

    # Notify the team
    try:
        email.announce_new_membership(user)
    except Exception as e:
        logger.error(f"Could not send announce new member '{user}'", e)

    # Invite them to slack
    if hasattr(settings, 'SLACK_API_TOKEN'):
        SlackAPI().invite_user_quiet(user)
Exemple #10
0
def membership_save_callback(sender, **kwargs):
    """When a membership is created, add the user to any opt-out mailing lists"""
    membership = kwargs['instance']
    created = kwargs['created']
    if not created:
        return

    # If the member is just switching from one membership to another, don't change subscriptions
    # But if this membership is created in the past there is no way to know what they want so subscribe them
    if membership.start_date > timezone.now().date():
        if Membership.objects.filter(user=membership.user, end_date=membership.start_date - timedelta(days=1)).count() != 0:
            return

    mailing_lists = MailingList.objects.filter(is_opt_out=True)
    for ml in mailing_lists:
        ml.subscribers.add(membership.user)

    # If this is their first membership, also invite them to Slack
    if Membership.objects.filter(user=membership.user).count() == 1:
        SlackAPI().invite_user_quiet(membership.user)
Exemple #11
0
def slack_users(request):
    active_emails = User.helper.active_member_emails()
    expired_users = []
    slack_emails = []
    deleted_slack_users = []
    non_slack_users = []

    # Loop through all the slack members and compare them to our active members.
    slack_users = SlackAPI().users.list().body['members']
    for u in slack_users:
        real_name = u.get('real_name', None)
        if 'profile' in u and 'email' in u['profile'] and u['profile'][
                'email'] and not u['is_bot']:
            email = u['profile']['email']
            slack_emails.append(email)
            if u['deleted']:
                deleted_slack_users.append(u)
            elif email not in active_emails:
                expired_users.append({'email': email, 'real_name': real_name})

    # Loop through the active users that didn't make the list and make sure
    # They are not actually a slack user
    for u in User.helper.active_members().exclude(email__in=slack_emails):
        is_slack_user = False
        for e in u.emailaddress_set.all():
            if e.email in slack_emails:
                is_slack_user = True
        if not is_slack_user:
            non_slack_users.append(u)

    context = {
        'deleted_slack_users': deleted_slack_users,
        'expired_users': expired_users,
        'non_slack_users': non_slack_users,
        'slack_url': settings.SLACK_TEAM_URL
    }
    return render(request, 'staff/members/slack_users.html', context)