Skip to content

Commit b70296c

Browse files
committed
Disable/hide things for closed discussion state
Summary: The hidden state is handled pretty well, but closed needed some attention. Test Plan: - Set a documents discussion state to "closed" - Support buttons, comment likes/flags should all be present, but disabled - New comment and reply forms should be hidden Reviewers: sethetter Reviewed By: sethetter Maniphest Tasks: T284 Differential Revision: https://phabricator.opengovfoundation.org/D174
1 parent 4973bc3 commit b70296c

File tree

8 files changed

+51
-10
lines changed

8 files changed

+51
-10
lines changed

app/Models/Doc.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,4 +667,9 @@ public function scopeOrderByRelevance($query, $dir = 'DESC')
667667
->orderByRaw("(title_relevance + content_relevance) $dir")
668668
;
669669
}
670+
671+
public function isDiscussionOpen()
672+
{
673+
return $this->discussion_state === static::DISCUSSION_STATE_OPEN;
674+
}
670675
}

resources/assets/js/annotator-madison.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ $.extend(Annotator.Plugin.Madison.prototype, new Annotator.Plugin(), {
2929
_token: window.Laravel.csrfToken
3030
};
3131

32+
if (this.annotator.options.discussionClosed) {
33+
return;
34+
}
35+
3236
if (this.options.userId) {
3337
$.post('/documents/' + this.options.docId + '/comments/' + annotationId + '/' + action, data)
3438
.done(function (data) {

resources/assets/js/document.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
window.loadAnnotations = function (contentElem, annotationContainerElem, docId, userId, discussionClosed) {
22
var ann = $(contentElem).annotator({
3-
readOnly: !!userId,
3+
readOnly: !!!userId,
44
discussionClosed: discussionClosed
55
});
66
ann.annotator('addPlugin', 'Unsupported');

resources/views/documents/partials/comment-base.blade.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
<button class="btn btn-simple like-btn thumbs-up" onclick="$(this).trigger('madison.addAction')"
2020
data-action-type="likes" data-annotation-id="{{ $comment->str_id }}"
2121
title="{{ trans('messages.document.like') }}"
22-
aria-label="{{ trans('messages.document.like') }}">
22+
aria-label="{{ trans('messages.document.like') }}"
23+
{{ !$comment->rootAnnotatable->isDiscussionOpen() ? 'disabled' : '' }}>
2324

2425
<i class="fa fa-thumbs-o-up" aria-hidden="true"></i>
2526
<span class="action-count">{{ $comment->likes_count }}</span>
@@ -56,13 +57,14 @@
5657
<button class="btn btn-simple flag pull-right {{ $comment->flags_count ? 'active' : ''}}" onclick="$(this).trigger('madison.addAction')"
5758
data-action-type="flags" data-annotation-id="{{ $comment->str_id }}"
5859
title="{{ trans('messages.document.flag') }}"
59-
aria-label="{{ trans('messages.document.flag') }}">
60+
aria-label="{{ trans('messages.document.flag') }}"
61+
{{ !$comment->rootAnnotatable->isDiscussionOpen() ? 'disabled' : '' }}>
6062

6163
<i class="fa fa-flag" aria-hidden="true"></i>
6264
</button>
6365
</div>
6466

65-
@if ($comment->annotatable_type === \App\Models\Doc::ANNOTATABLE_TYPE)
67+
@if ($comment->annotatable_type === \App\Models\Doc::ANNOTATABLE_TYPE && $comment->rootAnnotatable->isDiscussionOpen())
6668
@if (Auth::user())
6769
<div class="clearfix"></div>
6870

resources/views/documents/partials/support-btns.blade.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
{{ Form::open(['route' => ['documents.support', $document], 'method' => 'put']) }}
77
<input type="hidden" name="support" value="1">
88

9-
<button type="submit" class="support {{ $userSupport === true ? 'active' : '' }}">
9+
<button type="submit" class="btn support {{ $userSupport === true ? 'active' : '' }}"
10+
{{ !$document->isDiscussionOpen() ? 'disabled' : '' }}>
11+
1012
<i class="fa fa-thumbs-up" aria-hidden="true"></i>
1113
{{ trans('messages.document.support') }}
1214
<span class="count">{{ $supportCount }}</span>
@@ -17,7 +19,8 @@
1719
<div class="oppose-btn" role="group">
1820
{{ Form::open(['route' => ['documents.support', $document], 'method' => 'put']) }}
1921
<input type="hidden" name="support" value="0">
20-
<button type="submit" class="oppose {{ $userSupport === false ? 'active' : '' }}">
22+
<button type="submit" class="btn oppose {{ $userSupport === false ? 'active' : '' }}"
23+
{{ !$document->isDiscussionOpen() ? 'disabled' : '' }}>
2124
<i class="fa fa-thumbs-down" aria-hidden="true"></i>
2225
{{ trans('messages.document.oppose') }}
2326
<span class="count">{{ $opposeCount }}</span>

resources/views/documents/show.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
@choice('messages.document.comments_with_count', $document->all_comments_count)
9090
</div>
9191

92-
@if ($document->discussion_state === \App\Models\Doc::DISCUSSION_STATE_OPEN)
92+
@if ($document->isDiscussionOpen())
9393
<div class="floating-card">
9494
@if (Auth::user())
9595
@include('documents.partials.new-comment-form', ['route' => ['documents.comments.store', $document], 'message' => 'messages.document.add_comment'])

tests/Browser/DocumentPageTest.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,32 @@ public function testDiscussionHiddenHidesAllTheThings()
128128
$this->browse(function ($browser) {
129129
$browser
130130
->visit($this->page)
131-
->assertDontSee('@supportBtn')
132-
->assertDontSee('@opposeBtn')
133-
->assertDontSee('@annotationGroups')
131+
->assertMissing('@supportBtn')
132+
->assertMissing('@opposeBtn')
133+
->assertMissing('@noteBubble')
134+
->assertMissing('@newCommentForm')
135+
->assertMissing('@likeBtn')
136+
->assertMissing('@flagBtn')
137+
->assertMissing('@commentsDiv')
138+
;
139+
});
140+
}
141+
142+
public function testDiscussionClosedDisablesThings()
143+
{
144+
$this->document->update(['discussion_state' => Document::DISCUSSION_STATE_CLOSED]);
145+
146+
$this->browse(function ($browser) {
147+
$browser
148+
->visit($this->page)
149+
->assertVisible('@supportBtnDisabled')
150+
->assertVisible('@opposeBtnDisabled')
151+
->waitFor('@noteBubble')
152+
->assertVisible('@noteBubble')
153+
->assertMissing('@newCommentForm')
154+
->assertVisible('@likeBtnDisabled')
155+
->assertVisible('@flagBtnDisabled')
156+
->assertSeeComment($this->comment1)
134157
;
135158
});
136159
}

tests/Browser/Pages/DocumentPage.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,18 @@ public function elements()
3737
'@sponsorList' => '#doc-header .sponsors',
3838
'@stats' => '.document-stats',
3939
'@supportBtn' => '.support-btn button',
40+
'@supportBtnDisabled' => '.support-btn button[disabled]',
4041
'@opposeBtn' => '.oppose-btn button',
42+
'@opposeBtnDisabled' => '.oppose-btn button[disabled]',
4143
'@outline' => '#document-outline',
4244
'@noteBubble' => '.annotation-group',
4345
'@notesPane' => '.annotation-list',
4446
'@commentsDiv' => '#comments.comments',
4547
'@contentDiv' => '#content #page_content',
4648
'@likeBtn' => '[data-action-type="likes"]',
49+
'@likeBtnDisabled' => '[data-action-type="likes"][disabled]',
4750
'@flagBtn' => '[data-action-type="flags"]',
51+
'@flagBtnDisabled' => '[data-action-type="flags"][disabled]',
4852
'@newCommentForm' => '.new-comment-form',
4953
'@addCommentForm' => '.comment-form',
5054
'@noteReplyForm' => '.add-subcomment-form',

0 commit comments

Comments
 (0)