Skip to content

Commit

Permalink
fix(meetings): handle getMe error due to insufficient privileges
Browse files Browse the repository at this point in the history
  • Loading branch information
sreenara committed Nov 27, 2024
1 parent c4ba3e5 commit 109a25a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 40 deletions.
83 changes: 44 additions & 39 deletions packages/@webex/plugin-meetings/src/meetings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1044,48 +1044,53 @@ export default class Meetings extends WebexPlugin {
*/
fetchUserPreferredWebexSite() {
// @ts-ignore
return this.webex.people._getMe().then((me) => {
const isGuestUser = me.type === 'appuser';
if (!isGuestUser) {
return this.request.getMeetingPreferences().then((res) => {
if (res) {
const preferredWebexSite = MeetingsUtil.parseDefaultSiteFromMeetingPreferences(res);
this.preferredWebexSite = preferredWebexSite;
// @ts-ignore
this.webex.internal.services._getCatalog().addAllowedDomains([preferredWebexSite]);
}
return this.webex.people
._getMe()
.then((me) => {
const isGuestUser = me.type === 'appuser';
if (!isGuestUser) {
return this.request.getMeetingPreferences().then((res) => {
if (res) {
const preferredWebexSite = MeetingsUtil.parseDefaultSiteFromMeetingPreferences(res);
this.preferredWebexSite = preferredWebexSite;
// @ts-ignore
this.webex.internal.services._getCatalog().addAllowedDomains([preferredWebexSite]);
}

// fall back to getting the preferred site from the user information
if (!this.preferredWebexSite) {
// @ts-ignore
return this.webex.internal.user
.get()
.then((user) => {
const preferredWebexSite =
user?.userPreferences?.userPreferencesItems?.preferredWebExSite;
if (preferredWebexSite) {
this.preferredWebexSite = preferredWebexSite;
// @ts-ignore
this.webex.internal.services
._getCatalog()
.addAllowedDomains([preferredWebexSite]);
} else {
throw new Error('site not found');
}
})
.catch(() => {
LoggerProxy.logger.error(
'Failed to fetch preferred site from user - no site will be set'
);
});
}
// fall back to getting the preferred site from the user information
if (!this.preferredWebexSite) {
// @ts-ignore
return this.webex.internal.user
.get()
.then((user) => {
const preferredWebexSite =
user?.userPreferences?.userPreferencesItems?.preferredWebExSite;
if (preferredWebexSite) {
this.preferredWebexSite = preferredWebexSite;
// @ts-ignore
this.webex.internal.services
._getCatalog()
.addAllowedDomains([preferredWebexSite]);
} else {
throw new Error('site not found');
}
})
.catch(() => {
LoggerProxy.logger.error(
'Failed to fetch preferred site from user - no site will be set'
);
});
}

return Promise.resolve();
});
}
return Promise.resolve();
});
}

return Promise.resolve();
});
return Promise.resolve();
})
.catch(() => {
LoggerProxy.logger.error('Failed to retrieve user information. No site will be set');
});
}

/**
Expand Down
17 changes: 16 additions & 1 deletion packages/@webex/plugin-meetings/test/unit/spec/meetings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2077,6 +2077,21 @@ describe('plugin-meetings', () => {
]);
});

it('should handle failure to get user information if scopes are insufficient', async () => {
loggerProxySpy = sinon.spy(LoggerProxy.logger, 'error');
Object.assign(webex.people, {
_getMe: sinon.stub().returns(Promise.reject()),
});

await webex.meetings.fetchUserPreferredWebexSite();

assert.equal(webex.meetings.preferredWebexSite, '');
assert.calledOnceWithExactly(
loggerProxySpy,
'Failed to retrieve user information. No site will be set'
);
});

const setup = ({me = { type: 'validuser'}, user} = {}) => {
loggerProxySpy = sinon.spy(LoggerProxy.logger, 'error');
assert.deepEqual(webex.internal.services._getCatalog().getAllowedDomains(), []);
Expand All @@ -2093,7 +2108,7 @@ describe('plugin-meetings', () => {

Object.assign(webex.people, {
_getMe: sinon.stub().returns(Promise.resolve(me)),
});
});
};

it('should not call request.getMeetingPreferences if user is a guest', async () => {
Expand Down

0 comments on commit 109a25a

Please sign in to comment.