From 2a8b4fed137430775e8618d1f627a54c75bb35c4 Mon Sep 17 00:00:00 2001 From: Dominic R Date: Sat, 1 Feb 2025 17:31:01 -0500 Subject: [PATCH 1/5] web: sources: disable "delete" button for built-in source --- web/src/admin/sources/SourceListPage.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/web/src/admin/sources/SourceListPage.ts b/web/src/admin/sources/SourceListPage.ts index a9af5d2336d0..dae995212ea3 100644 --- a/web/src/admin/sources/SourceListPage.ts +++ b/web/src/admin/sources/SourceListPage.ts @@ -57,10 +57,13 @@ export class SourceListPage extends TablePage { } renderToolbarSelected(): TemplateResult { - const disabled = this.selectedElements.length < 1; + const disabled = + this.selectedElements.length < 1 || + this.selectedElements.some((item) => item.component === ""); + const nonBuiltInSources = this.selectedElements.filter((item) => item.component !== ""); return html` { return new SourcesApi(DEFAULT_CONFIG).sourcesAllUsedByList({ slug: item.slug, From 3a6867777adc9ae6eac1afc6f61f50b1aa7814f2 Mon Sep 17 00:00:00 2001 From: Dominic R Date: Sat, 1 Feb 2025 17:52:38 -0500 Subject: [PATCH 2/5] poetry doesn't like that I use python 3.13 / implement check on backend too --- authentik/core/api/sources.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/authentik/core/api/sources.py b/authentik/core/api/sources.py index c7d8205dd2f1..c39826fc268e 100644 --- a/authentik/core/api/sources.py +++ b/authentik/core/api/sources.py @@ -10,6 +10,7 @@ from rest_framework.request import Request from rest_framework.response import Response from rest_framework.viewsets import GenericViewSet +from rest_framework.exceptions import ValidationError from structlog.stdlib import get_logger from authentik.blueprints.v1.importer import SERIALIZER_CONTEXT_BLUEPRINT @@ -154,6 +155,17 @@ def user_settings(self, request: Request) -> Response: matching_sources.append(source_settings.validated_data) return Response(matching_sources) + def destroy(self, request: Request, *args, **kwargs): + """Prevent deletion of built-in sources""" + instance = self.get_object() + + if instance.slug.startswith("authentik-built-in"): + raise ValidationError( + {"detail": "Built-in sources cannot be deleted"}, code="protected" + ) + + return super().destroy(request, *args, **kwargs) + class UserSourceConnectionSerializer(SourceSerializer): """User source connection""" From 567d43cc84c72e6a3a66daa3d6cd974150b305e8 Mon Sep 17 00:00:00 2001 From: Dominic R Date: Sat, 1 Feb 2025 17:58:59 -0500 Subject: [PATCH 3/5] fix ruff i think Signed-off-by: Dominic R --- authentik/core/api/sources.py | 1 - 1 file changed, 1 deletion(-) diff --git a/authentik/core/api/sources.py b/authentik/core/api/sources.py index c39826fc268e..1cbd2bcb839d 100644 --- a/authentik/core/api/sources.py +++ b/authentik/core/api/sources.py @@ -30,7 +30,6 @@ LOGGER = get_logger() - class SourceSerializer(ModelSerializer, MetaNameSerializer): """Source Serializer""" From d3fb8cb8ce1324eeceb8647e70d02745b1b99784 Mon Sep 17 00:00:00 2001 From: Dominic R Date: Sat, 1 Feb 2025 17:59:13 -0500 Subject: [PATCH 4/5] nvm Signed-off-by: Dominic R --- authentik/core/api/sources.py | 1 + 1 file changed, 1 insertion(+) diff --git a/authentik/core/api/sources.py b/authentik/core/api/sources.py index 1cbd2bcb839d..b9aa4251451b 100644 --- a/authentik/core/api/sources.py +++ b/authentik/core/api/sources.py @@ -28,6 +28,7 @@ from authentik.policies.engine import PolicyEngine from authentik.rbac.decorators import permission_required + LOGGER = get_logger() class SourceSerializer(ModelSerializer, MetaNameSerializer): From f4cacc43f6953e55c35f7bda27181520630d49f4 Mon Sep 17 00:00:00 2001 From: Dominic R Date: Sat, 1 Feb 2025 23:24:44 +0000 Subject: [PATCH 5/5] reformat --- authentik/core/api/sources.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/authentik/core/api/sources.py b/authentik/core/api/sources.py index b9aa4251451b..4dff85b45a0c 100644 --- a/authentik/core/api/sources.py +++ b/authentik/core/api/sources.py @@ -5,12 +5,12 @@ from drf_spectacular.utils import OpenApiResponse, extend_schema from rest_framework import mixins from rest_framework.decorators import action +from rest_framework.exceptions import ValidationError from rest_framework.fields import CharField, ReadOnlyField, SerializerMethodField from rest_framework.parsers import MultiPartParser from rest_framework.request import Request from rest_framework.response import Response from rest_framework.viewsets import GenericViewSet -from rest_framework.exceptions import ValidationError from structlog.stdlib import get_logger from authentik.blueprints.v1.importer import SERIALIZER_CONTEXT_BLUEPRINT @@ -28,9 +28,9 @@ from authentik.policies.engine import PolicyEngine from authentik.rbac.decorators import permission_required - LOGGER = get_logger() + class SourceSerializer(ModelSerializer, MetaNameSerializer): """Source Serializer"""