chore: Custom Roles to manage permissions [ UI ] (#9865)
In admin settings, this Pr will add the UI for managing custom roles ( ref: https://github.com/chatwoot/chatwoot/pull/9995 ). It also handles the routing logic changes to accommodate fine-tuned permissions. --------- Co-authored-by: Pranav <pranavrajs@gmail.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: iamsivin <iamsivin@gmail.com> Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Profile API', type: :request do
|
||||
describe 'GET /api/v1/profile' do
|
||||
let(:account) { create(:account) }
|
||||
let!(:custom_role_account) { create(:account, name: 'Custom Role Account') }
|
||||
let!(:custom_role) { create(:custom_role, name: 'Custom Role', account: custom_role_account) }
|
||||
let!(:agent) { create(:user, account: account, custom_attributes: { test: 'test' }, role: :agent) }
|
||||
|
||||
before do
|
||||
create(:account_user, account: custom_role_account, user: agent, custom_role: custom_role)
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
it 'returns user custom role information' do
|
||||
get '/api/v1/profile',
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
parsed_response = response.parsed_body
|
||||
# map accounts object and make sure custom role id and name are present
|
||||
role_account = parsed_response['accounts'].find { |account| account['id'] == custom_role_account.id }
|
||||
expect(role_account['custom_role']['id']).to eq(custom_role.id)
|
||||
expect(role_account['custom_role']['name']).to eq(custom_role.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -3,10 +3,25 @@ require 'rails_helper'
|
||||
RSpec.describe 'Enterprise Agents API', type: :request do
|
||||
let(:account) { create(:account) }
|
||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||
let!(:custom_role) { create(:custom_role, account: account) }
|
||||
|
||||
describe 'POST /api/v1/accounts/{account.id}/agents' do
|
||||
let(:params) { { email: 'test@example.com', name: 'Test User', role: 'agent', custom_role_id: custom_role.id } }
|
||||
|
||||
context 'when it is an authenticated administrator' do
|
||||
it 'creates an agent with the specified custom role' do
|
||||
post "/api/v1/accounts/#{account.id}/agents", headers: admin.create_new_auth_token, params: params, as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
agent = account.agents.last
|
||||
expect(agent.account_users.first.custom_role_id).to eq(custom_role.id)
|
||||
expect(JSON.parse(response.body)['custom_role_id']).to eq(custom_role.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT /api/v1/accounts/{account.id}/agents/:id' do
|
||||
let(:other_agent) { create(:user, account: account, role: :agent) }
|
||||
let!(:custom_role) { create(:custom_role, account: account) }
|
||||
|
||||
context 'when it is an authenticated administrator' do
|
||||
it 'modified the custom role of the agent' do
|
||||
|
||||
Reference in New Issue
Block a user