]> git.ipfire.org Git - ipfire.org.git/commitdiff
docs: Move edit handler
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 1 Jul 2023 10:39:13 +0000 (10:39 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 1 Jul 2023 10:39:13 +0000 (10:39 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/templates/docs/edit.html [moved from src/templates/wiki/edit.html with 100% similarity]
src/web/__init__.py
src/web/docs.py
src/web/wiki.py

index 1dfc56ac5f9c364272a2d358bc0e98fe47d0b0fe..7962435d3001d227538ce15012c870d0a028effd 100644 (file)
@@ -202,6 +202,7 @@ templates_docs_DATA = \
        src/templates/docs/base.html \
        src/templates/docs/confirm-restore.html \
        src/templates/docs/diff.html \
+       src/templates/docs/edit.html \
        src/templates/docs/page.html \
        src/templates/docs/recent-changes.html \
        src/templates/docs/revisions.html \
@@ -347,8 +348,7 @@ templates_voip_modules_DATA = \
 templates_voip_modulesdir = $(templates_voipdir)/modules
 
 templates_wiki_DATA = \
-       src/templates/wiki/confirm-delete.html \
-       src/templates/wiki/edit.html
+       src/templates/wiki/confirm-delete.html
 
 templates_wikidir = $(templatesdir)/wiki
 
index f76d31d2653a5d303472dec8f01b5ba5441865d2..bfd2934f3af152002db0a8248a9f319b0fc39b73 100644 (file)
@@ -146,6 +146,8 @@ class Application(tornado.web.Application):
                        (r"/docs/search", docs.SearchHandler),
                        (r"/docs/tree", docs.TreeHandler),
                        (r"/docs/watchlist", docs.WatchlistHandler),
+                       (r"/docs/([A-Za-z0-9\-_\/]+)?/_edit", docs.ActionEditHandler),
+                       (r"/docs/([A-Za-z0-9\-_\/]+)?/_render", docs.ActionRenderHandler),
                        (r"/docs((?:[A-Za-z0-9\-_\/]+)?(?:.*)\.(?:\w+))$", docs.FileHandler),
                        (r"/docs([A-Za-z0-9\-_\/]+)?", docs.PageHandler),
 
@@ -347,8 +349,6 @@ class Application(tornado.web.Application):
 
                        # Actions
                        (r"((?:[A-Za-z0-9\-_\/]+)?(?:.*)\.(?:\w+))/_delete", wiki.ActionDeleteHandler),
-                       (r"([A-Za-z0-9\-_\/]+)?/_edit", wiki.ActionEditHandler),
-                       (r"([A-Za-z0-9\-_\/]+)?/_render", wiki.ActionRenderHandler),
                        (r"([A-Za-z0-9\-_\/]+)?/_(watch|unwatch)", wiki.ActionWatchHandler),
                        (r"/actions/restore", wiki.ActionRestoreHandler),
                        (r"/actions/upload", wiki.ActionUploadHandler),
index 0a55fffa54e8f3d27dd2db4608e96d483e49d1fd..ae93ce9b07e51b3eb4406dd6c7640e1b87a9f155 100644 (file)
@@ -138,6 +138,82 @@ class FileHandler(base.BaseHandler):
                self.finish(blob)
 
 
+class ActionEditHandler(base.BaseHandler):
+       @tornado.web.authenticated
+       def get(self, path):
+               if path is None:
+                       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 wiki page
+               page = self.backend.wiki.get_page(path)
+
+               # Empty page if it was deleted
+               if page and page.was_deleted():
+                       page = None
+
+               # Render page
+               self.render("docs/edit.html", page=page, path=path)
+
+       @tornado.web.authenticated
+       def post(self, path):
+               if path is None:
+                       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))
+
+               content = self.get_argument("content", None)
+               changes = self.get_argument("changes")
+
+               # Create a new page in the database
+               with self.db.transaction():
+                       page = self.backend.wiki.create_page(path,
+                               self.current_user, content, changes=changes, address=self.get_remote_ip())
+
+                       # Add user as a watcher if wanted
+                       watch = self.get_argument("watch", False)
+                       if watch:
+                               page.add_watcher(self.current_user)
+
+               # Redirect back
+               if page.was_deleted():
+                       self.redirect("/")
+               else:
+                       self.redirect(page.url)
+
+       def on_finish(self):
+               """
+                       Updates the search index after the page has been edited
+               """
+               # This is being executed in the background and after
+               # the response has been set to the client
+               with self.db.transaction():
+                       self.backend.wiki.refresh()
+
+
+class ActionRenderHandler(base.BaseHandler):
+       def check_xsrf_cookie(self):
+               pass # disabled
+
+       @tornado.web.authenticated
+       @base.ratelimit(minutes=5, requests=180)
+       def post(self, path):
+               if path is None:
+                       path = "/"
+
+               content = self.get_argument("content")
+
+               # Render the content
+               html = self.backend.wiki.render(path, content)
+
+               self.finish(html)
+
+
 class SearchHandler(base.BaseHandler):
        @base.ratelimit(minutes=5, requests=25)
        def get(self):
index 52a044143632d6f238e490958ba30e6a0b1b7be8..0c9858d78325d021213aae08464bf443656b0be3 100644 (file)
@@ -5,64 +5,6 @@ import tornado.web
 from . import base
 from . import ui_modules
 
-class ActionEditHandler(base.BaseHandler):
-       @tornado.web.authenticated
-       def get(self, path):
-               if path is None:
-                       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 wiki page
-               page = self.backend.wiki.get_page(path)
-
-               # Empty page if it was deleted
-               if page and page.was_deleted():
-                       page = None
-
-               # Render page
-               self.render("wiki/edit.html", page=page, path=path)
-
-       @tornado.web.authenticated
-       def post(self, path):
-               if path is None:
-                       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))
-
-               content = self.get_argument("content", None)
-               changes = self.get_argument("changes")
-
-               # Create a new page in the database
-               with self.db.transaction():
-                       page = self.backend.wiki.create_page(path,
-                               self.current_user, content, changes=changes, address=self.get_remote_ip())
-
-                       # Add user as a watcher if wanted
-                       watch = self.get_argument("watch", False)
-                       if watch:
-                               page.add_watcher(self.current_user)
-
-               # Redirect back
-               if page.was_deleted():
-                       self.redirect("/")
-               else:
-                       self.redirect(page.url)
-
-       def on_finish(self):
-               """
-                       Updates the search index after the page has been edited
-               """
-               # This is being executed in the background and after
-               # the response has been set to the client
-               with self.db.transaction():
-                       self.backend.wiki.refresh()
-
-
 class ActionUploadHandler(base.BaseHandler):
        @tornado.web.authenticated
        @base.ratelimit(minutes=60, requests=24)
@@ -177,24 +119,6 @@ class ActionWatchHandler(base.BaseHandler):
                self.redirect(page.url)
 
 
-class ActionRenderHandler(base.BaseHandler):
-       def check_xsrf_cookie(self):
-               pass # disabled
-
-       @tornado.web.authenticated
-       @base.ratelimit(minutes=5, requests=180)
-       def post(self, path):
-               if path is None:
-                       path = "/"
-
-               content = self.get_argument("content")
-
-               # Render the content
-               html = self.backend.wiki.render(path, content)
-
-               self.finish(html)
-
-
 class FilesHandler(base.BaseHandler):
        @tornado.web.authenticated
        def get(self, path):