feat(help-center): enable drag-and-drop category reordering (#13706)

This commit is contained in:
Sojan Jose
2026-03-04 23:23:38 -08:00
committed by GitHub
parent 3abe32a2c7
commit 42a244369d
33 changed files with 708 additions and 47 deletions

View File

@@ -192,6 +192,38 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
end
end
describe 'POST /api/v1/accounts/{account.id}/portals/{portal.slug}/articles/reorder' do
let!(:article_2) do
create(:article, category: category, portal: portal, account_id: account.id, author_id: agent.id, position: 20)
end
let(:positions_hash) do
{
article.id => 20,
article_2.id => 10
}
end
context 'when it is an unauthenticated user' do
it 'returns unauthorized' do
post "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles/reorder",
params: { positions_hash: positions_hash }
expect(response).to have_http_status(:unauthorized)
end
end
context 'when it is an authenticated user' do
it 'reorders articles' do
post "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles/reorder",
params: { positions_hash: positions_hash },
headers: admin.create_new_auth_token
expect(response).to have_http_status(:success)
expect(article.reload.position).to eq(20)
expect(article_2.reload.position).to eq(10)
end
end
end
describe 'GET /api/v1/accounts/{account.id}/portals/{portal.slug}/articles' do
context 'when it is an unauthenticated user' do
it 'returns unauthorized' do

View File

@@ -237,6 +237,47 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do
end
end
describe 'POST /api/v1/accounts/{account.id}/portals/{portal.slug}/categories/reorder' do
let(:positions_hash) do
{
category.id => 40,
category_to_associate.id => 10,
related_category_1.id => 30,
related_category_2.id => 20
}
end
context 'when it is an unauthenticated user' do
it 'returns unauthorized' do
post "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories/reorder",
params: { positions_hash: positions_hash }
expect(response).to have_http_status(:unauthorized)
end
end
context 'when it is an authenticated user' do
it 'reorders categories' do
post "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories/reorder",
params: { positions_hash: positions_hash },
headers: admin.create_new_auth_token
expect(response).to have_http_status(:success)
expect(category.reload.position).to eq(40)
expect(category_to_associate.reload.position).to eq(10)
expect(related_category_1.reload.position).to eq(30)
expect(related_category_2.reload.position).to eq(20)
end
it 'returns not found when portal does not exist' do
post "/api/v1/accounts/#{account.id}/portals/invalid-portal-slug/categories/reorder",
params: { positions_hash: positions_hash },
headers: admin.create_new_auth_token
expect(response).to have_http_status(:not_found)
end
end
end
describe 'GET /api/v1/accounts/{account.id}/portals/{portal.slug}/categories' do
context 'when it is an unauthenticated user' do
it 'returns unauthorized' do

View File

@@ -100,4 +100,18 @@ RSpec.describe 'Enterprise Articles API', type: :request do
end
end
end
describe 'POST /api/v1/accounts/:account_id/portals/:portal_slug/articles/reorder' do
context 'when it is an authenticated user' do
it 'returns success for agents with knowledge_base_manage permission' do
post "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles/reorder",
params: { positions_hash: { article.id => 20 } },
headers: agent_with_role.create_new_auth_token,
as: :json
expect(response).to have_http_status(:success)
expect(article.reload.position).to eq(20)
end
end
end
end

View File

@@ -108,4 +108,27 @@ RSpec.describe 'Enterprise Categories API', type: :request do
end
end
end
describe 'POST /api/v1/accounts/:account_id/portals/:portal_slug/categories/reorder' do
context 'when it is an authenticated user' do
it 'returns success for agents with knowledge_base_manage permission' do
post "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories/reorder",
params: { positions_hash: { category.id => 20 } },
headers: agent_with_role.create_new_auth_token,
as: :json
expect(response).to have_http_status(:success)
expect(category.reload.position).to eq(20)
end
it 'returns not found for invalid portal slug' do
post "/api/v1/accounts/#{account.id}/portals/invalid-portal-slug/categories/reorder",
params: { positions_hash: { category.id => 20 } },
headers: agent_with_role.create_new_auth_token,
as: :json
expect(response).to have_http_status(:not_found)
end
end
end
end