]> git.ipfire.org Git - ipfire.org.git/commitdiff
docs: Move restore handler
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 1 Jul 2023 10:56:12 +0000 (10:56 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 1 Jul 2023 10:56:12 +0000 (10:56 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/templates/docs/confirm-restore.html
src/web/__init__.py
src/web/docs.py
src/web/wiki.py

index d4c792b8963ea552bd4ef45f3d24d7f55d3c3451..3001a5faa8ef53934c0b6d6127f777ce8977be5e 100644 (file)
@@ -12,7 +12,7 @@
                                        {{ _("Do you really want to restore this page to its revision from %s?") % locale.format_date(page.timestamp) }}
                                </p>
 
-                               <form action="/actions/restore" method="POST">
+                               <form action="/docs/_restore" method="POST">
                                        {% raw xsrf_form_html() %}
 
                                        <input type="hidden" name="path" value="{{ page.page }}">
index 9eb11c0a98a6151f255ae189529b9ea0557a42aa..1bf9e69a6bc98dfd85ed51936daa32a15afa2870 100644 (file)
@@ -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") }),
index 9cf6ba76d216a755451f26a477938c3292bba696..77add707b3e952eae287fb887285335c34759680 100644 (file)
@@ -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)
index 2d94e7d260154edf96eb4f17800b17858ac669d5..1eb4a0ce9d583b8d16a31976cdb45fbf3ca866aa 100644 (file)
@@ -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):