stash
This commit is contained in:
parent
fc3484fe22
commit
e005d6fb6f
4 changed files with 43 additions and 35 deletions
|
@ -12,25 +12,7 @@ from knox.models import AuthToken
|
|||
from knox.views import LoginView as KnoxLoginView
|
||||
|
||||
from authentication.models import ExtendedUser
|
||||
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
permissions = serializers.SerializerMethodField()
|
||||
groups = serializers.SlugRelatedField(many=True, read_only=True, slug_field='name')
|
||||
|
||||
class Meta:
|
||||
model = ExtendedUser
|
||||
fields = ('id', 'username', 'email', 'first_name', 'last_name', 'permissions', 'groups')
|
||||
read_only_fields = ('id', 'username', 'email', 'first_name', 'last_name', 'permissions', 'groups')
|
||||
|
||||
def get_permissions(self, obj):
|
||||
return list(set(obj.get_permissions()))
|
||||
|
||||
|
||||
@receiver(post_save, sender=ExtendedUser)
|
||||
def create_auth_token(sender, instance=None, created=False, **kwargs):
|
||||
if created:
|
||||
AuthToken.objects.create(user=instance)
|
||||
from authentication.serializers import UserSerializer, GroupSerializer
|
||||
|
||||
|
||||
class UserViewSet(viewsets.ModelViewSet):
|
||||
|
@ -38,26 +20,17 @@ class UserViewSet(viewsets.ModelViewSet):
|
|||
serializer_class = UserSerializer
|
||||
|
||||
|
||||
class GroupSerializer(serializers.ModelSerializer):
|
||||
permissions = serializers.SerializerMethodField()
|
||||
members = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = Group
|
||||
fields = ('id', 'name', 'permissions', 'members')
|
||||
|
||||
def get_permissions(self, obj):
|
||||
return ["*:" + p.codename for p in obj.permissions.all()]
|
||||
|
||||
def get_members(self, obj):
|
||||
return [u.username for u in obj.user_set.all()]
|
||||
|
||||
|
||||
class GroupViewSet(viewsets.ModelViewSet):
|
||||
queryset = Group.objects.all()
|
||||
serializer_class = GroupSerializer
|
||||
|
||||
|
||||
@receiver(post_save, sender=ExtendedUser)
|
||||
def create_auth_token(sender, instance=None, created=False, **kwargs):
|
||||
if created:
|
||||
AuthToken.objects.create(user=instance)
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
@permission_classes([IsAuthenticated])
|
||||
def selfUser(request):
|
||||
|
|
32
core/authentication/serializers.py
Normal file
32
core/authentication/serializers.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
from rest_framework import serializers
|
||||
from django.contrib.auth.models import Group
|
||||
|
||||
from authentication.models import ExtendedUser
|
||||
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
permissions = serializers.SerializerMethodField()
|
||||
groups = serializers.SlugRelatedField(many=True, read_only=True, slug_field='name')
|
||||
|
||||
class Meta:
|
||||
model = ExtendedUser
|
||||
fields = ('id', 'username', 'email', 'first_name', 'last_name', 'permissions', 'groups')
|
||||
read_only_fields = ('id', 'username', 'email', 'first_name', 'last_name', 'permissions', 'groups')
|
||||
|
||||
def get_permissions(self, obj):
|
||||
return list(set(obj.get_permissions()))
|
||||
|
||||
|
||||
class GroupSerializer(serializers.ModelSerializer):
|
||||
permissions = serializers.SerializerMethodField()
|
||||
members = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = Group
|
||||
fields = ('id', 'name', 'permissions', 'members')
|
||||
|
||||
def get_permissions(self, obj):
|
||||
return ["*:" + p.codename for p in obj.permissions.all()]
|
||||
|
||||
def get_members(self, obj):
|
||||
return [u.username for u in obj.user_set.all()]
|
|
@ -9,6 +9,7 @@ from notifications.models import MessageTemplate, UserNotificationChannel
|
|||
from rest_framework import serializers
|
||||
|
||||
from notifications.templates import TEMPLATE_VARS
|
||||
from authentication.serializers import UserSerializer
|
||||
|
||||
|
||||
class MessageTemplateSerializer(serializers.ModelSerializer):
|
||||
|
@ -18,6 +19,8 @@ class MessageTemplateSerializer(serializers.ModelSerializer):
|
|||
|
||||
|
||||
class UserNotificationChannelSerializer(serializers.ModelSerializer):
|
||||
user = UserSerializer()
|
||||
|
||||
class Meta:
|
||||
model = UserNotificationChannel
|
||||
fields = '__all__'
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<template>
|
||||
<ul>
|
||||
<li v-for="channel in userNotificationChannels" :key="channel.id">
|
||||
{{ channel.name }}
|
||||
{{ channel.id }} - {{ channel.channel_type }} - {{ channel.channel_target }} - {{ channel.event_filter }} - {{ channel.active }} - {{ channel.created }} - {{ channel.user }}
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
|
|
Loading…
Reference in a new issue