mirror of
https://github.com/jambonz/jambonz-webapp.git
synced 2026-07-24 13:02:21 +00:00
Check if account or app is in use by a Microsoft Teams tenant before deleting
This commit is contained in:
@@ -88,7 +88,7 @@ const AccountsList = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if any application or phone number uses this account
|
||||
// Check if any application, phone number, or MS Teams tenant uses this account
|
||||
const applicationsPromise = axios({
|
||||
method: 'get',
|
||||
baseURL: process.env.REACT_APP_API_BASE_URL,
|
||||
@@ -105,12 +105,22 @@ const AccountsList = () => {
|
||||
Authorization: `Bearer ${localStorage.getItem('token')}`,
|
||||
},
|
||||
});
|
||||
const msTeamsTenantsPromise = axios({
|
||||
method: 'get',
|
||||
baseURL: process.env.REACT_APP_API_BASE_URL,
|
||||
url: '/MicrosoftTeamsTenants',
|
||||
headers: {
|
||||
Authorization: `Bearer ${localStorage.getItem('token')}`,
|
||||
},
|
||||
});
|
||||
const promiseAllValues = await Promise.all([
|
||||
applicationsPromise,
|
||||
phoneNumbersPromise,
|
||||
msTeamsTenantsPromise,
|
||||
]);
|
||||
const applications = promiseAllValues[0].data;
|
||||
const phoneNumbers = promiseAllValues[1].data;
|
||||
const applications = promiseAllValues[0].data;
|
||||
const phoneNumbers = promiseAllValues[1].data;
|
||||
const msTeamsTenants = promiseAllValues[2].data;
|
||||
|
||||
const accountApps = applications.filter(app => (
|
||||
app.account_sid === accountToDelete.sid
|
||||
@@ -118,6 +128,9 @@ const AccountsList = () => {
|
||||
const accountPhoneNumbers = phoneNumbers.filter(p => (
|
||||
p.account_sid === accountToDelete.sid
|
||||
));
|
||||
const accountMsTeamsTenants = msTeamsTenants.filter(tenant => (
|
||||
tenant.account_sid === accountToDelete.sid
|
||||
));
|
||||
let errorMessages = [];
|
||||
for (const app of accountApps) {
|
||||
errorMessages.push(`Application: ${app.name}`);
|
||||
@@ -125,6 +138,9 @@ const AccountsList = () => {
|
||||
for (const num of accountPhoneNumbers) {
|
||||
errorMessages.push(`Phone Number: ${num.number}`);
|
||||
}
|
||||
for (const tenant of accountMsTeamsTenants) {
|
||||
errorMessages.push(`Microsoft Teams Tenant: ${tenant.tenant_fqdn}`);
|
||||
}
|
||||
if (errorMessages.length) {
|
||||
return (
|
||||
<React.Fragment>
|
||||
|
||||
@@ -107,8 +107,8 @@ const ApplicationsList = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// check if any account requires this application for SIP device calls
|
||||
const accounts = await axios({
|
||||
// check if any account or Microsoft Teams Tenant uses this application
|
||||
const accountsPromise = axios({
|
||||
method: 'get',
|
||||
baseURL: process.env.REACT_APP_API_BASE_URL,
|
||||
url: '/Accounts',
|
||||
@@ -116,26 +116,51 @@ const ApplicationsList = () => {
|
||||
Authorization: `Bearer ${localStorage.getItem('token')}`,
|
||||
},
|
||||
});
|
||||
|
||||
const accountsRequiringThisApp = accounts.data.filter(acc => {
|
||||
return acc.device_calling_application_sid === applicationToDelete.sid;
|
||||
const msTeamsTenantsPromise = axios({
|
||||
method: 'get',
|
||||
baseURL: process.env.REACT_APP_API_BASE_URL,
|
||||
url: '/MicrosoftTeamsTenants',
|
||||
headers: {
|
||||
Authorization: `Bearer ${localStorage.getItem('token')}`,
|
||||
},
|
||||
});
|
||||
const promiseAllValues = await Promise.all([
|
||||
accountsPromise,
|
||||
msTeamsTenantsPromise,
|
||||
]);
|
||||
|
||||
if (accountsRequiringThisApp.length) {
|
||||
const accountName = accountsRequiringThisApp[0].name;
|
||||
const accounts = promiseAllValues[0].data;
|
||||
const msTeamsTenants = promiseAllValues[1].data;
|
||||
|
||||
const appAccounts = accounts.filter(acc => (
|
||||
acc.device_calling_application_sid === applicationToDelete.sid
|
||||
));
|
||||
const appMsTeamsTenants = msTeamsTenants.filter(tenant => (
|
||||
tenant.application_sid === applicationToDelete.sid
|
||||
));
|
||||
let errorMessages = [];
|
||||
for (const account of appAccounts) {
|
||||
errorMessages.push(`Account: ${account.name}`);
|
||||
}
|
||||
for (const tenant of appMsTeamsTenants) {
|
||||
errorMessages.push(`Microsoft Teams Tenant: ${tenant.tenant_fqdn}`);
|
||||
}
|
||||
if (errorMessages.length) {
|
||||
return (
|
||||
<React.Fragment>
|
||||
<p style={{ margin: '0.5rem 0' }}>
|
||||
This application cannot be deleted because the following
|
||||
account uses it to receive SIP Device Calls:
|
||||
This application cannot be deleted because it is in use by:
|
||||
</p>
|
||||
<ul style={{ margin: '0.5rem 0' }}>
|
||||
<li>{accountName}</li>
|
||||
{errorMessages.map((err, i) => (
|
||||
<li key={i}>{err}</li>
|
||||
))}
|
||||
</ul>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
// Delete application
|
||||
await axios({
|
||||
method: 'delete',
|
||||
baseURL: process.env.REACT_APP_API_BASE_URL,
|
||||
|
||||
Reference in New Issue
Block a user