Skip to content

Commit

Permalink
Resolves #3088 - Updated functions that call permission checks to use…
Browse files Browse the repository at this point in the history
… correct bucket id (#3089)

* Resolves #3088 - Updated functions that call permission checks to use correct bucket id
  • Loading branch information
alexcottner authored Dec 5, 2023
1 parent 68df14f commit 8ab0c6a
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/components/bucket/BucketForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/components/bucket/BucketPermissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function BucketPermissions() {
<PermissionsForm
permissions={permissions}
acls={acls}
readonly={!canEditBucket(session, bid)}
readonly={!canEditBucket(session, bucket.data.id)}
onSubmit={onSubmit}
/>
</BucketTabs>
Expand Down
6 changes: 5 additions & 1 deletion src/components/bucket/CollectionDataList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion src/components/bucket/GroupDataList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
3 changes: 2 additions & 1 deletion src/components/collection/CollectionPermissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface RouteParams {
export function CollectionPermissions() {
const { bid, cid } = useParams<RouteParams>();
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"];
Expand Down Expand Up @@ -49,7 +50,7 @@ export function CollectionPermissions() {
<PermissionsForm
permissions={permissions}
acls={acls}
readonly={!canEditCollection(session, bid, collection)}
readonly={!canEditCollection(session, bucket.data.id, collection)}
onSubmit={onSubmit}
/>
</CollectionTabs>
Expand Down
4 changes: 2 additions & 2 deletions src/components/collection/RecordTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="list-actions">
{canCreateRecord(session, bid, collection) && (
{canCreateRecord(session, bucket.data.id, collection) && (
<>
<AdminLink
key="__1"
Expand Down
3 changes: 2 additions & 1 deletion src/components/group/GroupPermissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useParams } from "react-router";

export function GroupPermissions() {
const group = useAppSelector(state => state.group);
const bucket = useAppSelector(state => state.bucket);
const { busy, permissions } = group;
const session = useAppSelector(state => state.session);
const { bid, gid } = useParams<GroupPermissionsRouteMatchParams>();
Expand Down Expand Up @@ -44,7 +45,7 @@ export function GroupPermissions() {
<PermissionsForm
permissions={permissions}
acls={["read", "write"]}
readonly={!canEditGroup(session, bid, group)}
readonly={!canEditGroup(session, bucket.data.id, group)}
onSubmit={onSubmit}
/>
</GroupTabs>
Expand Down
7 changes: 5 additions & 2 deletions src/components/record/RecordForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from "react";
import type {
BucketState,
SessionState,
CollectionState,
RecordState,
Expand Down Expand Up @@ -48,6 +49,7 @@ export function extendUiSchemaWhenDisabled(uiSchema: any, disabled: boolean) {

type Props = {
bid: string;
bucket: BucketState;
cid: string;
rid?: string;
session: SessionState;
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions test/components/bucket/CollectionDataList_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ describe("Bucket CollectionListActions", () => {
},
bucket: {
busy: false,
data: {
id: "test",
},
},
};

Expand Down
3 changes: 3 additions & 0 deletions test/components/bucket/GroupDataList_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ describe("Bucket GroupListActions", () => {
},
bucket: {
busy: false,
data: {
id: "test-bucket",
},
},
};

Expand Down

0 comments on commit 8ab0c6a

Please sign in to comment.