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), "name": verbose_name(subclass),
"description": subclass.__doc__, "description": subclass.__doc__,
"link": subclass.component, "component": subclass.component,
} }
) )
return Response(TypeCreateSerializer(data, many=True).data) return Response(TypeCreateSerializer(data, many=True).data)

View file

@ -23,7 +23,7 @@ class ProviderSerializer(ModelSerializer, MetaNameSerializer):
object_type = SerializerMethodField() 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""" """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", "") return obj._meta.object_name.lower().replace("provider", "")
@ -74,14 +74,14 @@ class ProviderViewSet(
{ {
"name": verbose_name(subclass), "name": verbose_name(subclass),
"description": subclass.__doc__, "description": subclass.__doc__,
"link": subclass().component, "component": subclass().component,
} }
) )
data.append( data.append(
{ {
"name": _("SAML Provider from Metadata"), "name": _("SAML Provider from Metadata"),
"description": _("Create a SAML Provider by importing its 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) return Response(TypeCreateSerializer(data, many=True).data)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -26,3 +26,10 @@ class TestPoliciesAPI(APITestCase):
self.assertJSONEqual( self.assertJSONEqual(
response.content.decode(), {"passing": True, "messages": ["dummy"]} 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: required:
- name - name
- description - description
- link - component
type: object type: object
properties: properties:
name: name:
@ -14832,8 +14832,8 @@ definitions:
title: Description title: Description
type: string type: string
minLength: 1 minLength: 1
link: component:
title: Link title: Component
type: string type: string
minLength: 1 minLength: 1
EventTopPerUser: EventTopPerUser:

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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