diff --git a/packages/hoppscotch-common/src/components/collections/index.vue b/packages/hoppscotch-common/src/components/collections/index.vue index f0109c810..cc84061d4 100644 --- a/packages/hoppscotch-common/src/components/collections/index.vue +++ b/packages/hoppscotch-common/src/components/collections/index.vue @@ -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(null) const editingRequestID = ref(null) const editingProperties = ref<{ - collection: HoppCollection | TeamCollection | null + collection: Omit | 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) => { toast.error(`${getErrorMessage(err)}`) }, - () => { - const { auth, headers } = - teamCollectionAdapter.cascadeParentCollectionForHeaderAuth(path) - + async () => { nextTick(() => { + const { auth, headers } = + teamCollectionAdapter.cascadeParentCollectionForHeaderAuth(path) + updateInheritedPropertiesForAffectedRequests( path, { diff --git a/packages/hoppscotch-common/src/helpers/collection/collection.ts b/packages/hoppscotch-common/src/helpers/collection/collection.ts index 0defe1996..08804da6d 100644 --- a/packages/hoppscotch-common/src/helpers/collection/collection.ts +++ b/packages/hoppscotch-common/src/helpers/collection/collection.ts @@ -120,7 +120,6 @@ export function updateInheritedPropertiesForAffectedRequests( type === "rest" ? getService(RESTTabService) : getService(GQLTabService) let tabs - if (workspace === "personal") { tabs = tabService.getTabsRefTo((tab) => { return ( diff --git a/packages/hoppscotch-common/src/helpers/teams/TeamCollectionAdapter.ts b/packages/hoppscotch-common/src/helpers/teams/TeamCollectionAdapter.ts index 9bcddc022..ad2042721 100644 --- a/packages/hoppscotch-common/src/helpers/teams/TeamCollectionAdapter.ts +++ b/packages/hoppscotch-common/src/helpers/teams/TeamCollectionAdapter.ts @@ -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, } diff --git a/packages/hoppscotch-common/src/newstore/collections.ts b/packages/hoppscotch-common/src/newstore/collections.ts index 87458cc48..11efea540 100644 --- a/packages/hoppscotch-common/src/newstore/collections.ts +++ b/packages/hoppscotch-common/src/newstore/collections.ts @@ -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, } }