From e3c706d280069e6063c19a821b1b8d1c8b8dc769 Mon Sep 17 00:00:00 2001 From: Steve McConnel Date: Tue, 16 Jan 2024 15:21:50 -0700 Subject: [PATCH] Require logging in for Grid draft and inCirculation columns (BL-12973) --- src/components/Grid/GridColumns.tsx | 3 +++ src/components/Grid/GridControlInternal.tsx | 23 +++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/components/Grid/GridColumns.tsx b/src/components/Grid/GridColumns.tsx index 823ac219..c0c9e326 100644 --- a/src/components/Grid/GridColumns.tsx +++ b/src/components/Grid/GridColumns.tsx @@ -20,6 +20,7 @@ import { BlorgLink } from "../BlorgLink"; export interface IGridColumn extends DevExpressColumn { moderatorOnly?: boolean; + loggedInOnly?: boolean; defaultVisible?: boolean; // A column definition specifies this if it needs a custom filter control getCustomFilterComponent?: FunctionComponent; @@ -222,6 +223,7 @@ export function getBookGridColumnsDefinitions(): IGridColumn[] { }, { name: "inCirculation", + loggedInOnly: true, sortingEnabled: false, // parse server doesn't seem to be able to sort on booleans? getCellValue: (b: Book) => (b.inCirculation ? "Yes" : "No"), getCustomFilterComponent: (props: TableFilterRow.CellProps) => ( @@ -235,6 +237,7 @@ export function getBookGridColumnsDefinitions(): IGridColumn[] { }, { name: "draft", + loggedInOnly: true, defaultVisible: false, sortingEnabled: false, // parse server doesn't seem to be able to sort on booleans? getCellValue: (b: Book) => (b.draft ? "Yes" : "No"), diff --git a/src/components/Grid/GridControlInternal.tsx b/src/components/Grid/GridControlInternal.tsx index 8201aedf..06683583 100644 --- a/src/components/Grid/GridControlInternal.tsx +++ b/src/components/Grid/GridControlInternal.tsx @@ -190,8 +190,12 @@ const GridControlInternal: React.FunctionComponent = observer useEffect(() => { setColumns( bookGridColumnDefinitions.filter( - // some columns we only include if we are logged in with the right permissions - (col) => !col.moderatorOnly || user?.moderator + // some columns we include only if we are logged in, or + // logged in with the right permissions + (col) => + user?.moderator || + (!col.moderatorOnly && !col.loggedInOnly) || + (!col.moderatorOnly && col.loggedInOnly && user) ) ); //setColumnNamesInDisplayOrder(bookGridColumns.map(c => c.name)); @@ -416,17 +420,24 @@ function CombineGridAndSearchBoxFilter( } } }); - // only moderators or uploaders can see draft books (BL-12973) + // only moderators or uploaders can see draft (or out-of-circulation) + // books (BL-12973) if (!user) { // if we don't know who the user is, we assume they are not a moderator f.draft = BooleanOptions.No; + f.inCirculation = BooleanOptions.Yes; } else if (!user.moderator) { - // if the user is not a moderator, allow draft books only if they - // are the uploader + // if the user is not a moderator, allow draft (or out-of-circulation) + // books only if they are the uploader f.anyOfThese = f.anyOfThese || []; - f.anyOfThese.push({ draft: BooleanOptions.No }); + f.anyOfThese.push({ + draft: BooleanOptions.No, + inCirculation: BooleanOptions.Yes, + }); f.anyOfThese.push({ search: `uploader:${user.email}`, + draft: BooleanOptions.All, + inCirculation: BooleanOptions.All, }); } return f;