Feature: Business logo API for web widget (#674)

Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
Sojan Jose
2020-04-07 10:19:19 +05:30
committed by GitHub
parent e04b37dfcf
commit 4feca1d88d
11 changed files with 71 additions and 37 deletions

View File

@@ -4,6 +4,10 @@ require:
- rubocop-rspec
inherit_from: .rubocop_todo.yml
Lint/RaiseException:
Enabled: true
Lint/StructNewOverride:
Enabled: true
Layout/LineLength:
Max: 150
Metrics/ClassLength:
@@ -16,6 +20,12 @@ Style/FrozenStringLiteralComment:
Enabled: false
Style/SymbolArray:
Enabled: false
Style/HashEachMethods:
Enabled: true
Style/HashTransformKeys:
Enabled: true
Style/HashTransformValues:
Enabled: true
Style/GlobalVars:
Exclude:
- 'config/initializers/redis.rb'

View File

@@ -17,7 +17,7 @@ class ContactMergeAction
def validate_contacts
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
def belongs_to_account?(contact)

View File

@@ -8,7 +8,7 @@ class Api::BaseController < ApplicationController
private
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
def set_conversation

View File

@@ -26,6 +26,6 @@ class Api::V1::Accounts::InboxesController < Api::BaseController
end
def inbox_update_params
params.require(:inbox).permit(:enable_auto_assignment)
params.require(:inbox).permit(:enable_auto_assignment, :avatar)
end
end

View File

@@ -5,7 +5,8 @@ module AccessTokenAuthHelper
}.freeze
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
token_owner = access_token.owner

View File

@@ -3,7 +3,7 @@
# Table name: accounts
#
# id :integer not null, primary key
# locale :integer default("eng")
# locale :integer default("en")
# name :string not null
# created_at :datetime not null
# updated_at :datetime not null

View File

@@ -20,6 +20,7 @@
class Inbox < ApplicationRecord
include Reportable
include Avatarable
validates :account_id, presence: true

View File

@@ -113,6 +113,19 @@ RSpec.describe 'Inboxes API', type: :request do
expect(inbox.reload.enable_auto_assignment).to be_falsey
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
agent = create(:user, account: account, role: :agent)

View File

@@ -1,9 +1,9 @@
patch:
tags:
- Inbox
operationId: disableAutoAssignment
summary: Disable auto assignment
description: Disable Auto Assignment for an inbox
operationId: updateInbox
summary: Update Inbox
description: Add avatar and disable auto assignment for an inbox
parameters:
- name: id
in: path
@@ -20,6 +20,10 @@ patch:
type: boolean
required: true
description: 'Enable Auto Assignment'
avatar:
type: file
required: false
description: 'Image file for avatar'
responses:
200:
description: Success

View File

@@ -1,37 +1,37 @@
# Widget
/account/{account_id}/widget/inboxes:
/accounts/{account_id}/widget/inboxes:
$ref: ./widget/inboxes/create.yml
/account/{account_id}/widget/inboxes/${id}:
/accounts/{account_id}/widget/inboxes/${id}:
$ref: ./widget/inboxes/update.yml
# Inboxes
/account/{account_id}/inboxes:
/accounts/{account_id}/inboxes:
$ref: ./inboxes/index.yml
/account/{account_id}/inboxes/{id}:
/accounts/{account_id}/inboxes/{id}:
$ref: ./inboxes/update.yml
# Conversations
/account/{account_id}/conversations:
/accounts/{account_id}/conversations:
$ref: ./conversation/list.yml
/account/{account_id}/conversations/{id}:
/accounts/{account_id}/conversations/{id}:
$ref: ./conversation/crud.yml
/account/{account_id}/conversations/{id}/toggle_status:
/accounts/{account_id}/conversations/{id}/toggle_status:
$ref: ./conversation/toggle_status.yml
# Messages
/account/{account_id}/conversations/{id}/messages:
/accounts/{account_id}/conversations/{id}/messages:
$ref: ./conversation/messages/index_create.yml
/account/{account_id}/conversations/{id}/labels:
/accounts/{account_id}/conversations/{id}/labels:
$ref: ./conversation/labels.yml
/account/{account_id}/conversations/{id}/assignments:
/accounts/{account_id}/conversations/{id}/assignments:
$ref: ./conversation/assignments.yml
# Contacts
/account/{account_id}/contacts:
/accounts/{account_id}/contacts:
$ref: ./contact/list_create.yml
/account/{account_id}/contacts/{id}:
/accounts/{account_id}/contacts/{id}:
$ref: ./contact/crud.yml
/account/{account_id}/contacts/{id}/conversations:
/accounts/{account_id}/contacts/{id}/conversations:
$ref: ./contact/conversations.yml

View File

@@ -25,7 +25,7 @@
"application/json; charset=utf-8"
],
"paths": {
"/account/{account_id}/widget/inboxes": {
"/accounts/{account_id}/widget/inboxes": {
"post": {
"tags": [
"Widget"
@@ -78,7 +78,7 @@
}
}
},
"/account/{account_id}/widget/inboxes/${id}": {
"/accounts/{account_id}/widget/inboxes/${id}": {
"patch": {
"tags": [
"Widget"
@@ -123,7 +123,7 @@
}
}
},
"/account/{account_id}/inboxes": {
"/accounts/{account_id}/inboxes": {
"get": {
"tags": [
"Inbox"
@@ -147,14 +147,14 @@
}
}
},
"/account/{account_id}/inboxes/{id}": {
"/accounts/{account_id}/inboxes/{id}": {
"patch": {
"tags": [
"Inbox"
],
"operationId": "disableAutoAssignment",
"summary": "Disable auto assignment",
"description": "Disable Auto Assignment for an inbox",
"operationId": "updateInbox",
"summary": "Update Inbox",
"description": "Add avatar and disable auto assignment for an inbox",
"parameters": [
{
"name": "id",
@@ -174,6 +174,11 @@
"type": "boolean",
"required": true,
"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": {
"tags": [
"Conversation"
@@ -262,7 +267,7 @@
}
}
},
"/account/{account_id}/conversations/{id}": {
"/accounts/{account_id}/conversations/{id}": {
"get": {
"tags": [
"Conversation"
@@ -295,7 +300,7 @@
}
}
},
"/account/{account_id}/conversations/{id}/toggle_status": {
"/accounts/{account_id}/conversations/{id}/toggle_status": {
"post": {
"tags": [
"Conversation"
@@ -347,7 +352,7 @@
}
}
},
"/account/{account_id}/conversations/{id}/messages": {
"/accounts/{account_id}/conversations/{id}/messages": {
"get": {
"tags": [
"Messages"
@@ -434,7 +439,7 @@
}
}
},
"/account/{account_id}/conversations/{id}/labels": {
"/accounts/{account_id}/conversations/{id}/labels": {
"get": {
"tags": [
"ConversationLabels"
@@ -515,7 +520,7 @@
}
}
},
"/account/{account_id}/conversations/{id}/assignments": {
"/accounts/{account_id}/conversations/{id}/assignments": {
"post": {
"tags": [
"ConversationAssignment"
@@ -561,7 +566,7 @@
}
}
},
"/account/{account_id}/contacts": {
"/accounts/{account_id}/contacts": {
"get": {
"tags": [
"Contact"
@@ -623,7 +628,7 @@
}
}
},
"/account/{account_id}/contacts/{id}": {
"/accounts/{account_id}/contacts/{id}": {
"get": {
"tags": [
"Contact"
@@ -693,7 +698,7 @@
}
}
},
"/account/{account_id}/contacts/{id}/conversations": {
"/accounts/{account_id}/contacts/{id}/conversations": {
"get": {
"tags": [
"Contact"