Other user aliases view.
[cas.git] / src / emails / views.py
1 from django.contrib.auth.decorators import login_required, permission_required
2 from django.contrib.auth.models import User
3 from django.shortcuts import render, get_object_or_404
4 from .models import Alias
5 from . import BASE_DOMAINS
6
7
8 @login_required
9 def my_aliases(request, user=None):
10     user = user or request.user  
11     return render(request, 'emails/my_aliases.html', {
12         'base': ['{}@{}'.format(user.username, dom) for dom in BASE_DOMAINS],
13         'from_me': Alias.get_from_user(user),
14         })
15
16
17 @permission_required('emails.can_add_alias')
18 def user_aliases(request, username):
19     user = get_object_or_404(User, username=username)
20     return my_aliases(request, user=user)
21