diff --git a/client/src/global/components/Annotation/Editor/index.js b/client/src/global/components/Annotation/Editor/index.js index 85e20976f7..6441b887c3 100644 --- a/client/src/global/components/Annotation/Editor/index.js +++ b/client/src/global/components/Annotation/Editor/index.js @@ -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; @@ -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() { diff --git a/client/src/reader/components/annotation/popup/menus/Main/index.js b/client/src/reader/components/annotation/popup/menus/Main/index.js index f2784e2e65..eb9a91b626 100644 --- a/client/src/reader/components/annotation/popup/menus/Main/index.js +++ b/client/src/reader/components/annotation/popup/menus/Main/index.js @@ -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"; @@ -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 (