From: Michael Tremer Date: Sat, 1 Jul 2023 10:56:12 +0000 (+0000) Subject: docs: Move restore handler X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bb998aca48e9b55d9e6c814bb4491866ca2cb929;p=ipfire.org.git docs: Move restore handler Signed-off-by: Michael Tremer --- diff --git a/src/templates/docs/confirm-restore.html b/src/templates/docs/confirm-restore.html index d4c792b8..3001a5fa 100644 --- a/src/templates/docs/confirm-restore.html +++ b/src/templates/docs/confirm-restore.html @@ -12,7 +12,7 @@ {{ _("Do you really want to restore this page to its revision from %s?") % locale.format_date(page.timestamp) }}

-
+ {% raw xsrf_form_html() %} diff --git a/src/web/__init__.py b/src/web/__init__.py index 9eb11c0a..1bf9e69a 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -146,6 +146,7 @@ class Application(tornado.web.Application): (r"/docs/search", docs.SearchHandler), (r"/docs/tree", docs.TreeHandler), (r"/docs/watchlist", docs.WatchlistHandler), + (r"/docs/_restore", docs.RestoreHandler), (r"/docs/_upload", docs.UploadHandler), (r"/docs/([A-Za-z0-9\-_\/]+)?/_edit", docs.EditHandler), (r"/docs/([A-Za-z0-9\-_\/]+)?/_render", docs.RenderHandler), @@ -352,7 +353,7 @@ class Application(tornado.web.Application): authentication_handlers + [ # Actions - (r"/actions/restore", wiki.ActionRestoreHandler), + # Serve any static files (r"/static/(.*)", tornado.web.StaticFileHandler, { "path" : self.settings.get("static_path") }), diff --git a/src/web/docs.py b/src/web/docs.py index 9cf6ba76..77add707 100644 --- a/src/web/docs.py +++ b/src/web/docs.py @@ -229,6 +229,34 @@ class RenderHandler(base.BaseHandler): self.finish(html) +class RestoreHandler(base.BaseHandler): + @tornado.web.authenticated + @base.ratelimit(minutes=60, requests=24) + def post(self): + path = self.get_argument("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)) + + # Check if we are asked to render a certain revision + revision = self.get_argument("revision", None) + comment = self.get_argument("comment", None) + + # Fetch the wiki page + page = self.backend.wiki.get_page(path, revision=revision) + + with self.db.transaction(): + page = page.restore( + author=self.current_user, + address=self.get_remote_ip(), + comment=comment, + ) + + # Redirect back to page + self.redirect(page.page) + + class UploadHandler(base.BaseHandler): @tornado.web.authenticated @base.ratelimit(minutes=60, requests=24) diff --git a/src/web/wiki.py b/src/web/wiki.py index 2d94e7d2..1eb4a0ce 100644 --- a/src/web/wiki.py +++ b/src/web/wiki.py @@ -1,38 +1,7 @@ #!/usr/bin/python3 -import tornado.web - -from . import base from . import ui_modules -class ActionRestoreHandler(base.BaseHandler): - @tornado.web.authenticated - @base.ratelimit(minutes=60, requests=24) - def post(self): - path = self.get_argument("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)) - - # Check if we are asked to render a certain revision - revision = self.get_argument("revision", None) - comment = self.get_argument("comment", None) - - # Fetch the wiki page - page = self.backend.wiki.get_page(path, revision=revision) - - with self.db.transaction(): - page = page.restore( - author=self.current_user, - address=self.get_remote_ip(), - comment=comment, - ) - - # Redirect back to page - self.redirect(page.page) - - class WikiListModule(ui_modules.UIModule): def render(self, pages, link_revision=False, show_breadcrumbs=True, show_author=True, show_changes=False):