fix(macros): disable public visibility for agents (#14349)

This commit is contained in:
Sojan Jose
2026-05-06 15:10:11 +05:30
committed by GitHub
parent b8108b71c1
commit 00ba468486
10 changed files with 281 additions and 23 deletions
@@ -239,6 +239,22 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
expect(json_response['error']).to eq('You are not authorized to do this action')
end
# A public macro can still point to an agent when an admin who authored it
# is later changed to the agent role. Public macros should remain
# admin-managed even when the original author is no longer an admin.
it 'does not allow agents to update public macros they created' do
macro = create(:macro, account: account, created_by: agent, updated_by: agent, visibility: :global)
put "/api/v1/accounts/#{account.id}/macros/#{macro.id}",
params: params,
headers: agent.create_new_auth_token
json_response = response.parsed_body
expect(response).to have_http_status(:unauthorized)
expect(json_response['error']).to eq('You are not authorized to do this action')
end
it 'allows update with existing blob_id' do
blob = ActiveStorage::Blob.create_and_upload!(
io: Rails.root.join('spec/assets/avatar.png').open,
@@ -551,6 +567,21 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
expect(json_response['error']).to eq('You are not authorized to do this action')
end
# A public macro can still point to an agent when an admin who authored it
# is later changed to the agent role. Public macros should remain
# admin-managed even when the original author is no longer an admin.
it 'does not allow agents to delete public macros they created' do
macro = create(:macro, account: account, created_by: agent, updated_by: agent, visibility: :global)
delete "/api/v1/accounts/#{account.id}/macros/#{macro.id}",
headers: agent.create_new_auth_token
json_response = response.parsed_body
expect(response).to have_http_status(:unauthorized)
expect(json_response['error']).to eq('You are not authorized to do this action')
end
it 'Unauthorize to delete the macro' do
macro = create(:macro, account: account, created_by: agent, updated_by: agent)