X-Git-Url: https://git.mdrn.pl/cas.git/blobdiff_plain/21765da5d86c0c20f785523ac5839c14e89f1237..48ac19869348402509d20001d1132d5c63468055:/src/emails/views.py diff --git a/src/emails/views.py b/src/emails/views.py index 16fa837..dc89aaa 100644 --- a/src/emails/views.py +++ b/src/emails/views.py @@ -1,13 +1,22 @@ -from django.contrib.auth.decorators import login_required -from django.shortcuts import render +from django.contrib.auth.decorators import login_required, permission_required +from django.contrib.auth.models import User +from django.shortcuts import render, get_object_or_404 from .models import Alias from . import BASE_DOMAINS @login_required -def my_aliases(request): +def my_aliases(request, user=None): + user = user or request.user 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), + 'user': user, + 'base': ['{}@{}'.format(user.username, dom) for dom in BASE_DOMAINS], + 'from_me': Alias.get_from_user(user), }) + + +@permission_required('emails.can_add_alias') +def user_aliases(request, username): + user = get_object_or_404(User, username=username) + return my_aliases(request, user=user) +