diff --git a/authentik/core/api/application_entitlements.py b/authentik/core/api/application_entitlements.py index 870dd0b5f7..9e3b02fa6d 100644 --- a/authentik/core/api/application_entitlements.py +++ b/authentik/core/api/application_entitlements.py @@ -1,15 +1,16 @@ """Application Roles API Viewset""" +from django.http import HttpRequest from django.utils.translation import gettext_lazy as _ from rest_framework.exceptions import ValidationError from rest_framework.viewsets import ModelViewSet +from authentik.blueprints.v1.importer import SERIALIZER_CONTEXT_BLUEPRINT from authentik.core.api.used_by import UsedByMixin from authentik.core.api.utils import ModelSerializer from authentik.core.models import ( Application, ApplicationEntitlement, - User, ) @@ -18,7 +19,10 @@ class ApplicationEntitlementSerializer(ModelSerializer): def validate_app(self, app: Application) -> Application: """Ensure user has permission to view""" - user: User = self._context["request"].user + request: HttpRequest = self.context.get("request") + if not request and SERIALIZER_CONTEXT_BLUEPRINT in self.context: + return app + user = request.user if user.has_perm("view_application", app) or user.has_perm( "authentik_core.view_application" ):