diff --git a/.rubocop.yml b/.rubocop.yml index ff4a0160a..48d234ba0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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' diff --git a/app/actions/contact_merge_action.rb b/app/actions/contact_merge_action.rb index 8261a51ad..343e78032 100644 --- a/app/actions/contact_merge_action.rb +++ b/app/actions/contact_merge_action.rb @@ -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) diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb index d512eeabf..8db37ced7 100644 --- a/app/controllers/api/base_controller.rb +++ b/app/controllers/api/base_controller.rb @@ -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 diff --git a/app/controllers/api/v1/accounts/inboxes_controller.rb b/app/controllers/api/v1/accounts/inboxes_controller.rb index 630f93e0d..3345a5883 100644 --- a/app/controllers/api/v1/accounts/inboxes_controller.rb +++ b/app/controllers/api/v1/accounts/inboxes_controller.rb @@ -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 diff --git a/app/controllers/concerns/access_token_auth_helper.rb b/app/controllers/concerns/access_token_auth_helper.rb index 3e3875333..c5173e422 100644 --- a/app/controllers/concerns/access_token_auth_helper.rb +++ b/app/controllers/concerns/access_token_auth_helper.rb @@ -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 diff --git a/app/models/account.rb b/app/models/account.rb index 883ed28aa..35cada140 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -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 diff --git a/app/models/inbox.rb b/app/models/inbox.rb index 867559ddc..118733399 100644 --- a/app/models/inbox.rb +++ b/app/models/inbox.rb @@ -20,6 +20,7 @@ class Inbox < ApplicationRecord include Reportable + include Avatarable validates :account_id, presence: true diff --git a/spec/controllers/api/v1/accounts/inboxes_controller_spec.rb b/spec/controllers/api/v1/accounts/inboxes_controller_spec.rb index f03fc2a29..6aa6286a4 100644 --- a/spec/controllers/api/v1/accounts/inboxes_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/inboxes_controller_spec.rb @@ -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) diff --git a/swagger/paths/inboxes/update.yml b/swagger/paths/inboxes/update.yml index bfa79c27c..35c843469 100644 --- a/swagger/paths/inboxes/update.yml +++ b/swagger/paths/inboxes/update.yml @@ -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 diff --git a/swagger/paths/index.yml b/swagger/paths/index.yml index dbbd8ce89..f82ed9673 100644 --- a/swagger/paths/index.yml +++ b/swagger/paths/index.yml @@ -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 diff --git a/swagger/swagger.json b/swagger/swagger.json index 049a1b21e..609c5bb93 100644 --- a/swagger/swagger.json +++ b/swagger/swagger.json @@ -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"