redirect to profile if no email when subscribe

This commit is contained in:
Élie Bouttier 2014-09-02 21:36:03 -07:00
parent 432db03fc0
commit aef23ff7ae
3 changed files with 12 additions and 2 deletions

View file

@ -19,11 +19,13 @@
</form> </form>
{% endcomment %} {% endcomment %}
{% if request.user in project.subscribers.all %} {% if request.user.is_authenticated %}
{% if request.user.email and request.user in project.subscribers.all %}
<li><a href="{% url 'unsubscribe-project' project.name %}?next={{ request.get_full_path }}"><span class="glyphicon glyphicon-eye-close"></span> Unwatch</a></li> <li><a href="{% url 'unsubscribe-project' project.name %}?next={{ request.get_full_path }}"><span class="glyphicon glyphicon-eye-close"></span> Unwatch</a></li>
{% else %} {% else %}
<li><a href="{% url 'subscribe-project' project.name %}?next={{ request.get_full_path }}"><span class="glyphicon glyphicon-eye-open"></span> Watch</a></li> <li><a href="{% url 'subscribe-project' project.name %}?next={{ request.get_full_path }}"><span class="glyphicon glyphicon-eye-open"></span> Watch</a></li>
{% endif %} {% endif %}
{% endif %}
{% if perm.manage_project_permission or perm.modify_project or perm.delete_project %} {% if perm.manage_project_permission or perm.modify_project or perm.delete_project %}
<li class="dropdown"> <li class="dropdown">

View file

@ -193,7 +193,7 @@
</h5> </h5>
<div class="row"> <div class="row">
<span style="display: inline-block; margin-left: 14px;"></span> <span style="display: inline-block; margin-left: 14px;"></span>
{% if request.user in project.subscribers.all %} {% if request.user.email and request.user in project.subscribers.all %}
Subscribed to the project Subscribed to the project
{% else %} {% else %}
{% if request.user in issue.subscribers.all %} {% if request.user in issue.subscribers.all %}

View file

@ -121,6 +121,10 @@ def project_delete(request, project):
@login_required @login_required
def project_subscribe(request, project): def project_subscribe(request, project):
if not request.user.email:
messages.error(request, 'You must set an email address in order to receive notifications.')
return redirect('profile')
if project.subscribers.filter(pk=request.user.pk).exists(): if project.subscribers.filter(pk=request.user.pk).exists():
messages.warning(request, messages.warning(request,
'You are already subscribed to this project.') 'You are already subscribed to this project.')
@ -531,6 +535,10 @@ def issue_subscribe(request, project, issue):
issue = get_object_or_404(Issue, project=project, id=issue) issue = get_object_or_404(Issue, project=project, id=issue)
if not request.user.email:
messages.error(request, 'You must set an email address in order to receive notifications.')
return redirect('profile')
if issue.subscribers.filter(pk=request.user.pk).exists(): if issue.subscribers.filter(pk=request.user.pk).exists():
messages.warning(request, 'You are already subscribed to this issue.') messages.warning(request, 'You are already subscribed to this issue.')
else: else: