Skip to content

Commit

Permalink
feat: support for multiple original sites (#835)
Browse files Browse the repository at this point in the history
  • Loading branch information
rofe authored Oct 15, 2024
1 parent fd17425 commit ea22ed5
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/extension/_locales/de/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@
"error_site_403": {
"message": "Zugriff verweigert. Versuchen Sie, sich mit einem anderen Benutzerkonto anzumelden, oder bitten Sie Ihre bzw. Ihren Admin um ausreichende Berechtigungen."
},
"error_status_400": {
"message": "400 – Ungültige Anfrage: Diese URL ist ungültig."
},
"error_status_403": {
"message": "403 Verboten: Bitten Sie Ihre bzw. Ihren Admin um ausreichende Berechtigungen."
},
Expand Down
3 changes: 3 additions & 0 deletions src/extension/_locales/es/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@
"error_site_403": {
"message": "Acceso denegado. Intente iniciar sesión con un usuario diferente o solicite al administrador los permisos necesarios."
},
"error_status_400": {
"message": "Error de solicitud 400: esta URL no es válida."
},
"error_status_403": {
"message": "403 Prohibido: Pídale al administrador permisos suficientes."
},
Expand Down
3 changes: 3 additions & 0 deletions src/extension/_locales/fr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@
"error_site_403": {
"message": "Accès refusé. Essayez de vous connecter avec une autre identité ou demandez à votre équipe d’administration des autorisations suffisantes."
},
"error_status_400": {
"message": "Demande incorrecte 400 : cette URL n’est pas valide."
},
"error_status_403": {
"message": "403 Accès interdit : demandez les autorisations nécessaires à votre administrateur ou à votre administratrice."
},
Expand Down
3 changes: 3 additions & 0 deletions src/extension/_locales/it/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@
"error_site_403": {
"message": "Accesso negato. Prova ad accedere con un altro utente o chiedi all’amministratore le autorizzazioni necessarie."
},
"error_status_400": {
"message": "400 - Richiesta non valida: questo URL non è valido."
},
"error_status_403": {
"message": "403 - Non consentito: chiedi all’amministratore le autorizzazioni necessarie."
},
Expand Down
3 changes: 3 additions & 0 deletions src/extension/_locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@
"error_site_403": {
"message": "アクセスが拒否されました。別のユーザーでログインするか、管理者に十分な権限を求めてください。"
},
"error_status_400": {
"message": "400 無効なリクエスト:この URL は無効です。"
},
"error_status_403": {
"message": "403 Forbidden:管理者に十分な許可を求めてください。"
},
Expand Down
3 changes: 3 additions & 0 deletions src/extension/_locales/ko/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@
"error_site_403": {
"message": "액세스가 거부되었습니다. 다른 사용자로 로그인을 시도하거나 관리자에게 권한을 요청하시기 바랍니다."
},
"error_status_400": {
"message": "400 잘못된 요청: 잘못된 URL입니다."
},
"error_status_403": {
"message": "403 금지됨: 관리자에게 충분한 권한을 요청하십시오."
},
Expand Down
3 changes: 3 additions & 0 deletions src/extension/_locales/pt_BR/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@
"error_site_403": {
"message": "Acesso negado. Tente fazer logon com um usuário diferente ou peça permissões suficientes à administração."
},
"error_status_400": {
"message": "400 Solicitação incorreta: este URL é inválido."
},
"error_status_403": {
"message": "403 Proibido: Solicite ao administrador as permissões necessárias."
},
Expand Down
3 changes: 3 additions & 0 deletions src/extension/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@
"error_site_403": {
"message": "访问被拒。请尝试以其他用户身份登录或向管理员申请足够的权限。"
},
"error_status_400": {
"message": "400 错误请求。该 URL 无效。"
},
"error_status_403": {
"message": "403 禁止:请向管理员请求足够的权限。"
},
Expand Down
7 changes: 5 additions & 2 deletions src/extension/_locales/zh_TW/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
"message": "大量作業失敗。請稍後再試。"
},
"bulk_error_illegal_file_name": {
"message": "檔案和資料夾名稱中僅允許使用標準化的小型拉丁字母、數字和連字號。以下路徑包含非法字元"
"message": "檔案和資料夾名稱中僅允許使用正規化的小寫拉丁字母、數字和連字號。以下路徑包含違規字元"
},
"bulk_error_illegal_file_names": {
"message": "檔案和資料夾名稱中僅允許使用標準化的小型拉丁字母、數字和連字號。以下路徑包含非法字元"
"message": "檔案和資料夾名稱中僅允許使用正規化的小寫拉丁字母、數字和連字號。以下路徑包含違規字元"
},
"bulk_error_preview_login_required": {
"message": "您必須登入才能產生超過 100 個檔案的預覽。"
Expand Down Expand Up @@ -407,6 +407,9 @@
"error_site_403": {
"message": "存取已遭拒。請嘗試使用不同的使用者登入,或向管理員要求足夠的權限。"
},
"error_status_400": {
"message": "400 錯誤的請求:此 URL 無效。"
},
"error_status_403": {
"message": "403 已禁止:請向管理員要求足夠的權限。"
},
Expand Down
27 changes: 18 additions & 9 deletions src/extension/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,17 +464,26 @@ export async function getProjectMatches(configs, tabUrl) {
});
}
}
if (matches.length === 0) {
const { org, site } = urlCache.length === 1
? urlCache[0] // use single match from url cache
: (urlCache.find((r) => r.originalSite) || {});
if (org && site) {
matches.push({
owner: org,
repo: site,
if (matches.length === 0 && urlCache.length >= 1) {
if (urlCache.length === 1) {
// use single match from url cache
const { org: owner, site: repo } = urlCache[0];
return [{
owner,
repo,
ref: 'main',
transient: true,
});
}];
} else {
// use all matches from url cache with originalSite flag
return urlCache
.filter((r) => r.originalSite)
.map(({ org: owner, site: repo }) => ({
owner,
repo,
ref: 'main',
transient: true,
}));
}
}
log.debug(`${matches.length} project match(es) found for ${tabUrl}`, matches);
Expand Down
13 changes: 8 additions & 5 deletions test/extension/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const CONFIGS = [
repo: 'bar3',
ref: 'main',
host: '3.foo.bar',
mountpoints: ['https://foo.sharepoint.com/something/boo/Shared%20Documents/root3'],
mountpoints: ['https://foo.sharepoint.com/something/boo/Shared%20Documents/root1'],
},
{
owner: 'foo',
Expand Down Expand Up @@ -260,7 +260,7 @@ describe('Test extension utils', () => {
it('queryUrlCache', async () => {
// known url
let results = await utils.queryUrlCache('https://foo.sharepoint.com/:w:/r/sites/foo/_layouts/15/Doc.aspx?sourcedoc=%7BBFD9A19C-4A68-4DBF-8641-DA2F1283C895%7D&file=index.docx&action=default&mobileredirect=true');
expect(results.length).to.equal(2);
expect(results.length).to.equal(3);
// unknown url
results = await utils.queryUrlCache('https://foo.sharepoint.com/:x:/r/sites/foo/_layouts/15/Doc.aspx?sourcedoc=%7ABFD9A19C-4A68-4DBF-8641-DA2F1283C895%7D&file=index.xlsx&action=default&mobileredirect=true');
expect(results.length).to.equal(0);
Expand All @@ -277,9 +277,9 @@ describe('Test extension utils', () => {

it('getProjectMatches', async () => {
// match sharepoint URL (docx)
expect((await utils.getProjectMatches(CONFIGS, 'https://foo.sharepoint.com/:w:/r/sites/foo/_layouts/15/Doc.aspx?sourcedoc=%7BBFD9A19C-4A68-4DBF-8641-DA2F1283C895%7D&file=index.docx&action=default&mobileredirect=true')).length).to.equal(1);
expect((await utils.getProjectMatches(CONFIGS, 'https://foo.sharepoint.com/:w:/r/sites/foo/_layouts/15/Doc.aspx?sourcedoc=%7BBFD9A19C-4A68-4DBF-8641-DA2F1283C895%7D&file=index.docx&action=default&mobileredirect=true')).length).to.equal(2);
// match gdrive URL
expect((await utils.getProjectMatches(CONFIGS, 'https://docs.google.com/document/d/1234567890/edit')).length).to.equal(1);
expect((await utils.getProjectMatches(CONFIGS, 'https://docs.google.com/document/d/1234567890/edit')).length).to.equal(2);
// match preview URL
expect((await utils.getProjectMatches(CONFIGS, 'https://main--bar1--foo.hlx.page/')).length).to.equal(1);
// match preview URL with any ref
Expand All @@ -293,8 +293,11 @@ describe('Test extension utils', () => {
// match production host
expect((await utils.getProjectMatches(CONFIGS, 'https://1.foo.bar/')).length).to.equal(1);
// match transient url
expect((await utils.getProjectMatches(CONFIGS, 'https://main--bar0--foo.hlx.live/')).length).to.equal(1);
expect((await utils.getProjectMatches([], 'https://main--bar1--foo.hlx.page/')).length).to.equal(1);
// match transient url from cache
await utils.populateUrlCache({ id: 0, url: 'https://foo.sharepoint.com/something/boo/Shared%20Documents/root1' });
expect((await utils.getProjectMatches([], 'https://foo.sharepoint.com/something/boo/Shared%20Documents/root1')).length).to.equal(2);
// match single url from cache
await utils.populateUrlCache({ id: 0, url: 'https://transient.foo.bar/' }, { owner: 'bar', repo: 'random' });
expect((await utils.getProjectMatches(CONFIGS, 'https://transient.foo.bar/')).length).to.equal(1);
// ignore disabled config
Expand Down
1 change: 1 addition & 0 deletions test/mocks/fetchMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const CONFIG_JSON = {
const DISCOVER_JSON = [
{ org: 'foo', site: 'bar1', originalSite: true },
{ org: 'foo', site: 'bar2', originalSite: false },
{ org: 'foo', site: 'bar3', originalSite: true },
];

const DRIVE_ITEM_JSON = {
Expand Down

0 comments on commit ea22ed5

Please sign in to comment.