chore: allow non-admin to call setup_channel_provider and add localization (#90)
* chore: allow non-admin to call `setup_channel_provider` and add localization * feat: allow agents to setup channel provider for assigned inboxes and handle unauthorized access
This commit is contained in:
parent
11f8aac294
commit
188119317e
@ -4,7 +4,7 @@ class Api::V1::Accounts::InboxesController < Api::V1::Accounts::BaseController
|
|||||||
before_action :fetch_agent_bot, only: [:set_agent_bot]
|
before_action :fetch_agent_bot, only: [:set_agent_bot]
|
||||||
before_action :validate_limit, only: [:create]
|
before_action :validate_limit, only: [:create]
|
||||||
# we are already handling the authorization in fetch inbox
|
# we are already handling the authorization in fetch inbox
|
||||||
before_action :check_authorization, except: [:show]
|
before_action :check_authorization, except: [:show, :setup_channel_provider]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@inboxes = policy_scope(Current.account.inboxes.order_by_name.includes(:channel, { avatar_attachment: [:blob] }))
|
@inboxes = policy_scope(Current.account.inboxes.order_by_name.includes(:channel, { avatar_attachment: [:blob] }))
|
||||||
|
|||||||
@ -477,7 +477,11 @@ export default {
|
|||||||
.catch(e => {
|
.catch(e => {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.error('Error setting up provider connection:', e);
|
console.error('Error setting up provider connection:', e);
|
||||||
useAlert('Failed to reconnect. Please try again or contact support.');
|
useAlert(
|
||||||
|
this.$t(
|
||||||
|
'CONVERSATION.INBOX.WHATSAPP_BAILEYS_PROVIDER_CONNECTION.RECONNECT_FAILED'
|
||||||
|
)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -255,7 +255,8 @@
|
|||||||
"WHATSAPP_BAILEYS_PROVIDER_CONNECTION": {
|
"WHATSAPP_BAILEYS_PROVIDER_CONNECTION": {
|
||||||
"NOT_CONNECTED": "WhatsApp is not connected. Please link your device again.",
|
"NOT_CONNECTED": "WhatsApp is not connected. Please link your device again.",
|
||||||
"NOT_CONNECTED_CONTACT_ADMIN": "WhatsApp is not connected. Click this button to try to reconnect, or please contact your administrator to link your device again.",
|
"NOT_CONNECTED_CONTACT_ADMIN": "WhatsApp is not connected. Click this button to try to reconnect, or please contact your administrator to link your device again.",
|
||||||
"LINK_DEVICE": "Link device"
|
"LINK_DEVICE": "Link device",
|
||||||
|
"RECONNECT_FAILED": "Failed to reconnect. Please contact your administrator to link your device again."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -255,7 +255,8 @@
|
|||||||
"WHATSAPP_BAILEYS_PROVIDER_CONNECTION": {
|
"WHATSAPP_BAILEYS_PROVIDER_CONNECTION": {
|
||||||
"NOT_CONNECTED": "O WhatsApp não está conectado. Por favor conecte o seu dispositivo novamente.",
|
"NOT_CONNECTED": "O WhatsApp não está conectado. Por favor conecte o seu dispositivo novamente.",
|
||||||
"NOT_CONNECTED_CONTACT_ADMIN": "O WhatsApp não está conectado. Clique no botão ao lado para tentar reconectar, ou contate o seu administrador para conectar o dispositivo novamente.",
|
"NOT_CONNECTED_CONTACT_ADMIN": "O WhatsApp não está conectado. Clique no botão ao lado para tentar reconectar, ou contate o seu administrador para conectar o dispositivo novamente.",
|
||||||
"LINK_DEVICE": "Conectar dispositivo"
|
"LINK_DEVICE": "Conectar dispositivo",
|
||||||
|
"RECONNECT_FAILED": "Falha ao reconectar. Por favor, contate o seu administrador para conectar o dispositivo novamente."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -58,10 +58,6 @@ class InboxPolicy < ApplicationPolicy
|
|||||||
@account_user.administrator?
|
@account_user.administrator?
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_channel_provider?
|
|
||||||
@account_user.administrator?
|
|
||||||
end
|
|
||||||
|
|
||||||
def disconnect_channel_provider?
|
def disconnect_channel_provider?
|
||||||
@account_user.administrator?
|
@account_user.administrator?
|
||||||
end
|
end
|
||||||
|
|||||||
@ -941,6 +941,28 @@ RSpec.describe 'Inboxes API', type: :request do
|
|||||||
|
|
||||||
expect(response).to have_http_status(:ok)
|
expect(response).to have_http_status(:ok)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'allows agents to setup channel provider for assigned inboxes' do
|
||||||
|
create(:inbox_member, user: agent, inbox: inbox)
|
||||||
|
service_double = instance_double(Whatsapp::Providers::WhatsappBaileysService, setup_channel_provider: true)
|
||||||
|
allow(Whatsapp::Providers::WhatsappBaileysService).to receive(:new)
|
||||||
|
.with(whatsapp_channel: channel)
|
||||||
|
.and_return(service_double)
|
||||||
|
|
||||||
|
post "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}/setup_channel_provider",
|
||||||
|
headers: agent.create_new_auth_token,
|
||||||
|
as: :json
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:ok)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns unauthorized for agents not assigned to the inbox' do
|
||||||
|
post "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}/setup_channel_provider",
|
||||||
|
headers: agent.create_new_auth_token,
|
||||||
|
as: :json
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:unauthorized)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -994,7 +1016,7 @@ RSpec.describe 'Inboxes API', type: :request do
|
|||||||
headers: admin.create_new_auth_token,
|
headers: admin.create_new_auth_token,
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
expect(response).to have_http_status(:internal_server_error)
|
expect(response).to have_http_status(:ok)
|
||||||
expect(channel.reload.provider_connection).to eq('connection' => 'close')
|
expect(channel.reload.provider_connection).to eq('connection' => 'close')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user