Skip to content

Commit

Permalink
Revert "Revert "core: applications api: add option to only list apps …
Browse files Browse the repository at this point in the history
…with launch url (#10336)""

This reverts commit 1eb9d7a.
  • Loading branch information
BeryJu committed Jul 4, 2024
1 parent 8b0058a commit 36e4184
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions authentik/core/api/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ def _get_allowed_applications(
applications.append(application)
return applications

def _filter_applications_with_launch_url(self, pagined_apps: Iterator[Application]) -> list[Application]:
applications = []
for app in pagined_apps:
if app.get_launch_url():
applications.append(app)
return applications

@extend_schema(
parameters=[
OpenApiParameter(
Expand Down Expand Up @@ -212,6 +219,11 @@ def check_access(self, request: Request, slug: str) -> Response:
location=OpenApiParameter.QUERY,
type=OpenApiTypes.INT,
),
OpenApiParameter(
name="only_with_launch_url",
location=OpenApiParameter.QUERY,
type=OpenApiTypes.BOOL,
),
]
)
def list(self, request: Request) -> Response:
Expand All @@ -224,6 +236,8 @@ def list(self, request: Request) -> Response:
if superuser_full_list and request.user.is_superuser:
return super().list(request)

only_with_launch_url = str(request.query_params.get("only_with_launch_url", "false")).lower()

queryset = self._filter_queryset_for_list(self.get_queryset())
paginator: Pagination = self.paginator
paginated_apps = paginator.paginate_queryset(queryset, request)
Expand Down Expand Up @@ -259,6 +273,10 @@ def list(self, request: Request) -> Response:
allowed_applications,
timeout=86400,
)

if only_with_launch_url == "true":
allowed_applications = self._filter_applications_with_launch_url(allowed_applications)

serializer = self.get_serializer(allowed_applications, many=True)
return self.get_paginated_response(serializer.data)

Expand Down
5 changes: 5 additions & 0 deletions authentik/core/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""authentik core models"""

from datetime import datetime
from functools import lru_cache
from hashlib import sha256
from typing import Any, Optional, Self
from uuid import uuid4
Expand Down Expand Up @@ -475,6 +476,10 @@ def get_meta_icon(self) -> str | None:
return self.meta_icon.name
return self.meta_icon.url

# maxsize is set as 2 since that is called once to check
# if we should return applications with a launch URL
# and a second time to actually get the launch_url
@lru_cache(maxsize=2)
def get_launch_url(self, user: Optional["User"] = None) -> str | None:
"""Get launch URL if set, otherwise attempt to get launch URL based on provider."""
url = None
Expand Down
4 changes: 4 additions & 0 deletions schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2682,6 +2682,10 @@ paths:
name: name
schema:
type: string
- in: query
name: only_with_launch_url
schema:
type: boolean
- name: ordering
required: false
in: query
Expand Down
1 change: 1 addition & 0 deletions web/src/user/LibraryPage/ak-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class LibraryPage extends AKElement {
ordering: "name",
page,
pageSize: 100,
onlyWithLaunchUrl: true,
});

const applicationListFetch = await coreApi().coreApplicationsList(applicationListParams(1));
Expand Down

0 comments on commit 36e4184

Please sign in to comment.