Skip to content

Fixes 'spo site set' command to handle site logo and thumbnail from another site. Closes #6689 #6690

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions src/m365/base/SpoCommand.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ describe('SpoCommand', () => {
'parentWebUrl',
'previewImageUrl',
'siteLogoUrl',
'siteThumbnailUrl',
'siteUrl',
'StartASiteFormUrl',
'targetUrl',
Expand Down Expand Up @@ -174,6 +175,7 @@ describe('SpoCommand', () => {
'parentWebUrl',
'previewImageUrl',
'siteLogoUrl',
'siteThumbnailUrl',
'siteUrl',
'StartASiteFormUrl',
'targetUrl',
Expand Down
1 change: 1 addition & 0 deletions src/m365/base/SpoCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default abstract class SpoCommand extends Command {
'parentWebUrl',
'previewImageUrl',
'siteLogoUrl',
'siteThumbnailUrl',
'siteUrl',
'StartASiteFormUrl',
'targetUrl',
Expand Down
108 changes: 108 additions & 0 deletions src/m365/spo/commands/site/site-set.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2262,6 +2262,33 @@ describe(commands.SITE_SET, () => {
assert.strictEqual(data.relativeLogoUrl, "/sites/logo/SiteAssets/parker-ms-1200.png");
});

it('applies site relative logo url from another site to the specified site', async () => {
let data: any = {};

sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === 'https://contoso.sharepoint.com/sites/logo/_api/site?$select=GroupId,Id') {
return {
Id: '255a50b2-527f-4413-8485-57f4c17a24d1',
GroupId: 'e10a459e-60c8-4000-8240-a68d6a12d39e'
};
}

throw 'Invalid request';
});

sinon.stub(request, 'post').callsFake(async (opts) => {
if (opts.url === 'https://contoso.sharepoint.com/sites/logo/_api/siteiconmanager/setsitelogo') {
data = opts.data;
return;
}

throw 'Invalid request';
});

await command.action(logger, { options: { url: 'https://contoso.sharepoint.com/sites/logo', siteLogoUrl: "/sites/another_site/SiteAssets/parker-ms-1200.png" } });
assert.strictEqual(data.relativeLogoUrl, "/sites/another_site/SiteAssets/parker-ms-1200.png");
});

it('applies site absolute logo url to the specified site', async () => {
let data: any = {};

Expand Down Expand Up @@ -2289,6 +2316,33 @@ describe(commands.SITE_SET, () => {
assert.strictEqual(data.relativeLogoUrl, "/sites/logo/SiteAssets/parker-ms-1200.png");
});

it('applies site absolute logo url from another site to the specified site', async () => {
let data: any = {};

sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === 'https://contoso.sharepoint.com/sites/logo/_api/site?$select=GroupId,Id') {
return {
Id: '255a50b2-527f-4413-8485-57f4c17a24d1',
GroupId: 'e10a459e-60c8-4000-8240-a68d6a12d39e'
};
}

throw 'Invalid request';
});

sinon.stub(request, 'post').callsFake(async (opts) => {
if (opts.url === 'https://contoso.sharepoint.com/sites/logo/_api/siteiconmanager/setsitelogo') {
data = opts.data;
return;
}

throw 'Invalid request';
});

await command.action(logger, { options: { url: 'https://contoso.sharepoint.com/sites/logo', siteLogoUrl: "https://contoso.sharepoint.com/sites/another_site/SiteAssets/parker-ms-1200.png" } });
assert.strictEqual(data.relativeLogoUrl, "/sites/another_site/SiteAssets/parker-ms-1200.png");
});

it('correctly handles unsetting the logo from the specified site', async () => {
let data: any = {};

Expand Down Expand Up @@ -2343,6 +2397,33 @@ describe(commands.SITE_SET, () => {
assert.strictEqual(data.relativeLogoUrl, "/sites/logo/SiteAssets/parker-ms-1200.png");
});

it('applies site relative thumbnail url from another site to the specified site', async () => {
let data: any = {};

sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === 'https://contoso.sharepoint.com/sites/logo/_api/site?$select=GroupId,Id') {
return {
Id: '255a50b2-527f-4413-8485-57f4c17a24d1',
GroupId: 'e10a459e-60c8-4000-8240-a68d6a12d39e'
};
}

throw 'Invalid request';
});

sinon.stub(request, 'post').callsFake(async (opts) => {
if (opts.url === 'https://contoso.sharepoint.com/sites/logo/_api/siteiconmanager/setsitelogo') {
data = opts.data;
return;
}

throw 'Invalid request';
});

await command.action(logger, { options: { url: 'https://contoso.sharepoint.com/sites/logo', siteThumbnailUrl: "/sites/another_site/SiteAssets/parker-ms-1200.png" } });
assert.strictEqual(data.relativeLogoUrl, "/sites/another_site/SiteAssets/parker-ms-1200.png");
});

it('applies site absolute thumbnail url to the specified site', async () => {
let data: any = {};

Expand Down Expand Up @@ -2370,6 +2451,33 @@ describe(commands.SITE_SET, () => {
assert.strictEqual(data.relativeLogoUrl, "/sites/logo/SiteAssets/parker-ms-1200.png");
});

it('applies site absolute thumbnail url from another site to the specified site', async () => {
let data: any = {};

sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === 'https://contoso.sharepoint.com/sites/logo/_api/site?$select=GroupId,Id') {
return {
Id: '255a50b2-527f-4413-8485-57f4c17a24d1',
GroupId: 'e10a459e-60c8-4000-8240-a68d6a12d39e'
};
}

throw 'Invalid request';
});

sinon.stub(request, 'post').callsFake(async (opts) => {
if (opts.url === 'https://contoso.sharepoint.com/sites/logo/_api/siteiconmanager/setsitelogo') {
data = opts.data;
return;
}

throw 'Invalid request';
});

await command.action(logger, { options: { url: 'https://contoso.sharepoint.com/sites/logo', siteThumbnailUrl: "https://contoso.sharepoint.com/sites/another_site/SiteAssets/parker-ms-1200.png" } });
assert.strictEqual(data.relativeLogoUrl, "/sites/another_site/SiteAssets/parker-ms-1200.png");
});

it('correctly handles unsetting the thumbnail from the specified site', async () => {
let data: any = {};

Expand Down
4 changes: 2 additions & 2 deletions src/m365/spo/commands/site/site-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class SpoSiteSetCommand extends SpoCommand {
await logger.logToStderr(`Setting the site its logo...`);
}

const logoUrl = args.options.siteLogoUrl ? urlUtil.getServerRelativePath(args.options.url, args.options.siteLogoUrl) : "";
const logoUrl = args.options.siteLogoUrl ? urlUtil.getUrlRelativePath(args.options.siteLogoUrl) : "";

const requestOptions: any = {
url: `${args.options.url}/_api/siteiconmanager/setsitelogo`,
Expand All @@ -337,7 +337,7 @@ class SpoSiteSetCommand extends SpoCommand {
await logger.logToStderr(`Setting the site thumbnail...`);
}

const thumbnailUrl = args.options.siteThumbnailUrl ? urlUtil.getServerRelativePath(args.options.url, args.options.siteThumbnailUrl) : "";
const thumbnailUrl = args.options.siteThumbnailUrl ? urlUtil.getUrlRelativePath(args.options.siteThumbnailUrl) : "";

const requestOptions: any = {
url: `${args.options.url}/_api/siteiconmanager/setsitelogo`,
Expand Down