Chore: Scope URLs with account_id (#601)
* Chore: Enable Users to create multiple accounts Addresses: #402 - migrations to split roles and other attributes from users table - make changes in code to accommodate this change Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
parent
2a6670f0da
commit
19ab0fe108
105 changed files with 480 additions and 402 deletions
55
.rubocop.yml
55
.rubocop.yml
|
@ -41,17 +41,54 @@ RSpec/NestedGroups:
|
||||||
Max: 4
|
Max: 4
|
||||||
RSpec/MessageSpies:
|
RSpec/MessageSpies:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
Metrics/MethodLength:
|
||||||
|
Exclude:
|
||||||
|
- 'db/migrate/20161123131628_devise_token_auth_create_users.rb'
|
||||||
|
Rails/CreateTableWithTimestamps:
|
||||||
|
Exclude:
|
||||||
|
- 'db/migrate/20170207092002_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb'
|
||||||
|
Style/GuardClause:
|
||||||
|
Exclude:
|
||||||
|
- 'app/builders/account_builder.rb'
|
||||||
|
- 'app/models/attachment.rb'
|
||||||
|
- 'app/models/message.rb'
|
||||||
|
- 'lib/webhooks/chargebee.rb'
|
||||||
|
- 'db/migrate/20190819005836_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb'
|
||||||
|
Metrics/AbcSize:
|
||||||
|
Exclude:
|
||||||
|
- 'db/migrate/20190819005836_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb'
|
||||||
|
Metrics/CyclomaticComplexity:
|
||||||
|
Exclude:
|
||||||
|
- 'db/migrate/20190819005836_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb'
|
||||||
|
Rails/ReversibleMigration:
|
||||||
|
Exclude:
|
||||||
|
- 'db/migrate/20161025070152_removechannelsfrommodels.rb'
|
||||||
|
- 'db/migrate/20161025070645_remchannel.rb'
|
||||||
|
- 'db/migrate/20161025070645_remchannel.rb'
|
||||||
|
- 'db/migrate/20161110102609_removeinboxid.rb'
|
||||||
|
- 'db/migrate/20170519091539_add_avatar_to_fb.rb'
|
||||||
|
- 'db/migrate/20191020085608_rename_old_tables.rb'
|
||||||
|
- 'db/migrate/20191126185833_update_user_invite_foreign_key.rb'
|
||||||
|
- 'db/migrate/20191130164019_add_template_type_to_messages.rb'
|
||||||
Rails/BulkChangeTable:
|
Rails/BulkChangeTable:
|
||||||
Exclude:
|
Exclude:
|
||||||
|
- 'db/migrate/20161025070152_removechannelsfrommodels.rb'
|
||||||
- 'db/migrate/20200121190901_create_account_users.rb'
|
- 'db/migrate/20200121190901_create_account_users.rb'
|
||||||
|
- 'db/migrate/20170211092540_notnullableusers.rb'
|
||||||
|
- 'db/migrate/20170403095203_contactadder.rb'
|
||||||
|
- 'db/migrate/20170406104018_add_default_status_conv.rb'
|
||||||
|
- 'db/migrate/20170511134418_latlong.rb'
|
||||||
|
- 'db/migrate/20191027054756_create_contact_inboxes.rb'
|
||||||
|
- 'db/migrate/20191130164019_add_template_type_to_messages.rb'
|
||||||
AllCops:
|
AllCops:
|
||||||
Exclude:
|
Exclude:
|
||||||
- db/*
|
- 'bin/**/*'
|
||||||
- bin/**/*
|
- 'db/schema.rb'
|
||||||
- db/**/*
|
- 'config/**/*'
|
||||||
- config/**/*
|
- 'public/**/*'
|
||||||
- public/**/*
|
- 'vendor/**/*'
|
||||||
- vendor/**/*
|
- 'node_modules/**/*'
|
||||||
- node_modules/**/*
|
- 'lib/tasks/auto_annotate_models.rake'
|
||||||
- lib/tasks/auto_annotate_models.rake
|
- 'config/environments/**/*'
|
||||||
- config/environments/**/*
|
- 'tmp/**/*'
|
||||||
|
- 'storage/**/*'
|
||||||
|
|
|
@ -282,15 +282,6 @@ Style/GlobalVars:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/redis/alfred.rb'
|
- 'lib/redis/alfred.rb'
|
||||||
|
|
||||||
# Offense count: 7
|
|
||||||
# Configuration parameters: MinBodyLength.
|
|
||||||
Style/GuardClause:
|
|
||||||
Exclude:
|
|
||||||
- 'app/builders/account_builder.rb'
|
|
||||||
- 'app/models/attachment.rb'
|
|
||||||
- 'app/models/message.rb'
|
|
||||||
- 'lib/webhooks/chargebee.rb'
|
|
||||||
|
|
||||||
# Offense count: 4
|
# Offense count: 4
|
||||||
Style/IdenticalConditionalBranches:
|
Style/IdenticalConditionalBranches:
|
||||||
Exclude:
|
Exclude:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
class Api::V1::AccountsController < Api::BaseController
|
class Api::V1::Accounts::AccountsController < Api::BaseController
|
||||||
include AuthHelper
|
include AuthHelper
|
||||||
|
|
||||||
skip_before_action :verify_authenticity_token, only: [:create]
|
skip_before_action :verify_authenticity_token, only: [:create]
|
||||||
|
@ -18,9 +18,7 @@ class Api::V1::AccountsController < Api::BaseController
|
||||||
).perform
|
).perform
|
||||||
if @user
|
if @user
|
||||||
send_auth_headers(@user)
|
send_auth_headers(@user)
|
||||||
render json: {
|
render 'devise/auth.json', locals: { resource: @user }
|
||||||
data: @user.token_validation_response
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
render_error_response(CustomExceptions::Account::SignupFailed.new({}))
|
render_error_response(CustomExceptions::Account::SignupFailed.new({}))
|
||||||
end
|
end
|
|
@ -1,4 +1,4 @@
|
||||||
class Api::V1::Actions::ContactMergesController < Api::BaseController
|
class Api::V1::Accounts::Actions::ContactMergesController < Api::BaseController
|
||||||
before_action :set_base_contact, only: [:create]
|
before_action :set_base_contact, only: [:create]
|
||||||
before_action :set_mergee_contact, only: [:create]
|
before_action :set_mergee_contact, only: [:create]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
class Api::V1::AgentsController < Api::BaseController
|
class Api::V1::Accounts::AgentsController < Api::BaseController
|
||||||
before_action :fetch_agent, except: [:create, :index]
|
before_action :fetch_agent, except: [:create, :index]
|
||||||
before_action :check_authorization
|
before_action :check_authorization
|
||||||
before_action :find_user, only: [:create]
|
before_action :find_user, only: [:create]
|
|
@ -1,6 +1,4 @@
|
||||||
require 'rest-client'
|
class Api::V1::Accounts::CallbacksController < Api::BaseController
|
||||||
require 'telegram/bot'
|
|
||||||
class Api::V1::CallbacksController < Api::BaseController
|
|
||||||
before_action :inbox, only: [:reauthorize_page]
|
before_action :inbox, only: [:reauthorize_page]
|
||||||
|
|
||||||
def register_facebook_page
|
def register_facebook_page
|
||||||
|
@ -18,7 +16,7 @@ class Api::V1::CallbacksController < Api::BaseController
|
||||||
render json: inbox
|
render json: inbox
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_facebook_pages
|
def facebook_pages
|
||||||
@page_details = mark_already_existing_facebook_pages(fb_object.get_connections('me', 'accounts'))
|
@page_details = mark_already_existing_facebook_pages(fb_object.get_connections('me', 'accounts'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -67,7 +65,7 @@ class Api::V1::CallbacksController < Api::BaseController
|
||||||
return [] if data.empty?
|
return [] if data.empty?
|
||||||
|
|
||||||
data.inject([]) do |result, page_detail|
|
data.inject([]) do |result, page_detail|
|
||||||
current_account.facebook_pages.exists?(page_id: page_detail['id']) ? page_detail.merge!(exists: true) : page_detail.merge!(exists: false)
|
page_detail[:exists] = current_account.facebook_pages.exists?(page_id: page_detail['id']) ? true : false
|
||||||
result << page_detail
|
result << page_detail
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -90,11 +88,12 @@ class Api::V1::CallbacksController < Api::BaseController
|
||||||
response = uri.open(redirect: false)
|
response = uri.open(redirect: false)
|
||||||
rescue OpenURI::HTTPRedirect => e
|
rescue OpenURI::HTTPRedirect => e
|
||||||
uri = e.uri # assigned from the "Location" response header
|
uri = e.uri # assigned from the "Location" response header
|
||||||
retry if (tries -= 1) > 0
|
retry if (tries -= 1).positive?
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
pic_url = response.base_uri.to_s
|
pic_url = response.base_uri.to_s
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
|
Rails.logger.debug "Rescued: #{e.inspect}"
|
||||||
pic_url = nil
|
pic_url = nil
|
||||||
end
|
end
|
||||||
pic_url
|
pic_url
|
|
@ -1,4 +1,4 @@
|
||||||
class Api::V1::CannedResponsesController < Api::BaseController
|
class Api::V1::Accounts::CannedResponsesController < Api::BaseController
|
||||||
before_action :fetch_canned_response, only: [:update, :destroy]
|
before_action :fetch_canned_response, only: [:update, :destroy]
|
||||||
|
|
||||||
def index
|
def index
|
|
@ -1,4 +1,4 @@
|
||||||
class Api::V1::Contacts::ConversationsController < Api::BaseController
|
class Api::V1::Accounts::Contacts::ConversationsController < Api::BaseController
|
||||||
def index
|
def index
|
||||||
@conversations = current_account.conversations.includes(
|
@conversations = current_account.conversations.includes(
|
||||||
:assignee, :contact, :inbox
|
:assignee, :contact, :inbox
|
|
@ -1,4 +1,4 @@
|
||||||
class Api::V1::ContactsController < Api::BaseController
|
class Api::V1::Accounts::ContactsController < Api::BaseController
|
||||||
protect_from_forgery with: :null_session
|
protect_from_forgery with: :null_session
|
||||||
|
|
||||||
before_action :check_authorization
|
before_action :check_authorization
|
|
@ -1,7 +1,8 @@
|
||||||
class Api::V1::Conversations::AssignmentsController < Api::BaseController
|
class Api::V1::Accounts::Conversations::AssignmentsController < Api::BaseController
|
||||||
before_action :set_conversation, only: [:create]
|
before_action :set_conversation, only: [:create]
|
||||||
|
|
||||||
def create # assign agent to a conversation
|
# assign agent to a conversation
|
||||||
|
def create
|
||||||
# if params[:assignee_id] is not a valid id, it will set to nil, hence unassigning the conversation
|
# if params[:assignee_id] is not a valid id, it will set to nil, hence unassigning the conversation
|
||||||
assignee = current_account.users.find_by(id: params[:assignee_id])
|
assignee = current_account.users.find_by(id: params[:assignee_id])
|
||||||
@conversation.update_assignee(assignee)
|
@conversation.update_assignee(assignee)
|
|
@ -1,4 +1,4 @@
|
||||||
class Api::V1::Conversations::LabelsController < Api::BaseController
|
class Api::V1::Accounts::Conversations::LabelsController < Api::BaseController
|
||||||
before_action :set_conversation, only: [:create, :index]
|
before_action :set_conversation, only: [:create, :index]
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@ -6,7 +6,8 @@ class Api::V1::Conversations::LabelsController < Api::BaseController
|
||||||
@labels = @conversation.label_list
|
@labels = @conversation.label_list
|
||||||
end
|
end
|
||||||
|
|
||||||
def index # all labels of the current conversation
|
# all labels of the current conversation
|
||||||
|
def index
|
||||||
@labels = @conversation.label_list
|
@labels = @conversation.label_list
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,4 +1,4 @@
|
||||||
class Api::V1::Conversations::MessagesController < Api::BaseController
|
class Api::V1::Accounts::Conversations::MessagesController < Api::BaseController
|
||||||
before_action :set_conversation, only: [:index, :create]
|
before_action :set_conversation, only: [:index, :create]
|
||||||
|
|
||||||
def index
|
def index
|
|
@ -1,5 +1,5 @@
|
||||||
class Api::V1::ConversationsController < Api::BaseController
|
class Api::V1::Accounts::ConversationsController < Api::BaseController
|
||||||
before_action :set_conversation, except: [:index]
|
before_action :conversation, except: [:index]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
result = conversation_finder.perform
|
result = conversation_finder.perform
|
||||||
|
@ -25,7 +25,7 @@ class Api::V1::ConversationsController < Api::BaseController
|
||||||
DateTime.strptime(params[:agent_last_seen_at].to_s, '%s')
|
DateTime.strptime(params[:agent_last_seen_at].to_s, '%s')
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_conversation
|
def conversation
|
||||||
@conversation ||= current_account.conversations.find_by(display_id: params[:id])
|
@conversation ||= current_account.conversations.find_by(display_id: params[:id])
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
class Api::V1::FacebookIndicatorsController < Api::BaseController
|
class Api::V1::Accounts::FacebookIndicatorsController < Api::BaseController
|
||||||
before_action :set_access_token
|
before_action :set_access_token
|
||||||
around_action :handle_with_exception
|
around_action :handle_with_exception
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ class Api::V1::FacebookIndicatorsController < Api::BaseController
|
||||||
def handle_with_exception
|
def handle_with_exception
|
||||||
yield
|
yield
|
||||||
rescue Facebook::Messenger::Error => e
|
rescue Facebook::Messenger::Error => e
|
||||||
|
Rails.logger.debug "Rescued: #{e.inspect}"
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
class Api::V1::InboxMembersController < Api::BaseController
|
class Api::V1::Accounts::InboxMembersController < Api::BaseController
|
||||||
before_action :fetch_inbox, only: [:create, :show]
|
before_action :fetch_inbox, only: [:create, :show]
|
||||||
before_action :current_agents_ids, only: [:create]
|
before_action :current_agents_ids, only: [:create]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
class Api::V1::InboxesController < Api::BaseController
|
class Api::V1::Accounts::InboxesController < Api::BaseController
|
||||||
before_action :check_authorization
|
before_action :check_authorization
|
||||||
before_action :fetch_inbox, only: [:destroy, :update]
|
before_action :fetch_inbox, only: [:destroy, :update]
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class Api::V1::LabelsController < Api::BaseController
|
class Api::V1::Accounts::LabelsController < Api::BaseController
|
||||||
def index # list all labels in account
|
# list all labels in account
|
||||||
|
def index
|
||||||
@labels = current_account.all_conversation_tags
|
@labels = current_account.all_conversation_tags
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
class Api::V1::User::NotificationSettingsController < Api::BaseController
|
class Api::V1::Accounts::NotificationSettingsController < Api::BaseController
|
||||||
before_action :set_user, :load_notification_setting
|
before_action :set_user, :load_notification_setting
|
||||||
|
|
||||||
def show; end
|
def show; end
|
|
@ -1,4 +1,4 @@
|
||||||
class Api::V1::ReportsController < Api::BaseController
|
class Api::V1::Accounts::ReportsController < Api::BaseController
|
||||||
include CustomExceptions::Report
|
include CustomExceptions::Report
|
||||||
include Constants::Report
|
include Constants::Report
|
||||||
|
|
||||||
|
@ -36,10 +36,6 @@ class Api::V1::ReportsController < Api::BaseController
|
||||||
current_user.account
|
current_user.account
|
||||||
end
|
end
|
||||||
|
|
||||||
def agent
|
|
||||||
@agent ||= current_account.users.find(params[:agent_id])
|
|
||||||
end
|
|
||||||
|
|
||||||
def account_summary_metrics
|
def account_summary_metrics
|
||||||
summary_metrics(ACCOUNT_METRICS, :account_summary_params, AVG_ACCOUNT_METRICS)
|
summary_metrics(ACCOUNT_METRICS, :account_summary_params, AVG_ACCOUNT_METRICS)
|
||||||
end
|
end
|
||||||
|
@ -51,16 +47,16 @@ class Api::V1::ReportsController < Api::BaseController
|
||||||
def summary_metrics(metrics, calc_function, avg_metrics)
|
def summary_metrics(metrics, calc_function, avg_metrics)
|
||||||
metrics.each_with_object({}) do |metric, result|
|
metrics.each_with_object({}) do |metric, result|
|
||||||
data = ReportBuilder.new(current_account, send(calc_function, metric)).build
|
data = ReportBuilder.new(current_account, send(calc_function, metric)).build
|
||||||
|
result[metric] = calculate_metric(data, metric, avg_metrics)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def calculate_metric(data, metric, avg_metrics)
|
||||||
|
sum = data.inject(0) { |val, hash| val + hash[:value].to_i }
|
||||||
if avg_metrics.include?(metric)
|
if avg_metrics.include?(metric)
|
||||||
sum = data.inject(0) { |sum, hash| sum + hash[:value].to_i }
|
|
||||||
sum /= data.length unless sum.zero?
|
sum /= data.length unless sum.zero?
|
||||||
else
|
|
||||||
sum = data.inject(0) { |sum, hash| sum + hash[:value].to_i }
|
|
||||||
end
|
|
||||||
|
|
||||||
result[metric] = sum
|
|
||||||
end
|
end
|
||||||
|
sum
|
||||||
end
|
end
|
||||||
|
|
||||||
def account_summary_params(metric)
|
def account_summary_params(metric)
|
|
@ -1,4 +1,4 @@
|
||||||
class Api::V1::SubscriptionsController < Api::BaseController
|
class Api::V1::Accounts::SubscriptionsController < Api::BaseController
|
||||||
skip_before_action :check_subscription
|
skip_before_action :check_subscription
|
||||||
|
|
||||||
before_action :check_billing_enabled
|
before_action :check_billing_enabled
|
|
@ -1,4 +1,4 @@
|
||||||
class Api::V1::Account::WebhooksController < Api::BaseController
|
class Api::V1::Accounts::WebhooksController < Api::BaseController
|
||||||
before_action :check_authorization
|
before_action :check_authorization
|
||||||
before_action :fetch_webhook, only: [:update, :destroy]
|
before_action :fetch_webhook, only: [:update, :destroy]
|
||||||
|
|
|
@ -11,9 +11,7 @@ class DeviseOverrides::PasswordsController < Devise::PasswordsController
|
||||||
@recoverable = User.find_by(reset_password_token: reset_password_token)
|
@recoverable = User.find_by(reset_password_token: reset_password_token)
|
||||||
if @recoverable && reset_password_and_confirmation(@recoverable)
|
if @recoverable && reset_password_and_confirmation(@recoverable)
|
||||||
send_auth_headers(@recoverable)
|
send_auth_headers(@recoverable)
|
||||||
render json: {
|
render 'devise/auth.json', locals: { resource: @recoverable }
|
||||||
data: @recoverable.token_validation_response
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
render json: { "message": 'Invalid token', "redirect_url": '/' }, status: 422
|
render json: { "message": 'Invalid token', "redirect_url": '/' }, status: 422
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,6 @@ class DeviseOverrides::SessionsController < ::DeviseTokenAuth::SessionsControlle
|
||||||
wrap_parameters format: []
|
wrap_parameters format: []
|
||||||
|
|
||||||
def render_create_success
|
def render_create_success
|
||||||
render 'devise/auth.json'
|
render 'devise/auth.json', locals: { resource: @resource }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,9 +3,25 @@
|
||||||
const API_VERSION = `/api/v1`;
|
const API_VERSION = `/api/v1`;
|
||||||
|
|
||||||
class ApiClient {
|
class ApiClient {
|
||||||
constructor(url) {
|
constructor(resource, options = {}) {
|
||||||
this.apiVersion = API_VERSION;
|
this.apiVersion = API_VERSION;
|
||||||
this.url = `${this.apiVersion}/${url}`;
|
this.options = options;
|
||||||
|
this.resource = resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
get url() {
|
||||||
|
let url = this.apiVersion;
|
||||||
|
if (this.options.accountScoped) {
|
||||||
|
const isInsideAccountScopedURLs = window.location.pathname.includes(
|
||||||
|
'/app/accounts'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isInsideAccountScopedURLs) {
|
||||||
|
const accountId = window.location.pathname.split('/')[3];
|
||||||
|
url = `${url}/accounts/${accountId}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return `${url}/${this.resource}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
get() {
|
get() {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import ApiClient from './ApiClient';
|
||||||
|
|
||||||
class Agents extends ApiClient {
|
class Agents extends ApiClient {
|
||||||
constructor() {
|
constructor() {
|
||||||
super('agents');
|
super('agents', { accountScoped: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import ApiClient from './ApiClient';
|
||||||
|
|
||||||
class CannedResponse extends ApiClient {
|
class CannedResponse extends ApiClient {
|
||||||
constructor() {
|
constructor() {
|
||||||
super('canned_responses');
|
super('canned_responses', { accountScoped: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
get({ searchKey }) {
|
get({ searchKey }) {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import ApiClient from './ApiClient';
|
||||||
|
|
||||||
class ContactAPI extends ApiClient {
|
class ContactAPI extends ApiClient {
|
||||||
constructor() {
|
constructor() {
|
||||||
super('contacts');
|
super('contacts', { accountScoped: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
getConversations(contactId) {
|
getConversations(contactId) {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import ApiClient from './ApiClient';
|
||||||
|
|
||||||
class ConversationApi extends ApiClient {
|
class ConversationApi extends ApiClient {
|
||||||
constructor() {
|
constructor() {
|
||||||
super('conversations');
|
super('conversations', { accountScoped: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
getLabels(conversationID) {
|
getLabels(conversationID) {
|
||||||
|
|
|
@ -28,23 +28,10 @@ const endPoints = {
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchFacebookPages: {
|
fetchFacebookPages: {
|
||||||
url: 'api/v1/callbacks/get_facebook_pages.json',
|
url: 'api/v1/callbacks/facebook_pages.json',
|
||||||
params: { omniauth_token: '' },
|
params: { omniauth_token: '' },
|
||||||
},
|
},
|
||||||
|
|
||||||
reports: {
|
|
||||||
account(metric, from, to) {
|
|
||||||
return {
|
|
||||||
url: `/api/v1/reports/account?metric=${metric}&since=${from}&to=${to}`,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
accountSummary(accountId, from, to) {
|
|
||||||
return {
|
|
||||||
url: `/api/v1/reports/${accountId}/account_summary?since=${from}&to=${to}`,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
subscriptions: {
|
subscriptions: {
|
||||||
get() {
|
get() {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import ApiClient from '../ApiClient';
|
||||||
|
|
||||||
class ConversationApi extends ApiClient {
|
class ConversationApi extends ApiClient {
|
||||||
constructor() {
|
constructor() {
|
||||||
super('conversations');
|
super('conversations', { accountScoped: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
get({ inboxId, status, assigneeType, page }) {
|
get({ inboxId, status, assigneeType, page }) {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import ApiClient from '../ApiClient';
|
||||||
|
|
||||||
class MessageApi extends ApiClient {
|
class MessageApi extends ApiClient {
|
||||||
constructor() {
|
constructor() {
|
||||||
super('conversations');
|
super('conversations', { accountScoped: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
create({ conversationId, message, private: isPrivate }) {
|
create({ conversationId, message, private: isPrivate }) {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import ApiClient from './ApiClient';
|
||||||
|
|
||||||
class InboxMembers extends ApiClient {
|
class InboxMembers extends ApiClient {
|
||||||
constructor() {
|
constructor() {
|
||||||
super('inbox_members');
|
super('inbox_members', { accountScoped: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
create({ inboxId, agentList }) {
|
create({ inboxId, agentList }) {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import ApiClient from './ApiClient';
|
||||||
|
|
||||||
class Inboxes extends ApiClient {
|
class Inboxes extends ApiClient {
|
||||||
constructor() {
|
constructor() {
|
||||||
super('inboxes');
|
super('inboxes', { accountScoped: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,22 @@
|
||||||
/* global axios */
|
/* global axios */
|
||||||
|
import ApiClient from './ApiClient';
|
||||||
|
|
||||||
import endPoints from './endPoints';
|
class ReportsAPI extends ApiClient {
|
||||||
|
constructor() {
|
||||||
|
super('reports', { accountScoped: true });
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
getAccountReports(metric, since, until) {
|
||||||
getAccountReports(metric, from, to) {
|
return axios.get(`${this.url}/account`, {
|
||||||
const { url } = endPoints('reports').account(metric, from, to);
|
params: { metric, since, until },
|
||||||
return axios.get(url);
|
});
|
||||||
},
|
}
|
||||||
getAccountSummary(accountId, from, to) {
|
|
||||||
const urlData = endPoints('reports').accountSummary(accountId, from, to);
|
getAccountSummary(accountId, since, until) {
|
||||||
return axios.get(urlData.url);
|
return axios.get(`${this.url}/${accountId}/account_summary`, {
|
||||||
},
|
params: { since, until },
|
||||||
};
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new ReportsAPI();
|
||||||
|
|
|
@ -3,7 +3,7 @@ import ApiClient from './ApiClient';
|
||||||
|
|
||||||
class UserNotificationSettings extends ApiClient {
|
class UserNotificationSettings extends ApiClient {
|
||||||
constructor() {
|
constructor() {
|
||||||
super('user/notification_settings');
|
super('notification_settings', { accountScoped: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
update(params) {
|
update(params) {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import ApiClient from './ApiClient';
|
||||||
|
|
||||||
class WebHooks extends ApiClient {
|
class WebHooks extends ApiClient {
|
||||||
constructor() {
|
constructor() {
|
||||||
super('account/webhooks');
|
super('webhooks', { accountScoped: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
>
|
>
|
||||||
<ul class="vertical dropdown menu">
|
<ul class="vertical dropdown menu">
|
||||||
<li>
|
<li>
|
||||||
<router-link to="/app/profile/settings">
|
<router-link :to="`/app/accounts/${accountId}/profile/settings`">
|
||||||
{{ $t('SIDEBAR.PROFILE_SETTINGS') }}
|
{{ $t('SIDEBAR.PROFILE_SETTINGS') }}
|
||||||
</router-link>
|
</router-link>
|
||||||
</li>
|
</li>
|
||||||
|
@ -144,18 +144,18 @@ export default {
|
||||||
newLink: true,
|
newLink: true,
|
||||||
key: 'inbox',
|
key: 'inbox',
|
||||||
cssClass: 'menu-title align-justify',
|
cssClass: 'menu-title align-justify',
|
||||||
toState: frontendURL('settings/inboxes'),
|
toState: frontendURL(`accounts/${this.accountId}/settings/inboxes`),
|
||||||
toStateName: 'settings_inbox_list',
|
toStateName: 'settings_inbox_list',
|
||||||
children: this.inboxes.map(inbox => ({
|
children: this.inboxes.map(inbox => ({
|
||||||
id: inbox.id,
|
id: inbox.id,
|
||||||
label: inbox.name,
|
label: inbox.name,
|
||||||
toState: frontendURL(`inbox/${inbox.id}`),
|
toState: frontendURL(`accounts/${this.accountId}/inbox/${inbox.id}`),
|
||||||
type: inbox.channel_type,
|
type: inbox.channel_type,
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
dashboardPath() {
|
dashboardPath() {
|
||||||
return frontendURL('dashboard');
|
return frontendURL(`accounts/${this.accountId}/dashboard`);
|
||||||
},
|
},
|
||||||
shouldShowStatusBox() {
|
shouldShowStatusBox() {
|
||||||
return (
|
return (
|
||||||
|
@ -176,6 +176,9 @@ export default {
|
||||||
trialMessage() {
|
trialMessage() {
|
||||||
return `${this.daysLeft} ${this.$t('APP_GLOBAL.TRIAL_MESSAGE')}`;
|
return `${this.daysLeft} ${this.$t('APP_GLOBAL.TRIAL_MESSAGE')}`;
|
||||||
},
|
},
|
||||||
|
accountId() {
|
||||||
|
return this.currentUser.account_id;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.$store.dispatch('inboxes/get');
|
this.$store.dispatch('inboxes/get');
|
||||||
|
|
|
@ -74,6 +74,7 @@ export default {
|
||||||
currentChat: 'getSelectedChat',
|
currentChat: 'getSelectedChat',
|
||||||
inboxesList: 'inboxes/getInboxes',
|
inboxesList: 'inboxes/getInboxes',
|
||||||
activeInbox: 'getSelectedInbox',
|
activeInbox: 'getSelectedInbox',
|
||||||
|
currentUser: 'getCurrentUser',
|
||||||
}),
|
}),
|
||||||
|
|
||||||
isActiveChat() {
|
isActiveChat() {
|
||||||
|
@ -96,7 +97,11 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
cardClick(chat) {
|
cardClick(chat) {
|
||||||
const { activeInbox } = this;
|
const { activeInbox } = this;
|
||||||
const path = conversationUrl(activeInbox, chat.id);
|
const path = conversationUrl(
|
||||||
|
this.currentUser.account_id,
|
||||||
|
activeInbox,
|
||||||
|
chat.id
|
||||||
|
);
|
||||||
router.push({ path: frontendURL(path) });
|
router.push({ path: frontendURL(path) });
|
||||||
},
|
},
|
||||||
extractMessageText(chatItem) {
|
extractMessageText(chatItem) {
|
||||||
|
|
|
@ -5,9 +5,9 @@ export const frontendURL = (path, params) => {
|
||||||
return `/app/${path}${stringifiedParams}`;
|
return `/app/${path}${stringifiedParams}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const conversationUrl = (activeInbox, id) => {
|
export const conversationUrl = (accountId, activeInbox, id) => {
|
||||||
const path = activeInbox
|
const path = activeInbox
|
||||||
? `inbox/${activeInbox}/conversations/${id}`
|
? `accounts/${accountId}/inbox/${activeInbox}/conversations/${id}`
|
||||||
: `conversations/${id}`;
|
: `accounts/${accountId}/conversations/${id}`;
|
||||||
return path;
|
return path;
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,10 +3,14 @@ import { frontendURL, conversationUrl } from '../URLHelper';
|
||||||
describe('#URL Helpers', () => {
|
describe('#URL Helpers', () => {
|
||||||
describe('conversationUrl', () => {
|
describe('conversationUrl', () => {
|
||||||
it('should return direct conversation URL if activeInbox is nil', () => {
|
it('should return direct conversation URL if activeInbox is nil', () => {
|
||||||
expect(conversationUrl(undefined, 1)).toBe('conversations/1');
|
expect(conversationUrl(1, undefined, 1)).toBe(
|
||||||
|
'accounts/1/conversations/1'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
it('should return ibox conversation URL if activeInbox is not nil', () => {
|
it('should return ibox conversation URL if activeInbox is not nil', () => {
|
||||||
expect(conversationUrl(2, 1)).toBe('inbox/2/conversations/1');
|
expect(conversationUrl(1, 2, 1)).toBe(
|
||||||
|
'accounts/1/inbox/2/conversations/1'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
import { frontendURL } from '../helper/URLHelper';
|
import { frontendURL } from '../helper/URLHelper';
|
||||||
|
import auth from '../api/auth';
|
||||||
|
|
||||||
|
const user = auth.getCurrentUser() || {};
|
||||||
|
const accountId = user.account_id;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
common: {
|
common: {
|
||||||
|
@ -18,7 +22,7 @@ export default {
|
||||||
label: 'Conversations',
|
label: 'Conversations',
|
||||||
hasSubMenu: false,
|
hasSubMenu: false,
|
||||||
key: '',
|
key: '',
|
||||||
toState: frontendURL('dashboard'),
|
toState: frontendURL(`accounts/${accountId}/dashboard`),
|
||||||
toolTip: 'Conversation from all subscribed inboxes',
|
toolTip: 'Conversation from all subscribed inboxes',
|
||||||
toStateName: 'home',
|
toStateName: 'home',
|
||||||
},
|
},
|
||||||
|
@ -26,14 +30,14 @@ export default {
|
||||||
icon: 'ion-arrow-graph-up-right',
|
icon: 'ion-arrow-graph-up-right',
|
||||||
label: 'Reports',
|
label: 'Reports',
|
||||||
hasSubMenu: false,
|
hasSubMenu: false,
|
||||||
toState: frontendURL('reports'),
|
toState: frontendURL(`accounts/${accountId}/reports`),
|
||||||
toStateName: 'settings_account_reports',
|
toStateName: 'settings_account_reports',
|
||||||
},
|
},
|
||||||
settings: {
|
settings: {
|
||||||
icon: 'ion-settings',
|
icon: 'ion-settings',
|
||||||
label: 'Settings',
|
label: 'Settings',
|
||||||
hasSubMenu: false,
|
hasSubMenu: false,
|
||||||
toState: frontendURL('settings'),
|
toState: frontendURL(`accounts/${accountId}/settings`),
|
||||||
toStateName: 'settings_home',
|
toStateName: 'settings_home',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -61,41 +65,43 @@ export default {
|
||||||
label: 'Home',
|
label: 'Home',
|
||||||
hasSubMenu: false,
|
hasSubMenu: false,
|
||||||
toStateName: 'home',
|
toStateName: 'home',
|
||||||
toState: frontendURL('dashboard'),
|
toState: frontendURL(`accounts/${accountId}/dashboard`),
|
||||||
},
|
},
|
||||||
agents: {
|
agents: {
|
||||||
icon: 'ion-person-stalker',
|
icon: 'ion-person-stalker',
|
||||||
label: 'Agents',
|
label: 'Agents',
|
||||||
hasSubMenu: false,
|
hasSubMenu: false,
|
||||||
toState: frontendURL('settings/agents/list'),
|
toState: frontendURL(`accounts/${accountId}/settings/agents/list`),
|
||||||
toStateName: 'agent_list',
|
toStateName: 'agent_list',
|
||||||
},
|
},
|
||||||
inboxes: {
|
inboxes: {
|
||||||
icon: 'ion-archive',
|
icon: 'ion-archive',
|
||||||
label: 'Inboxes',
|
label: 'Inboxes',
|
||||||
hasSubMenu: false,
|
hasSubMenu: false,
|
||||||
toState: frontendURL('settings/inboxes/list'),
|
toState: frontendURL(`accounts/${accountId}/settings/inboxes/list`),
|
||||||
toStateName: 'settings_inbox_list',
|
toStateName: 'settings_inbox_list',
|
||||||
},
|
},
|
||||||
cannedResponses: {
|
cannedResponses: {
|
||||||
icon: 'ion-chatbox-working',
|
icon: 'ion-chatbox-working',
|
||||||
label: 'Canned Responses',
|
label: 'Canned Responses',
|
||||||
hasSubMenu: false,
|
hasSubMenu: false,
|
||||||
toState: frontendURL('settings/canned-response/list'),
|
toState: frontendURL(
|
||||||
|
`accounts/${accountId}/settings/canned-response/list`
|
||||||
|
),
|
||||||
toStateName: 'canned_list',
|
toStateName: 'canned_list',
|
||||||
},
|
},
|
||||||
billing: {
|
billing: {
|
||||||
icon: 'ion-card',
|
icon: 'ion-card',
|
||||||
label: 'Billing',
|
label: 'Billing',
|
||||||
hasSubMenu: false,
|
hasSubMenu: false,
|
||||||
toState: frontendURL('settings/billing'),
|
toState: frontendURL(`accounts/${accountId}/settings/billing`),
|
||||||
toStateName: 'billing',
|
toStateName: 'billing',
|
||||||
},
|
},
|
||||||
settings_integrations: {
|
settings_integrations: {
|
||||||
icon: 'ion-flash',
|
icon: 'ion-flash',
|
||||||
label: 'Integrations',
|
label: 'Integrations',
|
||||||
hasSubMenu: false,
|
hasSubMenu: false,
|
||||||
toState: frontendURL('settings/integrations'),
|
toState: frontendURL(`accounts/${accountId}/settings/integrations`),
|
||||||
toStateName: 'settings_integrations',
|
toStateName: 'settings_integrations',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -22,9 +22,9 @@ export default {
|
||||||
Auth.verifyPasswordToken({
|
Auth.verifyPasswordToken({
|
||||||
confirmationToken: this.confirmationToken
|
confirmationToken: this.confirmationToken
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
window.location = res.data.redirect_url;
|
window.location = '/';
|
||||||
}).catch(res => {
|
}).catch(res => {
|
||||||
window.location = res.data.redirect_url;
|
window.location = '/';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,7 @@ export default {
|
||||||
Auth.setNewPassword(credentials)
|
Auth.setNewPassword(credentials)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
window.location = res.data.redirect_url;
|
window.location = '/';
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
|
|
@ -63,7 +63,7 @@
|
||||||
</form>
|
</form>
|
||||||
<div class="column text-center sigin--footer">
|
<div class="column text-center sigin--footer">
|
||||||
<span>Already have an account?</span>
|
<span>Already have an account?</span>
|
||||||
<router-link to="auth/login">
|
<router-link to="/app/login">
|
||||||
{{ $t('LOGIN.TITLE') }}
|
{{ $t('LOGIN.TITLE') }}
|
||||||
</router-link>
|
</router-link>
|
||||||
</div>
|
</div>
|
||||||
|
@ -77,7 +77,6 @@
|
||||||
|
|
||||||
import { required, minLength, email } from 'vuelidate/lib/validators';
|
import { required, minLength, email } from 'vuelidate/lib/validators';
|
||||||
import Auth from '../../api/auth';
|
import Auth from '../../api/auth';
|
||||||
import { frontendURL } from '../../helper/URLHelper';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
|
@ -118,7 +117,7 @@ export default {
|
||||||
Auth.register(this.credentials)
|
Auth.register(this.credentials)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
window.location = frontendURL('dashboard');
|
window.location = '/';
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { frontendURL } from '../../../helper/URLHelper';
|
||||||
export default {
|
export default {
|
||||||
routes: [
|
routes: [
|
||||||
{
|
{
|
||||||
path: frontendURL('dashboard'),
|
path: frontendURL('accounts/:accountId/dashboard'),
|
||||||
name: 'home',
|
name: 'home',
|
||||||
roles: ['administrator', 'agent'],
|
roles: ['administrator', 'agent'],
|
||||||
component: ConversationView,
|
component: ConversationView,
|
||||||
|
@ -14,7 +14,7 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: frontendURL('inbox/:inbox_id'),
|
path: frontendURL('accounts/:accountId/inbox/:inbox_id'),
|
||||||
name: 'inbox_dashboard',
|
name: 'inbox_dashboard',
|
||||||
roles: ['administrator', 'agent'],
|
roles: ['administrator', 'agent'],
|
||||||
component: ConversationView,
|
component: ConversationView,
|
||||||
|
@ -23,7 +23,7 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: frontendURL('conversations/:conversation_id'),
|
path: frontendURL('accounts/:accountId/conversations/:conversation_id'),
|
||||||
name: 'inbox_conversation',
|
name: 'inbox_conversation',
|
||||||
roles: ['administrator', 'agent'],
|
roles: ['administrator', 'agent'],
|
||||||
component: ConversationView,
|
component: ConversationView,
|
||||||
|
@ -32,7 +32,9 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: frontendURL('inbox/:inbox_id/conversations/:conversation_id'),
|
path: frontendURL(
|
||||||
|
'accounts/:accountId/inbox/:inbox_id/conversations/:conversation_id'
|
||||||
|
),
|
||||||
name: 'conversation_through_inbox',
|
name: 'conversation_through_inbox',
|
||||||
roles: ['administrator', 'agent'],
|
roles: ['administrator', 'agent'],
|
||||||
component: ConversationView,
|
component: ConversationView,
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { frontendURL } from '../../helper/URLHelper';
|
||||||
export default {
|
export default {
|
||||||
routes: [
|
routes: [
|
||||||
{
|
{
|
||||||
path: frontendURL(''),
|
path: frontendURL('accounts/:account_id'),
|
||||||
component: AppContainer,
|
component: AppContainer,
|
||||||
children: [...conversation.routes, ...settings.routes],
|
children: [...conversation.routes, ...settings.routes],
|
||||||
},
|
},
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { frontendURL } from '../../../../helper/URLHelper';
|
||||||
export default {
|
export default {
|
||||||
routes: [
|
routes: [
|
||||||
{
|
{
|
||||||
path: frontendURL('settings/agents'),
|
path: frontendURL('accounts/:accountId/settings/agents'),
|
||||||
component: SettingsContent,
|
component: SettingsContent,
|
||||||
props: {
|
props: {
|
||||||
headerTitle: 'AGENT_MGMT.HEADER',
|
headerTitle: 'AGENT_MGMT.HEADER',
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { frontendURL } from '../../../../helper/URLHelper';
|
||||||
export default {
|
export default {
|
||||||
routes: [
|
routes: [
|
||||||
{
|
{
|
||||||
path: frontendURL('settings/billing'),
|
path: frontendURL('accounts/:accountId/settings/billing'),
|
||||||
component: SettingsContent,
|
component: SettingsContent,
|
||||||
props: {
|
props: {
|
||||||
headerTitle: 'BILLING.HEADER',
|
headerTitle: 'BILLING.HEADER',
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { frontendURL } from '../../../../helper/URLHelper';
|
||||||
export default {
|
export default {
|
||||||
routes: [
|
routes: [
|
||||||
{
|
{
|
||||||
path: frontendURL('settings/canned-response'),
|
path: frontendURL('accounts/:accountId/settings/canned-response'),
|
||||||
component: SettingsContent,
|
component: SettingsContent,
|
||||||
props: {
|
props: {
|
||||||
headerTitle: 'CANNED_MGMT.HEADER',
|
headerTitle: 'CANNED_MGMT.HEADER',
|
||||||
|
|
|
@ -47,7 +47,11 @@
|
||||||
<!-- Action Buttons -->
|
<!-- Action Buttons -->
|
||||||
<td>
|
<td>
|
||||||
<div class="button-wrapper">
|
<div class="button-wrapper">
|
||||||
<router-link :to="`/app/settings/inboxes/${item.id}`">
|
<router-link
|
||||||
|
:to="
|
||||||
|
`/app/accounts/${accountId}/settings/inboxes/${item.id}`
|
||||||
|
"
|
||||||
|
>
|
||||||
<woot-submit-button
|
<woot-submit-button
|
||||||
v-if="isAdmin()"
|
v-if="isAdmin()"
|
||||||
:button-text="$t('INBOX_MGMT.SETTINGS')"
|
:button-text="$t('INBOX_MGMT.SETTINGS')"
|
||||||
|
@ -101,6 +105,7 @@ import Settings from './Settings';
|
||||||
import DeleteInbox from './DeleteInbox';
|
import DeleteInbox from './DeleteInbox';
|
||||||
import adminMixin from '../../../../mixins/isAdmin';
|
import adminMixin from '../../../../mixins/isAdmin';
|
||||||
import { frontendURL } from '../../../../helper/URLHelper';
|
import { frontendURL } from '../../../../helper/URLHelper';
|
||||||
|
import auth from '../../../../api/auth';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
@ -136,6 +141,9 @@ export default {
|
||||||
this.selectedInbox.name
|
this.selectedInbox.name
|
||||||
} ?`;
|
} ?`;
|
||||||
},
|
},
|
||||||
|
accountId() {
|
||||||
|
return auth.getCurrentUser().account_id;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
openSettings(inbox) {
|
openSettings(inbox) {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import { frontendURL } from '../../../../helper/URLHelper';
|
||||||
export default {
|
export default {
|
||||||
routes: [
|
routes: [
|
||||||
{
|
{
|
||||||
path: frontendURL('settings/inboxes'),
|
path: frontendURL('accounts/:accountId/settings/inboxes'),
|
||||||
component: SettingsContent,
|
component: SettingsContent,
|
||||||
props: params => {
|
props: params => {
|
||||||
const showBackButton = params.name !== 'settings_inbox_list';
|
const showBackButton = params.name !== 'settings_inbox_list';
|
||||||
|
|
|
@ -17,7 +17,13 @@
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="small-2 column button-wrap">
|
<div class="small-2 column button-wrap">
|
||||||
<router-link :to="frontendURL('settings/integrations/webhook')">
|
<router-link
|
||||||
|
:to="
|
||||||
|
frontendURL(
|
||||||
|
`accounts/${accountId}/settings/integrations/webhook`
|
||||||
|
)
|
||||||
|
"
|
||||||
|
>
|
||||||
<button class="button success nice">
|
<button class="button success nice">
|
||||||
{{ $t('INTEGRATION_SETTINGS.WEBHOOK.CONFIGURE') }}
|
{{ $t('INTEGRATION_SETTINGS.WEBHOOK.CONFIGURE') }}
|
||||||
</button>
|
</button>
|
||||||
|
@ -34,9 +40,18 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
import { mapGetters } from 'vuex';
|
||||||
import { frontendURL } from '../../../../helper/URLHelper';
|
import { frontendURL } from '../../../../helper/URLHelper';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
computed: {
|
||||||
|
...mapGetters({
|
||||||
|
currentUser: 'getCurrentUser',
|
||||||
|
}),
|
||||||
|
accountId() {
|
||||||
|
return this.currentUser.account_id;
|
||||||
|
},
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
frontendURL,
|
frontendURL,
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { frontendURL } from '../../../../helper/URLHelper';
|
||||||
export default {
|
export default {
|
||||||
routes: [
|
routes: [
|
||||||
{
|
{
|
||||||
path: frontendURL('settings/integrations'),
|
path: frontendURL('accounts/:accountId/settings/integrations'),
|
||||||
component: SettingsContent,
|
component: SettingsContent,
|
||||||
props: params => {
|
props: params => {
|
||||||
const showBackButton = params.name !== 'settings_integrations';
|
const showBackButton = params.name !== 'settings_integrations';
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { frontendURL } from '../../../../helper/URLHelper';
|
||||||
export default {
|
export default {
|
||||||
routes: [
|
routes: [
|
||||||
{
|
{
|
||||||
path: frontendURL('profile'),
|
path: frontendURL('accounts/:accountId/profile'),
|
||||||
name: 'profile_settings',
|
name: 'profile_settings',
|
||||||
roles: ['administrator', 'agent'],
|
roles: ['administrator', 'agent'],
|
||||||
component: SettingsContent,
|
component: SettingsContent,
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { frontendURL } from '../../../../helper/URLHelper';
|
||||||
export default {
|
export default {
|
||||||
routes: [
|
routes: [
|
||||||
{
|
{
|
||||||
path: frontendURL('reports'),
|
path: frontendURL('accounts/:accountId/reports'),
|
||||||
component: SettingsContent,
|
component: SettingsContent,
|
||||||
props: {
|
props: {
|
||||||
headerTitle: 'REPORT.HEADER',
|
headerTitle: 'REPORT.HEADER',
|
||||||
|
|
|
@ -11,14 +11,14 @@ import integrations from './integrations/integrations.routes';
|
||||||
export default {
|
export default {
|
||||||
routes: [
|
routes: [
|
||||||
{
|
{
|
||||||
path: frontendURL('settings'),
|
path: frontendURL('accounts/:accountId/settings'),
|
||||||
name: 'settings_home',
|
name: 'settings_home',
|
||||||
roles: ['administrator', 'agent'],
|
roles: ['administrator', 'agent'],
|
||||||
redirect: () => {
|
redirect: () => {
|
||||||
if (Auth.isAdmin()) {
|
if (Auth.isAdmin()) {
|
||||||
return frontendURL('settings/agents');
|
return frontendURL('accounts/:accountId/settings/agents');
|
||||||
}
|
}
|
||||||
return frontendURL('settings/canned-response');
|
return frontendURL('accounts/:accountId/settings/canned-response');
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
...agent.routes,
|
...agent.routes,
|
||||||
|
|
|
@ -7,13 +7,14 @@ import dashboard from './dashboard/dashboard.routes';
|
||||||
import authRoute from './auth/auth.routes';
|
import authRoute from './auth/auth.routes';
|
||||||
import { frontendURL } from '../helper/URLHelper';
|
import { frontendURL } from '../helper/URLHelper';
|
||||||
|
|
||||||
|
const loggedInUser = auth.getCurrentUser() || {};
|
||||||
const routes = [
|
const routes = [
|
||||||
...login.routes,
|
...login.routes,
|
||||||
...dashboard.routes,
|
...dashboard.routes,
|
||||||
...authRoute.routes,
|
...authRoute.routes,
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
redirect: frontendURL('dashboard'),
|
redirect: frontendURL(`accounts/${loggedInUser.account_id}/dashboard`),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -102,7 +103,8 @@ const validateRouteAccess = (to, from, next) => {
|
||||||
to.meta &&
|
to.meta &&
|
||||||
to.meta.requireSignupEnabled
|
to.meta.requireSignupEnabled
|
||||||
) {
|
) {
|
||||||
next(frontendURL('dashboard'));
|
const user = auth.getCurrentUser();
|
||||||
|
next(frontendURL(`accounts/${user.account_id}/dashboard`));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (authIgnoreRoutes.includes(to.name)) {
|
if (authIgnoreRoutes.includes(to.name)) {
|
||||||
|
@ -114,7 +116,8 @@ const validateRouteAccess = (to, from, next) => {
|
||||||
// protecting routes
|
// protecting routes
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
if (!to.name) {
|
if (!to.name) {
|
||||||
return next(frontendURL('dashboard'));
|
const user = auth.getCurrentUser();
|
||||||
|
return next(frontendURL(`accounts/${user.account_id}/dashboard`));
|
||||||
}
|
}
|
||||||
|
|
||||||
return validateRouteAccess(to, from, next);
|
return validateRouteAccess(to, from, next);
|
||||||
|
|
|
@ -3,7 +3,6 @@ import axios from 'axios';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
import * as types from '../mutation-types';
|
import * as types from '../mutation-types';
|
||||||
import router from '../../routes';
|
|
||||||
import authAPI from '../../api/auth';
|
import authAPI from '../../api/auth';
|
||||||
import createAxios from '../../helper/APIHelper';
|
import createAxios from '../../helper/APIHelper';
|
||||||
import actionCable from '../../helper/actionCable';
|
import actionCable from '../../helper/actionCable';
|
||||||
|
@ -65,7 +64,7 @@ export const actions = {
|
||||||
commit(types.default.SET_CURRENT_USER);
|
commit(types.default.SET_CURRENT_USER);
|
||||||
window.axios = createAxios(axios);
|
window.axios = createAxios(axios);
|
||||||
actionCable.init(Vue);
|
actionCable.init(Vue);
|
||||||
router.replace({ name: 'home' });
|
window.location = '/';
|
||||||
resolve();
|
resolve();
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
json.array! @agents do |agent|
|
|
||||||
json.account_id agent.account_id
|
|
||||||
json.availability_status agent.availability_status
|
|
||||||
json.confirmed agent.confirmed?
|
|
||||||
json.email agent.email
|
|
||||||
json.id agent.id
|
|
||||||
json.name agent.name
|
|
||||||
json.role agent.role
|
|
||||||
json.thumbnail agent.avatar_url
|
|
||||||
end
|
|
|
@ -1,14 +1,14 @@
|
||||||
json.data do
|
json.data do
|
||||||
json.id @resource.id
|
json.id resource.id
|
||||||
json.provider @resource.provider
|
json.provider resource.provider
|
||||||
json.uid @resource.uid
|
json.uid resource.uid
|
||||||
json.name @resource.name
|
json.name resource.name
|
||||||
json.nickname @resource.nickname
|
json.nickname resource.nickname
|
||||||
json.email @resource.email
|
json.email resource.email
|
||||||
json.account_id @resource.account.id
|
json.account_id resource.account.id
|
||||||
json.pubsub_token @resource.pubsub_token
|
json.pubsub_token resource.pubsub_token
|
||||||
json.role @resource.account_user.role
|
json.role resource.account_user.role
|
||||||
json.inviter_id @resource.account_user.inviter_id
|
json.inviter_id resource.account_user.inviter_id
|
||||||
json.confirmed @resource.confirmed?
|
json.confirmed resource.confirmed?
|
||||||
json.avatar_url @resource.avatar_url
|
json.avatar_url resource.avatar_url
|
||||||
end
|
end
|
||||||
|
|
106
config/routes.rb
106
config/routes.rb
|
@ -19,58 +19,23 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
namespace :api, defaults: { format: 'json' } do
|
namespace :api, defaults: { format: 'json' } do
|
||||||
namespace :v1 do
|
namespace :v1 do
|
||||||
resources :callbacks, only: [] do
|
# ----------------------------------
|
||||||
collection do
|
# start of account scoped api routes
|
||||||
post :register_facebook_page
|
resources :accounts, only: [:create], module: :accounts do
|
||||||
get :register_facebook_page
|
|
||||||
post :get_facebook_pages
|
|
||||||
post :reauthorize_page
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
namespace :widget do
|
|
||||||
resources :messages, only: [:index, :create, :update]
|
|
||||||
resources :inboxes, only: [:create, :update]
|
|
||||||
resources :inbox_members, only: [:index]
|
|
||||||
end
|
|
||||||
|
|
||||||
namespace :actions do
|
namespace :actions do
|
||||||
resource :contact_merge, only: [:create]
|
resource :contact_merge, only: [:create]
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :account do
|
|
||||||
resources :webhooks, except: [:show]
|
|
||||||
end
|
|
||||||
|
|
||||||
resource :profile, only: [:show, :update]
|
|
||||||
resources :accounts, only: [:create]
|
|
||||||
resources :inboxes, only: [:index, :destroy, :update]
|
|
||||||
resources :agents, except: [:show, :edit, :new]
|
resources :agents, except: [:show, :edit, :new]
|
||||||
resources :labels, only: [:index] do
|
resources :callbacks, only: [] do
|
||||||
collection do
|
collection do
|
||||||
get :most_used
|
post :register_facebook_page
|
||||||
|
get :register_facebook_page
|
||||||
|
post :facebook_pages
|
||||||
|
post :reauthorize_page
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :canned_responses, except: [:show, :edit, :new]
|
resources :canned_responses, except: [:show, :edit, :new]
|
||||||
resources :inbox_members, only: [:create, :show], param: :inbox_id
|
|
||||||
resources :facebook_indicators, only: [] do
|
|
||||||
collection do
|
|
||||||
post :mark_seen
|
|
||||||
post :typing_on
|
|
||||||
post :typing_off
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
resources :reports, only: [] do
|
|
||||||
collection do
|
|
||||||
get :account
|
|
||||||
get :agent
|
|
||||||
end
|
|
||||||
member do
|
|
||||||
get :account_summary
|
|
||||||
get :agent_summary
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
resources :conversations, only: [:index, :show] do
|
resources :conversations, only: [:index, :show] do
|
||||||
scope module: :conversations do
|
scope module: :conversations do
|
||||||
|
@ -90,6 +55,35 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resources :facebook_indicators, only: [] do
|
||||||
|
collection do
|
||||||
|
post :mark_seen
|
||||||
|
post :typing_on
|
||||||
|
post :typing_off
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
resources :inboxes, only: [:index, :destroy, :update]
|
||||||
|
resources :inbox_members, only: [:create, :show], param: :inbox_id
|
||||||
|
resources :labels, only: [:index] do
|
||||||
|
collection do
|
||||||
|
get :most_used
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
resource :notification_settings, only: [:show, :update]
|
||||||
|
|
||||||
|
resources :reports, only: [] do
|
||||||
|
collection do
|
||||||
|
get :account
|
||||||
|
get :agent
|
||||||
|
end
|
||||||
|
member do
|
||||||
|
get :account_summary
|
||||||
|
get :agent_summary
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# this block is only required if subscription via chargebee is enabled
|
# this block is only required if subscription via chargebee is enabled
|
||||||
resources :subscriptions, only: [:index] do
|
resources :subscriptions, only: [:index] do
|
||||||
collection do
|
collection do
|
||||||
|
@ -97,15 +91,25 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resources :webhooks, except: [:show]
|
||||||
|
end
|
||||||
|
|
||||||
|
# end of account scoped api routes
|
||||||
|
# ----------------------------------
|
||||||
|
|
||||||
|
resource :profile, only: [:show, :update]
|
||||||
|
|
||||||
|
namespace :widget do
|
||||||
|
resources :messages, only: [:index, :create, :update]
|
||||||
|
resources :inboxes, only: [:create, :update]
|
||||||
|
resources :inbox_members, only: [:index]
|
||||||
|
end
|
||||||
|
|
||||||
resources :webhooks, only: [] do
|
resources :webhooks, only: [] do
|
||||||
collection do
|
collection do
|
||||||
post :chargebee
|
post :chargebee
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :user do
|
|
||||||
resource :notification_settings, only: [:show, :update]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -114,17 +118,19 @@ Rails.application.routes.draw do
|
||||||
resource :callback, only: [:show]
|
resource :callback, only: [:show]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------
|
||||||
# Used in mailer templates
|
# Used in mailer templates
|
||||||
resource :app, only: [:index] do
|
resource :app, only: [:index] do
|
||||||
resources :conversations, only: [:show]
|
resources :conversations, only: [:show]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------
|
||||||
|
# Routes for social integrations
|
||||||
mount Facebook::Messenger::Server, at: 'bot'
|
mount Facebook::Messenger::Server, at: 'bot'
|
||||||
get 'webhooks/twitter', to: 'api/v1/webhooks#twitter_crc'
|
get 'webhooks/twitter', to: 'api/v1/webhooks#twitter_crc'
|
||||||
post 'webhooks/twitter', to: 'api/v1/webhooks#twitter_events'
|
post 'webhooks/twitter', to: 'api/v1/webhooks#twitter_events'
|
||||||
|
|
||||||
post '/webhooks/telegram/:account_id/:inbox_id' => 'home#telegram'
|
# ----------------------------------------------------------------------
|
||||||
|
|
||||||
# Routes for testing
|
# Routes for testing
|
||||||
resources :widget_tests, only: [:index] unless Rails.env.production?
|
resources :widget_tests, only: [:index] unless Rails.env.production?
|
||||||
|
|
||||||
|
@ -147,8 +153,8 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
mount Sidekiq::Web, at: '/sidekiq'
|
mount Sidekiq::Web, at: '/sidekiq'
|
||||||
end
|
end
|
||||||
# ----------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------
|
||||||
# Routes for swagger docs
|
# Routes for swagger docs
|
||||||
get '/swagger/*path', to: 'swagger#respond'
|
get '/swagger/*path', to: 'swagger#respond'
|
||||||
get '/swagger', to: 'swagger#respond'
|
get '/swagger', to: 'swagger#respond'
|
||||||
|
|
|
@ -20,7 +20,7 @@ class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
|
||||||
|
|
||||||
t.datetime :created_at, null: false
|
t.datetime :created_at, null: false
|
||||||
|
|
||||||
t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true
|
t.index [:record_type, :record_id, :name, :blob_id], name: 'index_active_storage_attachments_uniqueness', unique: true
|
||||||
t.foreign_key :active_storage_blobs, column: :blob_id
|
t.foreign_key :active_storage_blobs, column: :blob_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,10 +5,10 @@ RSpec.describe 'Contact Merge Action API', type: :request do
|
||||||
let!(:base_contact) { create(:contact, account: account) }
|
let!(:base_contact) { create(:contact, account: account) }
|
||||||
let!(:mergee_contact) { create(:contact, account: account) }
|
let!(:mergee_contact) { create(:contact, account: account) }
|
||||||
|
|
||||||
describe 'POST /api/v1/actions/contact_merge' do
|
describe 'POST /api/v1/accounts/{account.id}/actions/contact_merge' do
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
post '/api/v1/actions/contact_merge'
|
post "/api/v1/accounts/#{account.id}/actions/contact_merge"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -24,7 +24,7 @@ RSpec.describe 'Contact Merge Action API', type: :request do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'merges two contacts by calling contact merge action' do
|
it 'merges two contacts by calling contact merge action' do
|
||||||
post '/api/v1/actions/contact_merge',
|
post "/api/v1/accounts/#{account.id}/actions/contact_merge",
|
||||||
params: { base_contact_id: base_contact.id, mergee_contact_id: mergee_contact.id },
|
params: { base_contact_id: base_contact.id, mergee_contact_id: mergee_contact.id },
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
|
@ -3,20 +3,20 @@ require 'rails_helper'
|
||||||
RSpec.describe 'Agents API', type: :request do
|
RSpec.describe 'Agents API', type: :request do
|
||||||
let(:account) { create(:account) }
|
let(:account) { create(:account) }
|
||||||
|
|
||||||
describe 'GET /api/v1/agents' do
|
describe 'GET /api/v1/accounts/{account.id}/agents' do
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
get '/api/v1/agents'
|
get "/api/v1/accounts/#{account.id}/agents"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when it is an authenticated user' do
|
context 'when it is an authenticated user' do
|
||||||
let(:agent) { create(:user, account: account, role: :agent) }
|
let!(:agent) { create(:user, account: account, role: :agent) }
|
||||||
|
|
||||||
it 'returns all agents of account' do
|
it 'returns all agents of account' do
|
||||||
get '/api/v1/agents',
|
get "/api/v1/accounts/#{account.id}/agents",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
|
@ -26,12 +26,12 @@ RSpec.describe 'Agents API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'DELETE /api/v1/agents/:id' do
|
describe 'DELETE /api/v1/accounts/{account.id}/agents/:id' do
|
||||||
let(:other_agent) { create(:user, account: account, role: :agent) }
|
let(:other_agent) { create(:user, account: account, role: :agent) }
|
||||||
|
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
delete "/api/v1/agents/#{other_agent.id}"
|
delete "/api/v1/accounts/#{account.id}/agents/#{other_agent.id}"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -41,7 +41,7 @@ RSpec.describe 'Agents API', type: :request do
|
||||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||||
|
|
||||||
it 'deletes an agent' do
|
it 'deletes an agent' do
|
||||||
delete "/api/v1/agents/#{other_agent.id}",
|
delete "/api/v1/accounts/#{account.id}/agents/#{other_agent.id}",
|
||||||
headers: admin.create_new_auth_token,
|
headers: admin.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
|
@ -51,12 +51,12 @@ RSpec.describe 'Agents API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'PUT /api/v1/agents/:id' do
|
describe 'PUT /api/v1/accounts/{account.id}/agents/:id' do
|
||||||
let(:other_agent) { create(:user, account: account, role: :agent) }
|
let(:other_agent) { create(:user, account: account, role: :agent) }
|
||||||
|
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
put "/api/v1/agents/#{other_agent.id}"
|
put "/api/v1/accounts/#{account.id}/agents/#{other_agent.id}"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -68,7 +68,7 @@ RSpec.describe 'Agents API', type: :request do
|
||||||
params = { name: 'TestUser' }
|
params = { name: 'TestUser' }
|
||||||
|
|
||||||
it 'modifies an agent' do
|
it 'modifies an agent' do
|
||||||
put "/api/v1/agents/#{other_agent.id}",
|
put "/api/v1/accounts/#{account.id}/agents/#{other_agent.id}",
|
||||||
params: params,
|
params: params,
|
||||||
headers: admin.create_new_auth_token,
|
headers: admin.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
@ -79,12 +79,12 @@ RSpec.describe 'Agents API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST /api/v1/agents' do
|
describe 'POST /api/v1/accounts/{account.id}/agents' do
|
||||||
let(:other_agent) { create(:user, account: account, role: :agent) }
|
let(:other_agent) { create(:user, account: account, role: :agent) }
|
||||||
|
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
post '/api/v1/agents'
|
post "/api/v1/accounts/#{account.id}/agents"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -96,7 +96,7 @@ RSpec.describe 'Agents API', type: :request do
|
||||||
params = { name: 'NewUser', email: Faker::Internet.email, role: :agent }
|
params = { name: 'NewUser', email: Faker::Internet.email, role: :agent }
|
||||||
|
|
||||||
it 'creates a new agent' do
|
it 'creates a new agent' do
|
||||||
post '/api/v1/agents',
|
post "/api/v1/accounts/#{account.id}/agents",
|
||||||
params: params,
|
params: params,
|
||||||
headers: admin.create_new_auth_token,
|
headers: admin.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
|
@ -22,10 +22,10 @@ RSpec.describe 'Callbacks API', type: :request do
|
||||||
allow(koala_oauth).to receive(:exchange_access_token_info).and_return('access_token' => SecureRandom.hex(10))
|
allow(koala_oauth).to receive(:exchange_access_token_info).and_return('access_token' => SecureRandom.hex(10))
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST /api/v1/callbacks/register_facebook_page' do
|
describe 'POST /api/v1/accounts/{account.id}/callbacks/register_facebook_page' do
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
post '/api/v1/callbacks/register_facebook_page'
|
post "/api/v1/accounts/#{account.id}/callbacks/register_facebook_page"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -35,7 +35,7 @@ RSpec.describe 'Callbacks API', type: :request do
|
||||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||||
|
|
||||||
it 'registers a new facebook page with no avatar' do
|
it 'registers a new facebook page with no avatar' do
|
||||||
post '/api/v1/callbacks/register_facebook_page',
|
post "/api/v1/accounts/#{account.id}/callbacks/register_facebook_page",
|
||||||
headers: admin.create_new_auth_token,
|
headers: admin.create_new_auth_token,
|
||||||
params: valid_params,
|
params: valid_params,
|
||||||
as: :json
|
as: :json
|
||||||
|
@ -49,7 +49,7 @@ RSpec.describe 'Callbacks API', type: :request do
|
||||||
io.base_uri = URI.parse('https://example.org')
|
io.base_uri = URI.parse('https://example.org')
|
||||||
allow_any_instance_of(URI::HTTP).to receive(:open).and_return(io) # rubocop:disable RSpec/AnyInstance
|
allow_any_instance_of(URI::HTTP).to receive(:open).and_return(io) # rubocop:disable RSpec/AnyInstance
|
||||||
|
|
||||||
post '/api/v1/callbacks/register_facebook_page',
|
post "/api/v1/accounts/#{account.id}/callbacks/register_facebook_page",
|
||||||
headers: admin.create_new_auth_token,
|
headers: admin.create_new_auth_token,
|
||||||
params: valid_params,
|
params: valid_params,
|
||||||
as: :json
|
as: :json
|
||||||
|
@ -60,7 +60,7 @@ RSpec.describe 'Callbacks API', type: :request do
|
||||||
it 'registers a new facebook page with avatar on redirect' do
|
it 'registers a new facebook page with avatar on redirect' do
|
||||||
allow_any_instance_of(URI::HTTP).to receive(:open).and_raise(OpenURI::HTTPRedirect.new(nil, nil, URI.parse('https://example.org'))) # rubocop:disable RSpec/AnyInstance
|
allow_any_instance_of(URI::HTTP).to receive(:open).and_raise(OpenURI::HTTPRedirect.new(nil, nil, URI.parse('https://example.org'))) # rubocop:disable RSpec/AnyInstance
|
||||||
|
|
||||||
post '/api/v1/callbacks/register_facebook_page',
|
post "/api/v1/accounts/#{account.id}/callbacks/register_facebook_page",
|
||||||
headers: admin.create_new_auth_token,
|
headers: admin.create_new_auth_token,
|
||||||
params: valid_params,
|
params: valid_params,
|
||||||
as: :json
|
as: :json
|
||||||
|
@ -70,10 +70,10 @@ RSpec.describe 'Callbacks API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST /api/v1/callbacks/get_facebook_pages' do
|
describe 'POST /api/v1/accounts/{account.id}/callbacks/facebook_pages' do
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
post '/api/v1/callbacks/get_facebook_pages'
|
post "/api/v1/accounts/#{account.id}/callbacks/facebook_pages"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -83,7 +83,7 @@ RSpec.describe 'Callbacks API', type: :request do
|
||||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||||
|
|
||||||
it 'returns facebook pages of account' do
|
it 'returns facebook pages of account' do
|
||||||
post '/api/v1/callbacks/get_facebook_pages',
|
post "/api/v1/accounts/#{account.id}/callbacks/facebook_pages",
|
||||||
headers: admin.create_new_auth_token,
|
headers: admin.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
|
@ -93,10 +93,10 @@ RSpec.describe 'Callbacks API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST /api/v1/callbacks/reauthorize_page' do
|
describe 'POST /api/v1/accounts/{account.id}/callbacks/reauthorize_page' do
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
post '/api/v1/callbacks/reauthorize_page'
|
post "/api/v1/accounts/#{account.id}/callbacks/reauthorize_page"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -108,7 +108,7 @@ RSpec.describe 'Callbacks API', type: :request do
|
||||||
it 'reauthorizes the page' do
|
it 'reauthorizes the page' do
|
||||||
params = { inbox_id: inbox.id }
|
params = { inbox_id: inbox.id }
|
||||||
|
|
||||||
post '/api/v1/callbacks/reauthorize_page',
|
post "/api/v1/accounts/#{account.id}/callbacks/reauthorize_page",
|
||||||
headers: admin.create_new_auth_token,
|
headers: admin.create_new_auth_token,
|
||||||
params: params,
|
params: params,
|
||||||
as: :json
|
as: :json
|
||||||
|
@ -120,7 +120,7 @@ RSpec.describe 'Callbacks API', type: :request do
|
||||||
allow(koala_api).to receive(:get_connections).and_return([])
|
allow(koala_api).to receive(:get_connections).and_return([])
|
||||||
params = { inbox_id: inbox.id }
|
params = { inbox_id: inbox.id }
|
||||||
|
|
||||||
post '/api/v1/callbacks/reauthorize_page',
|
post "/api/v1/accounts/#{account.id}/callbacks/reauthorize_page",
|
||||||
headers: admin.create_new_auth_token,
|
headers: admin.create_new_auth_token,
|
||||||
params: params,
|
params: params,
|
||||||
as: :json
|
as: :json
|
|
@ -7,10 +7,10 @@ RSpec.describe 'Canned Responses API', type: :request do
|
||||||
create(:canned_response, account: account)
|
create(:canned_response, account: account)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET /api/v1/canned_responses' do
|
describe 'GET /api/v1/accounts/{account.id}/canned_responses' do
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
get '/api/v1/canned_responses'
|
get "/api/v1/accounts/#{account.id}/canned_responses"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -20,7 +20,7 @@ RSpec.describe 'Canned Responses API', type: :request do
|
||||||
let(:agent) { create(:user, account: account, role: :agent) }
|
let(:agent) { create(:user, account: account, role: :agent) }
|
||||||
|
|
||||||
it 'returns all the canned responses' do
|
it 'returns all the canned responses' do
|
||||||
get '/api/v1/canned_responses',
|
get "/api/v1/accounts/#{account.id}/canned_responses",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ RSpec.describe 'Canned Responses API', type: :request do
|
||||||
|
|
||||||
params = { search: CannedResponse.last.short_code }
|
params = { search: CannedResponse.last.short_code }
|
||||||
|
|
||||||
get '/api/v1/canned_responses',
|
get "/api/v1/accounts/#{account.id}/canned_responses",
|
||||||
params: params,
|
params: params,
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
@ -44,10 +44,10 @@ RSpec.describe 'Canned Responses API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST /api/v1/canned_responses' do
|
describe 'POST /api/v1/accounts/{account.id}/canned_responses' do
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
post '/api/v1/canned_responses'
|
post "/api/v1/accounts/#{account.id}/canned_responses"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -59,7 +59,7 @@ RSpec.describe 'Canned Responses API', type: :request do
|
||||||
it 'creates a new canned response' do
|
it 'creates a new canned response' do
|
||||||
params = { short_code: 'short', content: 'content' }
|
params = { short_code: 'short', content: 'content' }
|
||||||
|
|
||||||
post '/api/v1/canned_responses',
|
post "/api/v1/accounts/#{account.id}/canned_responses",
|
||||||
params: params,
|
params: params,
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
@ -70,12 +70,12 @@ RSpec.describe 'Canned Responses API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'PUT /api/v1/canned_responses/:id' do
|
describe 'PUT /api/v1/accounts/{account.id}/canned_responses/:id' do
|
||||||
let(:canned_response) { CannedResponse.last }
|
let(:canned_response) { CannedResponse.last }
|
||||||
|
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
put "/api/v1/canned_responses/#{canned_response.id}"
|
put "/api/v1/accounts/#{account.id}/canned_responses/#{canned_response.id}"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -87,7 +87,7 @@ RSpec.describe 'Canned Responses API', type: :request do
|
||||||
it 'updates an existing canned response' do
|
it 'updates an existing canned response' do
|
||||||
params = { short_code: 'B' }
|
params = { short_code: 'B' }
|
||||||
|
|
||||||
put "/api/v1/canned_responses/#{canned_response.id}",
|
put "/api/v1/accounts/#{account.id}/canned_responses/#{canned_response.id}",
|
||||||
params: params,
|
params: params,
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
@ -98,12 +98,12 @@ RSpec.describe 'Canned Responses API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'DELETE /api/v1/canned_responses/:id' do
|
describe 'DELETE /api/v1/accounts/{account.id}/canned_responses/:id' do
|
||||||
let(:canned_response) { CannedResponse.last }
|
let(:canned_response) { CannedResponse.last }
|
||||||
|
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
delete "/api/v1/canned_responses/#{canned_response.id}"
|
delete "/api/v1/accounts/#{account.id}/canned_responses/#{canned_response.id}"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -113,7 +113,7 @@ RSpec.describe 'Canned Responses API', type: :request do
|
||||||
let(:agent) { create(:user, account: account, role: :agent) }
|
let(:agent) { create(:user, account: account, role: :agent) }
|
||||||
|
|
||||||
it 'destroys the canned response' do
|
it 'destroys the canned response' do
|
||||||
delete "/api/v1/canned_responses/#{canned_response.id}",
|
delete "/api/v1/accounts/#{account.id}/canned_responses/#{canned_response.id}",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe '/api/v1/contacts/:id/conversations', type: :request do
|
RSpec.describe '/api/v1/accounts/{account.id}/contacts/:id/conversations', type: :request do
|
||||||
let(:account) { create(:account) }
|
let(:account) { create(:account) }
|
||||||
let(:contact) { create(:contact, account: account) }
|
let(:contact) { create(:contact, account: account) }
|
||||||
let(:inbox_1) { create(:inbox, account: account) }
|
let(:inbox_1) { create(:inbox, account: account) }
|
||||||
|
@ -17,10 +17,10 @@ RSpec.describe '/api/v1/contacts/:id/conversations', type: :request do
|
||||||
2.times.each { create(:conversation, account: account, inbox: inbox_2, contact: contact, contact_inbox: contact_inbox_2) }
|
2.times.each { create(:conversation, account: account, inbox: inbox_2, contact: contact, contact_inbox: contact_inbox_2) }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET /api/v1/contacts/:id/conversations' do
|
describe 'GET /api/v1/accounts/{account.id}/contacts/:id/conversations' do
|
||||||
context 'when unauthenticated user' do
|
context 'when unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
get "/api/v1/contacts/#{contact.id}/conversations"
|
get "/api/v1/accounts/#{account.id}/contacts/#{contact.id}/conversations"
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -28,7 +28,7 @@ RSpec.describe '/api/v1/contacts/:id/conversations', type: :request do
|
||||||
context 'when user is logged in' do
|
context 'when user is logged in' do
|
||||||
context 'with user as administrator' do
|
context 'with user as administrator' do
|
||||||
it 'returns conversations from all inboxes' do
|
it 'returns conversations from all inboxes' do
|
||||||
get "/api/v1/contacts/#{contact.id}/conversations", headers: admin.create_new_auth_token
|
get "/api/v1/accounts/#{account.id}/contacts/#{contact.id}/conversations", headers: admin.create_new_auth_token
|
||||||
|
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
json_response = JSON.parse(response.body)
|
json_response = JSON.parse(response.body)
|
||||||
|
@ -39,7 +39,7 @@ RSpec.describe '/api/v1/contacts/:id/conversations', type: :request do
|
||||||
|
|
||||||
context 'with user as agent' do
|
context 'with user as agent' do
|
||||||
it 'returns conversations from the inboxes which agent has access to' do
|
it 'returns conversations from the inboxes which agent has access to' do
|
||||||
get "/api/v1/contacts/#{contact.id}/conversations", headers: agent.create_new_auth_token
|
get "/api/v1/accounts/#{account.id}/contacts/#{contact.id}/conversations", headers: agent.create_new_auth_token
|
||||||
|
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
json_response = JSON.parse(response.body)
|
json_response = JSON.parse(response.body)
|
||||||
|
@ -50,7 +50,7 @@ RSpec.describe '/api/v1/contacts/:id/conversations', type: :request do
|
||||||
|
|
||||||
context 'with user as unknown role' do
|
context 'with user as unknown role' do
|
||||||
it 'returns conversations from no inboxes' do
|
it 'returns conversations from no inboxes' do
|
||||||
get "/api/v1/contacts/#{contact.id}/conversations", headers: unknown.create_new_auth_token
|
get "/api/v1/accounts/#{account.id}/contacts/#{contact.id}/conversations", headers: unknown.create_new_auth_token
|
||||||
|
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
json_response = JSON.parse(response.body)
|
json_response = JSON.parse(response.body)
|
|
@ -3,10 +3,10 @@ require 'rails_helper'
|
||||||
RSpec.describe 'Contacts API', type: :request do
|
RSpec.describe 'Contacts API', type: :request do
|
||||||
let(:account) { create(:account) }
|
let(:account) { create(:account) }
|
||||||
|
|
||||||
describe 'GET /api/v1/contacts' do
|
describe 'GET /api/v1/accounts/{account.id}/contacts' do
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
get '/api/v1/contacts'
|
get "/api/v1/accounts/#{account.id}/contacts"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -17,7 +17,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||||
let!(:contact) { create(:contact, account: account) }
|
let!(:contact) { create(:contact, account: account) }
|
||||||
|
|
||||||
it 'returns all contacts' do
|
it 'returns all contacts' do
|
||||||
get '/api/v1/contacts',
|
get "/api/v1/accounts/#{account.id}/contacts",
|
||||||
headers: admin.create_new_auth_token,
|
headers: admin.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
|
@ -27,12 +27,12 @@ RSpec.describe 'Contacts API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET /api/v1/contacts/:id' do
|
describe 'GET /api/v1/accounts/{account.id}/contacts/:id' do
|
||||||
let!(:contact) { create(:contact, account: account) }
|
let!(:contact) { create(:contact, account: account) }
|
||||||
|
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
get "/api/v1/contacts/#{contact.id}"
|
get "/api/v1/accounts/#{account.id}/contacts/#{contact.id}"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -42,7 +42,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||||
|
|
||||||
it 'shows the contact' do
|
it 'shows the contact' do
|
||||||
get "/api/v1/contacts/#{contact.id}",
|
get "/api/v1/accounts/#{account.id}/contacts/#{contact.id}",
|
||||||
headers: admin.create_new_auth_token,
|
headers: admin.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
|
@ -52,12 +52,12 @@ RSpec.describe 'Contacts API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST /api/v1/contacts' do
|
describe 'POST /api/v1/accounts/{account.id}/contacts' do
|
||||||
let(:valid_params) { { contact: { account_id: account.id } } }
|
let(:valid_params) { { contact: { account_id: account.id } } }
|
||||||
|
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'creates the contact' do
|
it 'creates the contact' do
|
||||||
expect { post '/api/v1/contacts', params: valid_params }.to change(Contact, :count).by(1)
|
expect { post "/api/v1/accounts/#{account.id}/contacts", params: valid_params }.to change(Contact, :count).by(1)
|
||||||
|
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
end
|
end
|
||||||
|
@ -67,20 +67,23 @@ RSpec.describe 'Contacts API', type: :request do
|
||||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||||
|
|
||||||
it 'creates the contact' do
|
it 'creates the contact' do
|
||||||
expect { post '/api/v1/contacts', headers: admin.create_new_auth_token, params: valid_params }.to change(Contact, :count).by(1)
|
expect do
|
||||||
|
post "/api/v1/accounts/#{account.id}/contacts", headers: admin.create_new_auth_token,
|
||||||
|
params: valid_params
|
||||||
|
end .to change(Contact, :count).by(1)
|
||||||
|
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'PATCH /api/v1/contacts/:id' do
|
describe 'PATCH /api/v1/accounts/{account.id}/contacts/:id' do
|
||||||
let!(:contact) { create(:contact, account: account) }
|
let!(:contact) { create(:contact, account: account) }
|
||||||
let(:valid_params) { { contact: { name: 'Test Blub' } } }
|
let(:valid_params) { { contact: { name: 'Test Blub' } } }
|
||||||
|
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
put "/api/v1/contacts/#{contact.id}",
|
put "/api/v1/accounts/#{account.id}/contacts/#{contact.id}",
|
||||||
params: valid_params
|
params: valid_params
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
|
@ -91,7 +94,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||||
|
|
||||||
it 'updates the contact' do
|
it 'updates the contact' do
|
||||||
patch "/api/v1/contacts/#{contact.id}",
|
patch "/api/v1/accounts/#{account.id}/contacts/#{contact.id}",
|
||||||
headers: admin.create_new_auth_token,
|
headers: admin.create_new_auth_token,
|
||||||
params: valid_params,
|
params: valid_params,
|
||||||
as: :json
|
as: :json
|
||||||
|
@ -104,7 +107,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||||
other_account = create(:account)
|
other_account = create(:account)
|
||||||
other_contact = create(:contact, account: other_account)
|
other_contact = create(:contact, account: other_account)
|
||||||
|
|
||||||
patch "/api/v1/contacts/#{other_contact.id}",
|
patch "/api/v1/accounts/#{account.id}/contacts/#{other_contact.id}",
|
||||||
headers: admin.create_new_auth_token,
|
headers: admin.create_new_auth_token,
|
||||||
params: valid_params,
|
params: valid_params,
|
||||||
as: :json
|
as: :json
|
|
@ -3,12 +3,12 @@ require 'rails_helper'
|
||||||
RSpec.describe 'Conversation Assignment API', type: :request do
|
RSpec.describe 'Conversation Assignment API', type: :request do
|
||||||
let(:account) { create(:account) }
|
let(:account) { create(:account) }
|
||||||
|
|
||||||
describe 'POST /api/v1/conversations/<id>/assignments' do
|
describe 'POST /api/v1/accounts/{account.id}/conversations/<id>/assignments' do
|
||||||
let(:conversation) { create(:conversation, account: account) }
|
let(:conversation) { create(:conversation, account: account) }
|
||||||
|
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
post api_v1_conversation_assignments_url(conversation.display_id)
|
post api_v1_account_conversation_assignments_url(account_id: account.id, conversation_id: conversation.display_id)
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -20,7 +20,7 @@ RSpec.describe 'Conversation Assignment API', type: :request do
|
||||||
it 'assigns a user to the conversation' do
|
it 'assigns a user to the conversation' do
|
||||||
params = { assignee_id: agent.id }
|
params = { assignee_id: agent.id }
|
||||||
|
|
||||||
post api_v1_conversation_assignments_url(conversation.display_id),
|
post api_v1_account_conversation_assignments_url(account_id: account.id, conversation_id: conversation.display_id),
|
||||||
params: params,
|
params: params,
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
|
@ -3,7 +3,7 @@ require 'rails_helper'
|
||||||
RSpec.describe 'Conversation Label API', type: :request do
|
RSpec.describe 'Conversation Label API', type: :request do
|
||||||
let(:account) { create(:account) }
|
let(:account) { create(:account) }
|
||||||
|
|
||||||
describe 'GET /api/v1/conversations/<id>/labels' do
|
describe 'GET /api/v1/accounts/{account.id}/conversations/<id>/labels' do
|
||||||
let(:conversation) { create(:conversation, account: account) }
|
let(:conversation) { create(:conversation, account: account) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
@ -12,7 +12,7 @@ RSpec.describe 'Conversation Label API', type: :request do
|
||||||
|
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
get api_v1_conversation_labels_url(conversation)
|
get api_v1_account_conversation_labels_url(account_id: account.id, conversation_id: conversation.display_id)
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -21,7 +21,7 @@ RSpec.describe 'Conversation Label API', type: :request do
|
||||||
let(:agent) { create(:user, account: account, role: :agent) }
|
let(:agent) { create(:user, account: account, role: :agent) }
|
||||||
|
|
||||||
it 'returns all the labels for the conversation' do
|
it 'returns all the labels for the conversation' do
|
||||||
get api_v1_conversation_labels_url(conversation.display_id),
|
get api_v1_account_conversation_labels_url(account_id: account.id, conversation_id: conversation.display_id),
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ RSpec.describe 'Conversation Label API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST /api/v1/conversations/<id>/labels' do
|
describe 'POST /api/v1/accounts/{account.id}/conversations/<id>/labels' do
|
||||||
let(:conversation) { create(:conversation, account: account) }
|
let(:conversation) { create(:conversation, account: account) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
@ -41,7 +41,7 @@ RSpec.describe 'Conversation Label API', type: :request do
|
||||||
|
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
post api_v1_conversation_labels_url(conversation.display_id),
|
post api_v1_account_conversation_labels_url(account_id: account.id, conversation_id: conversation.display_id),
|
||||||
params: { labels: 'label3,label4' },
|
params: { labels: 'label3,label4' },
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ RSpec.describe 'Conversation Label API', type: :request do
|
||||||
let(:agent) { create(:user, account: account, role: :agent) }
|
let(:agent) { create(:user, account: account, role: :agent) }
|
||||||
|
|
||||||
it 'creates labels for the conversation' do
|
it 'creates labels for the conversation' do
|
||||||
post api_v1_conversation_labels_url(conversation.display_id),
|
post api_v1_account_conversation_labels_url(account_id: account.id, conversation_id: conversation.display_id),
|
||||||
params: { labels: 'label3,label4' },
|
params: { labels: 'label3,label4' },
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
|
@ -3,12 +3,12 @@ require 'rails_helper'
|
||||||
RSpec.describe 'Conversation Messages API', type: :request do
|
RSpec.describe 'Conversation Messages API', type: :request do
|
||||||
let(:account) { create(:account) }
|
let(:account) { create(:account) }
|
||||||
|
|
||||||
describe 'POST /api/v1/conversations/<id>/messages' do
|
describe 'POST /api/v1/accounts/{account.id}/conversations/<id>/messages' do
|
||||||
let(:conversation) { create(:conversation, account: account) }
|
let(:conversation) { create(:conversation, account: account) }
|
||||||
|
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
post api_v1_conversation_messages_url(conversation.display_id)
|
post api_v1_account_conversation_messages_url(account_id: account.id, conversation_id: conversation.display_id)
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -20,7 +20,7 @@ RSpec.describe 'Conversation Messages API', type: :request do
|
||||||
it 'creates a new outgoing message' do
|
it 'creates a new outgoing message' do
|
||||||
params = { message: 'test-message', private: true }
|
params = { message: 'test-message', private: true }
|
||||||
|
|
||||||
post api_v1_conversation_messages_url(conversation.display_id),
|
post api_v1_account_conversation_messages_url(account_id: account.id, conversation_id: conversation.display_id),
|
||||||
params: params,
|
params: params,
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
@ -32,12 +32,12 @@ RSpec.describe 'Conversation Messages API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET /api/v1/conversations/:id/messages' do
|
describe 'GET /api/v1/accounts/{account.id}/conversations/:id/messages' do
|
||||||
let(:conversation) { create(:conversation, account: account) }
|
let(:conversation) { create(:conversation, account: account) }
|
||||||
|
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
get "/api/v1/conversations/#{conversation.display_id}/messages"
|
get "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}/messages"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -47,7 +47,7 @@ RSpec.describe 'Conversation Messages API', type: :request do
|
||||||
let(:agent) { create(:user, account: account, role: :agent) }
|
let(:agent) { create(:user, account: account, role: :agent) }
|
||||||
|
|
||||||
it 'shows the conversation' do
|
it 'shows the conversation' do
|
||||||
get "/api/v1/conversations/#{conversation.display_id}/messages",
|
get "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}/messages",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
|
@ -3,10 +3,10 @@ require 'rails_helper'
|
||||||
RSpec.describe 'Conversations API', type: :request do
|
RSpec.describe 'Conversations API', type: :request do
|
||||||
let(:account) { create(:account) }
|
let(:account) { create(:account) }
|
||||||
|
|
||||||
describe 'GET /api/v1/conversations' do
|
describe 'GET /api/v1/accounts/{account.id}/conversations' do
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
get '/api/v1/conversations'
|
get "/api/v1/accounts/#{account.id}/conversations"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -21,7 +21,7 @@ RSpec.describe 'Conversations API', type: :request do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns all conversations' do
|
it 'returns all conversations' do
|
||||||
get '/api/v1/conversations',
|
get "/api/v1/accounts/#{account.id}/conversations",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
|
@ -31,12 +31,12 @@ RSpec.describe 'Conversations API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET /api/v1/conversations/:id' do
|
describe 'GET /api/v1/accounts/{account.id}/conversations/:id' do
|
||||||
let(:conversation) { create(:conversation, account: account) }
|
let(:conversation) { create(:conversation, account: account) }
|
||||||
|
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
get "/api/v1/conversations/#{conversation.display_id}"
|
get "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -46,7 +46,7 @@ RSpec.describe 'Conversations API', type: :request do
|
||||||
let(:agent) { create(:user, account: account, role: :agent) }
|
let(:agent) { create(:user, account: account, role: :agent) }
|
||||||
|
|
||||||
it 'shows the conversation' do
|
it 'shows the conversation' do
|
||||||
get "/api/v1/conversations/#{conversation.display_id}",
|
get "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
|
@ -56,12 +56,12 @@ RSpec.describe 'Conversations API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST /api/v1/conversations/:id/toggle_status' do
|
describe 'POST /api/v1/accounts/{account.id}/conversations/:id/toggle_status' do
|
||||||
let(:conversation) { create(:conversation, account: account) }
|
let(:conversation) { create(:conversation, account: account) }
|
||||||
|
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
post "/api/v1/conversations/#{conversation.display_id}/toggle_status"
|
post "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}/toggle_status"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -73,7 +73,7 @@ RSpec.describe 'Conversations API', type: :request do
|
||||||
it 'toggles the conversation status' do
|
it 'toggles the conversation status' do
|
||||||
expect(conversation.status).to eq('open')
|
expect(conversation.status).to eq('open')
|
||||||
|
|
||||||
post "/api/v1/conversations/#{conversation.display_id}/toggle_status",
|
post "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}/toggle_status",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
|
@ -83,12 +83,12 @@ RSpec.describe 'Conversations API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST /api/v1/conversations/:id/update_last_seen' do
|
describe 'POST /api/v1/accounts/{account.id}/conversations/:id/update_last_seen' do
|
||||||
let(:conversation) { create(:conversation, account: account) }
|
let(:conversation) { create(:conversation, account: account) }
|
||||||
|
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
post "/api/v1/conversations/#{conversation.display_id}/update_last_seen"
|
post "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}/update_last_seen"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -100,7 +100,7 @@ RSpec.describe 'Conversations API', type: :request do
|
||||||
it 'updates last seen' do
|
it 'updates last seen' do
|
||||||
params = { agent_last_seen_at: '-1' }
|
params = { agent_last_seen_at: '-1' }
|
||||||
|
|
||||||
post "/api/v1/conversations/#{conversation.display_id}/update_last_seen",
|
post "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}/update_last_seen",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
params: params,
|
params: params,
|
||||||
as: :json
|
as: :json
|
|
@ -12,10 +12,10 @@ RSpec.describe 'Facebook Indicators API', type: :request do
|
||||||
allow(Facebook::Messenger::Subscriptions).to receive(:subscribe).and_return(true)
|
allow(Facebook::Messenger::Subscriptions).to receive(:subscribe).and_return(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST /api/v1/facebook_indicators/mark_seen' do
|
describe 'POST /api/v1/accounts/{account.id}/facebook_indicators/mark_seen' do
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
post '/api/v1/facebook_indicators/mark_seen'
|
post "/api/v1/accounts/#{account.id}/facebook_indicators/mark_seen"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -32,7 +32,7 @@ RSpec.describe 'Facebook Indicators API', type: :request do
|
||||||
access_token: inbox.channel.page_access_token
|
access_token: inbox.channel.page_access_token
|
||||||
)
|
)
|
||||||
|
|
||||||
post '/api/v1/facebook_indicators/mark_seen',
|
post "/api/v1/accounts/#{account.id}/facebook_indicators/mark_seen",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
params: valid_params,
|
params: valid_params,
|
||||||
as: :json
|
as: :json
|
||||||
|
@ -45,7 +45,7 @@ RSpec.describe 'Facebook Indicators API', type: :request do
|
||||||
|
|
||||||
allow(Facebook::Messenger::Bot).to receive(:deliver).and_raise(Facebook::Messenger::Error)
|
allow(Facebook::Messenger::Bot).to receive(:deliver).and_raise(Facebook::Messenger::Error)
|
||||||
|
|
||||||
post '/api/v1/facebook_indicators/mark_seen',
|
post "/api/v1/accounts/#{account.id}/facebook_indicators/mark_seen",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
params: valid_params,
|
params: valid_params,
|
||||||
as: :json
|
as: :json
|
||||||
|
@ -55,10 +55,10 @@ RSpec.describe 'Facebook Indicators API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST /api/v1/facebook_indicators/typing_on' do
|
describe 'POST /api/v1/accounts/{account.id}/facebook_indicators/typing_on' do
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
post '/api/v1/facebook_indicators/typing_on'
|
post "/api/v1/accounts/#{account.id}/facebook_indicators/typing_on"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -75,7 +75,7 @@ RSpec.describe 'Facebook Indicators API', type: :request do
|
||||||
access_token: inbox.channel.page_access_token
|
access_token: inbox.channel.page_access_token
|
||||||
)
|
)
|
||||||
|
|
||||||
post '/api/v1/facebook_indicators/typing_on',
|
post "/api/v1/accounts/#{account.id}/facebook_indicators/typing_on",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
params: valid_params,
|
params: valid_params,
|
||||||
as: :json
|
as: :json
|
||||||
|
@ -88,7 +88,7 @@ RSpec.describe 'Facebook Indicators API', type: :request do
|
||||||
|
|
||||||
allow(Facebook::Messenger::Bot).to receive(:deliver).and_raise(Facebook::Messenger::Error)
|
allow(Facebook::Messenger::Bot).to receive(:deliver).and_raise(Facebook::Messenger::Error)
|
||||||
|
|
||||||
post '/api/v1/facebook_indicators/typing_on',
|
post "/api/v1/accounts/#{account.id}/facebook_indicators/typing_on",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
params: valid_params,
|
params: valid_params,
|
||||||
as: :json
|
as: :json
|
||||||
|
@ -98,10 +98,10 @@ RSpec.describe 'Facebook Indicators API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST /api/v1/facebook_indicators/typing_off' do
|
describe 'POST /api/v1/accounts/{account.id}/facebook_indicators/typing_off' do
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
post '/api/v1/facebook_indicators/typing_off'
|
post "/api/v1/accounts/#{account.id}/facebook_indicators/typing_off"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -118,7 +118,7 @@ RSpec.describe 'Facebook Indicators API', type: :request do
|
||||||
access_token: inbox.channel.page_access_token
|
access_token: inbox.channel.page_access_token
|
||||||
)
|
)
|
||||||
|
|
||||||
post '/api/v1/facebook_indicators/typing_off',
|
post "/api/v1/accounts/#{account.id}/facebook_indicators/typing_off",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
params: valid_params,
|
params: valid_params,
|
||||||
as: :json
|
as: :json
|
||||||
|
@ -131,7 +131,7 @@ RSpec.describe 'Facebook Indicators API', type: :request do
|
||||||
|
|
||||||
allow(Facebook::Messenger::Bot).to receive(:deliver).and_raise(Facebook::Messenger::Error)
|
allow(Facebook::Messenger::Bot).to receive(:deliver).and_raise(Facebook::Messenger::Error)
|
||||||
|
|
||||||
post '/api/v1/facebook_indicators/typing_off',
|
post "/api/v1/accounts/#{account.id}/facebook_indicators/typing_off",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
params: valid_params,
|
params: valid_params,
|
||||||
as: :json
|
as: :json
|
|
@ -4,10 +4,10 @@ RSpec.describe 'Inbox Member API', type: :request do
|
||||||
let(:account) { create(:account) }
|
let(:account) { create(:account) }
|
||||||
let(:inbox) { create(:inbox, account: account) }
|
let(:inbox) { create(:inbox, account: account) }
|
||||||
|
|
||||||
describe 'POST /api/v1/inbox_members' do
|
describe 'POST /api/v1/accounts/{account.id}/inbox_members' do
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
post '/api/v1/inbox_members'
|
post "/api/v1/accounts/#{account.id}/inbox_members"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -19,7 +19,7 @@ RSpec.describe 'Inbox Member API', type: :request do
|
||||||
it 'modifies inbox members' do
|
it 'modifies inbox members' do
|
||||||
params = { inbox_id: inbox.id, user_ids: [agent.id] }
|
params = { inbox_id: inbox.id, user_ids: [agent.id] }
|
||||||
|
|
||||||
post '/api/v1/inbox_members',
|
post "/api/v1/accounts/#{account.id}/inbox_members",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
params: params,
|
params: params,
|
||||||
as: :json
|
as: :json
|
||||||
|
@ -32,7 +32,7 @@ RSpec.describe 'Inbox Member API', type: :request do
|
||||||
it 'renders not found when inbox not found' do
|
it 'renders not found when inbox not found' do
|
||||||
params = { inbox_id: nil, user_ids: [agent.id] }
|
params = { inbox_id: nil, user_ids: [agent.id] }
|
||||||
|
|
||||||
post '/api/v1/inbox_members',
|
post "/api/v1/accounts/#{account.id}/inbox_members",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
params: params,
|
params: params,
|
||||||
as: :json
|
as: :json
|
||||||
|
@ -43,7 +43,7 @@ RSpec.describe 'Inbox Member API', type: :request do
|
||||||
it 'renders error on invalid params' do
|
it 'renders error on invalid params' do
|
||||||
params = { inbox_id: inbox.id, user_ids: ['invalid'] }
|
params = { inbox_id: inbox.id, user_ids: ['invalid'] }
|
||||||
|
|
||||||
post '/api/v1/inbox_members',
|
post "/api/v1/accounts/#{account.id}/inbox_members",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
params: params,
|
params: params,
|
||||||
as: :json
|
as: :json
|
||||||
|
@ -54,12 +54,12 @@ RSpec.describe 'Inbox Member API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET /api/v1/inbox_members/:id' do
|
describe 'GET /api/v1/accounts/{account.id}/inbox_members/:id' do
|
||||||
let(:inbox_member) { create(:inbox_member, inbox: inbox) }
|
let(:inbox_member) { create(:inbox_member, inbox: inbox) }
|
||||||
|
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
get "/api/v1/inbox_members/#{inbox_member.id}"
|
get "/api/v1/accounts/#{account.id}/inbox_members/#{inbox_member.id}"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -69,7 +69,7 @@ RSpec.describe 'Inbox Member API', type: :request do
|
||||||
let(:agent) { create(:user, account: account, role: :agent) }
|
let(:agent) { create(:user, account: account, role: :agent) }
|
||||||
|
|
||||||
it 'returns inbox member' do
|
it 'returns inbox member' do
|
||||||
get "/api/v1/inbox_members/#{inbox.id}",
|
get "/api/v1/accounts/#{account.id}/inbox_members/#{inbox.id}",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
|
@ -3,10 +3,10 @@ require 'rails_helper'
|
||||||
RSpec.describe 'Inboxes API', type: :request do
|
RSpec.describe 'Inboxes API', type: :request do
|
||||||
let(:account) { create(:account) }
|
let(:account) { create(:account) }
|
||||||
|
|
||||||
describe 'GET /api/v1/inboxes' do
|
describe 'GET /api/v1/accounts/{account.id}/inboxes' do
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
get '/api/v1/inboxes'
|
get "/api/v1/accounts/#{account.id}/inboxes"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -23,7 +23,7 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns all inboxes of current_account as administrator' do
|
it 'returns all inboxes of current_account as administrator' do
|
||||||
get '/api/v1/inboxes',
|
get "/api/v1/accounts/#{account.id}/inboxes",
|
||||||
headers: admin.create_new_auth_token,
|
headers: admin.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns only assigned inboxes of current_account as agent' do
|
it 'returns only assigned inboxes of current_account as agent' do
|
||||||
get '/api/v1/inboxes',
|
get "/api/v1/accounts/#{account.id}/inboxes",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
|
@ -42,12 +42,12 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'DELETE /api/v1/inboxes/:id' do
|
describe 'DELETE /api/v1/accounts/{account.id}/inboxes/:id' do
|
||||||
let(:inbox) { create(:inbox, account: account) }
|
let(:inbox) { create(:inbox, account: account) }
|
||||||
|
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
delete "/api/v1/inboxes/#{inbox.id}"
|
delete "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -57,7 +57,7 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||||
|
|
||||||
it 'deletes inbox' do
|
it 'deletes inbox' do
|
||||||
delete "/api/v1/inboxes/#{inbox.id}",
|
delete "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}",
|
||||||
headers: admin.create_new_auth_token,
|
headers: admin.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||||
other_account = create(:account)
|
other_account = create(:account)
|
||||||
other_inbox = create(:inbox, account: other_account)
|
other_inbox = create(:inbox, account: other_account)
|
||||||
|
|
||||||
delete "/api/v1/inboxes/#{other_inbox.id}",
|
delete "/api/v1/accounts/#{account.id}/inboxes/#{other_inbox.id}",
|
||||||
headers: admin.create_new_auth_token,
|
headers: admin.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||||
it 'is unable to delete inbox as agent' do
|
it 'is unable to delete inbox as agent' do
|
||||||
agent = create(:user, account: account, role: :agent)
|
agent = create(:user, account: account, role: :agent)
|
||||||
|
|
||||||
delete "/api/v1/inboxes/#{inbox.id}",
|
delete "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
|
@ -88,12 +88,12 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'PATCH /api/v1/inboxes/:id' do
|
describe 'PATCH /api/v1/accounts/{account.id}/inboxes/:id' do
|
||||||
let(:inbox) { create(:inbox, account: account) }
|
let(:inbox) { create(:inbox, account: account) }
|
||||||
|
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
patch "/api/v1/inboxes/#{inbox.id}"
|
patch "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -104,7 +104,7 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||||
let(:valid_params) { { inbox: { enable_auto_assignment: false } } }
|
let(:valid_params) { { inbox: { enable_auto_assignment: false } } }
|
||||||
|
|
||||||
it 'updates inbox' do
|
it 'updates inbox' do
|
||||||
patch "/api/v1/inboxes/#{inbox.id}",
|
patch "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}",
|
||||||
headers: admin.create_new_auth_token,
|
headers: admin.create_new_auth_token,
|
||||||
params: valid_params,
|
params: valid_params,
|
||||||
as: :json
|
as: :json
|
||||||
|
@ -116,7 +116,7 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||||
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)
|
||||||
|
|
||||||
patch "/api/v1/inboxes/#{inbox.id}",
|
patch "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
params: valid_params,
|
params: valid_params,
|
||||||
as: :json
|
as: :json
|
|
@ -8,10 +8,10 @@ RSpec.describe 'Label API', type: :request do
|
||||||
conversation.update_labels('label1, label2')
|
conversation.update_labels('label1, label2')
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET /api/v1/labels' do
|
describe 'GET /api/v1/accounts/{account.id}/labels' do
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
get '/api/v1/labels'
|
get "/api/v1/accounts/#{account.id}/labels"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -21,7 +21,7 @@ RSpec.describe 'Label API', type: :request do
|
||||||
let(:agent) { create(:user, account: account, role: :agent) }
|
let(:agent) { create(:user, account: account, role: :agent) }
|
||||||
|
|
||||||
it 'returns all the labels in account' do
|
it 'returns all the labels in account' do
|
||||||
get '/api/v1/labels',
|
get "/api/v1/accounts/#{account.id}/labels",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
|
@ -32,10 +32,10 @@ RSpec.describe 'Label API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET /api/v1/labels/most_used' do
|
describe 'GET /api/v1/accounts/{account.id}/labels/most_used' do
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
get '/api/v1/labels'
|
get "/api/v1/accounts/#{account.id}/labels"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -45,7 +45,7 @@ RSpec.describe 'Label API', type: :request do
|
||||||
let(:agent) { create(:user, account: account, role: :agent) }
|
let(:agent) { create(:user, account: account, role: :agent) }
|
||||||
|
|
||||||
it 'returns most used labels' do
|
it 'returns most used labels' do
|
||||||
get '/api/v1/labels/most_used',
|
get "/api/v1/accounts/#{account.id}/labels/most_used",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
params: { count: 1 },
|
params: { count: 1 },
|
||||||
as: :json
|
as: :json
|
|
@ -3,10 +3,10 @@ require 'rails_helper'
|
||||||
RSpec.describe 'Notification Settings API', type: :request do
|
RSpec.describe 'Notification Settings API', type: :request do
|
||||||
let(:account) { create(:account) }
|
let(:account) { create(:account) }
|
||||||
|
|
||||||
describe 'GET /api/v1/user/notification_settings' do
|
describe 'GET /api/v1/accounts/{account.id}/notification_settings' do
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
get '/api/v1/user/notification_settings'
|
get "/api/v1/accounts/#{account.id}/notification_settings"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -16,7 +16,7 @@ RSpec.describe 'Notification Settings API', type: :request do
|
||||||
let(:agent) { create(:user, account: account, role: :agent) }
|
let(:agent) { create(:user, account: account, role: :agent) }
|
||||||
|
|
||||||
it 'returns current user notification settings' do
|
it 'returns current user notification settings' do
|
||||||
get '/api/v1/user/notification_settings',
|
get "/api/v1/accounts/#{account.id}/notification_settings",
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
|
@ -28,10 +28,10 @@ RSpec.describe 'Notification Settings API', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'PUT /api/v1/user/notification_settings' do
|
describe 'PUT /api/v1/accounts/{account.id}/notification_settings' do
|
||||||
context 'when it is an unauthenticated user' do
|
context 'when it is an unauthenticated user' do
|
||||||
it 'returns unauthorized' do
|
it 'returns unauthorized' do
|
||||||
put '/api/v1/user/notification_settings'
|
put "/api/v1/accounts/#{account.id}/notification_settings"
|
||||||
|
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
@ -41,7 +41,7 @@ RSpec.describe 'Notification Settings API', type: :request do
|
||||||
let(:agent) { create(:user, account: account, role: :agent) }
|
let(:agent) { create(:user, account: account, role: :agent) }
|
||||||
|
|
||||||
it 'updates the email related notification flags' do
|
it 'updates the email related notification flags' do
|
||||||
put '/api/v1/user/notification_settings',
|
put "/api/v1/accounts/#{account.id}/notification_settings",
|
||||||
params: { notification_settings: { selected_email_flags: ['conversation_assignment'] } },
|
params: { notification_settings: { selected_email_flags: ['conversation_assignment'] } },
|
||||||
headers: agent.create_new_auth_token,
|
headers: agent.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue