Skip to content

Commit

Permalink
Component: Add option to one time subscribe to unlock event
Browse files Browse the repository at this point in the history
Fixes #4077
  • Loading branch information
nijel committed Jun 30, 2020
1 parent 8550f2c commit 95fb213
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions weblate/accounts/urls.py
Expand Up @@ -71,6 +71,7 @@
url(r"^profile/$", weblate.accounts.views.user_profile, name="profile"),
url(r"^userdata/$", weblate.accounts.views.userdata, name="userdata"),
url(r"^unsubscribe/$", weblate.accounts.views.unsubscribe, name="unsubscribe"),
url(r"^subscribe/$", weblate.accounts.views.subscribe, name="subscribe"),
url(r"^watch/(?P<project>[^/]+)/$", weblate.accounts.views.watch, name="watch"),
url(
r"^unwatch/(?P<project>[^/]+)/$", weblate.accounts.views.unwatch, name="unwatch"
Expand Down
22 changes: 22 additions & 0 deletions weblate/accounts/views.py
Expand Up @@ -94,6 +94,7 @@
)
from weblate.accounts.models import AuditLog, Subscription, VerifiedEmail
from weblate.accounts.notifications import (
FREQ_INSTANT,
FREQ_NONE,
NOTIFICATIONS,
SCOPE_ADMIN,
Expand Down Expand Up @@ -1096,6 +1097,27 @@ def social_complete(request, backend):
)


@login_required
@require_POST
def subscribe(request):
if "onetime" in request.POST:
component = Component.objects.get(pk=request.POST["component"])
request.user.check_access_component(component)
subscription = Subscription(
user=request.user,
notification=request.POST["onetime"],
scope=SCOPE_COMPONENT,
frequency=FREQ_INSTANT,
component=component,
project=component.project,
onetime=True,
)
subscription.full_clean()
subscription.save()
messages.success(request, _("Notification settings adjusted."))
return redirect_profile("#notifications")


def unsubscribe(request):
if "i" in request.GET:
signer = TimestampSigner()
Expand Down
12 changes: 12 additions & 0 deletions weblate/templates/snippets/component/lock.html
@@ -0,0 +1,12 @@
{% extends "message.html" %}
{% load i18n %}

{% block tags %}warning{% endblock %}

{% block message %}
{% if user.is_authenticated %}
<a href="{% url 'subscribe' %}" data-params='{"onetime":"LockNotification","component":{{object.pk }}}' class="btn btn-primary pull-right flip link-post">{% trans "Get notified when this project is unlocked again" %}</a>
{% endif %}
{% trans "The translation is temporarily closed for contributions due to maintenance, please come back later." %}
<div class="clearfix"></div>
{% endblock %}
4 changes: 2 additions & 2 deletions weblate/templates/snippets/component/state.html
@@ -1,8 +1,8 @@
{% load translations %}
{% load i18n %}

{% if object.locked %}
{% trans "The translation is temporarily closed for contributions due to maintenance, please come back later." as msg %}
{% show_message "warning" msg %}
{% include "snippets/component/lock.html" %}
{% endif %}

{% show_contributor_agreement object %}
Expand Down

0 comments on commit 95fb213

Please sign in to comment.