This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/passbook/policies/models.py
2020-05-14 13:51:05 +02:00

42 lines
1.2 KiB
Python

"""Policy base models"""
from django.db import models
from django.utils.translation import gettext_lazy as _
from passbook.core.models import Policy
from passbook.lib.models import UUIDModel
class PolicyBindingModel(models.Model):
"""Base Model for objects that have policies applied to them."""
policies = models.ManyToManyField(
Policy, through="PolicyBinding", related_name="+", blank=True
)
class Meta:
verbose_name = _("Policy Binding Model")
verbose_name_plural = _("Policy Binding Models")
class PolicyBinding(UUIDModel):
"""Relationship between a Policy and a PolicyBindingModel."""
enabled = models.BooleanField(default=True)
policy = models.ForeignKey(Policy, on_delete=models.CASCADE, related_name="+")
target = models.ForeignKey(
PolicyBindingModel, on_delete=models.CASCADE, related_name="+"
)
# default value and non-unique for compatibility
order = models.IntegerField(default=0)
def __str__(self) -> str:
return f"PolicyBinding policy={self.policy} target={self.target} order={self.order}"
class Meta:
verbose_name = _("Policy Binding")
verbose_name_plural = _("Policy Bindings")