From b74873ae233fc1c6b1b67267c952f112c7378aeb Mon Sep 17 00:00:00 2001 From: Stefan Bethke Date: Sun, 19 May 2024 00:34:36 +0200 Subject: [PATCH] Small improvements --- README.md | 13 +++++++++---- hedgedoc-expire.py | 10 ++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1412028..cb9be7a 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,15 @@ of data protection reasons. With this utility, you can remove old revisions and ### Expiring old revisions -All revisions that have been created before the specified age will be removed. If all revisions are older the newest -revision that represents the current contents of the note will be retained. +All revisions that have been created before the specified age will be removed. If all revisions are expired, the note remains available, it just won't have any revisions to revert to. Once you continue editing it, new revisions will be added. -## Running hedgedoc-expire.py +### Expiring old notes + +Notes that are being expired will be emailed to the account that initially created the note. This allows that user to restore the note, if necessary. Expiring a note will also remove all existing revisions for the note. + +You will need to configure your environment for the `hedgedoc-expire` to be able to send mail. If the mail is not accepted by the mail server, the note will not be removed. + +## Running `hedgedoc-expire.py` Locally from the command line: @@ -26,7 +31,7 @@ From Docker Compose: ```yaml hedgedoc-expire: image: hedgedoc-expire - command: "-c -r .001 -n .001" + command: "-c -r 14 -n 95" environment: - "POSTGRES_HOSTNAME=database" depends_on: diff --git a/hedgedoc-expire.py b/hedgedoc-expire.py index 54aabd7..8351620 100644 --- a/hedgedoc-expire.py +++ b/hedgedoc-expire.py @@ -10,6 +10,7 @@ from email.mime.base import MIMEBase from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from os import getenv +from textwrap import dedent import humanize import pgsql @@ -73,6 +74,7 @@ def notes_to_be_expired(cutoff: datetime) -> list[any]: FROM "Notes", "Users" WHERE "Notes"."updatedAt" < $1 AND "Notes"."ownerId" = "Users"."id" + ORDER BY "Notes"."updatedAt" ''') as notes_older_than: for row in notes_older_than(cutoff): notes.append({ @@ -94,7 +96,6 @@ def revisions_to_be_expired(cutoff: datetime) -> list[any]: """ Obtain a list of revisions to be expired. :param cutoff: - :param users: :return: """ revisions = [] @@ -111,6 +112,7 @@ def revisions_to_be_expired(cutoff: datetime) -> list[any]: WHERE "Revisions"."createdAt" < $1 AND "Revisions"."noteId" = "Notes"."id" AND "Notes"."ownerId" = "Users"."id" + ORDER BY "Notes"."createdAt" ''') as revs_older_than: for row in revs_older_than(cutoff): revisions.append({ @@ -169,10 +171,10 @@ def expire_old_notes(age: timedelta, config: Config, mail: EmailSender) -> None: Please find attached the contents of the latest revision of your note. - The Hedgedoc Admin team + The admin team for {config.url} ''' - ))) + ))) md = MIMEBase('text', "markdown") md.add_header('Content-Disposition', f'attachment; filename={note["title"]}') md.set_payload(note["content"]) @@ -202,7 +204,7 @@ if __name__ == '__main__': epilog='See https://git.hamburg.ccc.de/CCCHH/hedgedoc-expire') parser.add_argument('-c', '--check', action='store_true', help='print what would be done, then exit') - parser.add_argument('-n', '--notes', metavar='DAYS', type=float, default=90, + parser.add_argument('-n', '--notes', metavar='DAYS', type=float, default=95, help='remove all notes not changed in these many days') parser.add_argument('-r', '--revisions', metavar='DAYS', type=float, default=14, help='remove all revisions created more than these many days ago')