authentik.stages.invitation.models

invitation stage models

 1"""invitation stage models"""
 2
 3from uuid import uuid4
 4
 5from django.core.validators import validate_slug
 6from django.db import models
 7from django.utils.translation import gettext_lazy as _
 8from django.views import View
 9from rest_framework.serializers import BaseSerializer, Serializer
10
11from authentik.core.models import ExpiringModel, User
12from authentik.flows.models import Stage
13from authentik.lib.models import SerializerModel
14
15
16class InvitationStage(Stage):
17    """Simplify enrollment; allow users to use a single
18    link to create their user with pre-defined parameters."""
19
20    continue_flow_without_invitation = models.BooleanField(
21        default=False,
22        help_text=_(
23            "If this flag is set, this Stage will jump to the next Stage when "
24            "no Invitation is given. By default this Stage will cancel the "
25            "Flow when no invitation is given."
26        ),
27    )
28
29    @property
30    def serializer(self) -> type[BaseSerializer]:
31        from authentik.stages.invitation.api import InvitationStageSerializer
32
33        return InvitationStageSerializer
34
35    @property
36    def view(self) -> type[View]:
37        from authentik.stages.invitation.stage import InvitationStageView
38
39        return InvitationStageView
40
41    @property
42    def component(self) -> str:
43        return "ak-stage-invitation-form"
44
45    class Meta:
46        verbose_name = _("Invitation Stage")
47        verbose_name_plural = _("Invitation Stages")
48
49
50class Invitation(SerializerModel, ExpiringModel):
51    """Single-use invitation link"""
52
53    invite_uuid = models.UUIDField(primary_key=True, editable=False, default=uuid4)
54
55    name = models.TextField(validators=[validate_slug])
56
57    flow = models.ForeignKey(
58        "authentik_flows.Flow",
59        default=None,
60        null=True,
61        on_delete=models.SET_DEFAULT,
62        help_text=_("When set, only the configured flow can use this invitation."),
63    )
64    single_use = models.BooleanField(
65        default=False,
66        help_text=_("When enabled, the invitation will be deleted after usage."),
67    )
68
69    created_by = models.ForeignKey(User, on_delete=models.CASCADE)
70    fixed_data = models.JSONField(
71        default=dict,
72        blank=True,
73        help_text=_("Optional fixed data to enforce on user enrollment."),
74    )
75
76    @property
77    def serializer(self) -> Serializer:
78        from authentik.stages.invitation.api import InvitationSerializer
79
80        return InvitationSerializer
81
82    def __str__(self):
83        return f"Invitation {str(self.invite_uuid)} created by {self.created_by_id}"
84
85    class Meta:
86        verbose_name = _("Invitation")
87        verbose_name_plural = _("Invitations")
88        indexes = ExpiringModel.Meta.indexes
class InvitationStage(authentik.flows.models.Stage):
17class InvitationStage(Stage):
18    """Simplify enrollment; allow users to use a single
19    link to create their user with pre-defined parameters."""
20
21    continue_flow_without_invitation = models.BooleanField(
22        default=False,
23        help_text=_(
24            "If this flag is set, this Stage will jump to the next Stage when "
25            "no Invitation is given. By default this Stage will cancel the "
26            "Flow when no invitation is given."
27        ),
28    )
29
30    @property
31    def serializer(self) -> type[BaseSerializer]:
32        from authentik.stages.invitation.api import InvitationStageSerializer
33
34        return InvitationStageSerializer
35
36    @property
37    def view(self) -> type[View]:
38        from authentik.stages.invitation.stage import InvitationStageView
39
40        return InvitationStageView
41
42    @property
43    def component(self) -> str:
44        return "ak-stage-invitation-form"
45
46    class Meta:
47        verbose_name = _("Invitation Stage")
48        verbose_name_plural = _("Invitation Stages")

Simplify enrollment; allow users to use a single link to create their user with pre-defined parameters.

def continue_flow_without_invitation(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]
30    @property
31    def serializer(self) -> type[BaseSerializer]:
32        from authentik.stages.invitation.api import InvitationStageSerializer
33
34        return InvitationStageSerializer

Get serializer for this model

view: type[django.views.generic.base.View]
36    @property
37    def view(self) -> type[View]:
38        from authentik.stages.invitation.stage import InvitationStageView
39
40        return InvitationStageView

Return StageView class that implements logic for this stage

component: str
42    @property
43    def component(self) -> str:
44        return "ak-stage-invitation-form"

Return component used to edit this object

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 InvitationStage.DoesNotExist(authentik.flows.models.Stage.DoesNotExist):

The requested object does not exist

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

The query returned multiple objects when only one was expected.

51class Invitation(SerializerModel, ExpiringModel):
52    """Single-use invitation link"""
53
54    invite_uuid = models.UUIDField(primary_key=True, editable=False, default=uuid4)
55
56    name = models.TextField(validators=[validate_slug])
57
58    flow = models.ForeignKey(
59        "authentik_flows.Flow",
60        default=None,
61        null=True,
62        on_delete=models.SET_DEFAULT,
63        help_text=_("When set, only the configured flow can use this invitation."),
64    )
65    single_use = models.BooleanField(
66        default=False,
67        help_text=_("When enabled, the invitation will be deleted after usage."),
68    )
69
70    created_by = models.ForeignKey(User, on_delete=models.CASCADE)
71    fixed_data = models.JSONField(
72        default=dict,
73        blank=True,
74        help_text=_("Optional fixed data to enforce on user enrollment."),
75    )
76
77    @property
78    def serializer(self) -> Serializer:
79        from authentik.stages.invitation.api import InvitationSerializer
80
81        return InvitationSerializer
82
83    def __str__(self):
84        return f"Invitation {str(self.invite_uuid)} created by {self.created_by_id}"
85
86    class Meta:
87        verbose_name = _("Invitation")
88        verbose_name_plural = _("Invitations")
89        indexes = ExpiringModel.Meta.indexes

Single-use invitation link

def invite_uuid(unknown):

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

def name(unknown):

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

flow

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 single_use(unknown):

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

created_by

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 fixed_data(unknown):

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

serializer: rest_framework.serializers.Serializer
77    @property
78    def serializer(self) -> Serializer:
79        from authentik.stages.invitation.api import InvitationSerializer
80
81        return InvitationSerializer

Get serializer for this model

def expires(unknown):

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

def expiring(unknown):

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

flow_id
created_by_id
class Invitation.DoesNotExist(django.core.exceptions.ObjectDoesNotExist):

The requested object does not exist

class Invitation.MultipleObjectsReturned(django.core.exceptions.MultipleObjectsReturned):

The query returned multiple objects when only one was expected.