Send invites

This commit is contained in:
Mouse Reeve 2021-03-21 09:13:21 -07:00
parent 685da1f5b8
commit 1644c421e5
7 changed files with 53 additions and 23 deletions

View file

@ -6,6 +6,16 @@ from bookwyrm import models
from bookwyrm.tasks import app from bookwyrm.tasks import app
def invite_email(invite_request):
""" send out an invite code """
site = models.SiteSettings.objects.get()
data = {
"site_name": site.name,
"invite_link": invite_request.invite.link,
}
send_email.delay(invite_request.email, "invite", data)
def password_reset_email(reset_code): def password_reset_email(reset_code):
""" generate a password reset email """ """ generate a password reset email """
site = models.SiteSettings.objects.get() site = models.SiteSettings.objects.get()

View file

@ -0,0 +1,2 @@
{% load i18n %}
<a href="{{ invite_link }}">{% blocktrans %}Join {{ site_name }}{% endblocktrans %}</a>

View file

@ -0,0 +1,2 @@
{% load i18n %}
{% blocktrans %}You're invited! Join {{ site_name }}{% endblocktrans %}

View file

@ -0,0 +1,2 @@
{% load i18n %}
{% blocktrans %}Join {{ site_name }}: {{ invite_link }}{% endblocktrans %}

View file

@ -15,8 +15,8 @@
<h2 class="menu-label">{% trans "Manage Users" %}</h2> <h2 class="menu-label">{% trans "Manage Users" %}</h2>
<ul class="menu-list"> <ul class="menu-list">
<li> <li>
{% url 'settings-invites' as url %} {% url 'settings-invite-requests' as url %}
{% url 'settings-invite-requests' as alt_url %} {% url 'settings-invites' as alt_url %}
<a href="{{ url }}"{% if url in request.path or request.path in alt_url %} class="is-active" aria-selected="true"{% endif %}>{% trans "Invites" %}</a> <a href="{{ url }}"{% if url in request.path or request.path in alt_url %} class="is-active" aria-selected="true"{% endif %}>{% trans "Invites" %}</a>
</li> </li>
<li> <li>

View file

@ -49,27 +49,29 @@
{% trans "Requested" %} {% trans "Requested" %}
{% endif %} {% endif %}
</td> </td>
<td> <td class="field is-grouped">
{% if req.invite and not req.invite.times_used %} <form name="send-invite" method="post" action="{% url 'settings-invite-requests' %}">
<button class="button is-danger is-light is-small">{% trans "Revoke invite" %}</button> {% csrf_token %}
{% else %} <input type="hidden" name="invite-request" value="{{ req.id }}">
<div class="field is-grouped"> {% if not req.invite %}
<form name="send-invite" method="post" action="{% url 'settings-invite-requests' %}"> <button type="submit" class="button is-link is-light is-small">{% trans "Send invite" %}</button>
{% csrf_token %} {% else %}
<input type="hidden" name="invite-request" value="{{ req.id }}"> <button type="submit" class="button is-link is-light is-small">{% trans "Re-send invite" %}</button>
<button type="submit" class="button is-link is-light is-small">{% trans "Send invite" %}</button> {% endif %}
</form> </form>
<form name="ignore-request" method="post" action="{% url 'settings-invite-requests-ignore' %}"> {% if req.invite and not req.invite.times_used %}
{% csrf_token %} {# <button class="button is-danger is-light is-small">{% trans "Revoke invite" %}</button> #}
<input type="hidden" name="invite-request" value="{{ req.id }}"> {% else %}
{% if not req.ignored %} <form name="ignore-request" method="post" action="{% url 'settings-invite-requests-ignore' %}">
<button type="submit" class="button is-danger is-light is-small">{% trans "Ignore" %}</button> {% csrf_token %}
{% else %} <input type="hidden" name="invite-request" value="{{ req.id }}">
<button type="submit" class="button is-danger is-light is-small">{% trans "Un-gnore" %}</button> {% if not req.ignored %}
{% endif %} <button type="submit" class="button is-danger is-light is-small">{% trans "Ignore" %}</button>
</form> {% else %}
</div> <button type="submit" class="button is-danger is-light is-small">{% trans "Un-gnore" %}</button>
{% endif %}
</form>
{% endif %} {% endif %}
</td> </td>
</tr> </tr>

View file

@ -8,7 +8,7 @@ from django.utils.decorators import method_decorator
from django.views import View from django.views import View
from django.views.decorators.http import require_POST from django.views.decorators.http import require_POST
from bookwyrm import forms, models from bookwyrm import emailing, forms, models
from bookwyrm.settings import PAGE_LENGTH from bookwyrm.settings import PAGE_LENGTH
from . import helpers from . import helpers
@ -107,6 +107,18 @@ class ManageInviteRequests(View):
def post(self, request): def post(self, request):
""" send out an invite """ """ send out an invite """
invite_request = get_object_or_404(
models.InviteRequest, id=request.POST.get("invite-request")
)
# allows re-sending invites
invite_request.invite, _ = models.SiteInvite.objects.get_or_create(
use_limit=1,
user=request.user,
)
invite_request.save()
emailing.invite_email(invite_request)
return redirect('settings-invite-requests')
class InviteRequest(View): class InviteRequest(View):