Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(meetings): handle getMe error due to insufficient privileges #4011

Merged
merged 5 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 46 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,55 @@ 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 preferredWebexSite will be set'
);
});
}

/**
Expand Down
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 preferredWebexSite 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