feat: Add draft status for help center locales (#13768)

This adds a draft status for Help Center locales so teams can prepare
localized content in the dashboard without exposing those locales in the
public portal switcher until they are ready to publish.

Fixes: https://github.com/chatwoot/chatwoot/issues/10412
Closes: https://github.com/chatwoot/chatwoot/issues/10412

## Why

Teams need a way to work on locale-specific Help Center content ahead of
launch. The public portal should only show ready locales, while the
admin dashboard should continue to expose every allowed locale for
ongoing article and category work.

## What this change does

- Adds `draft_locales` to portal config as a subset of `allowed_locales`
- Hides drafted locales from the public portal language switchers while
keeping direct locale URLs working
- Keeps drafted locales fully visible in the admin dashboard for article
and category management
- Adds locale actions to move an existing locale to draft, publish a
drafted locale, and keep the default locale protected from drafting
- Adds a status dropdown when creating a locale so new locales can be
created as `Published` or `Draft`
- Returns each admin locale with a `draft` flag so the locale UI can
reflect the public visibility state

## Validation

- Seed a portal with multiple locales, draft one locale, and confirm the
public portal switcher hides it while `/hc/:slug/:locale` still loads
directly
- In the admin dashboard, confirm drafted locales still appear in the
locale list and remain selectable for articles and categories
- Create a new locale with `Draft` status and confirm it stays out of
the public switcher until published
- Move an existing locale back and forth between `Published` and `Draft`
and confirm the public switcher updates accordingly


## Demo 



https://github.com/user-attachments/assets/ba22dc26-c2e7-463a-b1f5-adf1fda1f9be

---------

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
Sojan Jose
2026-03-17 01:45:54 -07:00
committed by GitHub
parent 270f3c6a80
commit 2a90652f05
19 changed files with 421 additions and 26 deletions

View File

@@ -117,7 +117,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
portal_params = {
portal: {
name: 'updated_test_portal',
config: { 'allowed_locales' => %w[en es] }
config: { 'allowed_locales' => %w[en es], 'draft_locales' => ['es'], 'default_locale' => 'en' }
}
}
@@ -130,8 +130,33 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
expect(response).to have_http_status(:success)
json_response = response.parsed_body
expect(json_response['name']).to eql(portal_params[:portal][:name])
expect(json_response['config']).to eql({ 'allowed_locales' => [{ 'articles_count' => 0, 'categories_count' => 0, 'code' => 'en' },
{ 'articles_count' => 0, 'categories_count' => 0, 'code' => 'es' }] })
expect(json_response['config']).to eql(
{
'allowed_locales' => [
{ 'articles_count' => 0, 'categories_count' => 0, 'code' => 'en', 'draft' => false },
{ 'articles_count' => 0, 'categories_count' => 0, 'code' => 'es', 'draft' => true }
]
}
)
end
it 'preserves drafted locales when draft_locales is omitted' do
portal.update!(config: { allowed_locales: %w[en es fr], draft_locales: ['es'], default_locale: 'en' })
put "/api/v1/accounts/#{account.id}/portals/#{portal.slug}",
params: {
portal: {
config: { allowed_locales: %w[en es fr], default_locale: 'en' }
}
},
headers: admin.create_new_auth_token
expect(response).to have_http_status(:success)
portal.reload
expect(portal.draft_locale_codes).to eq(['es'])
expect(response.parsed_body.dig('config', 'allowed_locales')).to include(
a_hash_including('code' => 'es', 'draft' => true)
)
end
it 'archive portal' do

View File

@@ -56,6 +56,48 @@ RSpec.describe Public::Api::V1::PortalsController, type: :request do
expect(response.body).not_to include('<link rel="icon" href=')
end
end
it 'hides drafted locales from the public locale switcher' do
portal.update!(config: { allowed_locales: %w[en es], draft_locales: ['es'], default_locale: 'en' })
get "/hc/#{portal.slug}/en"
expect(response).to have_http_status(:success)
expect(response.body).not_to include('value="es"')
expect(response.body).not_to include('locale-switcher')
end
it 'allows direct access to drafted locale pages' do
portal.update!(config: { allowed_locales: %w[en es], draft_locales: ['es'], default_locale: 'en' })
get "/hc/#{portal.slug}/es"
expect(response).to have_http_status(:success)
end
it 'shows the active drafted locale in the switcher state on direct locale access' do
portal.update!(config: { allowed_locales: %w[en es fr], draft_locales: ['es'], default_locale: 'en' })
get "/hc/#{portal.slug}/es"
expect(response).to have_http_status(:success)
document = Nokogiri::HTML(response.body)
switchers = document.css('select.locale-switcher')
expect(switchers).not_to be_empty
switchers.each do |switcher|
options = switcher.css('option')
expect(options.map { |option| option['value'] }).to include('en', 'es', 'fr')
expect(
options.any? do |option|
option['value'] == 'es' && option['selected'].present? && option['disabled'].present?
end
).to be(true)
end
end
end
describe 'GET /public/api/v1/portals/{portal_slug}/sitemap' do

View File

@@ -24,6 +24,7 @@ RSpec.describe Portal do
expect(portal.config).to be_present
expect(portal.config['allowed_locales']).to eq(['en'])
expect(portal.config['default_locale']).to eq('en')
expect(portal.config['draft_locales']).to eq([])
end
it 'Does not allow any other config than allowed_locales' do
@@ -32,6 +33,29 @@ RSpec.describe Portal do
expect(portal.errors.full_messages[0]).to eq('Cofig in portal on some_other_key is not supported.')
end
it 'falls back to no drafted locales for existing portals' do
portal.config = { 'allowed_locales' => %w[en es], 'default_locale' => 'en' }
expect(portal.draft_locale_codes).to eq([])
expect(portal.public_locale_codes).to eq(%w[en es])
end
it 'preserves drafted locales when draft_locales is omitted on update' do
portal.update!(config: { allowed_locales: %w[en es fr], draft_locales: ['es'], default_locale: 'en' })
portal.assign_attributes(config: { allowed_locales: %w[en es fr], default_locale: 'en' })
portal.valid?
expect(portal.config['draft_locales']).to eq(['es'])
end
it 'does not allow drafting the default locale' do
portal.update(config: { allowed_locales: %w[en es], draft_locales: ['en'], default_locale: 'en' })
expect(portal).not_to be_valid
expect(portal.errors.full_messages).to include('Config default locale cannot be drafted.')
end
it 'converts empty string to nil' do
portal.update(custom_domain: '')
expect(portal.custom_domain).to be_nil