Check if account or app is in use by a Microsoft Teams tenant before deleting

This commit is contained in:
user
2020-05-29 18:48:32 -07:00
parent e4124b7fe2
commit 4fc3add328
2 changed files with 54 additions and 13 deletions
+19 -3
View File
@@ -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,