Small improvements
Some checks failed
docker-image / docker (push) Failing after 5s

This commit is contained in:
Stefan Bethke 2024-05-19 00:34:36 +02:00
parent 5c37e0a2b4
commit b74873ae23
2 changed files with 15 additions and 8 deletions

View file

@ -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:

View file

@ -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')