Skip to content

Commit

Permalink
Merge pull request BloomBooks#532 from StephenMcConnel/BL-12973-HideD…
Browse files Browse the repository at this point in the history
…raftInGridFromNonStaff

Draft books are visible only to staff in the grid page (BL-12973)
  • Loading branch information
andrew-polk authored Jan 12, 2024
2 parents 8ecbc00 + 58c0902 commit ed524c2
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/components/Grid/GridControlInternal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import { getBookGridColumnsDefinitions, IGridColumn } from "./GridColumns";
import { useStorageState } from "react-storage-hooks";
import { Book } from "../../model/Book";
import StaffPanel from "../Admin/StaffPanel";
import { useGetLoggedInUser } from "../../connection/LoggedInUser";
import { useGetLoggedInUser, User } from "../../connection/LoggedInUser";
import { observer } from "mobx-react-lite";
import { IGridControlProps } from "./GridControl";
import { CachedTablesContext } from "../../model/CacheProvider";
Expand Down Expand Up @@ -144,7 +144,8 @@ const GridControlInternal: React.FunctionComponent<IGridControlProps> = observer
bookGridColumnDefinitions,
gridFilters,
props.contextFilter || {},
languages
languages,
user
);

if (props.setCurrentFilter) {
Expand Down Expand Up @@ -347,7 +348,8 @@ function CombineGridAndSearchBoxFilter(
bookGridColumns: IGridColumn[],
gridFilters: GridFilter[],
routerFilter: IFilter,
languages: ILanguage[]
languages: ILanguage[],
user: User | undefined
): IFilter {
// The result of the search box is encoded. We need it decoded in order to search correctly
// (e.g.) on things like "topic:math", where the colon would be encoded otherwise.
Expand Down Expand Up @@ -414,6 +416,19 @@ function CombineGridAndSearchBoxFilter(
}
}
});
// only moderators or uploaders can see draft 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;
} else if (!user.moderator) {
// if the user is not a moderator, allow draft books only if they
// are the uploader
f.anyOfThese = f.anyOfThese || [];
f.anyOfThese.push({ draft: BooleanOptions.No });
f.anyOfThese.push({
search: `uploader:${user.email}`,
});
}
return f;
}

Expand Down

0 comments on commit ed524c2

Please sign in to comment.