Don't show share link when team sharing disabled (#3714)
fix: Docs appear to be publicly shared when sharing previously enabled
This commit is contained in:
@@ -7,6 +7,7 @@ import Document from "~/models/Document";
|
|||||||
import Button from "~/components/Button";
|
import Button from "~/components/Button";
|
||||||
import Popover from "~/components/Popover";
|
import Popover from "~/components/Popover";
|
||||||
import Tooltip from "~/components/Tooltip";
|
import Tooltip from "~/components/Tooltip";
|
||||||
|
import useCurrentTeam from "~/hooks/useCurrentTeam";
|
||||||
import useStores from "~/hooks/useStores";
|
import useStores from "~/hooks/useStores";
|
||||||
import SharePopover from "./SharePopover";
|
import SharePopover from "./SharePopover";
|
||||||
|
|
||||||
@@ -17,10 +18,12 @@ type Props = {
|
|||||||
function ShareButton({ document }: Props) {
|
function ShareButton({ document }: Props) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { shares } = useStores();
|
const { shares } = useStores();
|
||||||
|
const team = useCurrentTeam();
|
||||||
const share = shares.getByDocumentId(document.id);
|
const share = shares.getByDocumentId(document.id);
|
||||||
const sharedParent = shares.getByDocumentParents(document.id);
|
const sharedParent = shares.getByDocumentParents(document.id);
|
||||||
const isPubliclyShared =
|
const isPubliclyShared =
|
||||||
share?.published || (sharedParent?.published && !document.isDraft);
|
team.sharing &&
|
||||||
|
(share?.published || (sharedParent?.published && !document.isDraft));
|
||||||
|
|
||||||
const popover = usePopoverState({
|
const popover = usePopoverState({
|
||||||
gutter: 0,
|
gutter: 0,
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import Input from "~/components/Input";
|
|||||||
import Notice from "~/components/Notice";
|
import Notice from "~/components/Notice";
|
||||||
import Switch from "~/components/Switch";
|
import Switch from "~/components/Switch";
|
||||||
import Text from "~/components/Text";
|
import Text from "~/components/Text";
|
||||||
|
import useCurrentTeam from "~/hooks/useCurrentTeam";
|
||||||
import useKeyDown from "~/hooks/useKeyDown";
|
import useKeyDown from "~/hooks/useKeyDown";
|
||||||
import usePolicy from "~/hooks/usePolicy";
|
import usePolicy from "~/hooks/usePolicy";
|
||||||
import useStores from "~/hooks/useStores";
|
import useStores from "~/hooks/useStores";
|
||||||
@@ -36,8 +37,9 @@ function SharePopover({
|
|||||||
onRequestClose,
|
onRequestClose,
|
||||||
visible,
|
visible,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
|
const team = useCurrentTeam();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { shares, auth } = useStores();
|
const { shares } = useStores();
|
||||||
const { showToast } = useToasts();
|
const { showToast } = useToasts();
|
||||||
const [isCopied, setIsCopied] = React.useState(false);
|
const [isCopied, setIsCopied] = React.useState(false);
|
||||||
const timeout = React.useRef<ReturnType<typeof setTimeout>>();
|
const timeout = React.useRef<ReturnType<typeof setTimeout>>();
|
||||||
@@ -47,22 +49,23 @@ function SharePopover({
|
|||||||
const canPublish =
|
const canPublish =
|
||||||
can.update &&
|
can.update &&
|
||||||
!document.isTemplate &&
|
!document.isTemplate &&
|
||||||
auth.team?.sharing &&
|
team.sharing &&
|
||||||
documentAbilities.share;
|
documentAbilities.share;
|
||||||
const isPubliclyShared =
|
const isPubliclyShared =
|
||||||
(share && share.published) ||
|
team.sharing &&
|
||||||
(sharedParent && sharedParent.published && !document.isDraft);
|
((share && share.published) ||
|
||||||
|
(sharedParent && sharedParent.published && !document.isDraft));
|
||||||
|
|
||||||
useKeyDown("Escape", onRequestClose);
|
useKeyDown("Escape", onRequestClose);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (visible) {
|
if (visible && team.sharing) {
|
||||||
document.share();
|
document.share();
|
||||||
buttonRef.current?.focus();
|
buttonRef.current?.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => (timeout.current ? clearTimeout(timeout.current) : undefined);
|
return () => (timeout.current ? clearTimeout(timeout.current) : undefined);
|
||||||
}, [document, visible]);
|
}, [document, visible, team.sharing]);
|
||||||
|
|
||||||
const handlePublishedChange = React.useCallback(
|
const handlePublishedChange = React.useCallback(
|
||||||
async (event) => {
|
async (event) => {
|
||||||
@@ -113,6 +116,9 @@ function SharePopover({
|
|||||||
|
|
||||||
const userLocale = useUserLocale();
|
const userLocale = useUserLocale();
|
||||||
const locale = userLocale ? dateLocale(userLocale) : undefined;
|
const locale = userLocale ? dateLocale(userLocale) : undefined;
|
||||||
|
const shareUrl = team.sharing
|
||||||
|
? share?.url ?? ""
|
||||||
|
: `${team.url}${document.url}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -199,14 +205,14 @@ function SharePopover({
|
|||||||
type="text"
|
type="text"
|
||||||
label={t("Link")}
|
label={t("Link")}
|
||||||
placeholder={`${t("Loading")}…`}
|
placeholder={`${t("Loading")}…`}
|
||||||
value={share ? share.url : ""}
|
value={shareUrl}
|
||||||
labelHidden
|
labelHidden
|
||||||
readOnly
|
readOnly
|
||||||
/>
|
/>
|
||||||
<CopyToClipboard text={share ? share.url : ""} onCopy={handleCopied}>
|
<CopyToClipboard text={shareUrl} onCopy={handleCopied}>
|
||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={isCopied || !share}
|
disabled={isCopied || (!share && team.sharing)}
|
||||||
ref={buttonRef}
|
ref={buttonRef}
|
||||||
primary
|
primary
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user