Skip to content

Commit

Permalink
AO3-6491 Change default comment setting to registered users only (#4556)
Browse files Browse the repository at this point in the history
* AO3-6491 Set default comment permissions to users only

* AO3-6491 Fix tests, make sure correct notice is shown to admins

* AO3-6491 Display non-Archive users error to admins on admin posts

* AO3-6491 Don't edit when error notice is shown in commentable

* AO3-6491 Correct feature step to ensure correct error notice

* AO3-6491 Feedback

* AO3-6491 Correct test to not assume guest comments enabled by default

* AO3-6491 Fix CommentsController spec

* AO3-6491 Fix the comments controller spec...

* AO3-6491 A happier Hound

* AO3-6491 Try to fix failing tests

* Tidy and try to fix tests

* AO3-6491 Fix features first

* AO3-6491 Fix and tidy specs

* AO3-6491 Remove wrong trait

* AO3-6491 Step consistency

* AO3-6491 Fix some tests..............

* AO3-6491 hello darkness my old friend

* AO3-6491 plz work?
  • Loading branch information
weeklies authored Apr 21, 2024
1 parent 30b8ac7 commit 90a1406
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 107 deletions.
2 changes: 1 addition & 1 deletion app/models/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def new_recipients_have_not_blocked_gift_giver
enable_all: 0,
disable_anon: 1,
disable_all: 2
}, _suffix: :comments
}, _suffix: :comments, _default: 1

########################################################################
# HOOKS
Expand Down
4 changes: 2 additions & 2 deletions app/views/works/new_import.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@
<fieldset>
<ul>
<li>
<%= radio_button_tag "comment_permissions", "enable_all", true %>
<%= radio_button_tag "comment_permissions", "enable_all" %>
<%= label_tag "comment_permissions_enable_all", t("comments.commentable.permissions.options.enable_all") %>
</li>
<li>
<%= radio_button_tag "comment_permissions", "disable_anon" %>
<%= radio_button_tag "comment_permissions", "disable_anon", true %>
<%= label_tag "comment_permissions_disable_anon", t("comments.commentable.permissions.options.disable_anon") %>
</li>
<li>
Expand Down
4 changes: 4 additions & 0 deletions factories/comments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
commentable { create(:fandom) }
end

trait :on_work_with_guest_comments_on do
commentable { create(:work, :guest_comments_on).first_chapter }
end

trait :unreviewed do
commentable { create(:work, moderated_commenting_enabled: true).last_posted_chapter }
unreviewed { true }
Expand Down
4 changes: 4 additions & 0 deletions factories/works.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
factory :draft do
posted { false }
end

trait :guest_comments_on do
comment_permissions { :enable_all }
end
end

factory :external_work do
Expand Down
10 changes: 6 additions & 4 deletions features/admins/admin_settings.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Feature: Admin Settings Page
And I edit the tag "Ianto Jones"
Then I should see "Wrangling is disabled at the moment. Please check back later."
And I should not see "Synonym of"

Scenario: Turn off Support form
Given the support form is disabled and its text field set to "Please don't contact us"
When I am logged in as a random user
Expand All @@ -41,19 +41,21 @@ Feature: Admin Settings Page
Given guest comments are on
And I am logged out
And <commentable>
And <commentable> with guest comments enabled
And I view <commentable> with comments
When I post a guest comment
Then I should see a link "Reply"

Examples:
| commentable |
| commentable |
| the work "Generic Work" |
| the admin post "Generic Post" |

Scenario Outline: Guests cannot comment when guest comments are disabled, even if works or admin posts allow commets
Given guest comments are off
And I am logged out
And <commentable>
And <commentable> with guest comments enabled
And a guest comment on <commentable>
When I view <commentable> with comments
Then I should see "Sorry, the Archive doesn't allow guests to comment right now."
Expand All @@ -64,12 +66,12 @@ Feature: Admin Settings Page
When I am logged in as a super admin
And I view <commentable> with comments
Then I should not see "Sorry, the Archive doesn't allow guests to comment right now."

Examples:
| commentable |
| the work "Generic Work" |
| the admin post "Generic Post" |

Scenario: Turn off guest comments (when the work itself does not allow guest comments)
Given guest comments are off
And I am logged in as "author"
Expand Down
6 changes: 4 additions & 2 deletions features/comments_and_kudos/guest_comment_replies.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Feature: Disallowing guest comment replies

Scenario Outline: Guests cannot reply to a user who has guest comments off on news posts and other users' works
Given <commentable>
And <commentable> with guest comments enabled
And the user "commenter" turns off guest comment replies
And a comment "OMG!" by "commenter" on <commentable>
When I view <commentable> with comments
Expand All @@ -18,7 +19,7 @@ Feature: Disallowing guest comment replies
| the admin post "Change Log" |

Scenario: Guests can reply to a user who has guest comments off on their own work
Given the work "Aftermath" by "creator"
Given the work "Aftermath" by "creator" with guest comments enabled
And the user "creator" turns off guest comment replies
And a comment "OMG!" by "creator" on the work "Aftermath"
When I view the work "Aftermath" with comments
Expand All @@ -31,7 +32,7 @@ Feature: Disallowing guest comment replies

Scenario: Guests can reply to a user who has guest comments off on works co-created by the user
Given the user "nemesis" turns off guest comment replies
And the work "Aftermath" by "creator" and "nemesis"
And the work "Aftermath" by "creator" and "nemesis" with guest comments enabled
And a comment "OMG!" by "nemesis" on the work "Aftermath"
When I view the work "Aftermath" with comments
Then I should see a "Comment" button
Expand All @@ -58,6 +59,7 @@ Feature: Disallowing guest comment replies

Scenario: Guests can reply to guests
Given the work "Aftermath"
And the work "Aftermath" with guest comments enabled
And a guest comment on the work "Aftermath"
When I view the work "Aftermath" with comments
Then I should see a "Comment" button
Expand Down
2 changes: 1 addition & 1 deletion features/comments_and_kudos/guest_comments.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Feature: Read guest comments

Scenario: View guest comments in homepage, inbox and works
Given I am logged in as "normal_user"
And I post the work "My very meta work about AO3"
And I post the work "My very meta work about AO3" with guest comments enabled
And I am logged out
When I post a guest comment
Then I should see "(Guest)"
Expand Down
4 changes: 2 additions & 2 deletions features/comments_and_kudos/hidden_works.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Feature: Comments on Hidden Works

Scenario: When a work is hidden, admins and the creator can see (but not edit or add) comments, while everyone else is redirected.
Given I am logged in as "creator"
And I post the work "To Be Hidden"
And I post the work "To Be Hidden" with guest comments enabled
And I post the comment "Can I change this?" on the work "To Be Hidden"
And I am logged in as "commenter"
And I post the comment "Do you see?" on the work "To Be Hidden"
Expand Down Expand Up @@ -40,7 +40,7 @@ Feature: Comments on Hidden Works

Scenario: When a work is unrevealed, admins and the creator can see (but not edit or add) comments, while everyone else is redirected.
Given I am logged in as "creator"
And I post the work "Murder, She Wrote"
And I post the work "Murder, She Wrote" with guest comments enabled
And I post the comment "Can I change this?" on the work "Murder, She Wrote"
And I am logged in as "commenter"
And I post the comment "Do you see?" on the work "Murder, She Wrote"
Expand Down
4 changes: 2 additions & 2 deletions features/comments_and_kudos/spam_comments.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Feature: Marking comments as spam

Scenario: Spam comments are not included in a work's comment count
Given I am logged in as "author"
And I post the work "Popular Fic"
And I post the work "Popular Fic" with guest comments enabled
And I log out
And I view the work "Popular Fic" with comments
And I post a guest comment
Expand Down Expand Up @@ -49,7 +49,7 @@ Feature: Marking comments as spam

Scenario: Author can mark comments as spam
Given I am logged in as "author"
And I post the work "Popular Fic"
And I post the work "Popular Fic" with guest comments enabled
And I log out
When I view the work "Popular Fic" with comments
And I post a spam comment
Expand Down
1 change: 1 addition & 0 deletions features/importing/work_import.feature
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ Feature: Import Works

Scenario: Imported works can have comment moderation on
When I start importing "http://import-site-with-tags" with a mock website
And I choose "comment_permissions_enable_all"
And I check "moderated_commenting_enabled"
And I press "Import"
And I press "Post"
Expand Down
14 changes: 13 additions & 1 deletion features/step_definitions/comment_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
}
)

Given "{commentable} with guest comments enabled" do |commentable|
assert !commentable.is_a?(Tag)
commentable.update_attribute(:comment_permissions, :enable_all)
end

Given "a guest comment on {commentable}" do |commentable|
commentable = Comment.commentable_object(commentable)
FactoryBot.create(:comment, :by_guest, commentable: commentable)
Expand Down Expand Up @@ -87,6 +92,13 @@
fill_in("comment[comment_content]", with: comment_text)
end

When "I set up the comment {string} on the work {string} with guest comments enabled" do |comment_text, work|
work = Work.find_by(title: work)
work.update_attribute(:comment_permissions, :enable_all)
visit work_path(work)
fill_in("comment[comment_content]", with: comment_text)
end

When /^I attempt to comment on "([^"]*)" with a pseud that is not mine$/ do |work|
step %{I am logged in as "commenter"}
step %{I set up the comment "This is a test" on the work "#{work}"}
Expand All @@ -112,7 +124,7 @@

When /^I post the comment "([^"]*)" on the work "([^"]*)" as a guest(?: with email "([^"]*)")?$/ do |comment_text, work, email|
step "I start a new session"
step "I set up the comment \"#{comment_text}\" on the work \"#{work}\""
step %{I set up the comment "#{comment_text}" on the work "#{work}" with guest comments enabled}
fill_in("Guest name", with: "guest")
fill_in("Guest email", with: (email || "guest@foo.com"))
click_button "Comment"
Expand Down
18 changes: 18 additions & 0 deletions features/step_definitions/work_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,23 @@
FactoryBot.create(:work, title: title, authors: [user.default_pseud])
end

Given "the work {string} by {string} with guest comments enabled" do |title, login|
user = ensure_user(login)
FactoryBot.create(:work, :guest_comments_on, title: title, authors: [user.default_pseud])
end

Given "the work {string} by {string} and {string}" do |title, login1, login2|
user1 = ensure_user(login1)
user2 = ensure_user(login2)
FactoryBot.create(:work, title: title, authors: [user1.default_pseud, user2.default_pseud])
end

Given "the work {string} by {string} and {string} with guest comments enabled" do |title, login1, login2|
user1 = ensure_user(login1)
user2 = ensure_user(login2)
FactoryBot.create(:work, :guest_comments_on, title: title, authors: [user1.default_pseud, user2.default_pseud])
end

Given /^the work "([^\"]*)" by "([^\"]*)" with chapter two co-authored with "([^\"]*)"$/ do |work, author, coauthor|
step %{I am logged in as "#{author}"}
step %{I post the work "#{work}"}
Expand Down Expand Up @@ -315,6 +326,12 @@
step %{I post the work "#{title}"}
end

When "I post the work {string} with guest comments enabled" do |title|
step %{I set up the draft "#{title}"}
choose("Registered users and guests can comment")
step "I post the work without preview"
end

When /^a chapter is added to "([^"]*)"$/ do |work_title|
step %{a draft chapter is added to "#{work_title}"}
click_button("Post")
Expand Down Expand Up @@ -419,6 +436,7 @@
When /^I edit multiple works with different comment moderation settings$/ do
step %{I set up the draft "Work with Comment Moderation Enabled"}
check("work_moderated_commenting_enabled")
choose("Registered users and guests can comment")
step %{I post the work without preview}
step %{I post the work "Work with Comment Moderation Disabled"}
step %{I go to my edit multiple works page}
Expand Down
4 changes: 2 additions & 2 deletions public/help/who-can-comment-on-this-work.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<h4>Who can comment on this work?</h4>
<dl>
<dt>Registered users and guests can comment</dt>
<dd>This is the default option. All users can comment on your work whether they are logged in or not.</dd>
<dd>All users can comment on your work whether they are logged in or not.</dd>
<dt>Only registered users can comment</dt>
<dd>With this enabled, only logged in users will be able to comment on your work.</dd>
<dd><strong>This is the default option.</strong> With this enabled, only logged in users will be able to comment on your work.</dd>
<dt>No one can comment</dt>
<dd>This will disable all new comments on your work.</dd>
</dl>
Expand Down
Loading

0 comments on commit 90a1406

Please sign in to comment.