This commit is contained in:
parent
5c37e0a2b4
commit
b74873ae23
13
README.md
13
README.md
|
@ -10,10 +10,15 @@ of data protection reasons. With this utility, you can remove old revisions and
|
||||||
|
|
||||||
### Expiring old revisions
|
### Expiring old revisions
|
||||||
|
|
||||||
All revisions that have been created before the specified age will be removed. If all revisions are older the newest
|
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.
|
||||||
revision that represents the current contents of the note will be retained.
|
|
||||||
|
|
||||||
## 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:
|
Locally from the command line:
|
||||||
|
|
||||||
|
@ -26,7 +31,7 @@ From Docker Compose:
|
||||||
```yaml
|
```yaml
|
||||||
hedgedoc-expire:
|
hedgedoc-expire:
|
||||||
image: hedgedoc-expire
|
image: hedgedoc-expire
|
||||||
command: "-c -r .001 -n .001"
|
command: "-c -r 14 -n 95"
|
||||||
environment:
|
environment:
|
||||||
- "POSTGRES_HOSTNAME=database"
|
- "POSTGRES_HOSTNAME=database"
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|
|
@ -10,6 +10,7 @@ from email.mime.base import MIMEBase
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
from os import getenv
|
from os import getenv
|
||||||
|
from textwrap import dedent
|
||||||
|
|
||||||
import humanize
|
import humanize
|
||||||
import pgsql
|
import pgsql
|
||||||
|
@ -73,6 +74,7 @@ def notes_to_be_expired(cutoff: datetime) -> list[any]:
|
||||||
FROM "Notes", "Users"
|
FROM "Notes", "Users"
|
||||||
WHERE "Notes"."updatedAt" < $1
|
WHERE "Notes"."updatedAt" < $1
|
||||||
AND "Notes"."ownerId" = "Users"."id"
|
AND "Notes"."ownerId" = "Users"."id"
|
||||||
|
ORDER BY "Notes"."updatedAt"
|
||||||
''') as notes_older_than:
|
''') as notes_older_than:
|
||||||
for row in notes_older_than(cutoff):
|
for row in notes_older_than(cutoff):
|
||||||
notes.append({
|
notes.append({
|
||||||
|
@ -94,7 +96,6 @@ def revisions_to_be_expired(cutoff: datetime) -> list[any]:
|
||||||
"""
|
"""
|
||||||
Obtain a list of revisions to be expired.
|
Obtain a list of revisions to be expired.
|
||||||
:param cutoff:
|
:param cutoff:
|
||||||
:param users:
|
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
revisions = []
|
revisions = []
|
||||||
|
@ -111,6 +112,7 @@ def revisions_to_be_expired(cutoff: datetime) -> list[any]:
|
||||||
WHERE "Revisions"."createdAt" < $1
|
WHERE "Revisions"."createdAt" < $1
|
||||||
AND "Revisions"."noteId" = "Notes"."id"
|
AND "Revisions"."noteId" = "Notes"."id"
|
||||||
AND "Notes"."ownerId" = "Users"."id"
|
AND "Notes"."ownerId" = "Users"."id"
|
||||||
|
ORDER BY "Notes"."createdAt"
|
||||||
''') as revs_older_than:
|
''') as revs_older_than:
|
||||||
for row in revs_older_than(cutoff):
|
for row in revs_older_than(cutoff):
|
||||||
revisions.append({
|
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.
|
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 = MIMEBase('text', "markdown")
|
||||||
md.add_header('Content-Disposition', f'attachment; filename={note["title"]}')
|
md.add_header('Content-Disposition', f'attachment; filename={note["title"]}')
|
||||||
md.set_payload(note["content"])
|
md.set_payload(note["content"])
|
||||||
|
@ -202,7 +204,7 @@ if __name__ == '__main__':
|
||||||
epilog='See https://git.hamburg.ccc.de/CCCHH/hedgedoc-expire')
|
epilog='See https://git.hamburg.ccc.de/CCCHH/hedgedoc-expire')
|
||||||
parser.add_argument('-c', '--check', action='store_true',
|
parser.add_argument('-c', '--check', action='store_true',
|
||||||
help='print what would be done, then exit')
|
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')
|
help='remove all notes not changed in these many days')
|
||||||
parser.add_argument('-r', '--revisions', metavar='DAYS', type=float, default=14,
|
parser.add_argument('-r', '--revisions', metavar='DAYS', type=float, default=14,
|
||||||
help='remove all revisions created more than these many days ago')
|
help='remove all revisions created more than these many days ago')
|
||||||
|
|
Loading…
Reference in a new issue