Other user aliases view.
authorRadek Czajka <rczajka@rczajka.pl>
Fri, 5 Apr 2019 12:52:48 +0000 (14:52 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Fri, 5 Apr 2019 12:53:51 +0000 (14:53 +0200)
src/emails/urls.py
src/emails/views.py

index 9e385e0..6d3d420 100644 (file)
@@ -3,5 +3,6 @@ from . import views
 
 
 urlpatterns = [
 
 
 urlpatterns = [
-    path('', views.my_aliases, name='emails')
+    path('', views.my_aliases, name='emails'),
+    path('user/<username>/', views.user_aliases, name='emails_user'),
 ]
 ]
index 16fa837..5c40218 100644 (file)
@@ -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
 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', {
     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)
+