From 8ab0c6a0b9d02052a3ab321dfe8c918ce1df0546 Mon Sep 17 00:00:00 2001 From: Alex Cottner <148472676+alexcottner@users.noreply.github.com> Date: Tue, 5 Dec 2023 08:21:57 -0700 Subject: [PATCH] Resolves #3088 - Updated functions that call permission checks to use correct bucket id (#3089) * Resolves #3088 - Updated functions that call permission checks to use correct bucket id --- src/components/bucket/BucketForm.tsx | 2 +- src/components/bucket/BucketPermissions.tsx | 2 +- src/components/bucket/CollectionDataList.tsx | 6 +++++- src/components/bucket/GroupDataList.tsx | 2 +- src/components/collection/CollectionPermissions.tsx | 3 ++- src/components/collection/RecordTable.tsx | 4 ++-- src/components/group/GroupPermissions.tsx | 3 ++- src/components/record/RecordForm.tsx | 7 +++++-- test/components/bucket/CollectionDataList_test.js | 3 +++ test/components/bucket/GroupDataList_test.js | 3 +++ 10 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/components/bucket/BucketForm.tsx b/src/components/bucket/BucketForm.tsx index ddf5fe764..d510a2983 100644 --- a/src/components/bucket/BucketForm.tsx +++ b/src/components/bucket/BucketForm.tsx @@ -53,7 +53,7 @@ export default function BucketForm({ onSubmit, }: Props) { const creation = !formData.id; - const hasWriteAccess = canEditBucket(session, bid); + const hasWriteAccess = canEditBucket(session, bucket.data.id); const formIsEditable = creation || hasWriteAccess; const showDeleteForm = !creation && hasWriteAccess; diff --git a/src/components/bucket/BucketPermissions.tsx b/src/components/bucket/BucketPermissions.tsx index d181af312..f95af9f28 100644 --- a/src/components/bucket/BucketPermissions.tsx +++ b/src/components/bucket/BucketPermissions.tsx @@ -38,7 +38,7 @@ export function BucketPermissions() { diff --git a/src/components/bucket/CollectionDataList.tsx b/src/components/bucket/CollectionDataList.tsx index b53344e66..ff4aa2b44 100644 --- a/src/components/bucket/CollectionDataList.tsx +++ b/src/components/bucket/CollectionDataList.tsx @@ -9,7 +9,11 @@ import { canCreateCollection } from "../../permission"; export function ListActions(props) { const { bid, session, bucket } = props; - if (session.busy || bucket.busy || !canCreateCollection(session, bid)) { + if ( + session.busy || + bucket.busy || + !canCreateCollection(session, bucket.data.id) + ) { return null; } return ( diff --git a/src/components/bucket/GroupDataList.tsx b/src/components/bucket/GroupDataList.tsx index 9c6a017fa..01a45ef50 100644 --- a/src/components/bucket/GroupDataList.tsx +++ b/src/components/bucket/GroupDataList.tsx @@ -67,7 +67,7 @@ export function DataList(props) { } export function ListActions({ bid, session, bucket }) { - if (session.busy || bucket.busy || !canCreateGroup(session, bid)) { + if (session.busy || bucket.busy || !canCreateGroup(session, bucket.data.id)) { return null; } return ( diff --git a/src/components/collection/CollectionPermissions.tsx b/src/components/collection/CollectionPermissions.tsx index 92a43e03c..b1dd4858d 100644 --- a/src/components/collection/CollectionPermissions.tsx +++ b/src/components/collection/CollectionPermissions.tsx @@ -17,6 +17,7 @@ interface RouteParams { export function CollectionPermissions() { const { bid, cid } = useParams(); const session = useAppSelector(state => state.session); + const bucket = useAppSelector(state => state.bucket); const collection = useAppSelector(state => state.collection); const { busy, permissions } = collection; const acls = ["read", "write", "record:create"]; @@ -49,7 +50,7 @@ export function CollectionPermissions() { diff --git a/src/components/collection/RecordTable.tsx b/src/components/collection/RecordTable.tsx index 7abce177c..d33dbe020 100644 --- a/src/components/collection/RecordTable.tsx +++ b/src/components/collection/RecordTable.tsx @@ -17,13 +17,13 @@ import SignoffContainer from "../../containers/signoff/SignoffToolBar"; import { CommonProps } from "./commonPropTypes"; export function ListActions(props) { - const { bid, cid, session, collection } = props; + const { bid, cid, session, collection, bucket } = props; if (session.busy || collection.busy) { return null; } return (
- {canCreateRecord(session, bid, collection) && ( + {canCreateRecord(session, bucket.data.id, collection) && ( <> state.group); + const bucket = useAppSelector(state => state.bucket); const { busy, permissions } = group; const session = useAppSelector(state => state.session); const { bid, gid } = useParams(); @@ -44,7 +45,7 @@ export function GroupPermissions() { diff --git a/src/components/record/RecordForm.tsx b/src/components/record/RecordForm.tsx index 4618327f5..12788bcd7 100644 --- a/src/components/record/RecordForm.tsx +++ b/src/components/record/RecordForm.tsx @@ -1,5 +1,6 @@ import React, { useState } from "react"; import type { + BucketState, SessionState, CollectionState, RecordState, @@ -48,6 +49,7 @@ export function extendUiSchemaWhenDisabled(uiSchema: any, disabled: boolean) { type Props = { bid: string; + bucket: BucketState; cid: string; rid?: string; session: SessionState; @@ -71,11 +73,12 @@ export default function RecordForm(props: Props) { deleteRecord, onSubmit, capabilities, + bucket, } = props; const allowEditing = record - ? canEditRecord(session, bid, collection, record) - : canCreateRecord(session, bid, collection); + ? canEditRecord(session, bucket.data.id, collection, record) + : canCreateRecord(session, bucket.data.id, collection); const handleDeleteRecord = () => { const { rid } = props; diff --git a/test/components/bucket/CollectionDataList_test.js b/test/components/bucket/CollectionDataList_test.js index ab0ef108c..3fd8a398a 100644 --- a/test/components/bucket/CollectionDataList_test.js +++ b/test/components/bucket/CollectionDataList_test.js @@ -82,6 +82,9 @@ describe("Bucket CollectionListActions", () => { }, bucket: { busy: false, + data: { + id: "test", + }, }, }; diff --git a/test/components/bucket/GroupDataList_test.js b/test/components/bucket/GroupDataList_test.js index 6d9133da2..daf4c7b60 100644 --- a/test/components/bucket/GroupDataList_test.js +++ b/test/components/bucket/GroupDataList_test.js @@ -58,6 +58,9 @@ describe("Bucket GroupListActions", () => { }, bucket: { busy: false, + data: { + id: "test-bucket", + }, }, };