Skip to content
This repository has been archived by the owner on Nov 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #322 from adobe/issue-321
Browse files Browse the repository at this point in the history
fix: support custom sharepoint domain
  • Loading branch information
rofe authored Jul 8, 2022
2 parents cd2f435 + c0b885b commit ae0f620
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/sidekick/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
* @prop {string} owner The GitHub owner or organization (mandatory)
* @prop {string} repo The GitHub owner or organization (mandatory)
* @prop {string} ref=main The Git reference or branch (optional)
* @prop {string} mountpoint The content source URL (optional)
* @prop {string} project The name of the Helix project used in the sharing link (optional)
* @prop {plugin[]} plugins An array of plugin configurations (optional)
* @prop {string} outerHost The outer CDN's host name (optional)
Expand Down Expand Up @@ -249,17 +250,6 @@
*/
const DEV_URL = new URL('http://localhost:3000');

/**
* Checks if the current location is an editor URL (SharePoint or Google Docs).
* @private
* @param {Location} loc The location object
* @returns {boolean} <code>true</code> if editor URL, else <code>false</code>
*/
function isEditor(loc) {
return /.*\.sharepoint\.com/.test(loc.host)
|| loc.host === 'docs.google.com';
}

/**
* Retrieves Helix project details from a host name.
* @private
Expand Down Expand Up @@ -1994,7 +1984,10 @@
* @returns {boolean} <code>true</code> if editor URL, else <code>false</code>
*/
isEditor() {
return isEditor(this.location);
const { config, location } = this;
return /.*\.sharepoint\.com/.test(location.host)
|| location.host === 'docs.google.com'
|| (config.mountpoint && new URL(config.mountpoint).host === location.host);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,24 @@ describe('Test sidekick bookmarklet', () => {
assert.ok(notification.className.includes('modal-share-success'), 'Did not copy sharing URL to clipboard');
}).timeout(IT_DEFAULT_TIMEOUT);

it('Detects edit environment correctly', async () => {
const test = new SidekickTest({
page,
allowNavigation: true,
checkPage: async (p) => p.evaluate(() => window.hlx.sidekick.isEditor()),
});
// check with google docs url
const { checkPageResult: gdocsUrl } = await test.run('https://docs.google.com/document/d/1234567890/edit');
assert.ok(gdocsUrl, 'Did not detect google docs URL');
// check with sharepoint url
const { checkPageResult: standardSharepointUrl } = await test.run('https://adobe.sharepoint.com/:w:/r/sites/TheBlog/_layouts/15/Doc.aspx?sourcedoc=%7BE8EC80CB-24C3-4B95-B082-C51FD8BC8760%7D&file=bla.docx&action=default&mobileredirect=true');
assert.ok(standardSharepointUrl, 'Did not detect standard sharepoint URL');
// check again with custom sharepoint url as mountpoint
test.sidekickConfig.mountpoint = 'https://foo.custom/sites/foo/Shared%20Documents/root1';
const { checkPageResult: customSharepointUrl } = await test.run('https://foo.custom/:w:/r/sites/foo/_layouts/15/Doc.aspx?sourcedoc=%7BBFD9A19C-4A68-4DBF-8641-DA2F1283C895%7D&file=index.docx&action=default&mobileredirect=true');
assert.ok(customSharepointUrl, 'Did not detect custom sharepoint URL');
}).timeout(IT_DEFAULT_TIMEOUT);

it('Detects development environment correctly', async () => {
const { checkPageResult } = await new SidekickTest({
page,
Expand Down

0 comments on commit ae0f620

Please sign in to comment.