forked from chatwoot/chatwoot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Conversation update API for sla_policy_id (chatwoot#8973)
- Add an endpoint for updating conversation attributes (priority / sla_policy_id ) - Swagger spec - minor chores around the conversation API/spec Fixes: https://linear.app/chatwoot/issue/CW-2100/feat-backend-api-to-update-the-sla-of-a-conversation
- Loading branch information
1 parent
2917156
commit 3dae3ff
Showing
17 changed files
with
301 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.partial! 'api/v1/conversations/partials/conversation', formats: [:json], conversation: @conversation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
enterprise/app/controllers/enterprise/api/v1/accounts/conversations_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Enterprise::Api::V1::Accounts::ConversationsController | ||
def permitted_update_params | ||
super.merge(params.permit(:sla_policy_id)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
spec/enterprise/controllers/enterprise/api/v1/accounts/conversations_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'Enterprise Conversations API', type: :request do | ||
let(:account) { create(:account) } | ||
let(:admin) { create(:user, account: account, role: :administrator) } | ||
|
||
describe 'PATCH /api/v1/accounts/{account.id}/conversations/:id' do | ||
let(:conversation) { create(:conversation, account: account) } | ||
let(:sla_policy) { create(:sla_policy, account: account) } | ||
let(:params) { { sla_policy_id: sla_policy.id } } | ||
|
||
context 'when it is an authenticated user' do | ||
let(:agent) { create(:user, account: account, role: :agent) } | ||
|
||
before do | ||
create(:inbox_member, user: agent, inbox: conversation.inbox) | ||
end | ||
|
||
it 'updates the conversation if you are an agent with access to inbox' do | ||
patch "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}", | ||
params: params, | ||
headers: agent.create_new_auth_token, | ||
as: :json | ||
|
||
expect(response).to have_http_status(:success) | ||
expect(JSON.parse(response.body, symbolize_names: true)[:sla_policy_id]).to eq(sla_policy.id) | ||
end | ||
|
||
it 'throws error if conversation already has a different sla' do | ||
conversation.update(sla_policy: create(:sla_policy, account: account)) | ||
patch "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}", | ||
params: params, | ||
headers: agent.create_new_auth_token, | ||
as: :json | ||
|
||
expect(response).to have_http_status(:unprocessable_entity) | ||
expect(JSON.parse(response.body, symbolize_names: true)[:message]).to eq('Sla policy conversation already has a different sla') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
tags: | ||
- Conversations | ||
operationId: update-conversation | ||
summary: Update Conversation | ||
description: Update Conversation Attributes | ||
security: | ||
- userApiKey: [] | ||
- agentBotApiKey: [] | ||
parameters: | ||
- name: data | ||
in: body | ||
required: true | ||
schema: | ||
type: object | ||
properties: | ||
priority: | ||
type: string | ||
enum: ["urgent", "high", "medium", "low", "none"] | ||
description: "The priority of the conversation" | ||
sla_policy_id: | ||
type: number | ||
description: "The ID of the SLA policy (Available only in Enterprise edition)" | ||
responses: | ||
200: | ||
description: Success | ||
404: | ||
description: Conversation not found | ||
401: | ||
description: Unauthorized |
Oops, something went wrong.