From 0d52a952314e4eae348787e43acf190fa9e2cd4d Mon Sep 17 00:00:00 2001 From: Mathijs Verbeeck Date: Thu, 2 Apr 2026 23:06:36 +0200 Subject: [PATCH] =?UTF-8?q?Adds=20command=20=C2=B4outlook=20calendargroup?= =?UTF-8?q?=20set=C2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calendargroup/calendargroup-set.mdx | 83 ++++ docs/src/config/sidebars.ts | 5 + src/m365/outlook/commands.ts | 1 + .../calendargroup/calendargroup-set.spec.ts | 375 ++++++++++++++++++ .../calendargroup/calendargroup-set.ts | 141 +++++++ 5 files changed, 605 insertions(+) create mode 100644 docs/docs/cmd/outlook/calendargroup/calendargroup-set.mdx create mode 100644 src/m365/outlook/commands/calendargroup/calendargroup-set.spec.ts create mode 100644 src/m365/outlook/commands/calendargroup/calendargroup-set.ts diff --git a/docs/docs/cmd/outlook/calendargroup/calendargroup-set.mdx b/docs/docs/cmd/outlook/calendargroup/calendargroup-set.mdx new file mode 100644 index 00000000000..54427fd2f44 --- /dev/null +++ b/docs/docs/cmd/outlook/calendargroup/calendargroup-set.mdx @@ -0,0 +1,83 @@ +import Global from '../../_global.mdx'; +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# outlook calendargroup set + +Updates a calendar group for a user. + +## Usage + +```sh +m365 outlook calendargroup set [options] +``` + +## Options + +```md definition-list +`--id [id]` +: ID of the calendar group. Specify either `id` or `name`, but not both. + +`--name [name]` +: Name of the calendar group. Specify either `id` or `name`, but not both. + +`--userId [userId]` +: ID of the user. Specify either `userId` or `userName`, but not both. + +`--userName [userName]` +: UPN of the user. Specify either `userId` or `userName`, but not both. + +`--newName ` +: New name of the calendar group. +``` + + + +## Permissions + + + + + | Resource | Permissions | + |-----------------|----------------------------------------| + | Microsoft Graph | Calendars.ReadWrite, Calendars.ReadWrite.Shared | + + + + + | Resource | Permissions | + |-----------------|----------------------| + | Microsoft Graph | Calendars.ReadWrite | + + + + +:::note + +When using delegated permissions, specifying `userId` or `userName` for a different user requires the `Calendars.ReadWrite.Shared` scope. When the specified user matches the signed-in user, no shared scope is needed. + +::: + +## Examples + +Update the calendar group specified by name for the current user. + +```sh +m365 outlook calendargroup set --name "Personal Evts" --newName "Personal Events" +``` + +Update the calendar group specified by id for a user. + +```sh +m365 outlook calendargroup set --id "AAMkADIxYjJiYm" --newName "Personal Events" --userId "44288f7d-7710-4293-8c8e-36f310ed2e6a" +``` + +Update the calendar group specified by name for a user specified by email. + +```sh +m365 outlook calendargroup set --name "Personal Evts" --newName "Personal Events" --userName "john.doe@contoso.com" +``` + +## Response + +The command won't return a response on success. diff --git a/docs/src/config/sidebars.ts b/docs/src/config/sidebars.ts index e0f837d676a..e6fa9eb9ecc 100644 --- a/docs/src/config/sidebars.ts +++ b/docs/src/config/sidebars.ts @@ -1327,6 +1327,11 @@ const sidebars: SidebarsConfig = { type: 'doc', label: 'calendargroup list', id: 'cmd/outlook/calendargroup/calendargroup-list' + }, + { + type: 'doc', + label: 'calendargroup set', + id: 'cmd/outlook/calendargroup/calendargroup-set' } ] }, diff --git a/src/m365/outlook/commands.ts b/src/m365/outlook/commands.ts index fb433f5842c..fefaf8800c9 100644 --- a/src/m365/outlook/commands.ts +++ b/src/m365/outlook/commands.ts @@ -5,6 +5,7 @@ export default { CALENDAR_GET: `${prefix} calendar get`, CALENDAR_REMOVE: `${prefix} calendar remove`, CALENDARGROUP_LIST: `${prefix} calendargroup list`, + CALENDARGROUP_SET: `${prefix} calendargroup set`, EVENT_CANCEL: `${prefix} event cancel`, EVENT_LIST: `${prefix} event list`, EVENT_REMOVE: `${prefix} event remove`, diff --git a/src/m365/outlook/commands/calendargroup/calendargroup-set.spec.ts b/src/m365/outlook/commands/calendargroup/calendargroup-set.spec.ts new file mode 100644 index 00000000000..d312a5d922f --- /dev/null +++ b/src/m365/outlook/commands/calendargroup/calendargroup-set.spec.ts @@ -0,0 +1,375 @@ +import assert from 'assert'; +import sinon from 'sinon'; +import auth from '../../../../Auth.js'; +import { CommandError } from '../../../../Command.js'; +import { CommandInfo } from '../../../../cli/CommandInfo.js'; +import { Logger } from '../../../../cli/Logger.js'; +import { cli } from '../../../../cli/cli.js'; +import request from '../../../../request.js'; +import { telemetry } from '../../../../telemetry.js'; +import { accessToken } from '../../../../utils/accessToken.js'; +import { calendarGroup } from '../../../../utils/calendarGroup.js'; +import { pid } from '../../../../utils/pid.js'; +import { session } from '../../../../utils/session.js'; +import { sinonUtil } from '../../../../utils/sinonUtil.js'; +import commands from '../../commands.js'; +import command, { options } from './calendargroup-set.js'; +import { z } from 'zod'; + +describe(commands.CALENDARGROUP_SET, () => { + const calendarGroupId = 'AAMkAGE0MGM1Y2M5LWEzMmUtNGVlNy05MjRlLTk0YmYyY2I5NTM3ZAAuAAAAAAC_0WfqSjt_SqLtNkuO-bj1AQAbfYq5lmBxQ6a4t1fGbeYAAAAAAEOAAA='; + const calendarGroupName = 'My Calendars'; + const newName = 'Personal Events'; + const userId = 'b743445a-112c-4fda-9afd-05943f9c7b36'; + const userName = 'john.doe@contoso.com'; + const currentUserId = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'; + const currentUserName = 'current.user@contoso.com'; + + let log: string[]; + let logger: Logger; + let commandInfo: CommandInfo; + let commandOptionsSchema: typeof options; + let refinedSchema: z.ZodTypeAny; + + before(() => { + sinon.stub(auth, 'restoreAuth').resolves(); + sinon.stub(telemetry, 'trackEvent').resolves(); + sinon.stub(pid, 'getProcessName').returns(''); + sinon.stub(session, 'getId').returns(''); + auth.connection.active = true; + if (!auth.connection.accessTokens[auth.defaultResource]) { + auth.connection.accessTokens[auth.defaultResource] = { + expiresOn: 'abc', + accessToken: 'abc' + }; + } + commandInfo = cli.getCommandInfo(command); + commandOptionsSchema = commandInfo.command.getSchemaToParse() as typeof options; + refinedSchema = commandInfo.command.getRefinedSchema!(commandOptionsSchema as any)!; + }); + + beforeEach(() => { + log = []; + logger = { + log: async (msg: string) => { + log.push(msg); + }, + logRaw: async (msg: string) => { + log.push(msg); + }, + logToStderr: async (msg: string) => { + log.push(msg); + } + }; + sinon.stub(accessToken, 'isAppOnlyAccessToken').returns(false); + sinon.stub(accessToken, 'getScopesFromAccessToken').returns([]); + sinon.stub(accessToken, 'getUserIdFromAccessToken').returns(currentUserId); + sinon.stub(accessToken, 'getUserNameFromAccessToken').returns(currentUserName); + }); + + afterEach(() => { + sinonUtil.restore([ + accessToken.isAppOnlyAccessToken, + accessToken.getScopesFromAccessToken, + accessToken.getUserIdFromAccessToken, + accessToken.getUserNameFromAccessToken, + calendarGroup.getUserCalendarGroupByName, + request.get, + request.patch + ]); + }); + + after(() => { + sinon.restore(); + auth.connection.active = false; + }); + + it('has correct name', () => { + assert.strictEqual(command.name, commands.CALENDARGROUP_SET); + }); + + it('has a description', () => { + assert.notStrictEqual(command.description, null); + }); + + it('passes validation with id and newName', () => { + const actual = commandOptionsSchema.safeParse({ id: calendarGroupId, newName }); + assert.strictEqual(actual.success, true); + }); + + it('passes validation with name and newName', () => { + const actual = commandOptionsSchema.safeParse({ name: calendarGroupName, newName }); + assert.strictEqual(actual.success, true); + }); + + it('passes validation with id, newName and userId', () => { + const actual = commandOptionsSchema.safeParse({ id: calendarGroupId, newName, userId }); + assert.strictEqual(actual.success, true); + }); + + it('passes validation with id, newName and userName', () => { + const actual = commandOptionsSchema.safeParse({ id: calendarGroupId, newName, userName }); + assert.strictEqual(actual.success, true); + }); + + it('fails validation if both userId and userName are specified', () => { + const actual = refinedSchema.safeParse({ id: calendarGroupId, newName, userId, userName }); + assert.notStrictEqual(actual.success, true); + }); + + it('fails validation if neither id nor name is specified', () => { + const actual = refinedSchema.safeParse({ newName }); + assert.notStrictEqual(actual.success, true); + }); + + it('fails validation if both id and name are specified', () => { + const actual = refinedSchema.safeParse({ id: calendarGroupId, name: calendarGroupName, newName }); + assert.notStrictEqual(actual.success, true); + }); + + it('fails validation if userId is not a valid GUID', () => { + const actual = commandOptionsSchema.safeParse({ id: calendarGroupId, newName, userId: 'foo' }); + assert.notStrictEqual(actual.success, true); + }); + + it('fails validation if userName is not a valid UPN', () => { + const actual = commandOptionsSchema.safeParse({ id: calendarGroupId, newName, userName: 'foo' }); + assert.notStrictEqual(actual.success, true); + }); + + it('fails validation with unknown options', () => { + const actual = commandOptionsSchema.safeParse({ id: calendarGroupId, newName, unknownOption: 'value' }); + assert.notStrictEqual(actual.success, true); + }); + + it('updates a calendar group by id for the signed-in user', async () => { + const patchStub = sinon.stub(request, 'patch').callsFake(async (opts) => { + if (opts.url === `https://graph.microsoft.com/v1.0/me/calendarGroups/${calendarGroupId}`) { + return; + } + + throw 'Invalid request'; + }); + + await command.action(logger, { options: commandOptionsSchema.parse({ id: calendarGroupId, newName }) }); + assert.deepStrictEqual(patchStub.lastCall.args[0].data, { name: newName }); + }); + + it('updates a calendar group by name for the signed-in user', async () => { + sinon.stub(calendarGroup, 'getUserCalendarGroupByName').resolves({ id: calendarGroupId, name: calendarGroupName }); + + const patchStub = sinon.stub(request, 'patch').callsFake(async (opts) => { + if (opts.url === `https://graph.microsoft.com/v1.0/me/calendarGroups/${calendarGroupId}`) { + return; + } + + throw 'Invalid request'; + }); + + await command.action(logger, { options: commandOptionsSchema.parse({ name: calendarGroupName, newName }) }); + assert.deepStrictEqual(patchStub.lastCall.args[0].data, { name: newName }); + }); + + it('updates a calendar group by id for the signed-in user (verbose)', async () => { + sinon.stub(request, 'patch').callsFake(async (opts) => { + if (opts.url === `https://graph.microsoft.com/v1.0/me/calendarGroups/${calendarGroupId}`) { + return; + } + + throw 'Invalid request'; + }); + + await command.action(logger, { options: commandOptionsSchema.parse({ id: calendarGroupId, newName, verbose: true }) }); + assert(log.some((l: any) => l.indexOf('Updating calendar group for the signed-in user...') > -1)); + assert(log.some((l: any) => l.indexOf(`Updating calendar group '${calendarGroupId}'...`) > -1)); + }); + + it('updates a calendar group by id for a user specified by userId using app-only permissions (verbose)', async () => { + sinonUtil.restore(accessToken.isAppOnlyAccessToken); + sinon.stub(accessToken, 'isAppOnlyAccessToken').returns(true); + + sinon.stub(request, 'patch').callsFake(async (opts) => { + if (opts.url === `https://graph.microsoft.com/v1.0/users('${userId}')/calendarGroups/${calendarGroupId}`) { + return; + } + + throw 'Invalid request'; + }); + + await command.action(logger, { options: commandOptionsSchema.parse({ id: calendarGroupId, newName, userId, verbose: true }) }); + assert(log.some((l: any) => l.indexOf(`Updating calendar group using application permissions for user '${userId}'...`) > -1)); + }); + + it('updates a calendar group by id for a user specified by userId using delegated permissions (verbose)', async () => { + sinonUtil.restore(accessToken.getScopesFromAccessToken); + sinon.stub(accessToken, 'getScopesFromAccessToken').returns(['Calendars.ReadWrite.Shared']); + + sinon.stub(request, 'patch').callsFake(async (opts) => { + if (opts.url === `https://graph.microsoft.com/v1.0/users('${userId}')/calendarGroups/${calendarGroupId}`) { + return; + } + + throw 'Invalid request'; + }); + + await command.action(logger, { options: commandOptionsSchema.parse({ id: calendarGroupId, newName, userId, verbose: true }) }); + assert(log.some((l: any) => l.indexOf(`Updating calendar group using delegated permissions for user '${userId}'...`) > -1)); + }); + + it('updates a calendar group by id for a user specified by userId using app-only permissions', async () => { + sinonUtil.restore(accessToken.isAppOnlyAccessToken); + sinon.stub(accessToken, 'isAppOnlyAccessToken').returns(true); + + const patchStub = sinon.stub(request, 'patch').callsFake(async (opts) => { + if (opts.url === `https://graph.microsoft.com/v1.0/users('${userId}')/calendarGroups/${calendarGroupId}`) { + return; + } + + throw 'Invalid request'; + }); + + await command.action(logger, { options: commandOptionsSchema.parse({ id: calendarGroupId, newName, userId }) }); + assert.deepStrictEqual(patchStub.lastCall.args[0].data, { name: newName }); + }); + + it('updates a calendar group by id for a user specified by userName using app-only permissions', async () => { + sinonUtil.restore(accessToken.isAppOnlyAccessToken); + sinon.stub(accessToken, 'isAppOnlyAccessToken').returns(true); + + const patchStub = sinon.stub(request, 'patch').callsFake(async (opts) => { + if (opts.url === `https://graph.microsoft.com/v1.0/users('john.doe%40contoso.com')/calendarGroups/${calendarGroupId}`) { + return; + } + + throw 'Invalid request'; + }); + + await command.action(logger, { options: commandOptionsSchema.parse({ id: calendarGroupId, newName, userName }) }); + assert.deepStrictEqual(patchStub.lastCall.args[0].data, { name: newName }); + }); + + it('updates a calendar group by name for a user specified by userId using app-only permissions', async () => { + sinonUtil.restore(accessToken.isAppOnlyAccessToken); + sinon.stub(accessToken, 'isAppOnlyAccessToken').returns(true); + + sinon.stub(calendarGroup, 'getUserCalendarGroupByName').resolves({ id: calendarGroupId, name: calendarGroupName }); + + const patchStub = sinon.stub(request, 'patch').callsFake(async (opts) => { + if (opts.url === `https://graph.microsoft.com/v1.0/users('${userId}')/calendarGroups/${calendarGroupId}`) { + return; + } + + throw 'Invalid request'; + }); + + await command.action(logger, { options: commandOptionsSchema.parse({ name: calendarGroupName, newName, userId }) }); + assert.deepStrictEqual(patchStub.lastCall.args[0].data, { name: newName }); + }); + + it('updates a calendar group by id for a user specified by userId using delegated permissions with Calendars.ReadWrite.Shared scope', async () => { + sinonUtil.restore(accessToken.getScopesFromAccessToken); + sinon.stub(accessToken, 'getScopesFromAccessToken').returns(['Calendars.ReadWrite.Shared']); + + const patchStub = sinon.stub(request, 'patch').callsFake(async (opts) => { + if (opts.url === `https://graph.microsoft.com/v1.0/users('${userId}')/calendarGroups/${calendarGroupId}`) { + return; + } + + throw 'Invalid request'; + }); + + await command.action(logger, { options: commandOptionsSchema.parse({ id: calendarGroupId, newName, userId }) }); + assert.deepStrictEqual(patchStub.lastCall.args[0].data, { name: newName }); + }); + + it('updates a calendar group by id for a user specified by userName using delegated permissions with Calendars.ReadWrite.Shared scope', async () => { + sinonUtil.restore(accessToken.getScopesFromAccessToken); + sinon.stub(accessToken, 'getScopesFromAccessToken').returns(['Calendars.ReadWrite.Shared']); + + const patchStub = sinon.stub(request, 'patch').callsFake(async (opts) => { + if (opts.url === `https://graph.microsoft.com/v1.0/users('john.doe%40contoso.com')/calendarGroups/${calendarGroupId}`) { + return; + } + + throw 'Invalid request'; + }); + + await command.action(logger, { options: commandOptionsSchema.parse({ id: calendarGroupId, newName, userName }) }); + assert.deepStrictEqual(patchStub.lastCall.args[0].data, { name: newName }); + }); + + it('does not check shared scope when userId matches the signed-in user', async () => { + sinonUtil.restore(accessToken.getUserIdFromAccessToken); + sinon.stub(accessToken, 'getUserIdFromAccessToken').returns(userId); + + const patchStub = sinon.stub(request, 'patch').callsFake(async (opts) => { + if (opts.url === `https://graph.microsoft.com/v1.0/users('${userId}')/calendarGroups/${calendarGroupId}`) { + return; + } + + throw 'Invalid request'; + }); + + await command.action(logger, { options: commandOptionsSchema.parse({ id: calendarGroupId, newName, userId }) }); + assert.deepStrictEqual(patchStub.lastCall.args[0].data, { name: newName }); + }); + + it('does not check shared scope when userName matches the signed-in user', async () => { + sinonUtil.restore(accessToken.getUserNameFromAccessToken); + sinon.stub(accessToken, 'getUserNameFromAccessToken').returns(userName); + + const patchStub = sinon.stub(request, 'patch').callsFake(async (opts) => { + if (opts.url === `https://graph.microsoft.com/v1.0/users('john.doe%40contoso.com')/calendarGroups/${calendarGroupId}`) { + return; + } + + throw 'Invalid request'; + }); + + await command.action(logger, { options: commandOptionsSchema.parse({ id: calendarGroupId, newName, userName }) }); + assert.deepStrictEqual(patchStub.lastCall.args[0].data, { name: newName }); + }); + + it('throws error when running with app-only permissions without userId or userName', async () => { + sinonUtil.restore(accessToken.isAppOnlyAccessToken); + sinon.stub(accessToken, 'isAppOnlyAccessToken').returns(true); + + await assert.rejects( + command.action(logger, { options: commandOptionsSchema.parse({ id: calendarGroupId, newName }) }), + new CommandError('When running with application permissions either userId or userName is required.') + ); + }); + + it('throws error when using delegated permissions with other userId without shared scope', async () => { + await assert.rejects( + command.action(logger, { options: commandOptionsSchema.parse({ id: calendarGroupId, newName, userId }) }), + new CommandError('To update calendar groups of other users, the Entra ID application used for authentication must have the Calendars.ReadWrite.Shared delegated permission assigned.') + ); + }); + + it('throws error when using delegated permissions with other userName without shared scope', async () => { + await assert.rejects( + command.action(logger, { options: commandOptionsSchema.parse({ id: calendarGroupId, newName, userName }) }), + new CommandError('To update calendar groups of other users, the Entra ID application used for authentication must have the Calendars.ReadWrite.Shared delegated permission assigned.') + ); + }); + + it('throws error when calendar group with specified name is not found', async () => { + sinon.stub(calendarGroup, 'getUserCalendarGroupByName').rejects(new Error("The specified calendar group 'NonExistent Group' does not exist.")); + + await assert.rejects( + command.action(logger, { options: commandOptionsSchema.parse({ name: 'NonExistent Group', newName }) }), + new CommandError("The specified calendar group 'NonExistent Group' does not exist.") + ); + }); + + it('correctly handles API OData error', async () => { + const errorMessage = 'Something went wrong'; + sinon.stub(request, 'patch').rejects({ error: { error: { message: errorMessage } } }); + + await assert.rejects( + command.action(logger, { options: commandOptionsSchema.parse({ id: calendarGroupId, newName }) }), + new CommandError(errorMessage) + ); + }); +}); diff --git a/src/m365/outlook/commands/calendargroup/calendargroup-set.ts b/src/m365/outlook/commands/calendargroup/calendargroup-set.ts new file mode 100644 index 00000000000..2359b2a89df --- /dev/null +++ b/src/m365/outlook/commands/calendargroup/calendargroup-set.ts @@ -0,0 +1,141 @@ +import { z } from 'zod'; +import { globalOptionsZod } from '../../../../Command.js'; +import GraphCommand from '../../../base/GraphCommand.js'; +import { Logger } from '../../../../cli/Logger.js'; +import commands from '../../commands.js'; +import { validation } from '../../../../utils/validation.js'; +import request, { CliRequestOptions } from '../../../../request.js'; +import { accessToken } from '../../../../utils/accessToken.js'; +import auth from '../../../../Auth.js'; +import { formatting } from '../../../../utils/formatting.js'; +import { calendarGroup } from '../../../../utils/calendarGroup.js'; + +export const options = z.strictObject({ + ...globalOptionsZod.shape, + id: z.string().optional(), + name: z.string().optional(), + userId: z.string().refine(id => validation.isValidGuid(id), { + error: e => `'${e.input}' is not a valid GUID.` + }).optional(), + userName: z.string().refine(name => validation.isValidUserPrincipalName(name), { + error: e => `'${e.input}' is not a valid UPN.` + }).optional(), + newName: z.string() +}); + +declare type Options = z.infer; + +interface CommandArgs { + options: Options; +} + +class OutlookCalendarGroupSetCommand extends GraphCommand { + public get name(): string { + return commands.CALENDARGROUP_SET; + } + + public get description(): string { + return 'Updates a calendar group for a user'; + } + + public get schema(): z.ZodType | undefined { + return options; + } + + public getRefinedSchema(schema: typeof options): z.ZodObject | undefined { + return schema + .refine(options => !(options.userId && options.userName), { + error: 'Specify either userId or userName, but not both.' + }) + .refine(options => !(!options.id && !options.name), { + error: 'Specify either id or name.' + }) + .refine(options => !(options.id && options.name), { + error: 'Specify either id or name, but not both.' + }); + } + + public async commandAction(logger: Logger, args: CommandArgs): Promise { + try { + const token = auth.connection.accessTokens[auth.defaultResource].accessToken; + const isAppOnlyAccessToken = accessToken.isAppOnlyAccessToken(token); + + let userUrl: string; + let graphUserId: string; + + if (isAppOnlyAccessToken) { + if (!args.options.userId && !args.options.userName) { + throw 'When running with application permissions either userId or userName is required.'; + } + + graphUserId = (args.options.userId ?? args.options.userName)!; + userUrl = `${this.resource}/v1.0/users('${formatting.encodeQueryParameter(graphUserId)}')`; + + if (this.verbose) { + await logger.logToStderr(`Updating calendar group using application permissions for user '${graphUserId}'...`); + } + } + else if (args.options.userId || args.options.userName) { + const currentUserId = accessToken.getUserIdFromAccessToken(token); + const currentUserName = accessToken.getUserNameFromAccessToken(token); + const isOtherUser = (args.options.userId && args.options.userId !== currentUserId) || + (args.options.userName && args.options.userName.toLowerCase() !== currentUserName?.toLowerCase()); + + if (isOtherUser) { + const scopes = accessToken.getScopesFromAccessToken(token); + const hasSharedScope = scopes.some(s => s === 'Calendars.ReadWrite.Shared'); + + if (!hasSharedScope) { + throw `To update calendar groups of other users, the Entra ID application used for authentication must have the Calendars.ReadWrite.Shared delegated permission assigned.`; + } + } + + graphUserId = (args.options.userId ?? args.options.userName)!; + userUrl = `${this.resource}/v1.0/users('${formatting.encodeQueryParameter(graphUserId)}')`; + + if (this.verbose) { + await logger.logToStderr(`Updating calendar group using delegated permissions for user '${graphUserId}'...`); + } + } + else { + graphUserId = accessToken.getUserIdFromAccessToken(token); + userUrl = `${this.resource}/v1.0/me`; + + if (this.verbose) { + await logger.logToStderr('Updating calendar group for the signed-in user...'); + } + } + + let calendarGroupId: string; + if (args.options.id) { + calendarGroupId = args.options.id; + } + else { + const calendarGroupResult = await calendarGroup.getUserCalendarGroupByName(graphUserId, args.options.name!); + calendarGroupId = calendarGroupResult.id!; + } + + if (this.verbose) { + await logger.logToStderr(`Updating calendar group '${calendarGroupId}'...`); + } + + const requestOptions: CliRequestOptions = { + url: `${userUrl}/calendarGroups/${calendarGroupId}`, + headers: { + accept: 'application/json;odata.metadata=none' + }, + responseType: 'json', + data: { + name: args.options.newName + } + }; + + await request.patch(requestOptions); + } + catch (err: any) { + this.handleRejectedODataJsonPromise(err); + } + } +} + +export default new OutlookCalendarGroupSetCommand();