2020-05-07 18:51:06 +00:00
|
|
|
"""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 which have Policies applied to them"""
|
|
|
|
|
2020-05-08 16:45:53 +00:00
|
|
|
policies = models.ManyToManyField(
|
|
|
|
Policy, through="PolicyBinding", related_name="+", blank=True
|
|
|
|
)
|
2020-05-07 18:51:06 +00:00
|
|
|
|
2020-05-08 12:33:14 +00:00
|
|
|
class Meta:
|
|
|
|
|
|
|
|
verbose_name = _("Policy Binding Model")
|
|
|
|
verbose_name_plural = _("Policy Binding Models")
|
|
|
|
|
2020-05-07 18:51:06 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2020-05-08 12:33:14 +00:00
|
|
|
def __str__(self) -> str:
|
|
|
|
return f"PolicyBinding policy={self.policy} target={self.target} order={self.order}"
|
|
|
|
|
2020-05-07 18:51:06 +00:00
|
|
|
class Meta:
|
|
|
|
|
|
|
|
verbose_name = _("Policy Binding")
|
|
|
|
verbose_name_plural = _("Policy Bindings")
|