Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Do not show quote copy button to anon #25471

Merged
merged 1 commit into from Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -260,7 +260,10 @@ export default class PostTextSelection extends Component {
}

get canCopyQuote() {
return this.siteSettings.enable_quote_copy;
return (
this.siteSettings.enable_quote_copy &&
this.currentUser?.get("user_option.enable_quoting")
);
}

// on Desktop, shows the bar at the beginning of the selection
Expand Down
39 changes: 25 additions & 14 deletions spec/system/post_selection_copy_quote_spec.rb
Expand Up @@ -8,27 +8,38 @@
fab!(:post) { Fabricate(:post, topic: topic, raw: "Hello world it's time for quoting!") }
fab!(:current_user) { Fabricate(:admin) }

before do
sign_in(current_user)
cdp.allow_clipboard
end
context "when logged in" do
before do
sign_in(current_user)
cdp.allow_clipboard
end

it "copies the selection from the post the clipboard" do
topic_page.visit_topic(topic)
it "copies the selection from the post the clipboard" do
topic_page.visit_topic(topic)

select_text_range("#{topic_page.post_by_number_selector(1)} .cooked p", 0, 10)
topic_page.copy_quote_button.click
select_text_range("#{topic_page.post_by_number_selector(1)} .cooked p", 0, 10)
topic_page.copy_quote_button.click

expect(cdp.read_clipboard.chomp).to eq(<<~QUOTE.chomp)
expect(cdp.read_clipboard.chomp).to eq(<<~QUOTE.chomp)
[quote=\"#{post.user.username}, post:1, topic:#{topic.id}\"]\nHello worl\n[/quote]\n
QUOTE
end

it "does not show the copy quote button if it has been disabled" do
SiteSetting.enable_quote_copy = false
topic_page.visit_topic(topic)

select_text_range("#{topic_page.post_by_number_selector(1)} .cooked p", 0, 10)
expect(page).not_to have_css(topic_page.copy_quote_button_selector)
end
end

it "does not show the copy quote button if it has been disabled" do
SiteSetting.enable_quote_copy = false
topic_page.visit_topic(topic)
context "when anon" do
it "does not show the copy quote button to anon users" do
topic_page.visit_topic(topic)

select_text_range("#{topic_page.post_by_number_selector(1)} .cooked p", 0, 10)
expect(page).not_to have_css(topic_page.copy_quote_button_selector)
select_text_range("#{topic_page.post_by_number_selector(1)} .cooked p", 0, 10)
expect(page).not_to have_css(topic_page.copy_quote_button_selector)
end
end
end