mirror of
https://github.com/discourse/discourse.git
synced 2025-10-03 17:21:20 +08:00
### What is this change? When visiting a restricted category or tag where the current user does not have permission to create a topic, we should still allow the user to write a new topic under a different category or tag. This is especially important when using the new topic button from the sidebar. #### When the user does not have permission, the composer category defaults to: 1) Subcategory (if SiteSetting.default_subcategory_on_read_only_category is true and subcategory exists) 2) Default category chooser value of Category... prompting the user to select a category from the dropdown This PR is a follow up to #33495 which was reverted previously due to a couple of issues which are now corrected: - we no longer set a default category based on `default_composer_category` (previously was step 2 above) - category banner text when a user cannot create a topic is now showing up correctly - added a title attribute with more info for the disabled category in the category dropdown in composer - for staff only tags, when creating a topic from the tag page as a non staff member we now automatically remove the restricted tag from the tags field in composer (as the user cannot use this tag)
121 lines
3.2 KiB
Ruby
121 lines
3.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe "Drafts dropdown", type: :system do
|
|
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
|
|
fab!(:category)
|
|
let(:composer) { PageObjects::Components::Composer.new }
|
|
let(:drafts_dropdown) { PageObjects::Components::DraftsMenu.new }
|
|
let(:discard_draft_modal) { PageObjects::Modals::DiscardDraft.new }
|
|
|
|
before { sign_in(user) }
|
|
|
|
describe "with no drafts" do
|
|
it "does not display drafts dropdown" do
|
|
page.visit "/"
|
|
expect(drafts_dropdown).to be_hidden
|
|
end
|
|
|
|
it "adds a draft dropdown menu when a draft is available" do
|
|
page.visit "/new-topic"
|
|
composer.fill_content("This is a draft")
|
|
|
|
expect(drafts_dropdown).to be_visible
|
|
end
|
|
end
|
|
|
|
describe "with multiple drafts" do
|
|
before do
|
|
Draft.set(
|
|
user,
|
|
Draft::NEW_TOPIC,
|
|
0,
|
|
{
|
|
title: "This is a test topic",
|
|
reply: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
|
|
}.to_json,
|
|
)
|
|
|
|
5.times do |i|
|
|
topic = Fabricate(:topic, user: user)
|
|
Draft.set(user, topic.draft_key, 0, { reply: "test reply #{i}" }.to_json)
|
|
end
|
|
end
|
|
|
|
it "displays the correct draft count" do
|
|
page.visit "/"
|
|
drafts_dropdown.open
|
|
|
|
expect(drafts_dropdown).to be_open
|
|
|
|
expect(drafts_dropdown.draft_item_count).to eq(4)
|
|
expect(drafts_dropdown.other_drafts_count).to eq(2)
|
|
|
|
drafts_dropdown.find(".topic-drafts-item:first-child").click
|
|
|
|
expect(drafts_dropdown).to be_closed
|
|
|
|
expect(composer).to be_opened
|
|
composer.create
|
|
|
|
wait_for { Draft.count == 5 }
|
|
|
|
page.visit "/"
|
|
drafts_dropdown.open
|
|
|
|
expect(drafts_dropdown.draft_item_count).to eq(4)
|
|
expect(drafts_dropdown.other_drafts_count).to eq(1)
|
|
end
|
|
|
|
it "shows the view all drafts when there are other drafts to display" do
|
|
page.visit "/"
|
|
drafts_dropdown.open
|
|
|
|
expect(drafts_dropdown).to be_open
|
|
expect(drafts_dropdown).to have_view_all_link
|
|
end
|
|
|
|
it "does not show the view all drafts link when all drafts are displayed" do
|
|
Draft.where(user_id: user.id).order("created_at DESC").limit(2).destroy_all
|
|
|
|
page.visit "/"
|
|
drafts_dropdown.open
|
|
|
|
expect(drafts_dropdown).to be_open
|
|
expect(drafts_dropdown).to have_no_view_all_link
|
|
end
|
|
end
|
|
|
|
describe "with private category" do
|
|
fab!(:group)
|
|
fab!(:group_user) { Fabricate(:group_user, user: user, group: group) }
|
|
fab!(:category) { Fabricate(:private_category, group: group, permission_type: 3) }
|
|
fab!(:subcategory) do
|
|
Fabricate(
|
|
:private_category,
|
|
parent_category_id: category.id,
|
|
group: group,
|
|
permission_type: 1,
|
|
)
|
|
end
|
|
|
|
let(:category_page) { PageObjects::Pages::Category.new }
|
|
|
|
before do
|
|
SiteSetting.default_subcategory_on_read_only_category = false
|
|
|
|
Draft.set(
|
|
user,
|
|
Draft::NEW_TOPIC,
|
|
0,
|
|
{ title: "This is a test topic", reply: "Lorem ipsum dolor sit amet" }.to_json,
|
|
)
|
|
end
|
|
|
|
it "is still enabled" do
|
|
category_page.visit(category)
|
|
|
|
expect(category_page).to have_button("New Topic", disabled: false)
|
|
expect(drafts_dropdown).to be_enabled
|
|
end
|
|
end
|
|
end
|