From 979b9b7e25d241f6850643c992d47ccf63cb5d94 Mon Sep 17 00:00:00 2001 From: Mathijs Verbeeck Date: Sat, 21 Sep 2024 20:24:52 +0200 Subject: [PATCH] Renames 'site rename' to 'tenant site rename'. Closes #6142 --- docs/docs/about/release-notes.mdx | 2 +- .../tenant-site-rename.mdx} | 14 ++--- docs/docs/v10-upgrade-guidance.mdx | 8 +++ docs/docs/v6-upgrade-guidance.mdx | 2 +- docs/src/config/sidebars.ts | 10 ++-- src/m365/spo/commands.ts | 2 +- .../tenant-site-rename.spec.ts} | 12 ++--- .../tenant-site-rename.ts} | 51 +++++++++---------- 8 files changed, 51 insertions(+), 50 deletions(-) rename docs/docs/cmd/spo/{site/site-rename.mdx => tenant/tenant-site-rename.mdx} (86%) rename src/m365/spo/commands/{site/site-rename.spec.ts => tenant/tenant-site-rename.spec.ts} (98%) rename src/m365/spo/commands/{site/site-rename.ts => tenant/tenant-site-rename.ts} (76%) diff --git a/docs/docs/about/release-notes.mdx b/docs/docs/about/release-notes.mdx index 7a3f451c7e6..77a3e8b11a0 100644 --- a/docs/docs/about/release-notes.mdx +++ b/docs/docs/about/release-notes.mdx @@ -3019,7 +3019,7 @@ sidebar_position: 3 **SharePoint:** - [spo feature disable](../cmd/spo/feature/feature-disable.mdx) - disables feature for the specified site or web [#676](https://github.com/pnp/cli-microsoft365/issues/676) -- [spo site rename](../cmd/spo/site/site-rename.mdx) - renames the URL and title of a site collection [#1197](https://github.com/pnp/cli-microsoft365/issues/1197) +- [spo site rename](../cmd/spo/tenant/tenant-site-rename.mdx) - renames the URL and title of a site collection [#1197](https://github.com/pnp/cli-microsoft365/issues/1197) **Yammer:** diff --git a/docs/docs/cmd/spo/site/site-rename.mdx b/docs/docs/cmd/spo/tenant/tenant-site-rename.mdx similarity index 86% rename from docs/docs/cmd/spo/site/site-rename.mdx rename to docs/docs/cmd/spo/tenant/tenant-site-rename.mdx index d12ae83a5a7..e06a6f6cc10 100644 --- a/docs/docs/cmd/spo/site/site-rename.mdx +++ b/docs/docs/cmd/spo/tenant/tenant-site-rename.mdx @@ -2,14 +2,14 @@ import Global from '/docs/cmd/_global.mdx'; import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; -# spo site rename +# spo tenant site rename Renames the URL and title of a site collection ## Usage ```sh -m365 spo site rename [options] +m365 spo tenant site rename [options] ``` ## Options @@ -38,7 +38,7 @@ m365 spo site rename [options] ## Remarks -Renaming site collections is by default asynchronous and depending on the current state of Microsoft 365, might take up to few minutes. If you're building a script with steps that require the operation to complete fully, you should use the `--wait` flag. When using this flag, the `spo site rename` command will keep running until it receives confirmation from Microsoft 365 that the site rename operation has completed. +Renaming site collections is by default asynchronous and depending on the current state of Microsoft 365, might take up to few minutes. If you're building a script with steps that require the operation to complete fully, you should use the `--wait` flag. When using this flag, the `spo tenant site rename` command will keep running until it receives confirmation from Microsoft 365 that the site rename operation has completed. :::info @@ -51,19 +51,19 @@ To use this command you must have permissions to access the tenant admin site. Starts the rename of the site collection with name "samplesite" to "renamed" without modifying the title ```sh -m365 spo site rename --url http://contoso.sharepoint.com/samplesite --newUrl http://contoso.sharepoint.com/renamed +m365 spo tenant site rename --url http://contoso.sharepoint.com/samplesite --newUrl http://contoso.sharepoint.com/renamed ``` Starts the rename of the site collection with name "samplesite" to "renamed" modifying the title of the site to "New Title" ```sh -m365 spo site rename --url http://contoso.sharepoint.com/samplesite --newUrl http://contoso.sharepoint.com/renamed --newTitle "New Title" +m365 spo tenant site rename --url http://contoso.sharepoint.com/samplesite --newUrl http://contoso.sharepoint.com/renamed --newTitle "New Title" ``` Renames the specified site collection and waits for the operation to complete ```sh -m365 spo site rename --url http://contoso.sharepoint.com/samplesite --newUrl http://contoso.sharepoint.com/renamed --newTitle "New Title" --wait +m365 spo tenant site rename --url http://contoso.sharepoint.com/samplesite --newUrl http://contoso.sharepoint.com/renamed --newTitle "New Title" --wait ``` ## Response @@ -130,7 +130,7 @@ m365 spo site rename --url http://contoso.sharepoint.com/samplesite --newUrl htt ```md - # spo site rename --url "https://contoso.sharepoint.com/sites/team1" --newUrl "https://contoso.sharepoint.com/sites/team2" + # spo tenant site rename --url "https://contoso.sharepoint.com/sites/team1" --newUrl "https://contoso.sharepoint.com/sites/team2" Date: 2023-06-21 diff --git a/docs/docs/v10-upgrade-guidance.mdx b/docs/docs/v10-upgrade-guidance.mdx index d7de47998d8..d49609a33fa 100644 --- a/docs/docs/v10-upgrade-guidance.mdx +++ b/docs/docs/v10-upgrade-guidance.mdx @@ -249,6 +249,14 @@ We updated the output from the [`spo sitescript get`](./cmd/spo/sitescript/sites Please update your scripts to reflect the new output of the [`spo sitescript get`](./cmd/spo/sitescript/sitescript-get.mdx) command. +### Renamed `spo site rename` to `spo tenant site rename` + +The `spo site rename` command was renamed to [`spo tenant site rename`](./cmd/spo/tenant/tenant-site-rename.mdx) to better reflect the command's purpose as this is an action that only an administrator can do. + +#### What action do I need to take? + +Please update your scripts to use the new command name. + ## SharePoint Framework ### Removed overwrite option from `spfx project github workflow add` command diff --git a/docs/docs/v6-upgrade-guidance.mdx b/docs/docs/v6-upgrade-guidance.mdx index 8bea4893ddd..bd1e4d8afbf 100644 --- a/docs/docs/v6-upgrade-guidance.mdx +++ b/docs/docs/v6-upgrade-guidance.mdx @@ -350,7 +350,7 @@ pa solution reference add|`path`|`projectPath` [spo site apppermission set](./cmd/spo/site/site-apppermission-set.mdx)|`permissionId`|`id` [spo site chrome set](./cmd/spo/site/site-chrome-set.mdx)|`url`|`siteUrl` [spo site groupify](./cmd/spo/site/site-groupify.mdx)|`siteUrl`|`url` -[spo site rename](./cmd/spo/site/site-rename.mdx)|`siteUrl`|`url` +[spo site rename](./cmd/spo/tenant/tenant-site-rename.mdx)|`siteUrl`|`url` [spo sitedesign rights grant](./cmd/spo/sitedesign/sitedesign-rights-grant.mdx)|`id`|`siteDesignId` [spo sitedesign rights list](./cmd/spo/sitedesign/sitedesign-rights-list.mdx)|`id`|`siteDesignId` [spo sitedesign rights revoke](./cmd/spo/sitedesign/sitedesign-rights-revoke.mdx)|`id`|`siteDesignId` diff --git a/docs/src/config/sidebars.ts b/docs/src/config/sidebars.ts index ac7892bcb74..24cfc6fb0f8 100644 --- a/docs/src/config/sidebars.ts +++ b/docs/src/config/sidebars.ts @@ -3402,11 +3402,6 @@ const sidebars: SidebarsConfig = { label: 'site remove', id: 'cmd/spo/site/site-remove' }, - { - type: 'doc', - label: 'site rename', - id: 'cmd/spo/site/site-rename' - }, { type: 'doc', label: 'site set', @@ -3743,6 +3738,11 @@ const sidebars: SidebarsConfig = { label: 'tenant site archive', id: 'cmd/spo/tenant/tenant-site-archive' }, + { + type: 'doc', + label: 'tenant site rename', + id: 'cmd/spo/tenant/tenant-site-rename' + }, { type: 'doc', label: 'tenant site unarchive', diff --git a/src/m365/spo/commands.ts b/src/m365/spo/commands.ts index 763f442a5d4..19bd81ff09d 100644 --- a/src/m365/spo/commands.ts +++ b/src/m365/spo/commands.ts @@ -271,7 +271,6 @@ export default { SITE_RECYCLEBINITEM_REMOVE: `${prefix} site recyclebinitem remove`, SITE_RECYCLEBINITEM_RESTORE: `${prefix} site recyclebinitem restore`, SITE_REMOVE: `${prefix} site remove`, - SITE_RENAME: `${prefix} site rename`, SITE_SET: `${prefix} site set`, SITE_CHROME_SET: `${prefix} site chrome set`, SITEDESIGN_ADD: `${prefix} sitedesign add`, @@ -322,6 +321,7 @@ export default { TENANT_SETTINGS_LIST: `${prefix} tenant settings list`, TENANT_SETTINGS_SET: `${prefix} tenant settings set`, TENANT_SITE_ARCHIVE: `${prefix} tenant site archive`, + TENANT_SITE_RENAME: `${prefix} tenant site rename`, TENANT_SITE_UNARCHIVE: `${prefix} tenant site unarchive`, TERM_ADD: `${prefix} term add`, TERM_GET: `${prefix} term get`, diff --git a/src/m365/spo/commands/site/site-rename.spec.ts b/src/m365/spo/commands/tenant/tenant-site-rename.spec.ts similarity index 98% rename from src/m365/spo/commands/site/site-rename.spec.ts rename to src/m365/spo/commands/tenant/tenant-site-rename.spec.ts index e32dce3bc9b..1176c40a236 100644 --- a/src/m365/spo/commands/site/site-rename.spec.ts +++ b/src/m365/spo/commands/tenant/tenant-site-rename.spec.ts @@ -12,10 +12,11 @@ import { session } from '../../../../utils/session.js'; import { sinonUtil } from '../../../../utils/sinonUtil.js'; import { spo } from '../../../../utils/spo.js'; import commands from '../../commands.js'; -import command from './site-rename.js'; +import command from './tenant-site-rename.js'; import { settingsNames } from '../../../../settingsNames.js'; +import { timersUtil } from '../../../../utils/timersUtil.js'; -describe(commands.SITE_RENAME, () => { +describe(commands.TENANT_SITE_RENAME, () => { let log: string[]; let logger: Logger; let loggerLogSpy: sinon.SinonSpy; @@ -27,10 +28,7 @@ describe(commands.SITE_RENAME, () => { sinon.stub(telemetry, 'trackEvent').returns(); sinon.stub(pid, 'getProcessName').returns(''); sinon.stub(session, 'getId').returns(''); - sinon.stub(global, 'setTimeout').callsFake((fn) => { - fn(); - return {} as any; - }); + sinon.stub(timersUtil, 'setTimeout').resolves(); auth.connection.active = true; auth.connection.spoUrl = 'https://contoso.sharepoint.com'; commandInfo = cli.getCommandInfo(command); @@ -73,7 +71,7 @@ describe(commands.SITE_RENAME, () => { }); it('has correct name', () => { - assert.strictEqual(command.name, commands.SITE_RENAME); + assert.strictEqual(command.name, commands.TENANT_SITE_RENAME); }); it('has a description', () => { diff --git a/src/m365/spo/commands/site/site-rename.ts b/src/m365/spo/commands/tenant/tenant-site-rename.ts similarity index 76% rename from src/m365/spo/commands/site/site-rename.ts rename to src/m365/spo/commands/tenant/tenant-site-rename.ts index 9c707582051..e18825765a6 100644 --- a/src/m365/spo/commands/site/site-rename.ts +++ b/src/m365/spo/commands/tenant/tenant-site-rename.ts @@ -1,8 +1,9 @@ import { Logger } from '../../../../cli/Logger.js'; import GlobalOptions from '../../../../GlobalOptions.js'; -import request from '../../../../request.js'; +import request, { CliRequestOptions } from '../../../../request.js'; import { formatting } from '../../../../utils/formatting.js'; import { FormDigestInfo, spo } from '../../../../utils/spo.js'; +import { timersUtil } from '../../../../utils/timersUtil.js'; import SpoCommand from '../../../base/SpoCommand.js'; import commands from '../../commands.js'; @@ -24,13 +25,13 @@ interface SiteRenameJob { JobState: string; } -class SpoSiteRenameCommand extends SpoCommand { +class SpoTenantSiteRenameCommand extends SpoCommand { private context?: FormDigestInfo; private operationData?: SiteRenameJob; private static readonly checkIntervalInMs: number = 5000; public get name(): string { - return commands.SITE_RENAME; + return commands.TENANT_SITE_RENAME; } public get description(): string { @@ -48,10 +49,10 @@ class SpoSiteRenameCommand extends SpoCommand { #initTelemetry(): void { this.telemetry.push((args: CommandArgs) => { Object.assign(this.telemetryProperties, { - newTitle: args.options.newTitle ? true : false, - suppressMarketplaceAppCheck: args.options.suppressMarketplaceAppCheck, - suppressWorkflow2013Check: args.options.suppressWorkflow2013Check, - wait: args.options.wait + newTitle: typeof args.options.newTitle !== 'undefined', + suppressMarketplaceAppCheck: !!args.options.suppressMarketplaceAppCheck, + suppressWorkflow2013Check: !!args.options.suppressWorkflow2013Check, + wait: !!args.options.wait }); }); } @@ -111,27 +112,25 @@ class SpoSiteRenameCommand extends SpoCommand { optionsBitmask = optionsBitmask | 16; } - const requestOptions = { - "SourceSiteUrl": options.url, - "TargetSiteUrl": options.newUrl, - "TargetSiteTitle": options.newTitle || null, - "Option": optionsBitmask, - "Reserve": null, - "SkipGestures": null, - "OperationId": "00000000-0000-0000-0000-000000000000" - }; - - const postData: any = { + const requestOptions: CliRequestOptions = { url: `${spoAdminUrl}/_api/SiteRenameJobs?api-version=1.4.7`, headers: { 'X-RequestDigest': this.context.FormDigestValue, 'Content-Type': 'application/json' }, responseType: 'json', - data: requestOptions + data: { + SourceSiteUrl: options.url, + TargetSiteUrl: options.newUrl, + TargetSiteTitle: options.newTitle || null, + Option: optionsBitmask, + Reserve: null, + SkipGestures: null, + OperationId: '00000000-0000-0000-0000-000000000000' + } }; - const res = await request.post(postData); + const res = await request.post(requestOptions); if (options.verbose) { await logger.logToStderr(res); @@ -160,10 +159,10 @@ class SpoSiteRenameCommand extends SpoCommand { } } - protected async waitForRenameCompletion(command: SpoSiteRenameCommand, isVerbose: boolean, spoAdminUrl: string, siteUrl: string, iteration: number): Promise { + protected async waitForRenameCompletion(command: SpoTenantSiteRenameCommand, isVerbose: boolean, spoAdminUrl: string, siteUrl: string, iteration: number): Promise { iteration++; - const requestOptions: any = { + const requestOptions: CliRequestOptions = { url: `${spoAdminUrl}/_api/SiteRenameJobs/GetJobsBySiteUrl(url='${formatting.encodeQueryParameter(siteUrl)}')?api-version=1.4.7`, headers: { 'X-AttemptNumber': iteration.toString() @@ -182,13 +181,9 @@ class SpoSiteRenameCommand extends SpoCommand { return; } - await this.sleep(SpoSiteRenameCommand.checkIntervalInMs); + await timersUtil.setTimeout(SpoTenantSiteRenameCommand.checkIntervalInMs); await command.waitForRenameCompletion(command, isVerbose, spoAdminUrl, siteUrl, iteration); } - - protected sleep(ms: number): Promise { - return new Promise(resolve => setTimeout(resolve, ms)); - } } -export default new SpoSiteRenameCommand(); \ No newline at end of file +export default new SpoTenantSiteRenameCommand(); \ No newline at end of file