Skip to content

Commit

Permalink
[B] Correct reading group privacy checks
Browse files Browse the repository at this point in the history
  • Loading branch information
zdavis committed Feb 23, 2024
1 parent abca722 commit ba71802
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
21 changes: 15 additions & 6 deletions client/src/global/components/Annotation/Editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,26 @@ class AnnotationEditor extends PureComponent {
return this.props.t("navigation.reading_group.my_private_annotations");
}

get currentGroupObject() {
if (
this.props.currentAnnotatingReadingGroup === "public" ||
this.props.currentAnnotatingReadingGroup === "private" ||
!this.props.currentAnnotatingReadingGroup
)
return null;

return this.readingGroups.find(
group => group.id === this.props.currentAnnotatingReadingGroup
);
}

get currentGroupName() {
if (this.props.currentAnnotatingReadingGroup === "public")
return this.publicLabel;
if (this.props.currentAnnotatingReadingGroup === "private")
return this.privateLabel;

const currentGroup = this.readingGroups.find(
group => group.id === this.props.currentAnnotatingReadingGroup
);
const currentGroup = this.currentGroupObject;

if (!currentGroup) return this.setReadingGroup("private");
return currentGroup.attributes.name;
Expand All @@ -123,9 +134,7 @@ class AnnotationEditor extends PureComponent {
if (currentGroup === "private") return false;
if (currentGroup === "public") return true;

if (currentGroup?.attributes.privacy === "public") return true;

return false;
return this.currentGroupObject?.attributes.privacy === "public";
}

get disableSubmit() {
Expand Down
24 changes: 21 additions & 3 deletions client/src/reader/components/annotation/popup/menus/Main/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import { useTranslation } from "react-i18next";
import { useCurrentUser } from "hooks";
import PropTypes from "prop-types";
import Menu from "../../parts/Menu";
import MenuItems from "./Items";
Expand All @@ -21,6 +22,19 @@ function MainMenu({
...restProps
};
const { t } = useTranslation();
const currentUser = useCurrentUser();

const { readingGroups, currentReadingGroup } = itemProps;

// Users who are neither trusted nor established cannot create public annotations or highlights.
const isPublic =
currentReadingGroup === "public" ||
readingGroups.find(group => group.id === currentReadingGroup)?.attributes
?.privacy === "public";
const established = currentUser?.attributes.established;
const trusted = currentUser?.attributes.trusted;

const permitAnnotation = established || trusted || !isPublic;

return (
<Menu
Expand All @@ -33,9 +47,13 @@ function MainMenu({
onKeyDown={onKeyDown}
>
<MenuItems.Share {...itemProps} onClick={() => openSubmenu("share")} />
<MenuItems.Notate {...itemProps} />
<MenuItems.Annotate {...itemProps} />
<MenuItems.Highlight {...itemProps} />
{permitAnnotation && (
<>
<MenuItems.Notate {...itemProps} />
<MenuItems.Annotate {...itemProps} />
<MenuItems.Highlight {...itemProps} />
</>
)}
<MenuItems.CurrentReadingGroup
{...itemProps}
onClick={() => openSubmenu("readingGroup")}
Expand Down

0 comments on commit ba71802

Please sign in to comment.