From: Michael Tremer Date: Sat, 1 Jul 2023 10:44:36 +0000 (+0000) Subject: docs: Move watch handler X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=01ddad9bb4dc7deb5547dac3846c4bcd5e1a055b;p=ipfire.org.git docs: Move watch handler Signed-off-by: Michael Tremer --- diff --git a/src/web/__init__.py b/src/web/__init__.py index bfd2934f..3da28e23 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -148,6 +148,7 @@ class Application(tornado.web.Application): (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\-_\/]+)?/_(watch|unwatch)", docs.ActionWatchHandler), (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): # Actions (r"((?:[A-Za-z0-9\-_\/]+)?(?:.*)\.(?:\w+))/_delete", wiki.ActionDeleteHandler), - (r"([A-Za-z0-9\-_\/]+)?/_(watch|unwatch)", wiki.ActionWatchHandler), (r"/actions/restore", wiki.ActionRestoreHandler), (r"/actions/upload", wiki.ActionUploadHandler), diff --git a/src/web/docs.py b/src/web/docs.py index ae93ce9b..6682bcd0 100644 --- a/src/web/docs.py +++ b/src/web/docs.py @@ -214,6 +214,31 @@ class ActionRenderHandler(base.BaseHandler): self.finish(html) +class ActionWatchHandler(base.BaseHandler): + @tornado.web.authenticated + @base.ratelimit(minutes=60, requests=180) + def get(self, path, action): + if path is None: + path = "/" + + page = self.backend.wiki.get_page(path) + if not page: + raise tornado.web.HTTPError(404, "Page does not exist: %s" % 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)) + + with self.db.transaction(): + if action == "watch": + page.add_watcher(self.current_user) + elif action == "unwatch": + page.remove_watcher(self.current_user) + + # Redirect back to page + self.redirect(page.url) + + 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 0c9858d7..4c4ba134 100644 --- a/src/web/wiki.py +++ b/src/web/wiki.py @@ -94,31 +94,6 @@ class ActionRestoreHandler(base.BaseHandler): self.redirect(page.page) -class ActionWatchHandler(base.BaseHandler): - @tornado.web.authenticated - @base.ratelimit(minutes=60, requests=180) - def get(self, path, action): - if path is None: - path = "/" - - page = self.backend.wiki.get_page(path) - if not page: - raise tornado.web.HTTPError(404, "Page does not exist: %s" % 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)) - - with self.db.transaction(): - if action == "watch": - page.add_watcher(self.current_user) - elif action == "unwatch": - page.remove_watcher(self.current_user) - - # Redirect back to page - self.redirect(page.url) - - class FilesHandler(base.BaseHandler): @tornado.web.authenticated def get(self, path):