mirror of
https://github.com/goauthentik/authentik.git
synced 2026-06-17 19:09:11 +03:00
sources: refactor user connection api (#10607)
This commit is contained in:
committed by
GitHub
parent
984d64630b
commit
e65b905301
@@ -190,6 +190,7 @@ class UserSourceConnectionViewSet(
|
||||
queryset = UserSourceConnection.objects.all()
|
||||
serializer_class = UserSourceConnectionSerializer
|
||||
permission_classes = [OwnerSuperuserPermissions]
|
||||
filterset_fields = ["user"]
|
||||
filterset_fields = ["user", "source__slug"]
|
||||
search_fields = ["source__slug"]
|
||||
filter_backends = [OwnerFilter, DjangoFilterBackend, OrderingFilter, SearchFilter]
|
||||
ordering = ["pk"]
|
||||
ordering = ["source__slug", "pk"]
|
||||
|
||||
@@ -1,33 +1,28 @@
|
||||
"""OAuth Source Serializer"""
|
||||
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
from rest_framework.filters import OrderingFilter, SearchFilter
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
|
||||
from authentik.api.authorization import OwnerFilter, OwnerSuperuserPermissions
|
||||
from authentik.core.api.sources import UserSourceConnectionSerializer
|
||||
from authentik.core.api.used_by import UsedByMixin
|
||||
from authentik.core.api.sources import (
|
||||
UserSourceConnectionSerializer,
|
||||
UserSourceConnectionViewSet,
|
||||
)
|
||||
from authentik.sources.oauth.models import UserOAuthSourceConnection
|
||||
|
||||
|
||||
class UserOAuthSourceConnectionSerializer(UserSourceConnectionSerializer):
|
||||
"""OAuth Source Serializer"""
|
||||
|
||||
class Meta:
|
||||
class Meta(UserSourceConnectionSerializer.Meta):
|
||||
model = UserOAuthSourceConnection
|
||||
fields = ["pk", "user", "source", "identifier", "access_token"]
|
||||
fields = UserSourceConnectionSerializer.Meta.fields + ["identifier", "access_token"]
|
||||
extra_kwargs = {
|
||||
**UserSourceConnectionSerializer.Meta.extra_kwargs,
|
||||
"access_token": {"write_only": True},
|
||||
}
|
||||
|
||||
|
||||
class UserOAuthSourceConnectionViewSet(UsedByMixin, ModelViewSet):
|
||||
class UserOAuthSourceConnectionViewSet(UserSourceConnectionViewSet, ModelViewSet):
|
||||
"""Source Viewset"""
|
||||
|
||||
queryset = UserOAuthSourceConnection.objects.all()
|
||||
serializer_class = UserOAuthSourceConnectionSerializer
|
||||
filterset_fields = ["source__slug"]
|
||||
search_fields = ["source__slug"]
|
||||
permission_classes = [OwnerSuperuserPermissions]
|
||||
filter_backends = [OwnerFilter, DjangoFilterBackend, OrderingFilter, SearchFilter]
|
||||
ordering = ["source__slug"]
|
||||
|
||||
@@ -1,39 +1,28 @@
|
||||
"""Plex Source connection Serializer"""
|
||||
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
from rest_framework.filters import OrderingFilter, SearchFilter
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
|
||||
from authentik.api.authorization import OwnerFilter, OwnerSuperuserPermissions
|
||||
from authentik.core.api.sources import UserSourceConnectionSerializer
|
||||
from authentik.core.api.used_by import UsedByMixin
|
||||
from authentik.core.api.sources import UserSourceConnectionSerializer, UserSourceConnectionViewSet
|
||||
from authentik.sources.plex.models import PlexSourceConnection
|
||||
|
||||
|
||||
class PlexSourceConnectionSerializer(UserSourceConnectionSerializer):
|
||||
"""Plex Source connection Serializer"""
|
||||
|
||||
class Meta:
|
||||
class Meta(UserSourceConnectionSerializer.Meta):
|
||||
model = PlexSourceConnection
|
||||
fields = [
|
||||
"pk",
|
||||
"user",
|
||||
"source",
|
||||
fields = UserSourceConnectionSerializer.Meta.fields + [
|
||||
"identifier",
|
||||
"plex_token",
|
||||
]
|
||||
extra_kwargs = {
|
||||
"user": {"read_only": True},
|
||||
**UserSourceConnectionSerializer.Meta.extra_kwargs,
|
||||
"plex_token": {"write_only": True},
|
||||
}
|
||||
|
||||
|
||||
class PlexSourceConnectionViewSet(UsedByMixin, ModelViewSet):
|
||||
class PlexSourceConnectionViewSet(UserSourceConnectionViewSet, ModelViewSet):
|
||||
"""Plex Source connection Serializer"""
|
||||
|
||||
queryset = PlexSourceConnection.objects.all()
|
||||
serializer_class = PlexSourceConnectionSerializer
|
||||
filterset_fields = ["source__slug"]
|
||||
permission_classes = [OwnerSuperuserPermissions]
|
||||
filter_backends = [OwnerFilter, DjangoFilterBackend, OrderingFilter, SearchFilter]
|
||||
ordering = ["pk"]
|
||||
search_fields = ["source__slug"]
|
||||
|
||||
@@ -1,30 +1,24 @@
|
||||
"""SAML Source Serializer"""
|
||||
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
from rest_framework.filters import OrderingFilter, SearchFilter
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
|
||||
from authentik.api.authorization import OwnerFilter, OwnerSuperuserPermissions
|
||||
from authentik.core.api.sources import UserSourceConnectionSerializer
|
||||
from authentik.core.api.used_by import UsedByMixin
|
||||
from authentik.core.api.sources import (
|
||||
UserSourceConnectionSerializer,
|
||||
UserSourceConnectionViewSet,
|
||||
)
|
||||
from authentik.sources.saml.models import UserSAMLSourceConnection
|
||||
|
||||
|
||||
class UserSAMLSourceConnectionSerializer(UserSourceConnectionSerializer):
|
||||
"""SAML Source Serializer"""
|
||||
|
||||
class Meta:
|
||||
class Meta(UserSourceConnectionSerializer.Meta):
|
||||
model = UserSAMLSourceConnection
|
||||
fields = ["pk", "user", "source", "identifier"]
|
||||
fields = UserSourceConnectionSerializer.Meta.fields + ["identifier"]
|
||||
|
||||
|
||||
class UserSAMLSourceConnectionViewSet(UsedByMixin, ModelViewSet):
|
||||
class UserSAMLSourceConnectionViewSet(UserSourceConnectionViewSet, ModelViewSet):
|
||||
"""Source Viewset"""
|
||||
|
||||
queryset = UserSAMLSourceConnection.objects.all()
|
||||
serializer_class = UserSAMLSourceConnectionSerializer
|
||||
filterset_fields = ["source__slug"]
|
||||
search_fields = ["source__slug"]
|
||||
permission_classes = [OwnerSuperuserPermissions]
|
||||
filter_backends = [OwnerFilter, DjangoFilterBackend, OrderingFilter, SearchFilter]
|
||||
ordering = ["source__slug"]
|
||||
|
||||
@@ -4816,10 +4816,6 @@
|
||||
"model_authentik_sources_oauth.useroauthsourceconnection": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user": {
|
||||
"type": "integer",
|
||||
"title": "User"
|
||||
},
|
||||
"identifier": {
|
||||
"type": "string",
|
||||
"maxLength": 255,
|
||||
@@ -5154,10 +5150,6 @@
|
||||
"model_authentik_sources_saml.usersamlsourceconnection": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user": {
|
||||
"type": "integer",
|
||||
"title": "User"
|
||||
},
|
||||
"identifier": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
|
||||
+35
-13
@@ -24472,6 +24472,10 @@ paths:
|
||||
description: A search term.
|
||||
schema:
|
||||
type: string
|
||||
- in: query
|
||||
name: source__slug
|
||||
schema:
|
||||
type: string
|
||||
- in: query
|
||||
name: user
|
||||
schema:
|
||||
@@ -24697,6 +24701,10 @@ paths:
|
||||
name: source__slug
|
||||
schema:
|
||||
type: string
|
||||
- in: query
|
||||
name: user
|
||||
schema:
|
||||
type: integer
|
||||
tags:
|
||||
- sources
|
||||
security:
|
||||
@@ -24961,6 +24969,10 @@ paths:
|
||||
name: source__slug
|
||||
schema:
|
||||
type: string
|
||||
- in: query
|
||||
name: user
|
||||
schema:
|
||||
type: integer
|
||||
tags:
|
||||
- sources
|
||||
security:
|
||||
@@ -25225,6 +25237,10 @@ paths:
|
||||
name: source__slug
|
||||
schema:
|
||||
type: string
|
||||
- in: query
|
||||
name: user
|
||||
schema:
|
||||
type: integer
|
||||
tags:
|
||||
- sources
|
||||
security:
|
||||
@@ -42880,6 +42896,7 @@ components:
|
||||
minLength: 1
|
||||
plex_token:
|
||||
type: string
|
||||
writeOnly: true
|
||||
minLength: 1
|
||||
PatchedPlexSourceRequest:
|
||||
type: object
|
||||
@@ -43773,8 +43790,6 @@ components:
|
||||
type: object
|
||||
description: OAuth Source Serializer
|
||||
properties:
|
||||
user:
|
||||
type: integer
|
||||
identifier:
|
||||
type: string
|
||||
minLength: 1
|
||||
@@ -43825,8 +43840,6 @@ components:
|
||||
type: object
|
||||
description: SAML Source Serializer
|
||||
properties:
|
||||
user:
|
||||
type: integer
|
||||
identifier:
|
||||
type: string
|
||||
minLength: 1
|
||||
@@ -44062,14 +44075,16 @@ components:
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/Source'
|
||||
readOnly: true
|
||||
created:
|
||||
type: string
|
||||
format: date-time
|
||||
readOnly: true
|
||||
identifier:
|
||||
type: string
|
||||
plex_token:
|
||||
type: string
|
||||
required:
|
||||
- created
|
||||
- identifier
|
||||
- pk
|
||||
- plex_token
|
||||
- source
|
||||
- user
|
||||
PlexSourceConnectionRequest:
|
||||
@@ -44081,6 +44096,7 @@ components:
|
||||
minLength: 1
|
||||
plex_token:
|
||||
type: string
|
||||
writeOnly: true
|
||||
minLength: 1
|
||||
required:
|
||||
- identifier
|
||||
@@ -48372,14 +48388,20 @@ components:
|
||||
title: ID
|
||||
user:
|
||||
type: integer
|
||||
readOnly: true
|
||||
source:
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/Source'
|
||||
readOnly: true
|
||||
created:
|
||||
type: string
|
||||
format: date-time
|
||||
readOnly: true
|
||||
identifier:
|
||||
type: string
|
||||
maxLength: 255
|
||||
required:
|
||||
- created
|
||||
- identifier
|
||||
- pk
|
||||
- source
|
||||
@@ -48388,8 +48410,6 @@ components:
|
||||
type: object
|
||||
description: OAuth Source Serializer
|
||||
properties:
|
||||
user:
|
||||
type: integer
|
||||
identifier:
|
||||
type: string
|
||||
minLength: 1
|
||||
@@ -48400,7 +48420,6 @@ components:
|
||||
nullable: true
|
||||
required:
|
||||
- identifier
|
||||
- user
|
||||
UserObjectPermission:
|
||||
type: object
|
||||
description: User-bound object level permission
|
||||
@@ -48501,13 +48520,19 @@ components:
|
||||
title: ID
|
||||
user:
|
||||
type: integer
|
||||
readOnly: true
|
||||
source:
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/Source'
|
||||
readOnly: true
|
||||
created:
|
||||
type: string
|
||||
format: date-time
|
||||
readOnly: true
|
||||
identifier:
|
||||
type: string
|
||||
required:
|
||||
- created
|
||||
- identifier
|
||||
- pk
|
||||
- source
|
||||
@@ -48516,14 +48541,11 @@ components:
|
||||
type: object
|
||||
description: SAML Source Serializer
|
||||
properties:
|
||||
user:
|
||||
type: integer
|
||||
identifier:
|
||||
type: string
|
||||
minLength: 1
|
||||
required:
|
||||
- identifier
|
||||
- user
|
||||
UserSelf:
|
||||
type: object
|
||||
description: User Serializer for information a user can retrieve about themselves
|
||||
|
||||
Reference in New Issue
Block a user