Skip to content

fl_server_core.models.user

Classes:

Name Description
Edc

EDC related configuration.

NotificationReceiver

Notification receiver base class.

User

User class.

Functions:

Name Description
create_auth_token

Ensure that an authentication token is created for every new user.

create_edc_bpn

Save EDC BPN for user.

get_edc_bpn_from_request

Get EDC BPN from http request object (headers).

Classes

Edc

Bases: Model


              flowchart TD
              fl_server_core.models.user.Edc[Edc]

              

              click fl_server_core.models.user.Edc href "" "fl_server_core.models.user.Edc"
            

EDC related configuration.

Attributes:

Name Type Description
bpn

Business Partner Number (BPN)

user

User related to the EDC configuration.

Source code in fl_server_core/models/user.py
class Edc(models.Model):
    """
    EDC related configuration.
    """

    bpn = models.CharField(max_length=20, primary_key=True)
    """Business Partner Number (BPN)"""
    user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    """User related to the EDC configuration."""

Attributes

bpn class-attribute instance-attribute
bpn = CharField(max_length=20, primary_key=True)

Business Partner Number (BPN)

user class-attribute instance-attribute
user = OneToOneField(AUTH_USER_MODEL, on_delete=CASCADE)

User related to the EDC configuration.

NotificationReceiver

Notification receiver base class.

Attributes:

Name Type Description
id UUID

Unique identifier for the notification receiver.

message_endpoint str

Endpoint to send the message to.

Source code in fl_server_core/models/user.py
class NotificationReceiver():
    """
    Notification receiver base class.
    """

    id: UUID
    """Unique identifier for the notification receiver."""
    message_endpoint: str
    """Endpoint to send the message to."""

Attributes

id instance-attribute
id: UUID

Unique identifier for the notification receiver.

message_endpoint instance-attribute
message_endpoint: str

Endpoint to send the message to.

User

Bases: AbstractUser, NotificationReceiver


              flowchart TD
              fl_server_core.models.user.User[User]
              fl_server_core.models.user.NotificationReceiver[NotificationReceiver]

                              fl_server_core.models.user.NotificationReceiver --> fl_server_core.models.user.User
                


              click fl_server_core.models.user.User href "" "fl_server_core.models.user.User"
              click fl_server_core.models.user.NotificationReceiver href "" "fl_server_core.models.user.NotificationReceiver"
            

User class.

Inherits from Django's AbstractUser and NotificationReceiver.

Attributes:

Name Type Description
actor BooleanField

Flag indicating whether the user is an actor.

client BooleanField

Flag indicating whether the user is a client.

id UUIDField

Unique identifier for the user.

message_endpoint URLField

Endpoint to send the message to.

Source code in fl_server_core/models/user.py
class User(AbstractUser, NotificationReceiver):
    """
    User class.

    Inherits from Django's AbstractUser and NotificationReceiver.
    """

    id: UUIDField = UUIDField(primary_key=True, editable=False, default=uuid4)
    """Unique identifier for the user."""
    actor: BooleanField = BooleanField(default=False)
    """Flag indicating whether the user is an actor."""
    client: BooleanField = BooleanField(default=False)
    """Flag indicating whether the user is a client."""
    message_endpoint: URLField = URLField()
    """Endpoint to send the message to."""

Attributes

actor class-attribute instance-attribute
actor: BooleanField = BooleanField(default=False)

Flag indicating whether the user is an actor.

client class-attribute instance-attribute
client: BooleanField = BooleanField(default=False)

Flag indicating whether the user is a client.

id class-attribute instance-attribute
id: UUIDField = UUIDField(primary_key=True, editable=False, default=uuid4)

Unique identifier for the user.

message_endpoint class-attribute instance-attribute
message_endpoint: URLField = URLField()

Endpoint to send the message to.

Functions:

create_auth_token

create_auth_token(sender, instance=None, created=False, *args, **kwargs)

Ensure that an authentication token is created for every new user.

Parameters:

Name Type Description Default

sender

The model class.

required

instance

User

The actual instance being saved. Defaults to None.

None

created

bool

A boolean; True if a new record was created. Defaults to False.

False

*args

Additional arguments.

()

**kwargs

Arbitrary keyword arguments.

{}
Source code in fl_server_core/models/user.py
@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_auth_token(sender, instance=None, created=False, *args, **kwargs):
    """
    Ensure that an authentication token is created for every new user.

    Args:
        sender: The model class.
        instance (User, optional): The actual instance being saved. Defaults to None.
        created (bool, optional): A boolean; True if a new record was created. Defaults to False.
        *args: Additional arguments.
        **kwargs: Arbitrary keyword arguments.
    """
    if created:
        Token.objects.create(user=instance)

create_edc_bpn

create_edc_bpn(user: User, bpn: str | HttpRequest) -> Edc | None

Save EDC BPN for user.

Parameters:

Name Type Description Default

user

User

User.

required

bpn

str | HttpRequest

EDC BPN or http request where the EDC BPN is included inside the header.

required

Returns:

Type Description
Edc | None

Edc | None: EDC object or None if not successful.

Source code in fl_server_core/models/user.py
def create_edc_bpn(user: User, bpn: str | HttpRequest) -> Edc | None:
    """
    Save EDC BPN for user.

    Args:
        user (User): User.
        bpn (str | HttpRequest): EDC BPN or http request where the EDC BPN is included inside the header.

    Returns:
        Edc | None: EDC object or None if not successful.
    """
    if not isinstance(bpn, str):
        bpn = get_edc_bpn_from_request(bpn)
    if bpn is None:
        return None
    return Edc.objects.create(user=user, bpn=bpn)

get_edc_bpn_from_request

get_edc_bpn_from_request(request: HttpRequest) -> str | None

Get EDC BPN from http request object (headers).

Parameters:

Name Type Description Default

request

HttpRequest

http request object.

required

Returns:

Type Description
str | None

str | None: EDC BPN or None if not found.

Source code in fl_server_core/models/user.py
def get_edc_bpn_from_request(request: HttpRequest) -> str | None:
    """
    Get EDC BPN from http request object (headers).

    Args:
        request (HttpRequest): http request object.

    Returns:
        str | None: EDC BPN or None if not found.
    """
    bpn = request.META.get("Edc-Bpn", "")
    contract_agreement_id = request.META.get("Edc-Contract-Agreement-Id", "")
    if not bpn or not contract_agreement_id:
        return None
    return bpn