authentik.enterprise.requests.models
1from typing import Any 2from uuid import uuid4 3 4from django.db import models, transaction 5from django.http import HttpRequest 6from django.utils.timezone import now 7from django.utils.translation import gettext_lazy as _ 8from rest_framework.serializers import Serializer 9 10from authentik.core.models import AttributesMixin, Group, User 11from authentik.events.models import Event, EventAction 12from authentik.flows.models import Flow 13from authentik.lib.models import ( 14 CreatedUpdatedModel, 15 ExpiringModel, 16 InternallyManagedMixin, 17 SerializerModel, 18 SimpleThroughModel, 19) 20from authentik.lib.utils.time import timedelta_from_string, timedelta_string_validator 21from authentik.policies.engine import FilterPolicyEngine 22from authentik.policies.models import PolicyBinding, PolicyBindingModel 23 24 25class RequestNotificationMode(models.TextChoices): 26 """Who to notify when a request is created against a rule.""" 27 28 ALL = "all", _("Everyone who can approve") 29 DIRECT = "direct", _("Only individually-selected reviewers") 30 RANDOM_MIN_REVIEWERS = ( 31 "random_min_reviewers", 32 _("A random subset of size min_reviewers, from everyone who can approve"), 33 ) 34 35 36class RequestRuleChildBinding(SerializerModel): 37 """Binding between request rule binding and a child/related model""" 38 39 uuid = models.UUIDField(default=uuid4, primary_key=True) 40 binding = models.ForeignKey("RequestRuleBinding", on_delete=models.CASCADE) 41 target = models.ForeignKey(PolicyBindingModel, on_delete=models.CASCADE, related_name="+") 42 43 @property 44 def serializer(self): 45 from authentik.enterprise.requests.api.request_rule_child_bindings import ( 46 RequestRuleChildBindingSerializer, 47 ) 48 49 return RequestRuleChildBindingSerializer 50 51 class Meta: 52 verbose_name = _("Request Rule Child Binding") 53 verbose_name_plural = _("Request Rule Child Bindings") 54 unique_together = ("binding", "target") 55 56 57# PBM here configures who can request access 58class RequestRuleBinding(SerializerModel, PolicyBindingModel): 59 """Binding between a request rule and a requestable model, optionally also 60 carrying n RequestableChildModel""" 61 62 uuid = models.UUIDField(default=uuid4, primary_key=True) 63 64 rule = models.ForeignKey("RequestRule", on_delete=models.CASCADE) 65 target = models.ForeignKey( 66 PolicyBindingModel, on_delete=models.CASCADE, related_name="request_rule_bindings" 67 ) 68 related = models.ManyToManyField( 69 PolicyBindingModel, 70 through=RequestRuleChildBinding, 71 related_name="request_rule_child_bindings", 72 ) 73 74 expiry_pending = models.TextField( 75 default="hours=1", 76 validators=[timedelta_string_validator], 77 help_text=_( 78 "How long a request against this binding stays pending before it " 79 "automatically lapses if not approved or denied." 80 ), 81 ) 82 expiry_granted_max = models.TextField( 83 default="hours=1", 84 validators=[timedelta_string_validator], 85 help_text=_("The maximum duration a grant approved against this binding can last."), 86 ) 87 88 @property 89 def serializer(self): 90 from authentik.enterprise.requests.api.request_rule_bindings import ( 91 RequestRuleBindingSerializer, 92 ) 93 94 return RequestRuleBindingSerializer 95 96 class Meta: 97 verbose_name = _("Request Rule Binding") 98 verbose_name_plural = _("Request Rule Bindings") 99 unique_together = ("rule", "target") 100 101 102# PBM here configures who can approve 103class RequestRule(CreatedUpdatedModel, SerializerModel, PolicyBindingModel): 104 """A rule defining who can request access and who can approve access to any of the 105 requestable models this rule is bound to.""" 106 107 uuid = models.UUIDField(default=uuid4, primary_key=True) 108 109 name = models.TextField() 110 targets = models.ManyToManyField( 111 PolicyBindingModel, 112 through=RequestRuleBinding, 113 related_name="request_rules", 114 through_fields=("rule", "target"), 115 ) 116 117 min_reviewers = models.PositiveSmallIntegerField(default=1) 118 min_reviewers_is_per_group = models.BooleanField(default=False) 119 120 request_flow = models.ForeignKey(Flow, null=True, on_delete=models.SET_DEFAULT, default=None) 121 122 notification_transports = models.ManyToManyField( 123 "authentik_events.NotificationTransport", 124 blank=True, 125 through="RequestRuleNotificationTransport", 126 ) 127 notification_mode = models.TextField( 128 choices=RequestNotificationMode.choices, default=RequestNotificationMode.ALL 129 ) 130 131 @property 132 def serializer(self): 133 from authentik.enterprise.requests.api.request_rules import RequestRuleSerializer 134 135 return RequestRuleSerializer 136 137 def reviewers_among(self, users: models.QuerySet[User]) -> models.QuerySet[User]: 138 """Subset of `users` eligible to approve requests against this rule, per 139 this rule's own PolicyBindings (static user/group bindings, and any 140 dynamic Policy bound to it).""" 141 engine = FilterPolicyEngine(self, users) 142 # A rule with no reviewer bindings at all has nobody configured to approve 143 # it -- unlike app access, absence of bindings must not mean "anyone passes". 144 engine.empty_result = False 145 return engine.build().result 146 147 def notification_recipients(self) -> models.QuerySet[User]: 148 """Who to notify when a request is created against this rule, per 149 `notification_mode`.""" 150 all_reviewers = self.reviewers_among(User.objects.all()) 151 if self.notification_mode == RequestNotificationMode.DIRECT: 152 direct_ids = self.bindings.filter(enabled=True, user__isnull=False).values_list( 153 "user", flat=True 154 ) 155 return all_reviewers.filter(pk__in=direct_ids) 156 if self.notification_mode == RequestNotificationMode.RANDOM_MIN_REVIEWERS: 157 return all_reviewers.order_by("?")[: self.min_reviewers] 158 return all_reviewers 159 160 class Meta: 161 verbose_name = _("Request Rule") 162 verbose_name_plural = _("Request Rules") 163 164 165class RequestRuleNotificationTransport(SimpleThroughModel): 166 167 rule = models.ForeignKey(RequestRule, on_delete=models.CASCADE) 168 notification_transport = models.ForeignKey( 169 "authentik_events.NotificationTransport", 170 on_delete=models.CASCADE, 171 ) 172 173 class Meta: 174 unique_together = (("rule", "notification_transport"),) 175 verbose_name = _("Request Rule Notification Transport") 176 verbose_name_plural = _("Request Rule Notification Transports") 177 178 def __str__(self): 179 return ( 180 f"RequestRuleNotificationTransport for Requeset Rule {self.rule_id} " 181 f"and Notification Transport {self.notification_transport_id}." 182 ) 183 184 185class RequestStatus(models.TextChoices): 186 187 CREATED = "created" 188 APPROVED = "approved" 189 DENIED = "denied" 190 REVOKED = "revoked" 191 192 193class GrantRequest(SerializerModel, ExpiringModel, CreatedUpdatedModel): 194 """Request of a user to access target(s)""" 195 196 uuid = models.UUIDField(default=uuid4, primary_key=True) 197 198 created_by = models.ForeignKey( 199 User, on_delete=models.CASCADE, related_name="grant_requests_created" 200 ) 201 fulfilled_by = models.ForeignKey( 202 User, 203 on_delete=models.SET_DEFAULT, 204 related_name="grant_requests_fulfilled", 205 null=True, 206 default=None, 207 ) 208 revoked_by = models.ForeignKey( 209 User, 210 on_delete=models.SET_DEFAULT, 211 related_name="grant_requests_revoked", 212 null=True, 213 default=None, 214 ) 215 # Set when `created_by` is an Agent: the human the agent acts for, and the only user whose 216 # approval can fulfill it. An agent may only request access its owner already holds, so 217 # there is nothing left for RequestRule reviewers to decide. 218 agent_owner = models.ForeignKey( 219 User, 220 on_delete=models.SET_DEFAULT, 221 related_name="agent_grant_requests", 222 null=True, 223 default=None, 224 ) 225 226 # Targets access was requested to 227 targets = models.ManyToManyField(PolicyBindingModel, through="GrantRequestTarget") 228 # Justification data, inputted by the `created_by` user via a flow, used for approve/deny 229 requester_data = models.JSONField(default=dict) 230 fulfiller_data = models.JSONField(default=dict) 231 232 status = models.TextField(choices=RequestStatus.choices, default=RequestStatus.CREATED) 233 234 # How long the grant should last once approved, resolved at request-creation time 235 # from the granting RequestRuleBinding(s)' expiry_granted_max, already clamped 236 # against any requester-provided override. 237 requested_expiry = models.TextField(default="hours=1", validators=[timedelta_string_validator]) 238 239 @property 240 def serializer(self) -> type[Serializer]: 241 from authentik.enterprise.requests.api.grant_requests import GrantRequestSerializer 242 243 return GrantRequestSerializer 244 245 def _rule_satisfied(self, rule: RequestRule, approving_users) -> bool: 246 """Whether `approving_users` (pks) satisfies a single rule's reviewer requirements. 247 An approval from any individually-named reviewer satisfies the rule outright; 248 otherwise `min_reviewers` distinct approvers are needed from the reviewer groups, 249 either in total or from *each* group when `min_reviewers_is_per_group` is set.""" 250 passing_approvers = set( 251 rule.reviewers_among(User.objects.filter(pk__in=approving_users)).values_list( 252 "pk", flat=True 253 ) 254 ) 255 if not passing_approvers: 256 return False 257 direct_reviewer_ids = set( 258 rule.bindings.filter(enabled=True, user__isnull=False).values_list("user", flat=True) 259 ) 260 if passing_approvers & direct_reviewer_ids: 261 return True 262 group_ids = list( 263 rule.bindings.filter(enabled=True, group__isnull=False).values_list("group", flat=True) 264 ) 265 if not group_ids: 266 return False 267 if not rule.min_reviewers_is_per_group: 268 return len(passing_approvers) >= rule.min_reviewers 269 for group_id in group_ids: 270 # Count members of the group *or any descendant* -- reviewer eligibility 271 # (reviewers_among -> FilterPolicyEngine) matches groups with descendants, 272 # so the per-group quota must too, else a child-group reviewer would count 273 # as eligible yet never toward their group's quota. 274 descendants = Group.objects.filter(pk=group_id).with_descendants() 275 members_approving = ( 276 User.objects.filter(pk__in=passing_approvers, groups__in=descendants) 277 .distinct() 278 .count() 279 ) 280 if members_approving < rule.min_reviewers: 281 return False 282 return True 283 284 def is_satisfied(self) -> bool: 285 """Whether enough reviewers have approved to fulfill every rule attached to this 286 request's targets. A target with no rule attached needs no more than one approval.""" 287 approving_users = set( 288 GrantRequestApproval.objects.filter( 289 request=self, status=RequestStatus.APPROVED 290 ).values_list("reviewer", flat=True) 291 ) 292 # An agent acts for a human and can only ever have requested access that human already 293 # holds, so the owner's approval is the entire decision -- no reviewer can stand in for 294 # them, and none is needed. 295 if self.agent_owner_id: 296 return self.agent_owner_id in approving_users 297 rules = RequestRule.objects.filter(targets__in=self.targets.all()).distinct() 298 if not rules.exists(): 299 return bool(approving_users) 300 return all(self._rule_satisfied(rule, approving_users) for rule in rules) 301 302 @transaction.atomic 303 def record_approval( 304 self, request: HttpRequest, user: User, status: RequestStatus, data: dict[str, Any] 305 ): 306 """Record a single reviewer's approval/denial. A denial immediately finalizes the 307 request as denied; an approval only finalizes it (and grants access) once 308 `is_satisfied` is true across every rule attached to the request's targets.""" 309 # Lock the row so two concurrent final approvals can't both pass the 310 # CREATED guard and both grant access / emit events. `including_expired()` so a 311 # request whose pending window has lapsed (excluded by the default manager) can 312 # still be acted upon, matching the viewset's get_object(). 313 locked = GrantRequest.objects.including_expired().select_for_update().get(pk=self.pk) 314 if locked.status != RequestStatus.CREATED: 315 return 316 if user.pk == self.created_by_id: 317 return 318 GrantRequestApproval.objects.update_or_create( 319 request=self, reviewer=user, defaults={"status": status, "attributes": data} 320 ) 321 if status == RequestStatus.DENIED: 322 self._finalize(RequestStatus.DENIED, user, data, request) 323 return 324 if not self.is_satisfied(): 325 return 326 self._finalize(RequestStatus.APPROVED, user, data, request) 327 328 def _finalize( 329 self, status: RequestStatus, user: User, data: dict[str, Any], request: HttpRequest 330 ): 331 self.fulfilled_by = user 332 self.fulfiller_data = data 333 self.status = status 334 self.save() 335 action = ( 336 EventAction.ACCESS_REQUEST_APPROVED 337 if status == RequestStatus.APPROVED 338 else EventAction.ACCESS_REQUEST_DENIED 339 ) 340 Event.new( 341 action, 342 model=self, 343 targets=list(self.targets.all().select_subclasses()), 344 # Every reviewer's decision so far, not just the one that finalized the request, so 345 # notes left by earlier approvers of a multi-reviewer rule are kept with it too. 346 approvals=[ 347 { 348 "reviewer": approval.reviewer, 349 "status": approval.status, 350 "data": approval.attributes, 351 } 352 for approval in self.approvals.select_related("reviewer").order_by("created") 353 ], 354 ).from_http(request, user) 355 if status != RequestStatus.APPROVED: 356 return 357 grant_expires = now() + timedelta_from_string(self.requested_expiry) 358 # Until now `expires` held the pending-window lapse timer; once approved the 359 # request row should live as long as the grant it created, so it is not reaped 360 # by clean_expired_models while access is still live (which would orphan the 361 # PolicyBinding and drop the audit/revoke trail). 362 self.expires = grant_expires 363 self.save() 364 for target in GrantRequestTarget.objects.filter(request=self).all(): 365 target_binding = PolicyBinding.objects.create( 366 user=self.created_by, 367 target=target.target, 368 expiring=True, 369 expires=grant_expires, 370 order=1000, 371 ) 372 target.binding = target_binding 373 target.save() 374 375 @property 376 def is_active(self) -> bool: 377 """Whether this request currently grants live access: approved, and neither 378 revoked nor naturally expired yet.""" 379 if self.status != RequestStatus.APPROVED: 380 return False 381 if self.expiring and self.expires and self.expires < now(): 382 return False 383 return True 384 385 @transaction.atomic 386 def revoke(self, request: HttpRequest, user: User): 387 """End an active grant immediately, and mark the request revoked. A no-op unless the 388 request is currently approved.""" 389 # Lock the row so a concurrent approval/revoke can't race this transition. 390 locked = GrantRequest.objects.including_expired().select_for_update().get(pk=self.pk) 391 if locked.status != RequestStatus.APPROVED: 392 return 393 for target in GrantRequestTarget.objects.filter(request=self, binding__isnull=False): 394 # Expire the PolicyBindings created (rather than deleting them, 395 # since GrantRequestTarget.binding cascades on delete and would 396 # take the audit trail with it) 397 target.binding.expiring = True 398 target.binding.expires = now() 399 target.binding.save() 400 self.revoked_by = user 401 self.status = RequestStatus.REVOKED 402 self.save() 403 Event.new( 404 EventAction.ACCESS_REQUEST_REVOKED, 405 model=self, 406 targets=list(self.targets.all().select_subclasses()), 407 ).from_http(request, user) 408 409 class Meta(ExpiringModel.Meta): 410 verbose_name = _("Grant Request") 411 verbose_name_plural = _("Grant Requests") 412 permissions = [ 413 ("request_grantrequest", _("Can create a grant request")), 414 ("fulfill_grantrequest", _("Can fulfill (approve/deny) a grant request")), 415 ("revoke_grantrequest", _("Can revoke a grant request")), 416 ] 417 418 def __str__(self): 419 return f"Grant Request {self.uuid}" 420 421 422class GrantRequestTarget(InternallyManagedMixin, models.Model): 423 uuid = models.UUIDField(default=uuid4, primary_key=True) 424 425 request = models.ForeignKey(GrantRequest, on_delete=models.CASCADE) 426 binding = models.ForeignKey(PolicyBinding, on_delete=models.CASCADE, null=True) 427 target = models.ForeignKey(PolicyBindingModel, on_delete=models.CASCADE) 428 429 class Meta: 430 verbose_name = _("Grant Request Target") 431 verbose_name_plural = _("Grant Request Targets") 432 unique_together = ("request", "target") 433 434 def __str__(self): 435 return f"Grant Request-target {self.request_id} to {self.target_id}" 436 437 438class GrantRequestApproval(AttributesMixin, CreatedUpdatedModel): 439 """A single reviewer's approval or denial of a GrantRequest. A request needs enough of 440 these, per RequestRule attached to its targets, before it is actually 441 fulfilled.""" 442 443 uuid = models.UUIDField(default=uuid4, primary_key=True) 444 445 request = models.ForeignKey(GrantRequest, on_delete=models.CASCADE, related_name="approvals") 446 reviewer = models.ForeignKey(User, on_delete=models.CASCADE) 447 status = models.TextField(choices=RequestStatus.choices) 448 449 class Meta: 450 unique_together = ("request", "reviewer") 451 verbose_name = _("Grant Request Approval") 452 verbose_name_plural = _("Grant Request Approvals") 453 454 def __str__(self): 455 return f"Grant Request Approval {self.uuid}"
26class RequestNotificationMode(models.TextChoices): 27 """Who to notify when a request is created against a rule.""" 28 29 ALL = "all", _("Everyone who can approve") 30 DIRECT = "direct", _("Only individually-selected reviewers") 31 RANDOM_MIN_REVIEWERS = ( 32 "random_min_reviewers", 33 _("A random subset of size min_reviewers, from everyone who can approve"), 34 )
Who to notify when a request is created against a rule.
37class RequestRuleChildBinding(SerializerModel): 38 """Binding between request rule binding and a child/related model""" 39 40 uuid = models.UUIDField(default=uuid4, primary_key=True) 41 binding = models.ForeignKey("RequestRuleBinding", on_delete=models.CASCADE) 42 target = models.ForeignKey(PolicyBindingModel, on_delete=models.CASCADE, related_name="+") 43 44 @property 45 def serializer(self): 46 from authentik.enterprise.requests.api.request_rule_child_bindings import ( 47 RequestRuleChildBindingSerializer, 48 ) 49 50 return RequestRuleChildBindingSerializer 51 52 class Meta: 53 verbose_name = _("Request Rule Child Binding") 54 verbose_name_plural = _("Request Rule Child Bindings") 55 unique_together = ("binding", "target")
Binding between request rule binding and a child/related model
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
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.
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.
44 @property 45 def serializer(self): 46 from authentik.enterprise.requests.api.request_rule_child_bindings import ( 47 RequestRuleChildBindingSerializer, 48 ) 49 50 return RequestRuleChildBindingSerializer
Get serializer for this model
Inherited Members
The requested object does not exist
The query returned multiple objects when only one was expected.
59class RequestRuleBinding(SerializerModel, PolicyBindingModel): 60 """Binding between a request rule and a requestable model, optionally also 61 carrying n RequestableChildModel""" 62 63 uuid = models.UUIDField(default=uuid4, primary_key=True) 64 65 rule = models.ForeignKey("RequestRule", on_delete=models.CASCADE) 66 target = models.ForeignKey( 67 PolicyBindingModel, on_delete=models.CASCADE, related_name="request_rule_bindings" 68 ) 69 related = models.ManyToManyField( 70 PolicyBindingModel, 71 through=RequestRuleChildBinding, 72 related_name="request_rule_child_bindings", 73 ) 74 75 expiry_pending = models.TextField( 76 default="hours=1", 77 validators=[timedelta_string_validator], 78 help_text=_( 79 "How long a request against this binding stays pending before it " 80 "automatically lapses if not approved or denied." 81 ), 82 ) 83 expiry_granted_max = models.TextField( 84 default="hours=1", 85 validators=[timedelta_string_validator], 86 help_text=_("The maximum duration a grant approved against this binding can last."), 87 ) 88 89 @property 90 def serializer(self): 91 from authentik.enterprise.requests.api.request_rule_bindings import ( 92 RequestRuleBindingSerializer, 93 ) 94 95 return RequestRuleBindingSerializer 96 97 class Meta: 98 verbose_name = _("Request Rule Binding") 99 verbose_name_plural = _("Request Rule Bindings") 100 unique_together = ("rule", "target")
Binding between a request rule and a requestable model, optionally also carrying n RequestableChildModel
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
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.
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.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
89 @property 90 def serializer(self): 91 from authentik.enterprise.requests.api.request_rule_bindings import ( 92 RequestRuleBindingSerializer, 93 ) 94 95 return RequestRuleBindingSerializer
Get serializer for this model
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.
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager
class built by create_forward_many_to_many_manager() defined below.
Inherited Members
- authentik.policies.models.PolicyBindingModel
- pbm_uuid
- policies
- policy_engine_mode
- objects
- supported_policy_binding_targets
- get_policy_engine_mode_display
- bindings
- application
- applicationentitlement
- source
- flow
- flowstagebinding
- notificationrule
- device
- deviceaccessgroup
- oauth2dynamicclientregistration
- userexpirationrule
- request_rule_bindings
- request_rule_child_bindings
- requestrulebinding
- request_rules
- requestrule
- grantrequest_set
- grantrequesttarget_set
The requested object does not exist
The query returned multiple objects when only one was expected.
104class RequestRule(CreatedUpdatedModel, SerializerModel, PolicyBindingModel): 105 """A rule defining who can request access and who can approve access to any of the 106 requestable models this rule is bound to.""" 107 108 uuid = models.UUIDField(default=uuid4, primary_key=True) 109 110 name = models.TextField() 111 targets = models.ManyToManyField( 112 PolicyBindingModel, 113 through=RequestRuleBinding, 114 related_name="request_rules", 115 through_fields=("rule", "target"), 116 ) 117 118 min_reviewers = models.PositiveSmallIntegerField(default=1) 119 min_reviewers_is_per_group = models.BooleanField(default=False) 120 121 request_flow = models.ForeignKey(Flow, null=True, on_delete=models.SET_DEFAULT, default=None) 122 123 notification_transports = models.ManyToManyField( 124 "authentik_events.NotificationTransport", 125 blank=True, 126 through="RequestRuleNotificationTransport", 127 ) 128 notification_mode = models.TextField( 129 choices=RequestNotificationMode.choices, default=RequestNotificationMode.ALL 130 ) 131 132 @property 133 def serializer(self): 134 from authentik.enterprise.requests.api.request_rules import RequestRuleSerializer 135 136 return RequestRuleSerializer 137 138 def reviewers_among(self, users: models.QuerySet[User]) -> models.QuerySet[User]: 139 """Subset of `users` eligible to approve requests against this rule, per 140 this rule's own PolicyBindings (static user/group bindings, and any 141 dynamic Policy bound to it).""" 142 engine = FilterPolicyEngine(self, users) 143 # A rule with no reviewer bindings at all has nobody configured to approve 144 # it -- unlike app access, absence of bindings must not mean "anyone passes". 145 engine.empty_result = False 146 return engine.build().result 147 148 def notification_recipients(self) -> models.QuerySet[User]: 149 """Who to notify when a request is created against this rule, per 150 `notification_mode`.""" 151 all_reviewers = self.reviewers_among(User.objects.all()) 152 if self.notification_mode == RequestNotificationMode.DIRECT: 153 direct_ids = self.bindings.filter(enabled=True, user__isnull=False).values_list( 154 "user", flat=True 155 ) 156 return all_reviewers.filter(pk__in=direct_ids) 157 if self.notification_mode == RequestNotificationMode.RANDOM_MIN_REVIEWERS: 158 return all_reviewers.order_by("?")[: self.min_reviewers] 159 return all_reviewers 160 161 class Meta: 162 verbose_name = _("Request Rule") 163 verbose_name_plural = _("Request Rules")
A rule defining who can request access and who can approve access to any of the requestable models this rule is bound to.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example::
class Pizza(Model):
toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppings and Topping.pizzas are ManyToManyDescriptor
instances.
Most of the implementation is delegated to a dynamically defined manager
class built by create_forward_many_to_many_manager() defined below.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
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.
Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example::
class Pizza(Model):
toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppings and Topping.pizzas are ManyToManyDescriptor
instances.
Most of the implementation is delegated to a dynamically defined manager
class built by create_forward_many_to_many_manager() defined below.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
132 @property 133 def serializer(self): 134 from authentik.enterprise.requests.api.request_rules import RequestRuleSerializer 135 136 return RequestRuleSerializer
Get serializer for this model
138 def reviewers_among(self, users: models.QuerySet[User]) -> models.QuerySet[User]: 139 """Subset of `users` eligible to approve requests against this rule, per 140 this rule's own PolicyBindings (static user/group bindings, and any 141 dynamic Policy bound to it).""" 142 engine = FilterPolicyEngine(self, users) 143 # A rule with no reviewer bindings at all has nobody configured to approve 144 # it -- unlike app access, absence of bindings must not mean "anyone passes". 145 engine.empty_result = False 146 return engine.build().result
Subset of users eligible to approve requests against this rule, per
this rule's own PolicyBindings (static user/group bindings, and any
dynamic Policy bound to it).
148 def notification_recipients(self) -> models.QuerySet[User]: 149 """Who to notify when a request is created against this rule, per 150 `notification_mode`.""" 151 all_reviewers = self.reviewers_among(User.objects.all()) 152 if self.notification_mode == RequestNotificationMode.DIRECT: 153 direct_ids = self.bindings.filter(enabled=True, user__isnull=False).values_list( 154 "user", flat=True 155 ) 156 return all_reviewers.filter(pk__in=direct_ids) 157 if self.notification_mode == RequestNotificationMode.RANDOM_MIN_REVIEWERS: 158 return all_reviewers.order_by("?")[: self.min_reviewers] 159 return all_reviewers
Who to notify when a request is created against this rule, per
notification_mode.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
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.
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager
class built by create_forward_many_to_many_manager() defined below.
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager
class built by create_forward_many_to_many_manager() defined below.
Inherited Members
- authentik.policies.models.PolicyBindingModel
- pbm_uuid
- policies
- policy_engine_mode
- objects
- supported_policy_binding_targets
- get_policy_engine_mode_display
- bindings
- application
- applicationentitlement
- source
- flow
- flowstagebinding
- notificationrule
- device
- deviceaccessgroup
- oauth2dynamicclientregistration
- userexpirationrule
- request_rule_bindings
- request_rule_child_bindings
- requestrulebinding
- request_rules
- requestrule
- grantrequest_set
- grantrequesttarget_set
The requested object does not exist
The query returned multiple objects when only one was expected.
166class RequestRuleNotificationTransport(SimpleThroughModel): 167 168 rule = models.ForeignKey(RequestRule, on_delete=models.CASCADE) 169 notification_transport = models.ForeignKey( 170 "authentik_events.NotificationTransport", 171 on_delete=models.CASCADE, 172 ) 173 174 class Meta: 175 unique_together = (("rule", "notification_transport"),) 176 verbose_name = _("Request Rule Notification Transport") 177 verbose_name_plural = _("Request Rule Notification Transports") 178 179 def __str__(self): 180 return ( 181 f"RequestRuleNotificationTransport for Requeset Rule {self.rule_id} " 182 f"and Notification Transport {self.notification_transport_id}." 183 )
RequestRuleNotificationTransport(id, rule, notification_transport)
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.
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.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Inherited Members
The requested object does not exist
The query returned multiple objects when only one was expected.
186class RequestStatus(models.TextChoices): 187 188 CREATED = "created" 189 APPROVED = "approved" 190 DENIED = "denied" 191 REVOKED = "revoked"
Class for creating enumerated string choices.
194class GrantRequest(SerializerModel, ExpiringModel, CreatedUpdatedModel): 195 """Request of a user to access target(s)""" 196 197 uuid = models.UUIDField(default=uuid4, primary_key=True) 198 199 created_by = models.ForeignKey( 200 User, on_delete=models.CASCADE, related_name="grant_requests_created" 201 ) 202 fulfilled_by = models.ForeignKey( 203 User, 204 on_delete=models.SET_DEFAULT, 205 related_name="grant_requests_fulfilled", 206 null=True, 207 default=None, 208 ) 209 revoked_by = models.ForeignKey( 210 User, 211 on_delete=models.SET_DEFAULT, 212 related_name="grant_requests_revoked", 213 null=True, 214 default=None, 215 ) 216 # Set when `created_by` is an Agent: the human the agent acts for, and the only user whose 217 # approval can fulfill it. An agent may only request access its owner already holds, so 218 # there is nothing left for RequestRule reviewers to decide. 219 agent_owner = models.ForeignKey( 220 User, 221 on_delete=models.SET_DEFAULT, 222 related_name="agent_grant_requests", 223 null=True, 224 default=None, 225 ) 226 227 # Targets access was requested to 228 targets = models.ManyToManyField(PolicyBindingModel, through="GrantRequestTarget") 229 # Justification data, inputted by the `created_by` user via a flow, used for approve/deny 230 requester_data = models.JSONField(default=dict) 231 fulfiller_data = models.JSONField(default=dict) 232 233 status = models.TextField(choices=RequestStatus.choices, default=RequestStatus.CREATED) 234 235 # How long the grant should last once approved, resolved at request-creation time 236 # from the granting RequestRuleBinding(s)' expiry_granted_max, already clamped 237 # against any requester-provided override. 238 requested_expiry = models.TextField(default="hours=1", validators=[timedelta_string_validator]) 239 240 @property 241 def serializer(self) -> type[Serializer]: 242 from authentik.enterprise.requests.api.grant_requests import GrantRequestSerializer 243 244 return GrantRequestSerializer 245 246 def _rule_satisfied(self, rule: RequestRule, approving_users) -> bool: 247 """Whether `approving_users` (pks) satisfies a single rule's reviewer requirements. 248 An approval from any individually-named reviewer satisfies the rule outright; 249 otherwise `min_reviewers` distinct approvers are needed from the reviewer groups, 250 either in total or from *each* group when `min_reviewers_is_per_group` is set.""" 251 passing_approvers = set( 252 rule.reviewers_among(User.objects.filter(pk__in=approving_users)).values_list( 253 "pk", flat=True 254 ) 255 ) 256 if not passing_approvers: 257 return False 258 direct_reviewer_ids = set( 259 rule.bindings.filter(enabled=True, user__isnull=False).values_list("user", flat=True) 260 ) 261 if passing_approvers & direct_reviewer_ids: 262 return True 263 group_ids = list( 264 rule.bindings.filter(enabled=True, group__isnull=False).values_list("group", flat=True) 265 ) 266 if not group_ids: 267 return False 268 if not rule.min_reviewers_is_per_group: 269 return len(passing_approvers) >= rule.min_reviewers 270 for group_id in group_ids: 271 # Count members of the group *or any descendant* -- reviewer eligibility 272 # (reviewers_among -> FilterPolicyEngine) matches groups with descendants, 273 # so the per-group quota must too, else a child-group reviewer would count 274 # as eligible yet never toward their group's quota. 275 descendants = Group.objects.filter(pk=group_id).with_descendants() 276 members_approving = ( 277 User.objects.filter(pk__in=passing_approvers, groups__in=descendants) 278 .distinct() 279 .count() 280 ) 281 if members_approving < rule.min_reviewers: 282 return False 283 return True 284 285 def is_satisfied(self) -> bool: 286 """Whether enough reviewers have approved to fulfill every rule attached to this 287 request's targets. A target with no rule attached needs no more than one approval.""" 288 approving_users = set( 289 GrantRequestApproval.objects.filter( 290 request=self, status=RequestStatus.APPROVED 291 ).values_list("reviewer", flat=True) 292 ) 293 # An agent acts for a human and can only ever have requested access that human already 294 # holds, so the owner's approval is the entire decision -- no reviewer can stand in for 295 # them, and none is needed. 296 if self.agent_owner_id: 297 return self.agent_owner_id in approving_users 298 rules = RequestRule.objects.filter(targets__in=self.targets.all()).distinct() 299 if not rules.exists(): 300 return bool(approving_users) 301 return all(self._rule_satisfied(rule, approving_users) for rule in rules) 302 303 @transaction.atomic 304 def record_approval( 305 self, request: HttpRequest, user: User, status: RequestStatus, data: dict[str, Any] 306 ): 307 """Record a single reviewer's approval/denial. A denial immediately finalizes the 308 request as denied; an approval only finalizes it (and grants access) once 309 `is_satisfied` is true across every rule attached to the request's targets.""" 310 # Lock the row so two concurrent final approvals can't both pass the 311 # CREATED guard and both grant access / emit events. `including_expired()` so a 312 # request whose pending window has lapsed (excluded by the default manager) can 313 # still be acted upon, matching the viewset's get_object(). 314 locked = GrantRequest.objects.including_expired().select_for_update().get(pk=self.pk) 315 if locked.status != RequestStatus.CREATED: 316 return 317 if user.pk == self.created_by_id: 318 return 319 GrantRequestApproval.objects.update_or_create( 320 request=self, reviewer=user, defaults={"status": status, "attributes": data} 321 ) 322 if status == RequestStatus.DENIED: 323 self._finalize(RequestStatus.DENIED, user, data, request) 324 return 325 if not self.is_satisfied(): 326 return 327 self._finalize(RequestStatus.APPROVED, user, data, request) 328 329 def _finalize( 330 self, status: RequestStatus, user: User, data: dict[str, Any], request: HttpRequest 331 ): 332 self.fulfilled_by = user 333 self.fulfiller_data = data 334 self.status = status 335 self.save() 336 action = ( 337 EventAction.ACCESS_REQUEST_APPROVED 338 if status == RequestStatus.APPROVED 339 else EventAction.ACCESS_REQUEST_DENIED 340 ) 341 Event.new( 342 action, 343 model=self, 344 targets=list(self.targets.all().select_subclasses()), 345 # Every reviewer's decision so far, not just the one that finalized the request, so 346 # notes left by earlier approvers of a multi-reviewer rule are kept with it too. 347 approvals=[ 348 { 349 "reviewer": approval.reviewer, 350 "status": approval.status, 351 "data": approval.attributes, 352 } 353 for approval in self.approvals.select_related("reviewer").order_by("created") 354 ], 355 ).from_http(request, user) 356 if status != RequestStatus.APPROVED: 357 return 358 grant_expires = now() + timedelta_from_string(self.requested_expiry) 359 # Until now `expires` held the pending-window lapse timer; once approved the 360 # request row should live as long as the grant it created, so it is not reaped 361 # by clean_expired_models while access is still live (which would orphan the 362 # PolicyBinding and drop the audit/revoke trail). 363 self.expires = grant_expires 364 self.save() 365 for target in GrantRequestTarget.objects.filter(request=self).all(): 366 target_binding = PolicyBinding.objects.create( 367 user=self.created_by, 368 target=target.target, 369 expiring=True, 370 expires=grant_expires, 371 order=1000, 372 ) 373 target.binding = target_binding 374 target.save() 375 376 @property 377 def is_active(self) -> bool: 378 """Whether this request currently grants live access: approved, and neither 379 revoked nor naturally expired yet.""" 380 if self.status != RequestStatus.APPROVED: 381 return False 382 if self.expiring and self.expires and self.expires < now(): 383 return False 384 return True 385 386 @transaction.atomic 387 def revoke(self, request: HttpRequest, user: User): 388 """End an active grant immediately, and mark the request revoked. A no-op unless the 389 request is currently approved.""" 390 # Lock the row so a concurrent approval/revoke can't race this transition. 391 locked = GrantRequest.objects.including_expired().select_for_update().get(pk=self.pk) 392 if locked.status != RequestStatus.APPROVED: 393 return 394 for target in GrantRequestTarget.objects.filter(request=self, binding__isnull=False): 395 # Expire the PolicyBindings created (rather than deleting them, 396 # since GrantRequestTarget.binding cascades on delete and would 397 # take the audit trail with it) 398 target.binding.expiring = True 399 target.binding.expires = now() 400 target.binding.save() 401 self.revoked_by = user 402 self.status = RequestStatus.REVOKED 403 self.save() 404 Event.new( 405 EventAction.ACCESS_REQUEST_REVOKED, 406 model=self, 407 targets=list(self.targets.all().select_subclasses()), 408 ).from_http(request, user) 409 410 class Meta(ExpiringModel.Meta): 411 verbose_name = _("Grant Request") 412 verbose_name_plural = _("Grant Requests") 413 permissions = [ 414 ("request_grantrequest", _("Can create a grant request")), 415 ("fulfill_grantrequest", _("Can fulfill (approve/deny) a grant request")), 416 ("revoke_grantrequest", _("Can revoke a grant request")), 417 ] 418 419 def __str__(self): 420 return f"Grant Request {self.uuid}"
Request of a user to access target(s)
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
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.
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.
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.
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.
Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example::
class Pizza(Model):
toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppings and Topping.pizzas are ManyToManyDescriptor
instances.
Most of the implementation is delegated to a dynamically defined manager
class built by create_forward_many_to_many_manager() defined below.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
240 @property 241 def serializer(self) -> type[Serializer]: 242 from authentik.enterprise.requests.api.grant_requests import GrantRequestSerializer 243 244 return GrantRequestSerializer
Get serializer for this model
285 def is_satisfied(self) -> bool: 286 """Whether enough reviewers have approved to fulfill every rule attached to this 287 request's targets. A target with no rule attached needs no more than one approval.""" 288 approving_users = set( 289 GrantRequestApproval.objects.filter( 290 request=self, status=RequestStatus.APPROVED 291 ).values_list("reviewer", flat=True) 292 ) 293 # An agent acts for a human and can only ever have requested access that human already 294 # holds, so the owner's approval is the entire decision -- no reviewer can stand in for 295 # them, and none is needed. 296 if self.agent_owner_id: 297 return self.agent_owner_id in approving_users 298 rules = RequestRule.objects.filter(targets__in=self.targets.all()).distinct() 299 if not rules.exists(): 300 return bool(approving_users) 301 return all(self._rule_satisfied(rule, approving_users) for rule in rules)
Whether enough reviewers have approved to fulfill every rule attached to this request's targets. A target with no rule attached needs no more than one approval.
303 @transaction.atomic 304 def record_approval( 305 self, request: HttpRequest, user: User, status: RequestStatus, data: dict[str, Any] 306 ): 307 """Record a single reviewer's approval/denial. A denial immediately finalizes the 308 request as denied; an approval only finalizes it (and grants access) once 309 `is_satisfied` is true across every rule attached to the request's targets.""" 310 # Lock the row so two concurrent final approvals can't both pass the 311 # CREATED guard and both grant access / emit events. `including_expired()` so a 312 # request whose pending window has lapsed (excluded by the default manager) can 313 # still be acted upon, matching the viewset's get_object(). 314 locked = GrantRequest.objects.including_expired().select_for_update().get(pk=self.pk) 315 if locked.status != RequestStatus.CREATED: 316 return 317 if user.pk == self.created_by_id: 318 return 319 GrantRequestApproval.objects.update_or_create( 320 request=self, reviewer=user, defaults={"status": status, "attributes": data} 321 ) 322 if status == RequestStatus.DENIED: 323 self._finalize(RequestStatus.DENIED, user, data, request) 324 return 325 if not self.is_satisfied(): 326 return 327 self._finalize(RequestStatus.APPROVED, user, data, request)
Record a single reviewer's approval/denial. A denial immediately finalizes the
request as denied; an approval only finalizes it (and grants access) once
is_satisfied is true across every rule attached to the request's targets.
376 @property 377 def is_active(self) -> bool: 378 """Whether this request currently grants live access: approved, and neither 379 revoked nor naturally expired yet.""" 380 if self.status != RequestStatus.APPROVED: 381 return False 382 if self.expiring and self.expires and self.expires < now(): 383 return False 384 return True
Whether this request currently grants live access: approved, and neither revoked nor naturally expired yet.
386 @transaction.atomic 387 def revoke(self, request: HttpRequest, user: User): 388 """End an active grant immediately, and mark the request revoked. A no-op unless the 389 request is currently approved.""" 390 # Lock the row so a concurrent approval/revoke can't race this transition. 391 locked = GrantRequest.objects.including_expired().select_for_update().get(pk=self.pk) 392 if locked.status != RequestStatus.APPROVED: 393 return 394 for target in GrantRequestTarget.objects.filter(request=self, binding__isnull=False): 395 # Expire the PolicyBindings created (rather than deleting them, 396 # since GrantRequestTarget.binding cascades on delete and would 397 # take the audit trail with it) 398 target.binding.expiring = True 399 target.binding.expires = now() 400 target.binding.save() 401 self.revoked_by = user 402 self.status = RequestStatus.REVOKED 403 self.save() 404 Event.new( 405 EventAction.ACCESS_REQUEST_REVOKED, 406 model=self, 407 targets=list(self.targets.all().select_subclasses()), 408 ).from_http(request, user)
End an active grant immediately, and mark the request revoked. A no-op unless the request is currently approved.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager
class built by create_forward_many_to_many_manager() defined below.
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager
class built by create_forward_many_to_many_manager() defined below.
The requested object does not exist
The query returned multiple objects when only one was expected.
423class GrantRequestTarget(InternallyManagedMixin, models.Model): 424 uuid = models.UUIDField(default=uuid4, primary_key=True) 425 426 request = models.ForeignKey(GrantRequest, on_delete=models.CASCADE) 427 binding = models.ForeignKey(PolicyBinding, on_delete=models.CASCADE, null=True) 428 target = models.ForeignKey(PolicyBindingModel, on_delete=models.CASCADE) 429 430 class Meta: 431 verbose_name = _("Grant Request Target") 432 verbose_name_plural = _("Grant Request Targets") 433 unique_together = ("request", "target") 434 435 def __str__(self): 436 return f"Grant Request-target {self.request_id} to {self.target_id}"
GrantRequestTarget(uuid, request, binding, target)
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
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.
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.
The requested object does not exist
The query returned multiple objects when only one was expected.
439class GrantRequestApproval(AttributesMixin, CreatedUpdatedModel): 440 """A single reviewer's approval or denial of a GrantRequest. A request needs enough of 441 these, per RequestRule attached to its targets, before it is actually 442 fulfilled.""" 443 444 uuid = models.UUIDField(default=uuid4, primary_key=True) 445 446 request = models.ForeignKey(GrantRequest, on_delete=models.CASCADE, related_name="approvals") 447 reviewer = models.ForeignKey(User, on_delete=models.CASCADE) 448 status = models.TextField(choices=RequestStatus.choices) 449 450 class Meta: 451 unique_together = ("request", "reviewer") 452 verbose_name = _("Grant Request Approval") 453 verbose_name_plural = _("Grant Request Approvals") 454 455 def __str__(self): 456 return f"Grant Request Approval {self.uuid}"
A single reviewer's approval or denial of a GrantRequest. A request needs enough of these, per RequestRule attached to its targets, before it is actually fulfilled.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
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.
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.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
The requested object does not exist
The query returned multiple objects when only one was expected.