From: Radek Czajka Date: Fri, 5 Apr 2019 12:52:48 +0000 (+0200) Subject: Other user aliases view. X-Git-Url: https://git.mdrn.pl/cas.git/commitdiff_plain/122f148a7c94368973e13f0d868f3e520a544d01?ds=inline;hp=-c Other user aliases view. --- 122f148a7c94368973e13f0d868f3e520a544d01 diff --git a/src/emails/urls.py b/src/emails/urls.py index 9e385e0..6d3d420 100644 --- a/src/emails/urls.py +++ b/src/emails/urls.py @@ -3,5 +3,6 @@ from . import views urlpatterns = [ - path('', views.my_aliases, name='emails') + path('', views.my_aliases, name='emails'), + path('user//', views.user_aliases, name='emails_user'), ] diff --git a/src/emails/views.py b/src/emails/views.py index 16fa837..5c40218 100644 --- a/src/emails/views.py +++ b/src/emails/views.py @@ -1,13 +1,21 @@ -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), + '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) +