authentik.stages.user_write.models

write stage models

 1"""write stage models"""
 2
 3from django.db import models
 4from django.utils.translation import gettext_lazy as _
 5from django.views import View
 6from rest_framework.serializers import BaseSerializer
 7
 8from authentik.core.models import Group, UserTypes
 9from authentik.flows.models import Stage
10
11
12class UserCreationMode(models.TextChoices):
13    """Behavior of user_write stage when a user is not set in the flow context"""
14
15    NEVER_CREATE = "never_create"
16    CREATE_WHEN_REQUIRED = "create_when_required"
17    ALWAYS_CREATE = "always_create"
18
19
20class UserWriteStage(Stage):
21    """Write pending data into the pending user, or if no user exists,
22    create a new user with the data."""
23
24    user_creation_mode = models.TextField(
25        choices=UserCreationMode.choices,
26        default=UserCreationMode.CREATE_WHEN_REQUIRED,
27    )
28
29    create_users_as_inactive = models.BooleanField(
30        default=False,
31        help_text=_("When set, newly created users are inactive and cannot login."),
32    )
33
34    create_users_group = models.ForeignKey(
35        Group,
36        null=True,
37        default=None,
38        on_delete=models.SET_DEFAULT,
39        help_text=_("Optionally add newly created users to this group."),
40    )
41
42    user_type = models.TextField(
43        choices=UserTypes.choices,
44        default=UserTypes.EXTERNAL,
45    )
46    user_path_template = models.TextField(
47        default="",
48        blank=True,
49    )
50
51    @property
52    def serializer(self) -> type[BaseSerializer]:
53        from authentik.stages.user_write.api import UserWriteStageSerializer
54
55        return UserWriteStageSerializer
56
57    @property
58    def view(self) -> type[View]:
59        from authentik.stages.user_write.stage import UserWriteStageView
60
61        return UserWriteStageView
62
63    @property
64    def component(self) -> str:
65        return "ak-stage-user-write-form"
66
67    class Meta:
68        verbose_name = _("User Write Stage")
69        verbose_name_plural = _("User Write Stages")
class UserCreationMode(django.db.models.enums.TextChoices):
13class UserCreationMode(models.TextChoices):
14    """Behavior of user_write stage when a user is not set in the flow context"""
15
16    NEVER_CREATE = "never_create"
17    CREATE_WHEN_REQUIRED = "create_when_required"
18    ALWAYS_CREATE = "always_create"

Behavior of user_write stage when a user is not set in the flow context

CREATE_WHEN_REQUIRED = UserCreationMode.CREATE_WHEN_REQUIRED
class UserWriteStage(authentik.flows.models.Stage):
21class UserWriteStage(Stage):
22    """Write pending data into the pending user, or if no user exists,
23    create a new user with the data."""
24
25    user_creation_mode = models.TextField(
26        choices=UserCreationMode.choices,
27        default=UserCreationMode.CREATE_WHEN_REQUIRED,
28    )
29
30    create_users_as_inactive = models.BooleanField(
31        default=False,
32        help_text=_("When set, newly created users are inactive and cannot login."),
33    )
34
35    create_users_group = models.ForeignKey(
36        Group,
37        null=True,
38        default=None,
39        on_delete=models.SET_DEFAULT,
40        help_text=_("Optionally add newly created users to this group."),
41    )
42
43    user_type = models.TextField(
44        choices=UserTypes.choices,
45        default=UserTypes.EXTERNAL,
46    )
47    user_path_template = models.TextField(
48        default="",
49        blank=True,
50    )
51
52    @property
53    def serializer(self) -> type[BaseSerializer]:
54        from authentik.stages.user_write.api import UserWriteStageSerializer
55
56        return UserWriteStageSerializer
57
58    @property
59    def view(self) -> type[View]:
60        from authentik.stages.user_write.stage import UserWriteStageView
61
62        return UserWriteStageView
63
64    @property
65    def component(self) -> str:
66        return "ak-stage-user-write-form"
67
68    class Meta:
69        verbose_name = _("User Write Stage")
70        verbose_name_plural = _("User Write Stages")

Write pending data into the pending user, or if no user exists, create a new user with the data.

def user_creation_mode(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def create_users_as_inactive(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

create_users_group

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

def user_type(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def user_path_template(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

serializer: type[rest_framework.serializers.BaseSerializer]
52    @property
53    def serializer(self) -> type[BaseSerializer]:
54        from authentik.stages.user_write.api import UserWriteStageSerializer
55
56        return UserWriteStageSerializer

Get serializer for this model

view: type[django.views.generic.base.View]
58    @property
59    def view(self) -> type[View]:
60        from authentik.stages.user_write.stage import UserWriteStageView
61
62        return UserWriteStageView

Return StageView class that implements logic for this stage

component: str
64    @property
65    def component(self) -> str:
66        return "ak-stage-user-write-form"

Return component used to edit this object

def get_user_creation_mode_display(unknown):

Method descriptor with partial application of the given arguments and keywords.

Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.

create_users_group_id
def get_user_type_display(unknown):

Method descriptor with partial application of the given arguments and keywords.

Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.

stage_ptr_id
stage_ptr

Accessor to the related object on the forward side of a one-to-one relation.

In the example::

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Restaurant.place is a ForwardOneToOneDescriptor instance.

class UserWriteStage.DoesNotExist(authentik.flows.models.Stage.DoesNotExist):

The requested object does not exist

class UserWriteStage.MultipleObjectsReturned(authentik.flows.models.Stage.MultipleObjectsReturned):

The query returned multiple objects when only one was expected.