diff --git a/app/controllers/api/v1/accounts/contacts_controller.rb b/app/controllers/api/v1/accounts/contacts_controller.rb index c7b2348ab..b9b9ffafe 100644 --- a/app/controllers/api/v1/accounts/contacts_controller.rb +++ b/app/controllers/api/v1/accounts/contacts_controller.rb @@ -22,7 +22,7 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController render json: { error: 'Specify search string with parameter q' }, status: :unprocessable_entity if params[:q].blank? && return contacts = resolved_contacts.where( - 'name ILIKE :search OR email ILIKE :search OR phone_number ILIKE :search', + 'name ILIKE :search OR email ILIKE :search OR phone_number ILIKE :search OR contacts.identifier LIKE :search', search: "%#{params[:q]}%" ) @contacts_count = contacts.count @@ -108,7 +108,7 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController end def contact_params - params.require(:contact).permit(:name, :email, :phone_number, additional_attributes: {}, custom_attributes: {}) + params.require(:contact).permit(:name, :identifier, :email, :phone_number, additional_attributes: {}, custom_attributes: {}) end def contact_custom_attributes diff --git a/lib/exception_list.rb b/lib/exception_list.rb index 402523486..b0703626d 100644 --- a/lib/exception_list.rb +++ b/lib/exception_list.rb @@ -1,7 +1,8 @@ module ExceptionList REST_CLIENT_EXCEPTIONS = [RestClient::NotFound, RestClient::GatewayTimeout, RestClient::BadRequest, RestClient::MethodNotAllowed, RestClient::Forbidden, RestClient::InternalServerError, - RestClient::Exceptions::OpenTimeout, RestClient::Exceptions::ReadTimeout, SocketError].freeze + RestClient::Exceptions::OpenTimeout, RestClient::Exceptions::ReadTimeout, + RestClient::MovedPermanently, SocketError].freeze SMTP_EXCEPTIONS = [ Net::SMTPSyntaxError ].freeze diff --git a/spec/controllers/api/v1/accounts/contacts_controller_spec.rb b/spec/controllers/api/v1/accounts/contacts_controller_spec.rb index 1dd152898..dedd34e3c 100644 --- a/spec/controllers/api/v1/accounts/contacts_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/contacts_controller_spec.rb @@ -188,6 +188,19 @@ RSpec.describe 'Contacts API', type: :request do expect(response.body).to include(contact2.email) expect(response.body).not_to include(contact1.email) end + + it 'matches the contact respecting the identifier character casing' do + contact_normal = create(:contact, name: 'testcontact', account: account, identifier: 'testidentifer') + contact_special = create(:contact, name: 'testcontact', account: account, identifier: 'TestIdentifier') + get "/api/v1/accounts/#{account.id}/contacts/search", + params: { q: 'TestIdentifier' }, + headers: admin.create_new_auth_token, + as: :json + + expect(response).to have_http_status(:success) + expect(response.body).to include(contact_special.identifier) + expect(response.body).not_to include(contact_normal.identifier) + end end end @@ -284,7 +297,7 @@ RSpec.describe 'Contacts API', type: :request do expect(json_response['payload']['contact']['custom_attributes']).to eq({ 'test' => 'test', 'test1' => 'test1' }) end - it 'creates the contact identifier when inbox id is passed' do + it 'creates the contact inbox when inbox id is passed' do expect do post "/api/v1/accounts/#{account.id}/contacts", headers: admin.create_new_auth_token, params: valid_params.merge({ inbox_id: inbox.id }) diff --git a/swagger/definitions/request/contact/create.yml b/swagger/definitions/request/contact/create.yml index 5dc481a76..26e04463a 100644 --- a/swagger/definitions/request/contact/create.yml +++ b/swagger/definitions/request/contact/create.yml @@ -5,7 +5,13 @@ properties: required: true name: type: string + description: name of the contact email: type: string + description: email of the contact phone_number: type: string + description: phone number of the contact + identifier: + type: string + description: A unique identifier for the contact in external system diff --git a/swagger/definitions/request/contact/update.yml b/swagger/definitions/request/contact/update.yml index cafa35169..7e3d8fc36 100644 --- a/swagger/definitions/request/contact/update.yml +++ b/swagger/definitions/request/contact/update.yml @@ -2,7 +2,13 @@ type: object properties: name: type: string + description: name of the contact email: type: string + description: email of the contact phone_number: type: string + description: phone number of the contact + identifier: + type: string + description: A unique identifier for the contact in external system diff --git a/swagger/paths/contact/search.yml b/swagger/paths/contact/search.yml index 30ade7b5a..84e782d2d 100644 --- a/swagger/paths/contact/search.yml +++ b/swagger/paths/contact/search.yml @@ -8,6 +8,7 @@ get: - name: q in: query type: string + description: Search using contact `name`, `identifier`, `email` or `phone number` - $ref: '#/parameters/contact_sort_param' - $ref: '#/parameters/page' responses: diff --git a/swagger/swagger.json b/swagger/swagger.json index 935044734..43129026e 100644 --- a/swagger/swagger.json +++ b/swagger/swagger.json @@ -1281,7 +1281,8 @@ { "name": "q", "in": "query", - "type": "string" + "type": "string", + "description": "Search using contact `name`, `identifier`, `email` or `phone number`" }, { "$ref": "#/parameters/contact_sort_param" @@ -3376,13 +3377,20 @@ "required": true }, "name": { - "type": "string" + "type": "string", + "description": "name of the contact" }, "email": { - "type": "string" + "type": "string", + "description": "email of the contact" }, "phone_number": { - "type": "string" + "type": "string", + "description": "phone number of the contact" + }, + "identifier": { + "type": "string", + "description": "A unique identifier for the contact in external system" } } }, @@ -3390,13 +3398,20 @@ "type": "object", "properties": { "name": { - "type": "string" + "type": "string", + "description": "name of the contact" }, "email": { - "type": "string" + "type": "string", + "description": "email of the contact" }, "phone_number": { - "type": "string" + "type": "string", + "description": "phone number of the contact" + }, + "identifier": { + "type": "string", + "description": "A unique identifier for the contact in external system" } } },