Skip to content

Commit

Permalink
Merge pull request #533 from StephenMcConnel/BL-12973-RefineGridDispl…
Browse files Browse the repository at this point in the history
…ayMore

Require logging in for Grid draft and inCirculation columns (BL-12973)
  • Loading branch information
hatton authored Jan 16, 2024
2 parents ed524c2 + e3c706d commit e889d71
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/components/Grid/GridColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<TableFilterRow.CellProps>;
Expand Down Expand Up @@ -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) => (
Expand All @@ -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"),
Expand Down
23 changes: 17 additions & 6 deletions src/components/Grid/GridControlInternal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,12 @@ const GridControlInternal: React.FunctionComponent<IGridControlProps> = 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));
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e889d71

Please sign in to comment.