OSDN Git Service

fix /tag/<tagname>/<page> and /tag/<tagname>/<type>/ routing
authorhylom <hylom@users.sourceforge.jp>
Wed, 3 Apr 2019 09:20:31 +0000 (18:20 +0900)
committerhylom <hylom@users.sourceforge.jp>
Wed, 3 Apr 2019 09:20:31 +0000 (18:20 +0900)
src/newslash_web/dom_t/domtest.t
src/newslash_web/lib/Newslash/Web.pm
src/newslash_web/lib/Newslash/Web/Controller/Tag.pm

index 9721164..5d547f6 100644 (file)
@@ -80,8 +80,9 @@ SKIP: {
     skip "mode is 'test'", 4 if ($t->app->mode eq 'test');
     test_path("/tag/");
     test_path("/tag/linux/");
+    test_path("/tag/linux/2");
     test_path("/tag/linux/story/");
-    test_path("/tag/linux/story/?page=2");
+    test_path("/tag/linux/story/2/");
 }
 
 # user
index db9c0ca..b0a8223 100644 (file)
@@ -312,7 +312,8 @@ sub startup {
 
     # tag page
     $r->get('/tag/:tagname/:type/:page/')->to('tag#list_tagged_items');
-    $r->get('/tag/:tagname/:page/')->to('tag#list_tagged_items');
+    $r->get('/tag/:tagname/:page/' => [page => qr/\d+/])->to('tag#list_tagged_items');
+    $r->get('/tag/:tagname/:type/')->to('tag#list_tagged_items');
     $r->get('/tag/:tagname/')->to('tag#list_tagged_items');
     $r->get('/tag/')->to('tag#list_tags');
 
index 578f904..dd1b538 100644 (file)
@@ -28,19 +28,19 @@ sub list_tagged_items {
     my $type = $c->stash('type');
 
     # check parameter
-    my $page_num = $c->param('page') || 1;
+    my $page_num = $c->stash('page') || 1;
     my $config = $c->app->config("Timeline") || {};
     my $limit = $config->{item_per_page} || 10;
     my $offset = $limit * ($page_num - 1);
 
-    my $show_future = $user->{is_admin} ? 1 : 0;
-    my $show_nonpublic = $user->{is_admin} ? 1 : 0;
-
-    if ($page_num < 1 || $type && !any { $_ eq $type } qw(story journal submission)) {
+    if ($page_num !~ m/^\d+$/
+        || $page_num < 1
+        || $type && !any { $_ eq $type } qw(story journal submission)) {
         $c->rendered(404);
         return;
     }
 
+
     # get tagname id
     my $tagname_ids = [];
     my $tags = $c->model('tags');
@@ -77,7 +77,8 @@ sub list_tagged_items {
     }
     push @$tagname_ids, $rs->[0]->{tagnameid};
 
-    my $show_future = $user->{is_admin} || $user->{author} || 0;
+    my $show_future = $user->{is_admin} ? 1 : 0;
+    my $show_nonpublic = $user->{is_admin} ? 1 : 0;
 
     my $items = $c->model('firehose')->select(type => $type,
                                               tag_name_id => $tagname_ids,
@@ -85,7 +86,7 @@ sub list_tagged_items {
                                               limit => $limit + 1,
                                               offset => $offset,
                                               hide_future => !$show_future,
-                                              public_only => !$show_future,
+                                              public_only => !$show_nonpublic,
                                              );
     if (!$items) {
         $c->rendered(500);