{% extends "base.html" %}
{% load gravatar i18n %}
{% load use_ssh from services %}
+{% load use_email from emails %}
{% block content %}
<aside class="menu">
{% block menu %}
<p><a {% if menu == 'profile' %}class="active"{% endif %} href="{% url 'accounts_profile' %}">{% trans "Your profile" %}</a></p>
<p><a {% if menu == 'password' %}class="active"{% endif %} href="{% url 'password_change' %}">{% trans "Password change" %}</a></p>
- <!--p><a {% if menu == 'email' %}class="active"{% endif %} href="">{% trans "E-mail" %}</a></p-->
+ {% use_email as use_email %}
+ {% if use_email %}
+ <p><a {% if menu == 'email' %}class="active"{% endif %} href="{% url 'emails' %}">{% trans "E-mail" %}</a></p>
+ {% endif %}
{% use_ssh as use_ssh %}
{% if use_ssh %}
<p><a {% if menu == 'ssh' %}class="active"{% endif %} href="{% url 'ssh_keys' %}">{% trans "SSH keys" %}</a></p>
path('admin/', admin.site.urls),
path('accounts/', include('accounts.urls')),
+ path('email/', include('emails.urls')),
path('services/', include('services.urls')),
path('ssh/', include('ssh_keys.urls')),
path('auth/', include('django.contrib.auth.urls')),
+from django.conf import settings
+
+
+BASE_DOMAINS = getattr(settings, 'EMAILS_BASE_DOMAINS', [])
from django.db import models
from django.utils.translation import ugettext_lazy as _
+from . import BASE_DOMAINS
+
class Alias(models.Model):
def __str__(self):
return '{} -> {}'.format(self.source, self.destination)
+
+ @classmethod
+ def get_from_user(cls, user):
+ lookups = ["{}@{}".format(user.username, domain) for domain in BASE_DOMAINS]
+ return cls.objects.filter(source__in=lookups)
+
+ @classmethod
+ def get_to_user(cls, user):
+ lookups = ["{}@{}".format(user.username, domain) for domain in BASE_DOMAINS]
+ return cls.objects.filter(destination__in=lookups)
--- /dev/null
+{% extends "account/base.html" %}
+
+
+{% block menu %}
+ {% with menu='email' %}
+ {{ block.super }}
+ {% endwith %}
+{% endblock %}
--- /dev/null
+{% load list_aliases from emails %}
+<ul>
+ {% for alias in aliases %}
+ <li>
+ {% if admin_links %}
+ <a href="{% url 'admin:emails_alias_changelist' %}?source__exact={{ alias }}">
+ {% endif %}
+ {{ alias }}
+ {% if admin_links %}</a>{% endif %}
+ {% list_aliases alias %}
+ </li>
+ {% endfor %}
+</ul>
--- /dev/null
+{% extends "emails/base.html" %}
+{% load i18n %}
+{% load list_aliases from emails %}
+
+
+{% block accounts-content %}
+ <h1>{% trans "E-mail" %}</h1>
+
+ <h2>{% trans "Default addresses" %}:</h2>
+ <ul>
+ {% for a in base %}
+ <li>{{ a }}</li>
+ {% endfor %}
+ </ul>
+
+ <h2>{% trans "Aliases" %}:</h2>
+ {% list_aliases base %}
+
+ {% if from_me %}
+ <h2>{% trans "E-mail forwarded to" %}:</h2>
+ <ul>
+ {% for alias in from_me %}
+ <li>{{ alias.destination }}</li>
+ {% endfor %}
+ </ul>
+ {% endif %}
+
+{% endblock %}
--- /dev/null
+from django.template import Library
+from emails.models import Alias
+
+
+register = Library()
+
+
+@register.simple_tag(takes_context=True)
+def use_email(context):
+ user = context['request'].user
+ if user.is_anonymous: return False
+ return user.groups.filter(name='e-mail').exists()
+
+
+@register.inclusion_tag('emails/list_aliases.html', takes_context=True)
+def list_aliases(context, emails):
+ if isinstance(emails, str):
+ emails = [emails]
+ admin_links = context.get('admin_links', context['request'].user.has_perm('emails.can_change_alias'))
+ return {
+ "admin_links": admin_links,
+ "aliases": [a.source for a in Alias.objects.filter(destination__in=emails)],
+ "request": context['request'],
+ }
--- /dev/null
+from django.urls import path
+from . import views
+
+
+urlpatterns = [
+ path('', views.my_aliases, name='emails')
+]
--- /dev/null
+from django.contrib.auth.decorators import login_required
+from django.shortcuts import render
+from .models import Alias
+from . import BASE_DOMAINS
+
+
+@login_required
+def my_aliases(request):
+ return render(request, 'emails/my_aliases.html', {
+ 'base': ['{}@{}'.format(request.user.username, dom) for dom in BASE_DOMAINS],
+ 'to_me': Alias.get_to_user(request.user),
+ 'from_me': Alias.get_from_user(request.user),
+ })
@register.simple_tag(takes_context=True)
def use_ssh(context):
user = context['request'].user
- if user.is_anonymous: return True
+ if user.is_anonymous: return False
return Service.for_user(user).filter(uses_ssh=True).exists()