Skip to content

Commit

Permalink
Enable Create Path button on BrowserBreadcrumbs if User can create su…
Browse files Browse the repository at this point in the history
…bPath (minio#3131)
  • Loading branch information
jinapurapu authored and cesnietor committed Jan 12, 2024
1 parent 563ae70 commit 4877edb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface ICreatePath {
folderName: string;
onClose: () => any;
simplePath: string | null;
limitedSubPath?: boolean;
}

const CreatePathModal = ({
Expand All @@ -46,6 +47,7 @@ const CreatePathModal = ({
bucketName,
onClose,
simplePath,
limitedSubPath,
}: ICreatePath) => {
const dispatch = useAppDispatch();
const navigate = useNavigate();
Expand Down Expand Up @@ -158,6 +160,11 @@ const CreatePathModal = ({
onChange={inputChange}
onKeyPress={keyPressed}
required
tooltip={
(limitedSubPath &&
"You may only have write access on a limited set of subpaths within this path. Please carefully review your User permissions to understand the paths to which you may write.") ||
""
}
/>
<Grid item xs={12} sx={modalStyleUtils.modalButtonBar}>
<Button
Expand Down
25 changes: 23 additions & 2 deletions portal-ui/src/screens/Console/ObjectBrowser/BrowserBreadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import React, { Fragment, useState } from "react";
import React, { Fragment, useEffect, useState } from "react";
import { useSelector } from "react-redux";
import CopyToClipboard from "react-copy-to-clipboard";
import styled from "styled-components";
Expand Down Expand Up @@ -91,6 +91,7 @@ const BrowserBreadcrumbs = ({
);

const [createFolderOpen, setCreateFolderOpen] = useState<boolean>(false);
const [canCreateSubpath, setCanCreateSubpath] = useState<boolean>(false);

const putObjectPermScopes = [
IAM_SCOPES.S3_PUT_OBJECT,
Expand All @@ -117,11 +118,22 @@ const BrowserBreadcrumbs = ({
putObjectPermScopes,
);

useEffect(() => {
setCanCreateSubpath(false);
Object.keys(sessionGrants).forEach((grant) => {
grant.includes(pathToCheckPerms) &&
grant.includes("/*") &&
setCanCreateSubpath(true);
});
}, [pathToCheckPerms, internalPaths, sessionGrants]);

const canCreatePath =
hasPermission(
[pathToCheckPerms, ...sessionGrantWildCards],
putObjectPermScopes,
) || anonymousMode;
) ||
anonymousMode ||
canCreateSubpath;

let breadcrumbsMap = splitPaths.map((objectItem: string, index: number) => {
const subSplit = `${splitPaths.slice(0, index + 1).join("/")}/`;
Expand Down Expand Up @@ -226,6 +238,15 @@ const BrowserBreadcrumbs = ({
bucketName={bucketName}
folderName={internalPaths}
onClose={closeAddFolderModal}
limitedSubPath={
canCreateSubpath &&
!(
hasPermission(
[pathToCheckPerms, ...sessionGrantWildCards],
putObjectPermScopes,
) || anonymousMode
)
}
/>
)}
<Breadcrumbs
Expand Down

0 comments on commit 4877edb

Please sign in to comment.