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