feat: gate token API access and account webhooks behind api_and_webhooks flag

This commit is contained in:
Shivam Mishra
2026-07-09 17:51:05 +05:30
parent 8d2ef4ec5e
commit d3b294fe9c
12 changed files with 99 additions and 8 deletions
@@ -1,7 +1,7 @@
require 'rails_helper'
RSpec.describe 'Conversation Assignment API', type: :request do
let(:account) { create(:account) }
let(:account) { create(:account).tap { |account| account.enable_features!('api_and_webhooks') } }
describe 'POST /api/v1/accounts/{account.id}/conversations/<id>/assignments' do
let(:conversation) { create(:conversation, account: account) }
@@ -1,7 +1,7 @@
require 'rails_helper'
RSpec.describe 'Conversation Messages API', type: :request do
let!(:account) { create(:account) }
let!(:account) { create(:account).tap { |account| account.enable_features!('api_and_webhooks') } }
describe 'POST /api/v1/accounts/{account.id}/conversations/<id>/messages' do
let!(:inbox) { create(:inbox, account: account) }
@@ -1,7 +1,7 @@
require 'rails_helper'
RSpec.describe 'Conversations API', type: :request do
let(:account) { create(:account) }
let(:account) { create(:account).tap { |account| account.enable_features!('api_and_webhooks') } }
describe 'GET /api/v1/accounts/{account.id}/conversations' do
context 'when it is an unauthenticated user' do
@@ -1,7 +1,7 @@
require 'rails_helper'
RSpec.describe 'Webhooks API', type: :request do
let(:account) { create(:account) }
let(:account) { create(:account).tap { |account| account.enable_features!('api_and_webhooks') } }
let(:inbox) { create(:inbox, account: account) }
let(:webhook) { create(:webhook, account: account, inbox: inbox, url: 'https://hello.com', name: 'My Webhook') }
let(:administrator) { create(:user, account: account, role: :administrator) }
@@ -26,6 +26,16 @@ RSpec.describe 'Webhooks API', type: :request do
expect(response.parsed_body['payload']['webhooks'].count).to eql account.webhooks.count
end
end
context 'when api_and_webhooks feature is disabled' do
it 'returns unauthorized even for an admin' do
account.disable_features!('api_and_webhooks')
get "/api/v1/accounts/#{account.id}/webhooks",
headers: administrator.create_new_auth_token,
as: :json
expect(response).to have_http_status(:unauthorized)
end
end
end
describe 'POST /api/v1/accounts/<account_id>/webhooks' do