diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a6a247e..414366b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -16,17 +16,18 @@ Changelog ``cleanup_snipppet`` managemenent command. It's still encouraged to have the management command setup, just run it daily, so snippets which expired but never got fetched by a client are deleted properly. +- Onetime snippets which were never viewed a second time are now deleted if + they reach the default expire date. - New AppConfig setting ``APPLICATION_NAME`` that can be used to replace the term "dpaste" throughout the UI. -- New AppConfig setting ``EXTRA_HEAD_HTML`` that can be used to add custom HTML - to each template, specifically used for custom CSS styles, to easily override - the stock UI of dpaste. +- New AppConfig setting ``EXTRA_HEAD_HTML`` and similars that can be used to + add custom HTML to each template, to easily override the stock UI of dpaste. - New "Slim" view that displays the highlighted snippet without header, - options etc. + options etc, and can be iframed. - Forced line-break for superlongwordsthatwouldexceedthecanvas. -- Testsuite now uses pytest. - Local development is no longer centered around ``pipenv`` and is rather using docker-compose or the classic virtualenv based setups. +- Testsuite now uses pytest. 3.3.1 (2019-08-04): ------------------- diff --git a/dpaste/management/commands/cleanup_snippets.py b/dpaste/management/commands/cleanup_snippets.py index 1a60cc4..4542ba5 100644 --- a/dpaste/management/commands/cleanup_snippets.py +++ b/dpaste/management/commands/cleanup_snippets.py @@ -1,8 +1,14 @@ +from datetime import timedelta + from django.core.management.base import BaseCommand from django.utils import timezone +from django.apps import apps + from dpaste.models import Snippet +config = apps.get_app_config("dpaste") + class Command(BaseCommand): help = "Purges snippets that are expired" @@ -16,19 +22,35 @@ class Command(BaseCommand): ), def handle(self, *args, **options): - deleteable_snippets = Snippet.objects.filter( - expires__isnull=False, - expire_type=Snippet.EXPIRE_TIME, - expires__lte=timezone.now(), + deleteable_snippets = ( + # Snippets which are expired but haven't been deleted by + # the view. + Snippet.objects.filter( + expires__isnull=False, + expire_type=Snippet.EXPIRE_TIME, + expires__lte=timezone.now(), + ) + # Snipoets which are Onetime snippets but have never been viewed + # the second time. Delete them if they are older than our default + # expiration. + | Snippet.objects.filter( + expire_type=Snippet.EXPIRE_ONETIME, + published__lte=( + timezone.now() - timedelta(seconds=config.EXPIRE_DEFAULT) + ), + ) ) + if len(deleteable_snippets) == 0: self.stdout.write(u"No snippets to delete.") return None self.stdout.write( u"Will delete %s snippet(s):\n" % deleteable_snippets.count() ) + for d in deleteable_snippets: self.stdout.write(u"- %s (%s)\n" % (d.secret_id, d.expires)) + if options.get("dry_run"): self.stdout.write("Dry run - Not actually deleting snippets!\n") else: