Skip to content

Commit 6c776ea

Browse files
Changes code when userId id not specified when using delegated permissions
1 parent 3d01bba commit 6c776ea

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

src/m365/outlook/commands/calendargroup/calendargroup-remove.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import command, { options } from './calendargroup-remove.js';
1818
describe(commands.CALENDARGROUP_REMOVE, () => {
1919
const calendarGroupId = 'AAMkAGE0MGM1Y2M5LWEzMmUtNGVlNy05MjRlLTk0YmYyY2I5NTM3ZAAuAAAAAAC_0WfqSjt_SqLtNkuO-bj1AQAbfYq5lmBxQ6a4t1fGbeYAAAAAAEOAAA=';
2020
const calendarGroupName = 'Personal Events';
21+
const currentUserId = '2b4097f3-5b17-4153-a8b4-cd680e333555';
2122
const userId = 'b743445a-112c-4fda-9afd-05943f9c7b36';
2223
const userName = 'john.doe@contoso.com';
2324

@@ -61,12 +62,14 @@ describe(commands.CALENDARGROUP_REMOVE, () => {
6162
return Promise.resolve(false);
6263
});
6364
sinon.stub(accessToken, 'isAppOnlyAccessToken').returns(false);
65+
sinon.stub(accessToken, 'getUserIdFromAccessToken').returns(currentUserId);
6466
promptIssued = false;
6567
});
6668

6769
afterEach(() => {
6870
sinonUtil.restore([
6971
accessToken.isAppOnlyAccessToken,
72+
accessToken.getUserIdFromAccessToken,
7073
calendarGroup.getUserCalendarGroupByName,
7174
request.get,
7275
request.delete,
@@ -152,7 +155,7 @@ describe(commands.CALENDARGROUP_REMOVE, () => {
152155

153156
it('removes the calendar group specified by id for the signed-in user without prompting', async () => {
154157
const deleteRequestStub = sinon.stub(request, 'delete').callsFake(async (opts) => {
155-
if (opts.url === `https://graph.microsoft.com/v1.0/me/calendarGroups/${calendarGroupId}`) {
158+
if (opts.url === `https://graph.microsoft.com/v1.0/users('${currentUserId}')/calendarGroups/${calendarGroupId}`) {
156159
return;
157160
}
158161

@@ -165,7 +168,7 @@ describe(commands.CALENDARGROUP_REMOVE, () => {
165168

166169
it('removes the calendar group specified by id for the signed-in user (verbose)', async () => {
167170
const deleteRequestStub = sinon.stub(request, 'delete').callsFake(async (opts) => {
168-
if (opts.url === `https://graph.microsoft.com/v1.0/me/calendarGroups/${calendarGroupId}`) {
171+
if (opts.url === `https://graph.microsoft.com/v1.0/users('${currentUserId}')/calendarGroups/${calendarGroupId}`) {
169172
return;
170173
}
171174

@@ -180,7 +183,7 @@ describe(commands.CALENDARGROUP_REMOVE, () => {
180183
sinon.stub(calendarGroup, 'getUserCalendarGroupByName').resolves({ id: calendarGroupId, name: calendarGroupName });
181184

182185
const deleteRequestStub = sinon.stub(request, 'delete').callsFake(async (opts) => {
183-
if (opts.url === `https://graph.microsoft.com/v1.0/me/calendarGroups/${calendarGroupId}`) {
186+
if (opts.url === `https://graph.microsoft.com/v1.0/users('${currentUserId}')/calendarGroups/${calendarGroupId}`) {
184187
return;
185188
}
186189

@@ -198,7 +201,7 @@ describe(commands.CALENDARGROUP_REMOVE, () => {
198201
sinon.stub(calendarGroup, 'getUserCalendarGroupByName').resolves({ id: calendarGroupId, name: calendarGroupName });
199202

200203
const deleteRequestStub = sinon.stub(request, 'delete').callsFake(async (opts) => {
201-
if (opts.url === `https://graph.microsoft.com/v1.0/me/calendarGroups/${calendarGroupId}`) {
204+
if (opts.url === `https://graph.microsoft.com/v1.0/users('${currentUserId}')/calendarGroups/${calendarGroupId}`) {
202205
return;
203206
}
204207

src/m365/outlook/commands/calendargroup/calendargroup-remove.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ class OutlookCalendarGroupRemoveCommand extends GraphCommand {
7171

7272
if (args.options.userId || args.options.userName) {
7373
graphUserId = (args.options.userId ?? args.options.userName)!;
74-
endpoint = `${this.resource}/v1.0/users('${formatting.encodeQueryParameter(graphUserId)}')`;
7574
}
7675
else {
77-
graphUserId = 'me';
78-
endpoint = `${this.resource}/v1.0/me`;
76+
graphUserId = accessToken.getUserIdFromAccessToken(token);
7977
}
8078

79+
endpoint = `${this.resource}/v1.0/users('${formatting.encodeQueryParameter(graphUserId)}')`;
80+
8181
let calendarGroupId = args.options.id;
8282

8383
if (args.options.name) {

0 commit comments

Comments
 (0)