-
-
Notifications
You must be signed in to change notification settings - Fork 998
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
web/admin: rework initial wizard pages and add grid layout (#9668)
* remove @goauthentik/authentik as TS path Signed-off-by: Jens Langhammer <jens@goauthentik.io> * initial implementation Signed-off-by: Jens Langhammer <jens@goauthentik.io> * oh yeah Signed-off-by: Jens Langhammer <jens@goauthentik.io> * format earlier changes Signed-off-by: Jens Langhammer <jens@goauthentik.io> * support plain alert Signed-off-by: Jens Langhammer <jens@goauthentik.io> * initial attempt at dedupe Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make it a base class Signed-off-by: Jens Langhammer <jens@goauthentik.io> * migrate all wizards Signed-off-by: Jens Langhammer <jens@goauthentik.io> * create type create mixin to dedupe more, add icon to source create Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add ldap icon Signed-off-by: Jens Langhammer <jens@goauthentik.io> * Optimised images with calibre/image-actions * match inverting we should probably replace all icons with coloured ones so we don't need to invert them...I guess Signed-off-by: Jens Langhammer <jens@goauthentik.io> * format Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make everything more explicit Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add icons to provider Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add remaining provider icons Signed-off-by: Jens Langhammer <jens@goauthentik.io> * rework to not use inheritance Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix unrelated typo Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make app wizard use grid layout Signed-off-by: Jens Langhammer <jens@goauthentik.io> * keep wizard height consistent Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io> Co-authored-by: authentik-automation[bot] <135050075+authentik-automation[bot]@users.noreply.github.com>
- Loading branch information
1 parent
0ed4bba
commit 6c4c535
Showing
58 changed files
with
726 additions
and
791 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
"""API Utilities""" | ||
|
||
from drf_spectacular.utils import extend_schema | ||
from rest_framework.decorators import action | ||
from rest_framework.fields import ( | ||
BooleanField, | ||
CharField, | ||
) | ||
from rest_framework.request import Request | ||
from rest_framework.response import Response | ||
|
||
from authentik.core.api.utils import PassiveSerializer | ||
from authentik.enterprise.apps import EnterpriseConfig | ||
from authentik.lib.utils.reflection import all_subclasses | ||
|
||
|
||
class TypeCreateSerializer(PassiveSerializer): | ||
"""Types of an object that can be created""" | ||
|
||
name = CharField(required=True) | ||
description = CharField(required=True) | ||
component = CharField(required=True) | ||
model_name = CharField(required=True) | ||
|
||
icon_url = CharField(required=False) | ||
requires_enterprise = BooleanField(default=False) | ||
|
||
|
||
class CreatableType: | ||
"""Class to inherit from to mark a model as creatable, even if the model itself is marked | ||
as abstract""" | ||
|
||
|
||
class NonCreatableType: | ||
"""Class to inherit from to mark a model as non-creatable even if it is not abstract""" | ||
|
||
|
||
class TypesMixin: | ||
"""Mixin which adds an API endpoint to list all possible types that can be created""" | ||
|
||
@extend_schema(responses={200: TypeCreateSerializer(many=True)}) | ||
@action(detail=False, pagination_class=None, filter_backends=[]) | ||
def types(self, request: Request, additional: list[dict] | None = None) -> Response: | ||
"""Get all creatable types""" | ||
data = [] | ||
for subclass in all_subclasses(self.queryset.model): | ||
instance = None | ||
if subclass._meta.abstract: | ||
if not issubclass(subclass, CreatableType): | ||
continue | ||
# Circumvent the django protection for not being able to instantiate | ||
# abstract models. We need a model instance to access .component | ||
# and further down .icon_url | ||
instance = subclass.__new__(subclass) | ||
# Django re-sets abstract = False so we need to override that | ||
instance.Meta.abstract = True | ||
else: | ||
if issubclass(subclass, NonCreatableType): | ||
continue | ||
instance = subclass() | ||
try: | ||
data.append( | ||
{ | ||
"name": subclass._meta.verbose_name, | ||
"description": subclass.__doc__, | ||
"component": instance.component, | ||
"model_name": subclass._meta.model_name, | ||
"icon_url": getattr(instance, "icon_url", None), | ||
"requires_enterprise": isinstance( | ||
subclass._meta.app_config, EnterpriseConfig | ||
), | ||
} | ||
) | ||
except NotImplementedError: | ||
continue | ||
if additional: | ||
data.extend(additional) | ||
data = sorted(data, key=lambda x: x["name"]) | ||
return Response(TypeCreateSerializer(data, many=True).data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.