Commit 70545e0d by Karsa Zoltán István

add iac-token attribute to user profile

parent bc1ae921
...@@ -403,6 +403,15 @@ INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS ...@@ -403,6 +403,15 @@ INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
########## END APP CONFIGURATION ########## END APP CONFIGURATION
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAdminUser'
),
}
########## LOGGING CONFIGURATION ########## LOGGING CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#logging # See: https://docs.djangoproject.com/en/dev/ref/settings/#logging
# A sample logging configuration. The only tangible logging # A sample logging configuration. The only tangible logging
......
...@@ -42,6 +42,14 @@ ...@@ -42,6 +42,14 @@
{% trans "Email address" %}: {{ profile.email }} {% trans "Email address" %}: {{ profile.email }}
{% endif %} {% endif %}
</p> </p>
<p>
IAC-TOKEN:
{% if profile.is_superuser %}
<i>{{ iac_token }}</i>
{% else %}
for admin users only
{% endif %}
</p>
<p>{% trans "Last login" %}: <span title="{{ profile.last_login }}">{{ profile.last_login|arrowfilter:LANGUAGE_CODE}}</span></p> <p>{% trans "Last login" %}: <span title="{{ profile.last_login }}">{{ profile.last_login|arrowfilter:LANGUAGE_CODE}}</span></p>
{% if request.user == profile %} {% if request.user == profile %}
<p> <p>
......
...@@ -56,7 +56,7 @@ from ..models import Profile, GroupProfile, ConnectCommand ...@@ -56,7 +56,7 @@ from ..models import Profile, GroupProfile, ConnectCommand
from ..tables import ( from ..tables import (
UserKeyListTable, ConnectCommandListTable, UserListTable, UserKeyListTable, ConnectCommandListTable, UserListTable,
) )
from rest_framework.authtoken.models import Token
from .util import saml_available, DeleteViewBase, LoginView from .util import saml_available, DeleteViewBase, LoginView
try: try:
...@@ -68,6 +68,8 @@ except NameError: ...@@ -68,6 +68,8 @@ except NameError:
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def set_session_expiry(request, user): def set_session_expiry(request, user):
if user.is_superuser: if user.is_superuser:
messages.info(request, _("You've logged in with an administrator " messages.info(request, _("You've logged in with an administrator "
...@@ -387,6 +389,8 @@ class ProfileView(LoginRequiredMixin, SuccessMessageMixin, UpdateView): ...@@ -387,6 +389,8 @@ class ProfileView(LoginRequiredMixin, SuccessMessageMixin, UpdateView):
context['perm_email'] = ( context['perm_email'] = (
context['perm_group_list'] or self.request.user == user) context['perm_group_list'] or self.request.user == user)
context['iac_token'] = Token.objects.filter(user=user).get()
# filter the virtual machine list # filter the virtual machine list
# if the logged in user is not superuser or not the user itself # if the logged in user is not superuser or not the user itself
# filter the list so only those virtual machines are shown that are # filter the list so only those virtual machines are shown that are
......
...@@ -90,11 +90,11 @@ logger = logging.getLogger(__name__) ...@@ -90,11 +90,11 @@ logger = logging.getLogger(__name__)
from rest_framework import status from rest_framework import status
from rest_framework.decorators import api_view, authentication_classes, permission_classes from rest_framework.decorators import api_view, authentication_classes, permission_classes
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.authentication import SessionAuthentication, BasicAuthentication from rest_framework.authentication import TokenAuthentication
from rest_framework.permissions import IsAdminUser from rest_framework.permissions import IsAdminUser
@api_view(['GET']) @api_view(['GET'])
@authentication_classes([SessionAuthentication, BasicAuthentication]) @authentication_classes([TokenAuthentication])
@permission_classes([IsAdminUser]) @permission_classes([IsAdminUser])
def iac_vm_list(request): def iac_vm_list(request):
instances = Instance.objects.all() instances = Instance.objects.all()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment