fix: inherit auth-headers closest to path bug

This commit is contained in:
nivedin
2023-12-13 14:00:19 +05:30
committed by Andrew Bastin
parent 80d54565eb
commit b3bef85b87
3 changed files with 67 additions and 11 deletions

View File

@@ -110,6 +110,46 @@ export function updateSaveContextForAffectedRequests(
}
}
/**
* Used to check the new folder path is close to the save context folder path or not
* @param folderPathCurrent The path saved as the inherited path in the inherited properties
* @param newFolderPath The incomming path
* @param saveContextPath The save context of the request
* @returns The path which is close to saveContext.folderPath
*/
function folderPathCloseToSaveContext(
folderPathCurrent: string | undefined,
newFolderPath: string,
saveContextPath: string
) {
if (!folderPathCurrent) return newFolderPath
const folderPathCurrentArray = folderPathCurrent.split("/")
const newFolderPathArray = newFolderPath.split("/")
const saveContextFolderPathArray = saveContextPath.split("/")
let folderPathCurrentMatch = 0
for (let i = 0; i < folderPathCurrentArray.length; i++) {
if (folderPathCurrentArray[i] === saveContextFolderPathArray[i]) {
folderPathCurrentMatch++
}
}
let newFolderPathMatch = 0
for (let i = 0; i < newFolderPathArray.length; i++) {
if (newFolderPathArray[i] === saveContextFolderPathArray[i]) {
newFolderPathMatch++
}
}
if (folderPathCurrentMatch > newFolderPathMatch) {
return folderPathCurrent
}
return newFolderPath
}
export function updateInheritedPropertiesForAffectedRequests(
path: string,
inheritedProperties: HoppInheritedProperty,
@@ -137,9 +177,28 @@ export function updateInheritedPropertiesForAffectedRequests(
}
const tabsEffectedByAuth = tabs.filter((tab) => {
if (workspace === "personal") {
return (
tab.value.document.saveContext?.originLocation === "user-collection" &&
tab.value.document.saveContext.folderPath.startsWith(path) &&
path ===
folderPathCloseToSaveContext(
tab.value.document.inheritedProperties?.auth.parentID,
path,
tab.value.document.saveContext.folderPath
)
)
}
return (
tab.value.document.inheritedProperties &&
tab.value.document.inheritedProperties.auth.parentID === path
tab.value.document.saveContext?.originLocation === "team-collection" &&
tab.value.document.saveContext.collectionID?.startsWith(path) &&
path ===
folderPathCloseToSaveContext(
tab.value.document.inheritedProperties?.auth.parentID,
path,
tab.value.document.saveContext.collectionID
)
)
})
@@ -163,9 +222,7 @@ export function updateInheritedPropertiesForAffectedRequests(
return {
...header,
inheritedHeader: inheritedProperties.headers.find(
(inheritedHeader) =>
inheritedHeader.inheritedHeader?.key ===
header.inheritedHeader?.key
(inheritedHeader) => inheritedHeader.parentID === path
)?.inheritedHeader,
}
}

View File

@@ -1080,7 +1080,7 @@ export default class NewTeamCollectionAdapter {
authType: "inherit",
authActive: true,
}
auth.parentID = folderPath ?? parentFolder.id
auth.parentID = [...path.slice(0, i + 1)].join("/")
auth.parentName = parentFolder.title
}
@@ -1091,7 +1091,7 @@ export default class NewTeamCollectionAdapter {
if (parentFolderAuth?.authType === "inherit" && path.length === 1) {
auth = {
parentID: folderPath ?? parentFolder.id,
parentID: [...path.slice(0, i + 1)].join("/"),
parentName: parentFolder.title,
inheritedAuth: auth.inheritedAuth,
}
@@ -1099,7 +1099,7 @@ export default class NewTeamCollectionAdapter {
if (parentFolderAuth?.authType !== "inherit") {
auth = {
parentID: folderPath ?? parentFolder.id,
parentID: [...path.slice(0, i + 1)].join("/"),
parentName: parentFolder.title,
inheritedAuth: parentFolderAuth,
}

View File

@@ -105,11 +105,10 @@ export function cascadeParentCollectionForHeaderAuth(
const parentFolderAuth = parentFolder.auth
const parentFolderHeaders = parentFolder.headers
// check if the parent folder has authType 'inherit' and if it is the root folder
if (parentFolderAuth?.authType === "inherit" && path.length === 1) {
auth = {
parentID: folderPath,
parentID: [...path.slice(0, i + 1)].join("/"),
parentName: parentFolder.name,
inheritedAuth: auth.inheritedAuth,
}
@@ -117,7 +116,7 @@ export function cascadeParentCollectionForHeaderAuth(
if (parentFolderAuth?.authType !== "inherit") {
auth = {
parentID: folderPath,
parentID: [...path.slice(0, i + 1)].join("/"),
parentName: parentFolder.name,
inheritedAuth: parentFolderAuth,
}