Show subscription mailto: links to anonymous users

As suggested in <C4DCAJR6LQD2.GBNNZ1ME6L4N@homura>
This commit is contained in:
наб 2020-07-27 23:24:32 +02:00 committed by Drew DeVault
parent ce2683189f
commit caaab0c2c1
4 changed files with 52 additions and 6 deletions

View File

@ -20,10 +20,22 @@ from todosrht.webhooks import TrackerWebhook, TicketWebhook
ticket = Blueprint("ticket", __name__)
posting_domain = cfg("todo.sr.ht::mail", "posting-domain")
ticket_subscribe_body = """\
Sending this email will subscribe your email address to {ticket_ref},
in so doing you will start receiving comments on this ticket.
You don't need to subscribe to the ticket if you're already subscribed
to the entire {tracker_ref} tracker.
You can unsubscribe at any time by mailing <{ticket_email_ref}/unsubscribe@""" + \
posting_domain + ">.\n"
def get_ticket_context(ticket, tracker, access):
"""Returns the context required to render ticket.html"""
tracker_sub = None
ticket_sub = None
ticket_subscribe = None
if current_user:
tracker_sub = (TicketSubscription.query
@ -38,8 +50,14 @@ def get_ticket_context(ticket, tracker, access):
.filter(TicketSubscription.tracker_id == None)
.filter(Participant.user_id == current_user.id)
).one_or_none()
else:
subj = quote("Subscribing to " + ticket.ref())
ticket_subscribe = f"mailto:{ticket.ref(email=True)}/subscribe@" + \
f"{posting_domain}?subject={subj}&body=" + \
quote(ticket_subscribe_body.format(ticket_ref=ticket.ref(),
ticket_email_ref=ticket.ref(email=True),
tracker_ref=tracker.ref()))
posting_domain = cfg("todo.sr.ht::mail", "posting-domain")
reply_subject = quote("Re: " + ticket.title)
return {
@ -51,6 +69,7 @@ def get_ticket_context(ticket, tracker, access):
"access": access,
"tracker_sub": tracker_sub,
"ticket_sub": ticket_sub,
"ticket_subscribe": ticket_subscribe,
"recent_users": get_recent_users(tracker),
"reply_to": f"mailto:{ticket.ref(email=True)}@{posting_domain}" +
f"?subject={reply_subject}"

View File

@ -1,3 +1,4 @@
from urllib.parse import quote
from flask import Blueprint, render_template, request, url_for, abort, redirect
from todosrht.color import color_from_hex, color_to_hex, get_text_color
from todosrht.color import valid_hex_color_code
@ -24,6 +25,14 @@ tracker = Blueprint("tracker", __name__)
smtp_user = cfg("mail", "smtp-user", default=None)
smtp_from = cfg("mail", "smtp-from", default=None)
notify_from = cfg("todo.sr.ht", "notify-from", default=smtp_from)
posting_domain = cfg("todo.sr.ht::mail", "posting-domain")
tracker_subscribe_body = """\
Sending this email will subscribe your email address to {tracker_ref},
in so doing you will start receiving new tickets and all comments for this tracker.
You can unsubscribe at any time by mailing <{tracker_ref}/unsubscribe@""" + \
posting_domain + ">.\n"
@tracker.route("/tracker/create")
@loginrequired
@ -63,6 +72,7 @@ def return_tracker(tracker, access, **kwargs):
if another:
del session["another"]
is_subscribed = False
tracker_subscribe = None
if current_user:
sub = (TicketSubscription.query
.join(Participant)
@ -71,6 +81,11 @@ def return_tracker(tracker, access, **kwargs):
.filter(Participant.user_id == current_user.id)
).one_or_none()
is_subscribed = bool(sub)
else:
subj = quote("Subscribing to " + tracker.ref())
tracker_subscribe = f"mailto:{tracker.ref()}/subscribe@" + \
f"{posting_domain}?subject={subj}&body=" + \
quote(tracker_subscribe_body.format(tracker_ref=tracker.ref()))
tickets = (Ticket.query
.filter(Ticket.tracker_id == tracker.id)
@ -104,7 +119,7 @@ def return_tracker(tracker, access, **kwargs):
tracker=tracker, another=another, tickets=tickets,
access=access, is_subscribed=is_subscribed, search=terms,
comment_counts=comment_counts, seen_ticket_ids=seen_ticket_ids,
**pagination, **kwargs)
tracker_subscribe=tracker_subscribe, **pagination, **kwargs)
@tracker.route("/<owner>/<name>")
def tracker_GET(owner, name):

View File

@ -44,9 +44,9 @@
class="nav-link">edit</a>
</li>
{% endif %}
{% if current_user %}
<li class="flex-grow-1 d-none d-md-block"></li>
<li class="nav-item">
{% if current_user %}
<button
class="nav-link active"
{% if tracker_sub %}
@ -64,8 +64,14 @@
{% endif %}
{{icon("caret-right")}}
</button>
{% else %}
<a class="nav-link active" href="{{ ticket_subscribe }}">
{{icon("envelope-o")}}
Subscribe
{{icon("caret-right")}}
</a>
{% endif %}
</li>
{% endif %}
</ul>
{% if not tracker_sub %}
</form>

View File

@ -43,9 +43,9 @@
>settings</a>
</li>
{% endif %}
{% if current_user %}
<li class="flex-grow-1 d-none d-sm-block"></li>
<li class="nav-item d-none d-sm-block">
{% if current_user %}
<form method="POST" action="{{url_for("tracker." +
("disable_notifications" if is_subscribed else "enable_notifications"),
owner=tracker.owner.canonical_name,
@ -61,8 +61,14 @@
{{icon("caret-right")}}
</button>
</form>
{% else %}
<a class="nav-link active" href="{{ tracker_subscribe }}">
{{icon("envelope-o")}}
Subscribe
{{icon("caret-right")}}
</a>
{% endif %}
</li>
{% endif %}
</ul>
</div>
</div>