From 732e15428182cfd77133e8962e7e0049b9301954 Mon Sep 17 00:00:00 2001 From: Debora Crescenzo <dcrescenzo@sipwise.com> Date: Mon, 29 Jul 2024 11:11:24 +0100 Subject: [PATCH] MT#60583 Amend Login API calls and 403 Invalid Licence err We have introduced the concept of licenses which can be active or inactive (all active licenses are stored in the array "licenses" -GET 'api/platforminfo'). This means that a service (e.g. fax) can be activated, but the license to use it could be active or inactive. If the latter is true, the user is not allowed to use the service in fact the backend returns a 403 - Invalid license when the relevant endpoints are called. * Before this commit we were retrieving the fax services as part of the login phase, but with the new licenses logic the existing flow was broken by a 403 for those users with inactive fax license and it was impossible to login into the platform. With this commit we amend getUserData() to wrap the call to retrieve the fax settings in a statement that checks if the fax licence is active. * We edit the "Invalid license" message returned by the backend with a more user-friendly text. The text is showed in a small banner on top of the page every time the user opens a page that is not supposed to access because the relevant license is inactive. * We remove some unused code in CscLayoutMain.vue * v-if moved before class to silence warning in AuiMobileAppBadges Change-Id: Ie7831e0024475c3a5aa8acf3874e6eda442fc9a2 (cherry picked from commit 98eee9c1ff2579d16709384bd56da73f86726ece) --- src/api/common.js | 11 ++++--- src/api/user.js | 42 +++++++++++++++------------ src/components/AuiMobileAppBadges.vue | 2 +- src/layouts/CscLayoutMain.vue | 24 --------------- 4 files changed, 31 insertions(+), 48 deletions(-) diff --git a/src/api/common.js b/src/api/common.js index 473c1f32..e8e99c6e 100644 --- a/src/api/common.js +++ b/src/api/common.js @@ -168,12 +168,15 @@ export async function getList (options) { function handleResponseError (err) { const code = _.get(err, 'response.data.code', null) - const message = _.get(err, 'response.data.message', null) + let message = _.get(err, 'response.data.message', null) + if (code === 403 && message === 'Invalid license') { + message = 'Invalid or expired license. Contact your administrator to activate this functionality' + } if (code !== null && message !== null) { - throw new ApiResponseError(err.response.data.code, err.response.data.message) - } else { - throw err + throw new ApiResponseError(code, message) } + + throw err } export async function get (options) { diff --git a/src/api/user.js b/src/api/user.js index e26ad8ae..e32484e5 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -51,26 +51,30 @@ export async function loginByExchangeToken (token) { } } -export function getUserData (id) { - return new Promise((resolve, reject) => { - return Promise.all([ - getSubscriberById(id), - getCapabilities(id), - getFaxServerSettings(id), - getResellerBranding(), - getPlatformInfo() - ]).then(([subscriber, capabilities, faxServerSettings, resellerBranding, platformInfo]) => { +export async function getUserData (id) { + const allPromise = Promise.all([ + getSubscriberById(id), + getCapabilities(id), + getResellerBranding(), + getPlatformInfo() + ]) + + try { + const [subscriber, capabilities, resellerBranding, platformInfo] = await allPromise + if (capabilities.faxserver && platformInfo.licenses.find((license) => license === 'fax')) { + const faxServerSettings = await getFaxServerSettings(id) capabilities.faxactive = faxServerSettings.active - resolve({ - subscriber, - capabilities, - resellerBranding: resellerBranding?.items[0] || null, - platformInfo - }) - }).catch((err) => { - reject(err) - }) - }) + } + + return { + subscriber, + capabilities, + resellerBranding: resellerBranding?.items[0] || null, + platformInfo + } + } catch (error) { + throw new Error(error.response.data.message) + } } export function getSubscriberById (id) { diff --git a/src/components/AuiMobileAppBadges.vue b/src/components/AuiMobileAppBadges.vue index 7fed6213..929f34b2 100644 --- a/src/components/AuiMobileAppBadges.vue +++ b/src/components/AuiMobileAppBadges.vue @@ -1,7 +1,7 @@ <template> <q-list - class="absolute-bottom" v-if="appUrlAndroid || appUrlApple" + class="absolute-bottom" dense > <q-item-label diff --git a/src/layouts/CscLayoutMain.vue b/src/layouts/CscLayoutMain.vue index b16458f3..d394ed6c 100644 --- a/src/layouts/CscLayoutMain.vue +++ b/src/layouts/CscLayoutMain.vue @@ -352,36 +352,12 @@ export default { showQrBtn () { return this.platformInfo?.app?.show_qr }, - hasCommunicationCapabilities () { - return (this.hasSmsCapability && this.hasSendSmsFeature) || - (this.hasFaxCapabilityAndFaxActive && this.hasSendFaxFeature) - }, isMenuClosed () { return !this.sideStates.left }, isFullView () { return this.isMenuClosed || this.isMobile || this.mobileMenu }, - layoutClasses () { - const classes = [] - if (this.isCalling) { - classes.push('csc-layout-call-active') - } - if (this.menuMinimized) { - classes.push('csc-menu-minimized') - } - return classes - }, - headerClasses () { - const classes = ['transition-generic'] - if (this.isMobile) { - classes.push('csc-header-mobile') - } - if (this.isMobile || this.isMenuClosed) { - classes.push('csc-header-full') - } - return classes - }, pinMenuButtonIcon () { if (!this.menuPinned) { return 'push_pin'