From 165106181568affbea1082662eae13c73a709a90 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 1 Jul 2023 10:47:39 +0000 Subject: [PATCH] docs: Move delete file handler Signed-off-by: Michael Tremer --- Makefile.am | 4 +-- .../{wiki => docs}/confirm-delete.html | 0 src/web/__init__.py | 2 +- src/web/docs.py | 32 +++++++++++++++++++ src/web/wiki.py | 32 ------------------- 5 files changed, 34 insertions(+), 36 deletions(-) rename src/templates/{wiki => docs}/confirm-delete.html (100%) diff --git a/Makefile.am b/Makefile.am index 7962435d..5c45458e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -200,6 +200,7 @@ templates_donate_messagesdir = $(templates_donatedir)/messages templates_docs_DATA = \ src/templates/docs/404.html \ src/templates/docs/base.html \ + src/templates/docs/confirm-delete.html \ src/templates/docs/confirm-restore.html \ src/templates/docs/diff.html \ src/templates/docs/edit.html \ @@ -347,9 +348,6 @@ templates_voip_modules_DATA = \ templates_voip_modulesdir = $(templates_voipdir)/modules -templates_wiki_DATA = \ - src/templates/wiki/confirm-delete.html - templates_wikidir = $(templatesdir)/wiki templates_wiki_files_DATA = \ diff --git a/src/templates/wiki/confirm-delete.html b/src/templates/docs/confirm-delete.html similarity index 100% rename from src/templates/wiki/confirm-delete.html rename to src/templates/docs/confirm-delete.html diff --git a/src/web/__init__.py b/src/web/__init__.py index 3da28e23..d573e020 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -149,6 +149,7 @@ class Application(tornado.web.Application): (r"/docs/([A-Za-z0-9\-_\/]+)?/_edit", docs.ActionEditHandler), (r"/docs/([A-Za-z0-9\-_\/]+)?/_render", docs.ActionRenderHandler), (r"/docs/([A-Za-z0-9\-_\/]+)?/_(watch|unwatch)", docs.ActionWatchHandler), + (r"/docs/((?:[A-Za-z0-9\-_\/]+)?(?:.*)\.(?:\w+))/_delete", docs.DeleteFileHandler), (r"/docs((?:[A-Za-z0-9\-_\/]+)?(?:.*)\.(?:\w+))$", docs.FileHandler), (r"/docs([A-Za-z0-9\-_\/]+)?", docs.PageHandler), @@ -349,7 +350,6 @@ class Application(tornado.web.Application): authentication_handlers + [ # Actions - (r"((?:[A-Za-z0-9\-_\/]+)?(?:.*)\.(?:\w+))/_delete", wiki.ActionDeleteHandler), (r"/actions/restore", wiki.ActionRestoreHandler), (r"/actions/upload", wiki.ActionUploadHandler), diff --git a/src/web/docs.py b/src/web/docs.py index 6682bcd0..84fa848c 100644 --- a/src/web/docs.py +++ b/src/web/docs.py @@ -239,6 +239,38 @@ class ActionWatchHandler(base.BaseHandler): self.redirect(page.url) +class DeleteFileHandler(base.BaseHandler): + @tornado.web.authenticated + def get(self, path): + # Check permissions + if not self.backend.wiki.check_acl(path, self.current_user): + raise tornado.web.HTTPError(403, "Access to %s not allowed for %s" % (path, self.current_user)) + + # Fetch the file + file = self.backend.wiki.get_file_by_path(path) + if not file: + raise tornado.web.HTTPError(404, "Could not find %s" % path) + + self.render("docs/confirm-delete.html", file=file) + + @tornado.web.authenticated + @base.ratelimit(minutes=60, requests=24) + def post(self, path): + # Check permissions + if not self.backend.wiki.check_acl(path, self.current_user): + raise tornado.web.HTTPError(403, "Access to %s not allowed for %s" % (path, self.current_user)) + + # Fetch the file + file = self.backend.wiki.get_file_by_path(path) + if not file: + raise tornado.web.HTTPError(404, "Could not find %s" % path) + + with self.db.transaction(): + file.delete(self.current_user) + + self.redirect("%s/_files" % file.path) + + class SearchHandler(base.BaseHandler): @base.ratelimit(minutes=5, requests=25) def get(self): diff --git a/src/web/wiki.py b/src/web/wiki.py index 4c4ba134..ba914ba1 100644 --- a/src/web/wiki.py +++ b/src/web/wiki.py @@ -34,38 +34,6 @@ class ActionUploadHandler(base.BaseHandler): self.redirect("%s/_files" % path) -class ActionDeleteHandler(base.BaseHandler): - @tornado.web.authenticated - def get(self, path): - # Check permissions - if not self.backend.wiki.check_acl(path, self.current_user): - raise tornado.web.HTTPError(403, "Access to %s not allowed for %s" % (path, self.current_user)) - - # Fetch the file - file = self.backend.wiki.get_file_by_path(path) - if not file: - raise tornado.web.HTTPError(404, "Could not find %s" % path) - - self.render("wiki/confirm-delete.html", file=file) - - @tornado.web.authenticated - @base.ratelimit(minutes=60, requests=24) - def post(self, path): - # Check permissions - if not self.backend.wiki.check_acl(path, self.current_user): - raise tornado.web.HTTPError(403, "Access to %s not allowed for %s" % (path, self.current_user)) - - # Fetch the file - file = self.backend.wiki.get_file_by_path(path) - if not file: - raise tornado.web.HTTPError(404, "Could not find %s" % path) - - with self.db.transaction(): - file.delete(self.current_user) - - self.redirect("%s/_files" % file.path) - - class ActionRestoreHandler(base.BaseHandler): @tornado.web.authenticated @base.ratelimit(minutes=60, requests=24) -- 2.47.3