core: change TypeCreateSerializer to component

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-04-02 23:12:17 +02:00
parent 1dc01ef857
commit 448dd7ed54
18 changed files with 28 additions and 21 deletions

View File

@ -91,7 +91,7 @@ class PropertyMappingViewSet(
{
"name": verbose_name(subclass),
"description": subclass.__doc__,
"link": subclass.component,
"component": subclass.component,
}
)
return Response(TypeCreateSerializer(data, many=True).data)

View File

@ -23,7 +23,7 @@ class ProviderSerializer(ModelSerializer, MetaNameSerializer):
object_type = SerializerMethodField()
def get_object_type(self, obj):
def get_object_type(self, obj): # pragma: no cover
"""Get object type so that we know which API Endpoint to use to get the full object"""
return obj._meta.object_name.lower().replace("provider", "")
@ -74,14 +74,14 @@ class ProviderViewSet(
{
"name": verbose_name(subclass),
"description": subclass.__doc__,
"link": subclass().component,
"component": subclass().component,
}
)
data.append(
{
"name": _("SAML Provider from Metadata"),
"description": _("Create a SAML Provider by importing its Metadata."),
"link": "ak-provider-saml-import-form",
"component": "ak-provider-saml-import-form",
}
)
return Response(TypeCreateSerializer(data, many=True).data)

View File

@ -71,7 +71,7 @@ class SourceViewSet(
{
"name": verbose_name(subclass),
"description": subclass.__doc__,
"link": subclass().component,
"component": subclass().component,
}
)
return Response(TypeCreateSerializer(data, many=True).data)

View File

@ -34,7 +34,7 @@ class TypeCreateSerializer(PassiveSerializer):
name = CharField(required=True)
description = CharField(required=True)
link = CharField(required=True)
component = CharField(required=True)
class CacheSerializer(PassiveSerializer):

View File

@ -156,7 +156,7 @@ class EventViewSet(ReadOnlyModelViewSet):
{
"name": name,
"description": "",
"link": value,
"component": value,
}
)
return Response(TypeCreateSerializer(data, many=True).data)

View File

@ -70,7 +70,7 @@ class StageViewSet(
{
"name": verbose_name(subclass),
"description": subclass.__doc__,
"link": reverse("authentik_admin:stage-create")
"component": reverse("authentik_admin:stage-create")
+ f"?type={subclass.__name__}",
}
)

View File

@ -104,7 +104,7 @@ class PolicyViewSet(
{
"name": verbose_name(subclass),
"description": subclass.__doc__,
"link": subclass().component,
"component": subclass().component,
}
)
return Response(TypeCreateSerializer(data, many=True).data)

View File

@ -26,3 +26,10 @@ class TestPoliciesAPI(APITestCase):
self.assertJSONEqual(
response.content.decode(), {"passing": True, "messages": ["dummy"]}
)
def test_types(self):
"""Test Policy's types endpoint"""
response = self.client.get(
reverse("authentik_api:policy-types"),
)
self.assertEqual(response.status_code, 200)

View File

@ -14821,7 +14821,7 @@ definitions:
required:
- name
- description
- link
- component
type: object
properties:
name:
@ -14832,8 +14832,8 @@ definitions:
title: Description
type: string
minLength: 1
link:
title: Link
component:
title: Component
type: string
minLength: 1
EventTopPerUser:

View File

@ -133,7 +133,7 @@ export class BoundStagesList extends Table<FlowStageBinding> {
${until(new StagesApi(DEFAULT_CONFIG).stagesAllTypes().then((types) => {
return types.map((type) => {
return html`<li>
<ak-modal-button href="${type.link}">
<ak-modal-button href="${type.component}">
<button slot="trigger" class="pf-c-dropdown__menu-item">${type.name}<br>
<small>${type.description}</small>
</button>

View File

@ -129,7 +129,7 @@ export class OutpostServiceConnectionListPage extends TablePage<ServiceConnectio
</span>
<ak-proxy-form
slot="form"
type=${type.link}>
type=${type.component}>
</ak-proxy-form>
<button slot="trigger" class="pf-c-dropdown__menu-item">
${type.name}<br>

View File

@ -167,7 +167,7 @@ export class BoundPoliciesList extends Table<PolicyBinding> {
${until(new PoliciesApi(DEFAULT_CONFIG).policiesAllTypes().then((types) => {
return types.map((type) => {
return html`<li>
<ak-modal-button href="${type.link}">
<ak-modal-button href="${type.component}">
<button slot="trigger" class="pf-c-dropdown__menu-item">${type.name}<br>
<small>${type.description}</small>
</button>

View File

@ -147,7 +147,7 @@ export class PolicyListPage extends TablePage<Policy> {
</span>
<ak-proxy-form
slot="form"
type=${type.link}>
type=${type.component}>
</ak-proxy-form>
<button slot="trigger" class="pf-c-dropdown__menu-item">
${type.name}<br>

View File

@ -73,7 +73,7 @@ export class EventMatcherPolicyForm extends Form<EventMatcherPolicy> {
<option value="" ?selected=${this.policy?.action === undefined}>---------</option>
${until(new EventsApi(DEFAULT_CONFIG).eventsEventsActions().then(actions => {
return actions.map(action => {
return html`<option value=${action.link} ?selected=${this.policy?.action === action.link}>${action.name}</option>`;
return html`<option value=${action.component} ?selected=${this.policy?.action === action.component}>${action.name}</option>`;
});
}))}
</select>

View File

@ -135,7 +135,7 @@ export class PropertyMappingListPage extends TablePage<PropertyMapping> {
</span>
<ak-proxy-form
slot="form"
type=${type.link}>
type=${type.component}>
</ak-proxy-form>
<button slot="trigger" class="pf-c-dropdown__menu-item">
${type.name}<br>

View File

@ -126,7 +126,7 @@ export class ProviderListPage extends TablePage<Provider> {
</span>
<ak-proxy-form
slot="form"
type=${type.link}>
type=${type.component}>
</ak-proxy-form>
<button slot="trigger" class="pf-c-dropdown__menu-item">
${type.name}<br>

View File

@ -119,7 +119,7 @@ export class SourceListPage extends TablePage<Source> {
</span>
<ak-proxy-form
slot="form"
type=${type.link}>
type=${type.component}>
</ak-proxy-form>
<button slot="trigger" class="pf-c-dropdown__menu-item">
${type.name}<br>

View File

@ -93,7 +93,7 @@ export class StageListPage extends TablePage<Stage> {
${until(new StagesApi(DEFAULT_CONFIG).stagesAllTypes().then((types) => {
return types.map((type) => {
return html`<li>
<ak-modal-button href="${type.link}">
<ak-modal-button href="${type.component}">
<button slot="trigger" class="pf-c-dropdown__menu-item">${type.name}<br>
<small>${type.description}</small>
</button>