fix: inherit auth from ancestor bug
This commit is contained in:
@@ -194,6 +194,8 @@ import {
|
||||
import TeamCollectionAdapter from "~/helpers/teams/TeamCollectionAdapter"
|
||||
import {
|
||||
HoppCollection,
|
||||
HoppRESTAuth,
|
||||
HoppRESTHeaders,
|
||||
HoppRESTRequest,
|
||||
makeCollection,
|
||||
} from "@hoppscotch/data"
|
||||
@@ -290,7 +292,7 @@ const editingRequestIndex = ref<number | null>(null)
|
||||
const editingRequestID = ref<string | null>(null)
|
||||
|
||||
const editingProperties = ref<{
|
||||
collection: HoppCollection | TeamCollection | null
|
||||
collection: Omit<HoppCollection, "v"> | TeamCollection | null
|
||||
isRootCollection: boolean
|
||||
path: string
|
||||
inheritedProperties?: HoppInheritedProperty
|
||||
@@ -2011,7 +2013,7 @@ const editProperties = (payload: {
|
||||
parentID: "",
|
||||
parentName: "",
|
||||
inheritedAuth: {
|
||||
authType: "none",
|
||||
authType: "inherit",
|
||||
authActive: true,
|
||||
},
|
||||
},
|
||||
@@ -2045,17 +2047,21 @@ const editProperties = (payload: {
|
||||
} else if (hasTeamWriteAccess.value) {
|
||||
const parentIndex = collectionIndex.split("/").slice(0, -1).join("/") // remove last folder to get parent folder
|
||||
|
||||
const data = collection.data ? JSON.parse(collection.data) : null
|
||||
const data = (collection as TeamCollection).data
|
||||
? JSON.parse((collection as TeamCollection).data ?? "")
|
||||
: null
|
||||
|
||||
let inheritedProperties = {}
|
||||
let inheritedProperties = undefined
|
||||
let coll = {
|
||||
id: collection.id,
|
||||
name: collection.title,
|
||||
name: (collection as TeamCollection).title,
|
||||
auth: {
|
||||
authType: "none",
|
||||
authType: "inherit",
|
||||
authActive: true,
|
||||
},
|
||||
headers: [],
|
||||
} as HoppRESTAuth,
|
||||
headers: [] as HoppRESTHeaders,
|
||||
folders: null,
|
||||
requests: null,
|
||||
}
|
||||
|
||||
if (parentIndex) {
|
||||
@@ -2072,7 +2078,7 @@ const editProperties = (payload: {
|
||||
coll = {
|
||||
...coll,
|
||||
auth: data.auth,
|
||||
headers: data.headers,
|
||||
headers: data.headers as HoppRESTHeaders,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2124,11 +2130,11 @@ const setCollectionProperties = (newCollection: {
|
||||
(err: GQLError<string>) => {
|
||||
toast.error(`${getErrorMessage(err)}`)
|
||||
},
|
||||
() => {
|
||||
const { auth, headers } =
|
||||
teamCollectionAdapter.cascadeParentCollectionForHeaderAuth(path)
|
||||
|
||||
async () => {
|
||||
nextTick(() => {
|
||||
const { auth, headers } =
|
||||
teamCollectionAdapter.cascadeParentCollectionForHeaderAuth(path)
|
||||
|
||||
updateInheritedPropertiesForAffectedRequests(
|
||||
path,
|
||||
{
|
||||
|
||||
@@ -120,7 +120,6 @@ export function updateInheritedPropertiesForAffectedRequests(
|
||||
type === "rest" ? getService(RESTTabService) : getService(GQLTabService)
|
||||
|
||||
let tabs
|
||||
|
||||
if (workspace === "personal") {
|
||||
tabs = tabService.getTabsRefTo((tab) => {
|
||||
return (
|
||||
|
||||
@@ -1066,31 +1066,40 @@ export default class NewTeamCollectionAdapter {
|
||||
}
|
||||
|
||||
const data: {
|
||||
auth?: HoppRESTAuth
|
||||
headers?: HoppRESTHeader[]
|
||||
} = parentFolder.data ? JSON.parse(parentFolder.data) : null
|
||||
if (!data) return { auth, headers }
|
||||
auth: HoppRESTAuth
|
||||
headers: HoppRESTHeader[]
|
||||
} = parentFolder.data
|
||||
? JSON.parse(parentFolder.data)
|
||||
: {
|
||||
auth: null,
|
||||
headers: null,
|
||||
}
|
||||
|
||||
if (!data.auth) {
|
||||
data.auth = {
|
||||
authType: "inherit",
|
||||
authActive: true,
|
||||
}
|
||||
auth.parentID = folderPath ?? parentFolder.id
|
||||
auth.parentName = parentFolder.title
|
||||
}
|
||||
|
||||
if (!data.headers) data.headers = []
|
||||
|
||||
const parentFolderAuth = data.auth
|
||||
const parentFolderHeaders = data.headers
|
||||
|
||||
if (parentFolderAuth?.authType === "inherit") {
|
||||
if (parentFolderAuth?.authType === "inherit" && path.length === 1) {
|
||||
auth = {
|
||||
parentID: parentFolder.id ?? folderPath,
|
||||
parentID: folderPath ?? parentFolder.id,
|
||||
parentName: parentFolder.title,
|
||||
inheritedAuth: {
|
||||
authType: "none",
|
||||
authActive: true,
|
||||
},
|
||||
inheritedAuth: auth.inheritedAuth,
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
parentFolderAuth?.authType !== "inherit" &&
|
||||
parentFolderAuth?.authActive
|
||||
) {
|
||||
if (parentFolderAuth?.authType !== "inherit") {
|
||||
auth = {
|
||||
parentID: parentFolder.id ?? folderPath,
|
||||
parentID: folderPath ?? parentFolder.id,
|
||||
parentName: parentFolder.title,
|
||||
inheritedAuth: parentFolderAuth,
|
||||
}
|
||||
|
||||
@@ -74,8 +74,8 @@ export function cascadeParentCollectionForHeaderAuth(
|
||||
parentID: folderPath ?? "",
|
||||
parentName: "",
|
||||
inheritedAuth: {
|
||||
authType: "inherit",
|
||||
authActive: false,
|
||||
authType: "none",
|
||||
authActive: true,
|
||||
},
|
||||
}
|
||||
const headers: HoppInheritedProperty["headers"] = []
|
||||
@@ -106,14 +106,12 @@ export function cascadeParentCollectionForHeaderAuth(
|
||||
const parentFolderAuth = parentFolder.auth
|
||||
const parentFolderHeaders = parentFolder.headers
|
||||
|
||||
if (parentFolderAuth?.authType === "inherit") {
|
||||
// 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,
|
||||
parentName: parentFolder.name,
|
||||
inheritedAuth: {
|
||||
authType: "none",
|
||||
authActive: true,
|
||||
},
|
||||
inheritedAuth: auth.inheritedAuth,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user