Skip to content

Commit

Permalink
make sure we don't break something else
Browse files Browse the repository at this point in the history
Signed-off-by: Marc 'risson' Schmitt <[email protected]>
  • Loading branch information
rissson committed Oct 15, 2024
1 parent 2249b93 commit 863958b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
12 changes: 11 additions & 1 deletion authentik/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,17 @@ def expire_action(self, *args, **kwargs):
def filter_not_expired(cls, **kwargs) -> QuerySet["Token"]:
"""Filer for tokens which are not expired yet or are not expiring,
and match filters in `kwargs`"""
return cls.objects.filter(expires__gte=now(), expiring=True).filter(**kwargs)
return cls.objects.filter(expires__gt=now(), expiring=True).filter(**kwargs)

@classmethod
def delete_expired(cls) -> int:
objects = (
cls.objects.all().exclude(expiring=False).exclude(expiring=True, expires__gt=now())
)
amount = objects.count()
for obj in objects:
obj.expire_action()
return amount

@property
def is_expired(self) -> bool:
Expand Down
7 changes: 1 addition & 6 deletions authentik/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ def clean_expired_models(self: SystemTask):
messages = []
for cls in ExpiringModel.__subclasses__():
cls: ExpiringModel
objects = (
cls.objects.all().exclude(expiring=False).exclude(expiring=True, expires__gt=now())
)
amount = objects.count()
for obj in objects:
obj.expire_action()
amount = cls.delete_expired()
LOGGER.debug("Expired models", model=cls, amount=amount)
messages.append(f"Expired {amount} {cls._meta.verbose_name_plural}")
# Special case
Expand Down
2 changes: 2 additions & 0 deletions authentik/stages/consent/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def get(self, request: HttpRequest, *args, **kwargs) -> HttpResponse:
if PLAN_CONTEXT_PENDING_USER in self.executor.plan.context:
user = self.executor.plan.context[PLAN_CONTEXT_PENDING_USER]

# Remove expired consents to prevent database unique constraints errors
UserConsent.delete_expired()
consent: UserConsent | None = UserConsent.filter_not_expired(
user=user, application=application
).first()
Expand Down

0 comments on commit 863958b

Please sign in to comment.