Exemplo n.º 1
0
def add_user_to_instance(request, user, instance, admin_user):
    iuser_already_exists = (InstanceUser.objects.filter(
        user_id=user.pk, instance=instance).exists())

    if iuser_already_exists:
        raise ValidationError(
            _("A user with email address '%s' has already "
              "joined this map.") % user.email)

    iuser = InstanceUser(user_id=user.pk,
                         instance=instance,
                         role=instance.default_role)
    iuser.save_with_user(admin_user)

    ctxt = {'request': request, 'instance': instance}

    send_email('invite_to_existing_user', ctxt, (user.email, ))
Exemplo n.º 2
0
def invite_user_with_email_to_instance(request, email, instance):
    existing_invites = InstanceInvitation.objects.filter(email__iexact=email,
                                                         instance=instance)

    if existing_invites.exists():
        raise ValidationError(
            _("A user with email address '%s' has already been invited.") %
            email)

    invite = InstanceInvitation.objects.create(instance=instance,
                                               email=email,
                                               created_by=request.user,
                                               role=instance.default_role)

    ctxt = {'request': request, 'instance': instance, 'invite': invite}

    send_email('invite_to_new_user', ctxt, (email, ))
Exemplo n.º 3
0
def create_instance_users_from_invites(request, user, invites):
    ctxt = {'user': user,
            'request': request}
    for invite in invites:
        instance = invite.instance
        iuser = InstanceUser(user=user,
                             instance=instance,
                             role=invite.role,
                             admin=invite.admin)
        iuser.save_with_user(user)
        invite.accepted = True
        invite.save()

        emails_to_notify = InstanceUser.objects \
            .filter(instance=instance, admin=True) \
            .values_list('user__email', flat=True)

        send_email('user_joined_instance', ctxt, emails_to_notify)
Exemplo n.º 4
0
def add_user_to_instance(request, user, instance, admin_user):
    iuser_already_exists = (InstanceUser.objects
                            .filter(user_id=user.pk,
                                    instance=instance).exists())

    if iuser_already_exists:
        raise ValidationError(_("A user with email address '%s' has already "
                              "joined this map.") % user.email)

    iuser = InstanceUser(user_id=user.pk,
                         instance=instance,
                         role=instance.default_role)
    iuser.save_with_user(admin_user)

    ctxt = {'request': request,
            'instance': instance}

    send_email('invite_to_existing_user', ctxt, (user.email,))
Exemplo n.º 5
0
def invite_user_with_email_to_instance(request, email, instance):
    existing_invites = InstanceInvitation.objects.filter(
        email__iexact=email, instance=instance)

    if existing_invites.exists():
        raise ValidationError(
            _("A user with email address '%s' has already been invited.") %
            email)

    invite = InstanceInvitation.objects.create(instance=instance,
                                               email=email,
                                               created_by=request.user,
                                               role=instance.default_role)

    ctxt = {'request': request,
            'instance': instance,
            'invite': invite}

    send_email('invite_to_new_user', ctxt, (email,))
Exemplo n.º 6
0
def create_instance_users_from_invites(request, user, invites):
    ctxt = {'user': user, 'request': request}
    for invite in invites:
        instance = invite.instance
        iuser = InstanceUser(user=user,
                             instance=instance,
                             role=invite.role,
                             admin=invite.admin)
        iuser.save_with_user(user)
        invite.accepted = True
        invite.save()

        # The user who created the invitation is always notified when the
        # invitation is accepted. A plugin function provides additional email
        # addresses. The concatenation of the two lists is wrapped with `set()`
        # to remove duplicates.
        emails_to_notify = set([invite.created_by.email] +
                               invitation_accepted_notification_emails(invite))

        send_email('user_joined_instance', ctxt, emails_to_notify)
Exemplo n.º 7
0
def create_instance_users_from_invites(request, user, invites):
    ctxt = {'user': user,
            'request': request}
    for invite in invites:
        instance = invite.instance
        iuser = InstanceUser(user=user,
                             instance=instance,
                             role=invite.role,
                             admin=invite.admin)
        iuser.save_with_user(user)
        invite.accepted = True
        invite.save()

        # The user who created the invitation is always notified when the
        # invitation is accepted. A plugin function provides additional email
        # addresses. The concatenation of the two lists is wrapped with `set()`
        # to remove duplicates.
        emails_to_notify = set(
            [invite.created_by.email]
            + invitation_accepted_notification_emails(invite)
        )

        send_email('user_joined_instance', ctxt, emails_to_notify)