OSDN Git Service

fix comment allowed/denyed related problems
authorhylom <hylom@users.sourceforge.jp>
Thu, 5 Oct 2017 10:47:22 +0000 (19:47 +0900)
committerhylom <hylom@users.sourceforge.jp>
Thu, 5 Oct 2017 10:47:22 +0000 (19:47 +0900)
src/newslash_web/lib/Newslash/Web/Controller/Story.pm
src/newslash_web/lib/Newslash/Web/Controller/Submission.pm
src/newslash_web/templates/common/comment/comment_header.html.tt2
src/newslash_web/templates/common/js_vars.html.tt2

index 4da706e..8d236c9 100644 (file)
@@ -52,6 +52,7 @@ sub story {
                params => $params,
                authors => $authors,
                use_captcha => 1,
+               comment_allowed => 1,
               );
 }
 
index 765cd7f..f2fdd19 100644 (file)
@@ -5,6 +5,7 @@ use Data::Dumper;
 sub submission {
     my $c = shift;
     my $subid = $c->stash('id');
+    my $user = $c->stash('user');
     my $submission = $c->model('submissions')->select(subid => $subid);
     if (!$submission) {
         $c->render('Not found', status => '404');
@@ -13,12 +14,21 @@ sub submission {
     my $d_id = $submission->{discussion_id};
     my $comments = [];
     my $discuss = {};
+    my $comment_allowed => 0;
 
     if ($d_id) {
-        $discuss = $c->model('discussions')->select(id => $d_id);
+        my $discussions = $c->model('discussions');
+        $discuss = $discussions->select(id => $d_id);
         $comments = $c->model('comments')->select(discussion_id => $d_id);
+        $comment_allowed = $discussions->is_comment_allowed(discussion => $discuss,
+                                                            uid => $user->{uid});
     }
-    $c->render(submission => $submission, discussion => $discuss, comments => $comments);
+    $c->render(submission => $submission,
+               discussion => $discuss,
+               comments => $comments,
+               use_captcha => 1,
+               comment_allowed => $comment_allowed,
+              );
 }
 
 sub create {
index eb14686..253be76 100644 (file)
@@ -2,14 +2,14 @@
   <div v-if="archived" class="alert alert-info">
     この議論は賞味期限が切れたので、アーカイブ化されています。 新たにコメントを付けることはできません。
   </div>
-  <div v-if="!commentAllowed" class="alert alert-info">
+  <div v-else-if="!commentAllowed" class="alert alert-info">
     設定によりコメント投稿は許可されていません。
   </div>
   <div class="form-inline">
     [%#
     <button type="button" class="btn btn-default form-control">コメント元ページを表示</button>
     %]
-    <button type="button" class="btn btn-default form-control" v-if="commentAllowed">
+    <button type="button" class="btn btn-default form-control" v-if="commentAllowed && !archived">
       <span class="glyphicon glyphicon-comment"></span>
       <span class="btn-text"> コメントを書く</span>
     </button>
index f5d6c15..c1e8961 100644 (file)
     [%- END %]
   };
   var page = {};
+  [%- IF discussion.type != 'archived' && comment_allowed %]
+  page.commentAllowed = 1;
+  [%- ELSE %]
+  page.commentAllowed = 0;
+  [%- END %]
+  [%- IF discussion %] 
+  page.archived = [% IF discussion.type == 'archived' %]1[% ELSE %]0[% END %];
+  page.discussionID = [% discussion.id %];
+  [%- ELSE %]
+  page.archived = 0;
+  page.discussionID = 0;
+  [%- END %]
 
   [%- IF story && story.content_type == "story" -%]
   page.type = 'story';
   page.stoid =  [% story.stoid %];
   page.sid = '[% story.sid %]';
-  page.archived = [% IF discussion.type == 'archived' %]1[% ELSE %]0[% END %];
-  page.discussionID = [% story.discussion %];
-  page.commentAllowed = [% IF comment_allowed; comment_allowed; ELSE; 0; END %];
   [%- END -%]
 
   [%- IF journal && journal.content_type == "journal" -%]
   page.type = 'journal';
   page.id =  [% journal.id %];
-  page.archived = [% IF discussion.type == 'archived' %]1[% ELSE %]0[% END %];
-  page.discussionID = [% IF journal.discussion_id; journal.discussion_id; ELSE; 0; END %];
-  page.commentAllowed = [% IF comment_allowed; comment_allowed; ELSE; 0; END %];
   [%- END -%]
 
   [%- IF comment && comment.content_type == "comment" -%]
   page.parentID = [% comment.parent_id %];
   page.stoid =  [% discussion.stoid %];
   page.sid = '[% discussion.sid %]';
-  page.archived = [% IF discussion.type == 'archived' %]1[% ELSE %]0[% END %];
-  page.discussionID = [% discussion.id %];
-  page.commentAllowed = [% IF comment_allowed; comment_allowed; ELSE; 0; END %];
   [%- END -%]
 
   [%- IF story && story.content_type == "poll" -%]
   page.type = 'poll';
   page.qid =  [% story.qid %];
-  page.archived = [% IF discussion.type == 'archived' %]1[% ELSE %]0[% END %];
-  page.discussionID = [% story.discussion %];
-  page.commentAllowed = [% IF comment_allowed; comment_allowed; ELSE; 0; END %];
   [%- END -%]
 
 </script>