allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject git commit: [#6835] use default pagination values if URL params are invalid
Date Mon, 04 Nov 2013 21:12:42 GMT
Updated Branches:
  refs/heads/db/6835 [created] c3ec808dc


[#6835] use default pagination values if URL params are invalid


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/c3ec808d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/c3ec808d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/c3ec808d

Branch: refs/heads/db/6835
Commit: c3ec808dcdbd76096e9c5dc060129059a8458e97
Parents: 6e78041
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Mon Nov 4 21:12:29 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Mon Nov 4 21:12:29 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/feed.py               |  4 ++--
 Allura/allura/controllers/repository.py         |  8 ++++----
 ForgeBlog/forgeblog/main.py                     |  6 ++++--
 .../forgeblog/tests/functional/test_root.py     | 10 +++++++++-
 .../forgediscussion/controllers/forum.py        |  8 ++++----
 .../forgediscussion/controllers/root.py         |  4 ++--
 ForgeShortUrl/forgeshorturl/main.py             |  4 ++--
 ForgeTracker/forgetracker/tracker_main.py       | 16 ++++++++--------
 ForgeWiki/forgewiki/wiki_main.py                | 20 ++++++++++----------
 9 files changed, 45 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c3ec808d/Allura/allura/controllers/feed.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/feed.py b/Allura/allura/controllers/feed.py
index 9be693d..f6e1420 100644
--- a/Allura/allura/controllers/feed.py
+++ b/Allura/allura/controllers/feed.py
@@ -72,8 +72,8 @@ class FeedController(object):
     @validate(dict(
             since=h.DateTimeConverter(if_empty=None, if_invalid=None),
             until=h.DateTimeConverter(if_empty=None, if_invalid=None),
-            page=V.Int(if_empty=None),
-            limit=V.Int(if_empty=None)))
+            page=V.Int(if_empty=None, if_invalid=None),
+            limit=V.Int(if_empty=None, if_invalid=None)))
     def feed(self, since=None, until=None, page=None, limit=None, **kw):
         """Return a utf8-encoded XML feed (RSS or Atom) to the browser.
         """

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c3ec808d/Allura/allura/controllers/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index 14ce77a..d0e78e2 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -431,8 +431,8 @@ class CommitBrowser(BaseController):
         self.tree = self.TreeBrowserClass(self._commit, tree=self._commit.tree)
 
     @expose('jinja:allura:templates/repo/commit.html')
-    @validate(dict(page=validators.Int(if_empty=0),
-                   limit=validators.Int(if_empty=DEFAULT_PAGE_LIMIT)))
+    @validate(dict(page=validators.Int(if_empty=0, if_invalid=0),
+                   limit=validators.Int(if_empty=DEFAULT_PAGE_LIMIT, if_invalid=DEFAULT_PAGE_LIMIT)))
     def index(self, page=0, limit=DEFAULT_PAGE_LIMIT, **kw):
         c.revision_widget = self.revision_widget
         c.page_list = self.page_list
@@ -481,8 +481,8 @@ class CommitBrowser(BaseController):
 
     @expose('jinja:allura:templates/repo/log.html')
     @with_trailing_slash
-    @validate(dict(page=validators.Int(if_empty=0),
-                   limit=validators.Int(if_empty=25)))
+    @validate(dict(page=validators.Int(if_empty=0, if_invalid=0),
+                   limit=validators.Int(if_empty=25, if_invalid=25)))
     def log(self, limit=25, path=None, **kw):
         is_file = False
         if path:

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c3ec808d/ForgeBlog/forgeblog/main.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/main.py b/ForgeBlog/forgeblog/main.py
index 3abf4f0..0e408b5 100644
--- a/ForgeBlog/forgeblog/main.py
+++ b/ForgeBlog/forgeblog/main.py
@@ -209,6 +209,8 @@ class RootController(BaseController, FeedController):
 
     @expose('jinja:forgeblog:templates/blog/index.html')
     @with_trailing_slash
+    @validate(dict(page=validators.Int(if_empty=0, if_invalid=0),
+                   limit=validators.Int(if_empty=25, if_invalid=25)))
     def index(self, page=0, limit=10, **kw):
         query_filter = dict(app_config_id=c.app.config._id)
         if not has_access(c.app, 'write')():
@@ -290,8 +292,8 @@ class PostController(BaseController, FeedController):
 
     @expose('jinja:forgeblog:templates/blog/post.html')
     @with_trailing_slash
-    @validate(dict(page=validators.Int(if_empty=0),
-                   limit=validators.Int(if_empty=25)))
+    @validate(dict(page=validators.Int(if_empty=0, if_invalid=0),
+                   limit=validators.Int(if_empty=25, if_invalid=25)))
     def index(self, page=0, limit=25, **kw):
         if self.post.state == 'draft':
             require_access(self.post, 'write')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c3ec808d/ForgeBlog/forgeblog/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/tests/functional/test_root.py b/ForgeBlog/forgeblog/tests/functional/test_root.py
index 4409b33..96a8113 100644
--- a/ForgeBlog/forgeblog/tests/functional/test_root.py
+++ b/ForgeBlog/forgeblog/tests/functional/test_root.py
@@ -32,7 +32,7 @@ from allura import model as M
 # CommentController methods exposed:
 #     reply, delete
 
-class TestRootController(TestController):
+class Test(TestController):
 
     def _post(self, slug='', **kw):
         d = {
@@ -217,3 +217,11 @@ class TestRootController(TestController):
     def test_invalid_lookup(self):
         r = self.app.get('/blog/favicon.ico', status=404)
         assert_equal(r.status_int, 404)
+
+    def test_index_bad_url_params(self):
+        self.app.get('/blog/?limit=blah&page=2x', status=200)
+
+    def test_post_bad_url_params(self):
+        self._post()
+        d = self._blog_date()
+        self.app.get('/blog/%s/my-post/?limit=blah&page=2x' % d, status=200)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c3ec808d/ForgeDiscussion/forgediscussion/controllers/forum.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/controllers/forum.py b/ForgeDiscussion/forgediscussion/controllers/forum.py
index dab6dcd..50ed7fb 100644
--- a/ForgeDiscussion/forgediscussion/controllers/forum.py
+++ b/ForgeDiscussion/forgediscussion/controllers/forum.py
@@ -94,8 +94,8 @@ class ForumController(DiscussionController):
             raise exc.HTTPNotFound()
 
     @expose('jinja:forgediscussion:templates/index.html')
-    @validate(dict(page=validators.Int(if_empty=0),
-                   limit=validators.Int(if_empty=25)))
+    @validate(dict(page=validators.Int(if_empty=0, if_invalid=0),
+                   limit=validators.Int(if_empty=25, if_invalid=25)))
     def index(self, threads=None, limit=25, page=0, count=0, **kw):
         if self.discussion.deleted:
             redirect(self.discussion.url()+'deleted')
@@ -130,8 +130,8 @@ class ForumController(DiscussionController):
 class ForumThreadController(ThreadController):
 
     @expose('jinja:forgediscussion:templates/discussionforums/thread.html')
-    @validate(dict(page=validators.Int(if_empty=0),
-                   limit=validators.Int(if_empty=25)))
+    @validate(dict(page=validators.Int(if_empty=0, if_invalid=0),
+                   limit=validators.Int(if_empty=25, if_invalid=25)))
     def index(self, limit=25, page=0, count=0, **kw):
         if self.thread.discussion.deleted and not has_access(c.app, 'configure')():
             redirect(self.thread.discussion.url()+'deleted')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c3ec808d/ForgeDiscussion/forgediscussion/controllers/root.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/controllers/root.py b/ForgeDiscussion/forgediscussion/controllers/root.py
index ff74d63..d0526dc 100644
--- a/ForgeDiscussion/forgediscussion/controllers/root.py
+++ b/ForgeDiscussion/forgediscussion/controllers/root.py
@@ -138,8 +138,8 @@ class RootController(BaseController, DispatchIndex, FeedController):
     @validate(dict(q=validators.UnicodeString(if_empty=None),
                    history=validators.StringBool(if_empty=False),
                    project=validators.StringBool(if_empty=False),
-                   limit=validators.Int(if_empty=None),
-                   page=validators.Int(if_empty=0)))
+                   limit=validators.Int(if_empty=None, if_invalid=None),
+                   page=validators.Int(if_empty=0, if_invalid=0)))
     def search(self, q=None, history=None, project=None, limit=None, page=0, **kw):
         c.search_results = self.W.search_results
         c.help_modal = self.W.search_help

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c3ec808d/ForgeShortUrl/forgeshorturl/main.py
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/main.py b/ForgeShortUrl/forgeshorturl/main.py
index f9217df..8524cda 100644
--- a/ForgeShortUrl/forgeshorturl/main.py
+++ b/ForgeShortUrl/forgeshorturl/main.py
@@ -141,8 +141,8 @@ class RootController(BaseController):
         require_access(c.app, 'read')
 
     @expose('jinja:forgeshorturl:templates/index.html')
-    @validate(dict(page=validators.Int(if_empty=0),
-                   limit=validators.Int(if_empty=100)))
+    @validate(dict(page=validators.Int(if_empty=0, if_invalid=0),
+                   limit=validators.Int(if_empty=100, if_invalid=100)))
     def index(self, page=0, limit=100, **kw):
         c.page_list = W.page_list
         c.page_size = W.page_size

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c3ec808d/ForgeTracker/forgetracker/tracker_main.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index cef07d8..63e876b 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -83,7 +83,7 @@ search_validators = dict(
     history=validators.StringBool(if_empty=False),
     project=validators.StringBool(if_empty=False),
     limit=validators.Int(if_invalid=None),
-    page=validators.Int(if_empty=0),
+    page=validators.Int(if_empty=0, if_invalid=0),
     sort=validators.UnicodeString(if_empty=None),
     deleted=validators.StringBool(if_empty=False))
 
@@ -818,8 +818,8 @@ class RootController(BaseController, FeedController):
     @with_trailing_slash
     @expose('jinja:forgetracker:templates/tracker/mass_edit.html')
     @validate(dict(q=validators.UnicodeString(if_empty=None),
-                   limit=validators.Int(if_empty=10),
-                   page=validators.Int(if_empty=0),
+                   limit=validators.Int(if_empty=10, if_invalid=10),
+                   page=validators.Int(if_empty=0, if_invalid=0),
                    sort=validators.UnicodeString(if_empty='ticket_num_i asc')))
     def edit(self, q=None, limit=None, page=None, sort=None, **kw):
         require_access(c.app, 'update')
@@ -841,8 +841,8 @@ class RootController(BaseController, FeedController):
     @with_trailing_slash
     @expose('jinja:forgetracker:templates/tracker/mass_move.html')
     @validate(dict(q=validators.UnicodeString(if_empty=None),
-                   limit=validators.Int(if_empty=10),
-                   page=validators.Int(if_empty=0),
+                   limit=validators.Int(if_empty=10, if_invalid=10),
+                   page=validators.Int(if_empty=0, if_invalid=0),
                    sort=validators.UnicodeString(if_empty='ticket_num_i asc')))
     def move(self, q=None, limit=None, page=None, sort=None, **kw):
         require_access(c.app, 'admin')
@@ -1212,8 +1212,8 @@ class TicketController(BaseController, FeedController):
     @with_trailing_slash
     @expose('jinja:forgetracker:templates/tracker/ticket.html')
     @validate(dict(
-            page=validators.Int(if_empty=0),
-            limit=validators.Int(if_empty=10)))
+            page=validators.Int(if_empty=0, if_invalid=0),
+            limit=validators.Int(if_empty=10, if_invalid=10)))
     def index(self, page=0, limit=10, deleted=False, **kw):
         ticket_visible = self.ticket and not self.ticket.deleted
         if ticket_visible or has_access(self.ticket, 'delete'):
@@ -1728,7 +1728,7 @@ class MilestoneController(BaseController):
     @expose('jinja:forgetracker:templates/tracker/milestone.html')
     @validate(validators=dict(
             limit=validators.Int(if_invalid=None),
-            page=validators.Int(if_empty=0),
+            page=validators.Int(if_empty=0, if_invalid=0),
             sort=validators.UnicodeString(if_empty=None),
             deleted=validators.StringBool(if_empty=False)))
     def index(self, q=None, columns=None, page=0, query=None, sort=None, deleted=False, **kw):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c3ec808d/ForgeWiki/forgewiki/wiki_main.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index 108c14c..55ee9a3 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -348,8 +348,8 @@ class RootController(BaseController, DispatchIndex, FeedController):
     @expose('jinja:forgewiki:templates/wiki/browse.html')
     @validate(dict(sort=validators.UnicodeString(if_empty='alpha'),
                    show_deleted=validators.StringBool(if_empty=False),
-                   page=validators.Int(if_empty=0),
-                   limit=validators.Int(if_empty=None)))
+                   page=validators.Int(if_empty=0, if_invalid=0),
+                   limit=validators.Int(if_empty=None, if_invalid=None)))
     def browse_pages(self, sort='alpha', show_deleted=False, page=0, limit=None, **kw):
         'list of all pages in the wiki'
         c.page_list = W.page_list
@@ -390,8 +390,8 @@ class RootController(BaseController, DispatchIndex, FeedController):
     @with_trailing_slash
     @expose('jinja:forgewiki:templates/wiki/browse_tags.html')
     @validate(dict(sort=validators.UnicodeString(if_empty='alpha'),
-                   page=validators.Int(if_empty=0),
-                   limit=validators.Int(if_empty=25)))
+                   page=validators.Int(if_empty=0, if_invalid=0),
+                   limit=validators.Int(if_empty=25, if_invalid=25)))
     def browse_tags(self, sort='alpha', page=0, limit=None, **kw):
         'list of all labels in the wiki'
         c.page_list = W.page_list
@@ -474,9 +474,9 @@ class PageController(BaseController, FeedController):
 
     @with_trailing_slash
     @expose('jinja:forgewiki:templates/wiki/page_view.html')
-    @validate(dict(version=validators.Int(if_empty=None),
-                   page=validators.Int(if_empty=0),
-                   limit=validators.Int(if_empty=25)))
+    @validate(dict(version=validators.Int(if_empty=None, if_invalid=None),
+                   page=validators.Int(if_empty=0, if_invalid=0),
+                   limit=validators.Int(if_empty=25, if_invalid=25)))
     def index(self, version=None, page=0, limit=25, **kw):
         if not self.page:
             redirect(c.app.url+h.urlquote(self.title)+'/edit')
@@ -540,8 +540,8 @@ class PageController(BaseController, FeedController):
 
     @without_trailing_slash
     @expose('jinja:forgewiki:templates/wiki/page_history.html')
-    @validate(dict(page=validators.Int(if_empty=0),
-                   limit=validators.Int(if_empty=None)))
+    @validate(dict(page=validators.Int(if_empty=0, if_invalid=0),
+                   limit=validators.Int(if_empty=None, if_invalid=None)))
     def history(self, page=0, limit=None, **kw):
         if not self.page:
             raise exc.HTTPNotFound
@@ -592,7 +592,7 @@ class PageController(BaseController, FeedController):
     @without_trailing_slash
     @expose('json')
     @require_post()
-    @validate(dict(version=validators.Int(if_empty=1)))
+    @validate(dict(version=validators.Int(if_empty=1, if_invalid=1)))
     def revert(self, version, **kw):
         if not self.page:
             raise exc.HTTPNotFound


Mime
View raw message