Feature: Business logo API for web widget (#674)
Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
parent
e04b37dfcf
commit
4feca1d88d
11 changed files with 71 additions and 37 deletions
10
.rubocop.yml
10
.rubocop.yml
|
@ -4,6 +4,10 @@ require:
|
||||||
- rubocop-rspec
|
- rubocop-rspec
|
||||||
inherit_from: .rubocop_todo.yml
|
inherit_from: .rubocop_todo.yml
|
||||||
|
|
||||||
|
Lint/RaiseException:
|
||||||
|
Enabled: true
|
||||||
|
Lint/StructNewOverride:
|
||||||
|
Enabled: true
|
||||||
Layout/LineLength:
|
Layout/LineLength:
|
||||||
Max: 150
|
Max: 150
|
||||||
Metrics/ClassLength:
|
Metrics/ClassLength:
|
||||||
|
@ -16,6 +20,12 @@ Style/FrozenStringLiteralComment:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
Style/SymbolArray:
|
Style/SymbolArray:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
Style/HashEachMethods:
|
||||||
|
Enabled: true
|
||||||
|
Style/HashTransformKeys:
|
||||||
|
Enabled: true
|
||||||
|
Style/HashTransformValues:
|
||||||
|
Enabled: true
|
||||||
Style/GlobalVars:
|
Style/GlobalVars:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'config/initializers/redis.rb'
|
- 'config/initializers/redis.rb'
|
||||||
|
|
|
@ -17,7 +17,7 @@ class ContactMergeAction
|
||||||
def validate_contacts
|
def validate_contacts
|
||||||
return if belongs_to_account?(@base_contact) && belongs_to_account?(@mergee_contact)
|
return if belongs_to_account?(@base_contact) && belongs_to_account?(@mergee_contact)
|
||||||
|
|
||||||
raise Exception, 'contact does not belong to the account'
|
raise StandardError, 'contact does not belong to the account'
|
||||||
end
|
end
|
||||||
|
|
||||||
def belongs_to_account?(contact)
|
def belongs_to_account?(contact)
|
||||||
|
|
|
@ -8,7 +8,7 @@ class Api::BaseController < ApplicationController
|
||||||
private
|
private
|
||||||
|
|
||||||
def authenticate_by_access_token?
|
def authenticate_by_access_token?
|
||||||
request.headers[:api_access_token].present?
|
request.headers[:api_access_token].present? || request.headers[:HTTP_API_ACCESS_TOKEN].present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_conversation
|
def set_conversation
|
||||||
|
|
|
@ -26,6 +26,6 @@ class Api::V1::Accounts::InboxesController < Api::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def inbox_update_params
|
def inbox_update_params
|
||||||
params.require(:inbox).permit(:enable_auto_assignment)
|
params.require(:inbox).permit(:enable_auto_assignment, :avatar)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,8 @@ module AccessTokenAuthHelper
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
def authenticate_access_token!
|
def authenticate_access_token!
|
||||||
access_token = AccessToken.find_by(token: request.headers[:api_access_token])
|
token = request.headers[:api_access_token] || request.headers[:HTTP_API_ACCESS_TOKEN]
|
||||||
|
access_token = AccessToken.find_by(token: token)
|
||||||
render_unauthorized('Invalid Access Token') && return unless access_token
|
render_unauthorized('Invalid Access Token') && return unless access_token
|
||||||
|
|
||||||
token_owner = access_token.owner
|
token_owner = access_token.owner
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# Table name: accounts
|
# Table name: accounts
|
||||||
#
|
#
|
||||||
# id :integer not null, primary key
|
# id :integer not null, primary key
|
||||||
# locale :integer default("eng")
|
# locale :integer default("en")
|
||||||
# name :string not null
|
# name :string not null
|
||||||
# created_at :datetime not null
|
# created_at :datetime not null
|
||||||
# updated_at :datetime not null
|
# updated_at :datetime not null
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
class Inbox < ApplicationRecord
|
class Inbox < ApplicationRecord
|
||||||
include Reportable
|
include Reportable
|
||||||
|
include Avatarable
|
||||||
|
|
||||||
validates :account_id, presence: true
|
validates :account_id, presence: true
|
||||||
|
|
||||||
|
|
|
@ -113,6 +113,19 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||||
expect(inbox.reload.enable_auto_assignment).to be_falsey
|
expect(inbox.reload.enable_auto_assignment).to be_falsey
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'updates avatar' do
|
||||||
|
# no avatar before upload
|
||||||
|
expect(inbox.avatar.attached?).to eq(false)
|
||||||
|
file = fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png')
|
||||||
|
patch "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}",
|
||||||
|
params: { inbox: { avatar: file } },
|
||||||
|
headers: admin.create_new_auth_token
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
inbox.reload
|
||||||
|
expect(inbox.avatar.attached?).to eq(true)
|
||||||
|
end
|
||||||
|
|
||||||
it 'will not update inbox for agent' do
|
it 'will not update inbox for agent' do
|
||||||
agent = create(:user, account: account, role: :agent)
|
agent = create(:user, account: account, role: :agent)
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
patch:
|
patch:
|
||||||
tags:
|
tags:
|
||||||
- Inbox
|
- Inbox
|
||||||
operationId: disableAutoAssignment
|
operationId: updateInbox
|
||||||
summary: Disable auto assignment
|
summary: Update Inbox
|
||||||
description: Disable Auto Assignment for an inbox
|
description: Add avatar and disable auto assignment for an inbox
|
||||||
parameters:
|
parameters:
|
||||||
- name: id
|
- name: id
|
||||||
in: path
|
in: path
|
||||||
|
@ -20,6 +20,10 @@ patch:
|
||||||
type: boolean
|
type: boolean
|
||||||
required: true
|
required: true
|
||||||
description: 'Enable Auto Assignment'
|
description: 'Enable Auto Assignment'
|
||||||
|
avatar:
|
||||||
|
type: file
|
||||||
|
required: false
|
||||||
|
description: 'Image file for avatar'
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: Success
|
description: Success
|
||||||
|
|
|
@ -1,37 +1,37 @@
|
||||||
# Widget
|
# Widget
|
||||||
/account/{account_id}/widget/inboxes:
|
/accounts/{account_id}/widget/inboxes:
|
||||||
$ref: ./widget/inboxes/create.yml
|
$ref: ./widget/inboxes/create.yml
|
||||||
/account/{account_id}/widget/inboxes/${id}:
|
/accounts/{account_id}/widget/inboxes/${id}:
|
||||||
$ref: ./widget/inboxes/update.yml
|
$ref: ./widget/inboxes/update.yml
|
||||||
|
|
||||||
# Inboxes
|
# Inboxes
|
||||||
/account/{account_id}/inboxes:
|
/accounts/{account_id}/inboxes:
|
||||||
$ref: ./inboxes/index.yml
|
$ref: ./inboxes/index.yml
|
||||||
/account/{account_id}/inboxes/{id}:
|
/accounts/{account_id}/inboxes/{id}:
|
||||||
$ref: ./inboxes/update.yml
|
$ref: ./inboxes/update.yml
|
||||||
|
|
||||||
# Conversations
|
# Conversations
|
||||||
/account/{account_id}/conversations:
|
/accounts/{account_id}/conversations:
|
||||||
$ref: ./conversation/list.yml
|
$ref: ./conversation/list.yml
|
||||||
/account/{account_id}/conversations/{id}:
|
/accounts/{account_id}/conversations/{id}:
|
||||||
$ref: ./conversation/crud.yml
|
$ref: ./conversation/crud.yml
|
||||||
/account/{account_id}/conversations/{id}/toggle_status:
|
/accounts/{account_id}/conversations/{id}/toggle_status:
|
||||||
$ref: ./conversation/toggle_status.yml
|
$ref: ./conversation/toggle_status.yml
|
||||||
|
|
||||||
# Messages
|
# Messages
|
||||||
/account/{account_id}/conversations/{id}/messages:
|
/accounts/{account_id}/conversations/{id}/messages:
|
||||||
$ref: ./conversation/messages/index_create.yml
|
$ref: ./conversation/messages/index_create.yml
|
||||||
|
|
||||||
/account/{account_id}/conversations/{id}/labels:
|
/accounts/{account_id}/conversations/{id}/labels:
|
||||||
$ref: ./conversation/labels.yml
|
$ref: ./conversation/labels.yml
|
||||||
|
|
||||||
/account/{account_id}/conversations/{id}/assignments:
|
/accounts/{account_id}/conversations/{id}/assignments:
|
||||||
$ref: ./conversation/assignments.yml
|
$ref: ./conversation/assignments.yml
|
||||||
|
|
||||||
# Contacts
|
# Contacts
|
||||||
/account/{account_id}/contacts:
|
/accounts/{account_id}/contacts:
|
||||||
$ref: ./contact/list_create.yml
|
$ref: ./contact/list_create.yml
|
||||||
/account/{account_id}/contacts/{id}:
|
/accounts/{account_id}/contacts/{id}:
|
||||||
$ref: ./contact/crud.yml
|
$ref: ./contact/crud.yml
|
||||||
/account/{account_id}/contacts/{id}/conversations:
|
/accounts/{account_id}/contacts/{id}/conversations:
|
||||||
$ref: ./contact/conversations.yml
|
$ref: ./contact/conversations.yml
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
"application/json; charset=utf-8"
|
"application/json; charset=utf-8"
|
||||||
],
|
],
|
||||||
"paths": {
|
"paths": {
|
||||||
"/account/{account_id}/widget/inboxes": {
|
"/accounts/{account_id}/widget/inboxes": {
|
||||||
"post": {
|
"post": {
|
||||||
"tags": [
|
"tags": [
|
||||||
"Widget"
|
"Widget"
|
||||||
|
@ -78,7 +78,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/account/{account_id}/widget/inboxes/${id}": {
|
"/accounts/{account_id}/widget/inboxes/${id}": {
|
||||||
"patch": {
|
"patch": {
|
||||||
"tags": [
|
"tags": [
|
||||||
"Widget"
|
"Widget"
|
||||||
|
@ -123,7 +123,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/account/{account_id}/inboxes": {
|
"/accounts/{account_id}/inboxes": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": [
|
"tags": [
|
||||||
"Inbox"
|
"Inbox"
|
||||||
|
@ -147,14 +147,14 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/account/{account_id}/inboxes/{id}": {
|
"/accounts/{account_id}/inboxes/{id}": {
|
||||||
"patch": {
|
"patch": {
|
||||||
"tags": [
|
"tags": [
|
||||||
"Inbox"
|
"Inbox"
|
||||||
],
|
],
|
||||||
"operationId": "disableAutoAssignment",
|
"operationId": "updateInbox",
|
||||||
"summary": "Disable auto assignment",
|
"summary": "Update Inbox",
|
||||||
"description": "Disable Auto Assignment for an inbox",
|
"description": "Add avatar and disable auto assignment for an inbox",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"name": "id",
|
"name": "id",
|
||||||
|
@ -174,6 +174,11 @@
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"required": true,
|
"required": true,
|
||||||
"description": "Enable Auto Assignment"
|
"description": "Enable Auto Assignment"
|
||||||
|
},
|
||||||
|
"avatar": {
|
||||||
|
"type": "file",
|
||||||
|
"required": false,
|
||||||
|
"description": "Image file for avatar"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,7 +200,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/account/{account_id}/conversations": {
|
"/accounts/{account_id}/conversations": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": [
|
"tags": [
|
||||||
"Conversation"
|
"Conversation"
|
||||||
|
@ -262,7 +267,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/account/{account_id}/conversations/{id}": {
|
"/accounts/{account_id}/conversations/{id}": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": [
|
"tags": [
|
||||||
"Conversation"
|
"Conversation"
|
||||||
|
@ -295,7 +300,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/account/{account_id}/conversations/{id}/toggle_status": {
|
"/accounts/{account_id}/conversations/{id}/toggle_status": {
|
||||||
"post": {
|
"post": {
|
||||||
"tags": [
|
"tags": [
|
||||||
"Conversation"
|
"Conversation"
|
||||||
|
@ -347,7 +352,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/account/{account_id}/conversations/{id}/messages": {
|
"/accounts/{account_id}/conversations/{id}/messages": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": [
|
"tags": [
|
||||||
"Messages"
|
"Messages"
|
||||||
|
@ -434,7 +439,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/account/{account_id}/conversations/{id}/labels": {
|
"/accounts/{account_id}/conversations/{id}/labels": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": [
|
"tags": [
|
||||||
"ConversationLabels"
|
"ConversationLabels"
|
||||||
|
@ -515,7 +520,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/account/{account_id}/conversations/{id}/assignments": {
|
"/accounts/{account_id}/conversations/{id}/assignments": {
|
||||||
"post": {
|
"post": {
|
||||||
"tags": [
|
"tags": [
|
||||||
"ConversationAssignment"
|
"ConversationAssignment"
|
||||||
|
@ -561,7 +566,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/account/{account_id}/contacts": {
|
"/accounts/{account_id}/contacts": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": [
|
"tags": [
|
||||||
"Contact"
|
"Contact"
|
||||||
|
@ -623,7 +628,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/account/{account_id}/contacts/{id}": {
|
"/accounts/{account_id}/contacts/{id}": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": [
|
"tags": [
|
||||||
"Contact"
|
"Contact"
|
||||||
|
@ -693,7 +698,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/account/{account_id}/contacts/{id}/conversations": {
|
"/accounts/{account_id}/contacts/{id}/conversations": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": [
|
"tags": [
|
||||||
"Contact"
|
"Contact"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue