From c85d9bcd84326ed9a9aa3a983196106bb6624037 Mon Sep 17 00:00:00 2001 From: pooja-bruno Date: Wed, 14 May 2025 16:01:42 +0530 Subject: [PATCH] fix: folder inherit auth --- .../FolderSettings/Auth/StyledWrapper.js | 3 + .../components/FolderSettings/Auth/index.js | 56 ++++++++++++++++++- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/packages/bruno-app/src/components/FolderSettings/Auth/StyledWrapper.js b/packages/bruno-app/src/components/FolderSettings/Auth/StyledWrapper.js index ecb0976df..e20fde667 100644 --- a/packages/bruno-app/src/components/FolderSettings/Auth/StyledWrapper.js +++ b/packages/bruno-app/src/components/FolderSettings/Auth/StyledWrapper.js @@ -11,6 +11,9 @@ const Wrapper = styled.div` border: solid 1px ${(props) => props.theme.input.border}; background-color: ${(props) => props.theme.input.bg}; } + .inherit-mode-text { + color: ${(props) => props.theme.colors.text.yellow}; + } `; export default Wrapper; \ No newline at end of file diff --git a/packages/bruno-app/src/components/FolderSettings/Auth/index.js b/packages/bruno-app/src/components/FolderSettings/Auth/index.js index 27cd03380..05bb49bbd 100644 --- a/packages/bruno-app/src/components/FolderSettings/Auth/index.js +++ b/packages/bruno-app/src/components/FolderSettings/Auth/index.js @@ -16,6 +16,7 @@ import NTLMAuth from 'components/RequestPane/Auth/NTLMAuth'; import WsseAuth from 'components/RequestPane/Auth/WsseAuth'; import ApiKeyAuth from 'components/RequestPane/Auth/ApiKeyAuth'; import AwsV4Auth from 'components/RequestPane/Auth/AwsV4Auth'; +import { findItemInCollection, findParentItemInCollection, humanizeRequestAuthMode } from 'utils/collections/index'; const GrantTypeComponentMap = ({ collection, folder }) => { const dispatch = useDispatch(); @@ -44,6 +45,49 @@ const Auth = ({ collection, folder }) => { let request = get(folder, 'root.request', {}); const authMode = get(folder, 'root.request.auth.mode'); + const getTreePathFromCollectionToFolder = (collection, _folder) => { + let path = []; + let item = findItemInCollection(collection, _folder?.uid); + while (item) { + path.unshift(item); + item = findParentItemInCollection(collection, item?.uid); + } + return path; + }; + + const getEffectiveAuthSource = () => { + if (authMode !== 'inherit') return null; + + const collectionAuth = get(collection, 'root.request.auth'); + let effectiveSource = { + type: 'collection', + name: 'Collection', + auth: collectionAuth + }; + + // Get path from collection to current folder + const folderTreePath = getTreePathFromCollectionToFolder(collection, folder); + + // Check parent folders to find closest auth configuration + // Skip the last item which is the current folder + for (let i = 0; i < folderTreePath.length - 1; i++) { + const parentFolder = folderTreePath[i]; + if (parentFolder.type === 'folder') { + const folderAuth = get(parentFolder, 'root.request.auth'); + if (folderAuth && folderAuth.mode && folderAuth.mode !== 'none' && folderAuth.mode !== 'inherit') { + effectiveSource = { + type: 'folder', + name: parentFolder.name, + auth: folderAuth + }; + break; + } + } + } + + return effectiveSource; + }; + const handleSave = () => { dispatch(saveFolderRoot(collection.uid, folder.uid)); }; @@ -141,10 +185,14 @@ const Auth = ({ collection, folder }) => { ); } case 'inherit': { + const source = getEffectiveAuthSource(); return ( -
- Authentication settings will be inherited from the collection. -
+ <> +
+
Auth inherited from {source.name}:
+
{humanizeRequestAuthMode(source.auth?.mode)}
+
+ ); } case 'none': { @@ -155,6 +203,8 @@ const Auth = ({ collection, folder }) => { } }; + console.log('folder', folder); + return (