Skip to content

Commit

Permalink
feat: 20240418 release (#713)
Browse files Browse the repository at this point in the history
* fix: bulk selection in non-english sharepoint (#711)
* feat: reuse auth token within the same org (#712)
  • Loading branch information
rofe authored Apr 18, 2024
1 parent 9dfe593 commit d04d3d6
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ const externalActions = {
if (!url || new URL(url).origin !== 'https://admin.hlx.page') {
resp = 'unauthorized sender url';
} else if (authToken !== undefined && owner && repo) {
await storeAuthToken(owner, repo, authToken, exp);
await storeAuthToken(owner, authToken, exp);
resp = 'close';
}
} catch (e) {
Expand Down Expand Up @@ -638,8 +638,8 @@ const internalActions = {
chrome.runtime.onMessage.addListener(async ({ deleteAuthToken }, { tab }) => {
// check if message contains project config and is sent from tab
if (tab && tab.id && typeof deleteAuthToken === 'object') {
const { owner, repo } = deleteAuthToken;
await storeAuthToken(owner, repo, '');
const { owner } = deleteAuthToken;
await storeAuthToken(owner, '');
}
});

Expand Down
4 changes: 2 additions & 2 deletions src/extension/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -1654,8 +1654,8 @@ import sampleRUM from './rum.js';
.map((row) => {
const info = row.getAttribute('aria-label') || row.querySelector('span')?.textContent;
// info format: bla.docx, docx File, Private, Modified 8/28/2023, edited by Jane, 1 KB
const type = info.match(/, ([a-z0-9]+) File,/)?.[1];
const path = type && info.split(`, ${type} File,`)[0];
const type = info.match(/, ([a-z0-9]+) [A-Za-z]+,/)?.[1];
const path = type && info.split(`, ${type}`)[0];
return {
path,
type,
Expand Down
13 changes: 6 additions & 7 deletions src/extension/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ export async function updateAdminAuthHeaderRules() {
const projectConfigs = (await Promise.all(projects
.map((handle) => getConfig('session', handle))))
.filter((cfg) => !!cfg);
projectConfigs.forEach(({ owner, repo, authToken }) => {
projectConfigs.forEach(({ owner, authToken }) => {
if (authToken) {
addRules.push({
id,
Expand All @@ -825,14 +825,14 @@ export async function updateAdminAuthHeaderRules() {
}],
},
condition: {
regexFilter: `^https://admin.hlx.page/[a-z]+/${owner}/${repo}/.*`,
regexFilter: `^https://admin.hlx.page/[a-z]+/${owner}/.*`,
requestDomains: ['admin.hlx.page'],
requestMethods: ['get', 'post', 'delete'],
resourceTypes: ['xmlhttprequest'],
},
});
id += 1;
log.debug('added admin auth header rule for ', owner, repo);
log.debug('added admin auth header rule for ', owner);
}
});
if (addRules.length > 0) {
Expand All @@ -846,16 +846,15 @@ export async function updateAdminAuthHeaderRules() {
}
}

export async function storeAuthToken(owner, repo, token, exp) {
const handle = `${owner}/${repo}`;
export async function storeAuthToken(owner, token, exp) {
const handle = owner;
const projects = await getConfig('session', 'hlxSidekickProjects') || [];
const projectIndex = projects.indexOf(handle);
if (token) {
// store auth token in session storage
await setConfig('session', {
[handle]: {
owner,
repo,
authToken: token,
authTokenExpiry: exp ? exp * 1000 : 0, // store expiry in milliseconds
},
Expand All @@ -870,7 +869,7 @@ export async function storeAuthToken(owner, repo, token, exp) {
}
}
await setConfig('session', { hlxSidekickProjects: projects });
log.debug(`updated auth token for ${owner}--${repo}`);
log.debug(`updated auth token for ${owner}`);
// auth token changed, set/update admin auth header
updateAdminAuthHeaderRules();
}
11 changes: 5 additions & 6 deletions test/extension/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,21 +430,20 @@ describe('Test extension utils', () => {
const spy = sandbox.spy(window.chrome.storage.session, 'set');
const token = '1234';
const exp = (Date.now() / 1000) + 120;
await utils.storeAuthToken('foo', 'bar', token, exp);
await utils.storeAuthToken('foo', token, exp);
expect(spy.calledWith({
'foo/bar': {
foo: {
owner: 'foo',
repo: 'bar',
authToken: token,
authTokenExpiry: exp * 1000,
},
})).to.be.true;
expect(spy.calledWith({ hlxSidekickProjects: ['foo/bar'] })).to.be.true;
expect(spy.calledWith({ hlxSidekickProjects: ['foo'] })).to.be.true;
});

it('storeAuthToken (delete)', async () => {
const spy = sandbox.spy(window.chrome.storage.session, 'remove');
await utils.storeAuthToken('foo', 'bar', '');
expect(spy.calledWith('foo/bar')).to.be.true;
await utils.storeAuthToken('foo', '');
expect(spy.calledWith('foo')).to.be.true;
});
});
2 changes: 1 addition & 1 deletion test/fixtures/admin-sharepoint-grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<div data-automationid="name">file.pdf</div>
</div>
<div id="file-word" role="row" aria-selected="true">
<span>document.docx, docx File, Private</span>
<span>document.docx, docx Datei, Privat</span>
<i data-icon-name="svg/word_16x1.svg" aria-label="docx">
<img src="./icons/docx.svg">
</i>
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/admin-sharepoint.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<img src="./icons/icon.svg">
<button>file.pdf</button>
</div>
<div class="file" id="file-word" role="row" aria-selected="true" aria-label="document.docx, docx File, Private">
<div class="file" id="file-word" role="row" aria-selected="true" aria-label="document.docx, docx Datei, Privat">
<img src="./icons/docx.svg">
<button>document.docx</button>
</div>
Expand Down

0 comments on commit d04d3d6

Please sign in to comment.