mirror of
https://github.com/outline/outline.git
synced 2026-12-06 11:12:32 +03:00
* feat: Auto-save General and Profile settings, add settings sections - Save General and Profile fields on change and remove the Save button - Add SettingsSection with consistent spacing and a tinted Danger block - Right-align setting controls and center switches in their row - Let descriptions use the full row width beside switches * fix: Avoid settings autosave overwrites and IME Enter saves - Send only the changed team preference so concurrent saves do not revert each other - Save separate editing as a single preference instead of the whole team - Treat a cleared color input as empty so the default is restored - Ignore Enter during IME composition * feat: Add change and remove icon buttons below image inputs - Replace the Remove button with edit and trash icon buttons with tooltips - Show an upload icon on the image hover overlay - Re-render ImageInput when the image changes so the remove action appears immediately * feat: Use footer buttons in the change profile picture dialog - Add Replace and Delete buttons beside Done in the admin avatar dialog - Add showActions and an open handle to ImageInput so dialogs can supply their own controls * fix: Style the danger section with an outer shadow instead of tinted text
472 lines
14 KiB
TypeScript
472 lines
14 KiB
TypeScript
import { debounce } from "es-toolkit/compat";
|
|
import { observer } from "mobx-react";
|
|
import { ShieldIcon } from "outline-icons";
|
|
import { useState } from "react";
|
|
import * as React from "react";
|
|
import { useTranslation, Trans } from "react-i18next";
|
|
import { toast } from "sonner";
|
|
import { errToString } from "@shared/utils/error";
|
|
import { TeamValidation } from "@shared/validations";
|
|
import type { TeamPreferences, UserRole } from "@shared/types";
|
|
import { CommentingAccess, TeamPreference, EmailDisplay } from "@shared/types";
|
|
import ConfirmationDialog from "~/components/ConfirmationDialog";
|
|
import Heading from "~/components/Heading";
|
|
import type { Option } from "~/components/InputSelect";
|
|
import { InputSelect } from "~/components/InputSelect";
|
|
import Scene from "~/components/Scene";
|
|
import Switch from "~/components/Switch";
|
|
import Text from "~/components/Text";
|
|
import useCurrentTeam from "~/hooks/useCurrentTeam";
|
|
import usePolicy from "~/hooks/usePolicy";
|
|
import useStores from "~/hooks/useStores";
|
|
import isCloudHosted from "~/utils/isCloudHosted";
|
|
import SettingRow from "./components/SettingRow";
|
|
import { SettingsSection } from "./components/SettingsSection";
|
|
|
|
function Security() {
|
|
const { dialogs } = useStores();
|
|
const team = useCurrentTeam();
|
|
const { t } = useTranslation();
|
|
const can = usePolicy(team);
|
|
|
|
const [data, setData] = useState({
|
|
sharing: team.sharing,
|
|
defaultUserRole: team.defaultUserRole,
|
|
memberCollectionCreate: team.memberCollectionCreate,
|
|
memberTeamCreate: team.memberTeamCreate,
|
|
inviteRequired: team.inviteRequired,
|
|
});
|
|
|
|
const userRoleOptions: Option[] = React.useMemo(
|
|
() =>
|
|
[
|
|
{
|
|
type: "item",
|
|
label: t("Editor"),
|
|
value: "member",
|
|
},
|
|
{
|
|
type: "item",
|
|
label: t("Viewer"),
|
|
value: "viewer",
|
|
},
|
|
] satisfies Option[],
|
|
[t]
|
|
);
|
|
|
|
const emailDisplayOptions: Option[] = React.useMemo(
|
|
() =>
|
|
[
|
|
{
|
|
type: "item",
|
|
label: t("Members"),
|
|
value: EmailDisplay.Members,
|
|
},
|
|
{
|
|
type: "item",
|
|
label: t("Members and guests"),
|
|
value: EmailDisplay.Everyone,
|
|
},
|
|
{
|
|
type: "item",
|
|
label: t("No one"),
|
|
value: EmailDisplay.None,
|
|
},
|
|
] satisfies Option[],
|
|
[t]
|
|
);
|
|
|
|
const commentingOptions: Option[] = React.useMemo(
|
|
() =>
|
|
[
|
|
{
|
|
type: "item",
|
|
label: t("Members"),
|
|
value: CommentingAccess.Members,
|
|
},
|
|
{
|
|
type: "item",
|
|
label: t("Members and guests"),
|
|
value: CommentingAccess.Everyone,
|
|
},
|
|
{
|
|
type: "item",
|
|
label: t("No one"),
|
|
value: CommentingAccess.None,
|
|
},
|
|
] satisfies Option[],
|
|
[t]
|
|
);
|
|
|
|
const defaultShareExpiryOptions: Option[] = React.useMemo(
|
|
() =>
|
|
TeamValidation.defaultShareExpiryDays.map((count): Option => ({
|
|
type: "item",
|
|
label: count === 0 ? t("Never") : t("{{ count }} days", { count }),
|
|
value: String(count),
|
|
})),
|
|
[t]
|
|
);
|
|
|
|
const showSuccessMessage = React.useMemo(
|
|
() =>
|
|
debounce(() => {
|
|
toast.success(t("Settings saved"));
|
|
}, 250),
|
|
[t]
|
|
);
|
|
|
|
const saveData = React.useCallback(
|
|
async (
|
|
newData: Partial<typeof data> & { preferences?: TeamPreferences }
|
|
) => {
|
|
try {
|
|
setData((prev) => ({ ...prev, ...newData }));
|
|
await team.save(newData);
|
|
showSuccessMessage();
|
|
} catch (err) {
|
|
toast.error(errToString(err));
|
|
}
|
|
},
|
|
[team, showSuccessMessage]
|
|
);
|
|
|
|
const handleDefaultRoleChange = React.useCallback(
|
|
async (newDefaultRole: string) => {
|
|
await saveData({ defaultUserRole: newDefaultRole as UserRole });
|
|
},
|
|
[saveData]
|
|
);
|
|
|
|
const handleSharingChange = React.useCallback(
|
|
async (checked: boolean) => {
|
|
await saveData({ sharing: checked });
|
|
},
|
|
[saveData]
|
|
);
|
|
|
|
const handleMemberCollectionCreateChange = React.useCallback(
|
|
async (checked: boolean) => {
|
|
await saveData({ memberCollectionCreate: checked });
|
|
},
|
|
[saveData]
|
|
);
|
|
|
|
const handleMemberTeamCreateChange = React.useCallback(
|
|
async (checked: boolean) => {
|
|
await saveData({ memberTeamCreate: checked });
|
|
},
|
|
[saveData]
|
|
);
|
|
|
|
const handleMembersCanInviteChange = React.useCallback(
|
|
async (checked: boolean) => {
|
|
const preferences = {
|
|
...team.preferences,
|
|
[TeamPreference.MembersCanInvite]: checked,
|
|
};
|
|
await saveData({ preferences });
|
|
},
|
|
[saveData, team.preferences]
|
|
);
|
|
|
|
const handlePersonalDocsChange = React.useCallback(
|
|
async (checked: boolean) => {
|
|
const preferences = {
|
|
...team.preferences,
|
|
[TeamPreference.PersonalDocs]: checked,
|
|
};
|
|
await saveData({ preferences });
|
|
},
|
|
[saveData, team.preferences]
|
|
);
|
|
|
|
const handleViewersCanExportChange = React.useCallback(
|
|
async (checked: boolean) => {
|
|
const preferences = {
|
|
...team.preferences,
|
|
[TeamPreference.ViewersCanExport]: checked,
|
|
};
|
|
await saveData({ preferences });
|
|
},
|
|
[saveData, team.preferences]
|
|
);
|
|
|
|
const handleMembersCanDeleteAccountChange = React.useCallback(
|
|
async (checked: boolean) => {
|
|
const preferences = {
|
|
...team.preferences,
|
|
[TeamPreference.MembersCanDeleteAccount]: checked,
|
|
};
|
|
await saveData({ preferences });
|
|
},
|
|
[saveData, team.preferences]
|
|
);
|
|
|
|
const handleEmailDisplayChange = React.useCallback(
|
|
async (emailDisplay: string) => {
|
|
const preferences = {
|
|
...team.preferences,
|
|
[TeamPreference.EmailDisplay]: emailDisplay as EmailDisplay,
|
|
};
|
|
await saveData({ preferences });
|
|
},
|
|
[saveData, team.preferences]
|
|
);
|
|
|
|
const handleCommentingChange = React.useCallback(
|
|
async (commenting: string) => {
|
|
const preferences = {
|
|
...team.preferences,
|
|
[TeamPreference.Commenting]: commenting as CommentingAccess,
|
|
};
|
|
await saveData({ preferences });
|
|
},
|
|
[saveData, team.preferences]
|
|
);
|
|
|
|
const handleDefaultShareExpiryChange = React.useCallback(
|
|
async (days: string) => {
|
|
const preferences = {
|
|
...team.preferences,
|
|
[TeamPreference.DefaultShareExpiryDays]: Number(days),
|
|
};
|
|
await saveData({ preferences });
|
|
},
|
|
[saveData, team.preferences]
|
|
);
|
|
|
|
const handleInviteRequiredChange = React.useCallback(
|
|
async (checked: boolean) => {
|
|
const inviteRequired = checked;
|
|
const newData = { ...data, inviteRequired };
|
|
|
|
if (inviteRequired) {
|
|
dialogs.openModal({
|
|
title: t("Are you sure you want to require invites?"),
|
|
content: (
|
|
<ConfirmationDialog
|
|
onSubmit={async () => {
|
|
await saveData(newData);
|
|
}}
|
|
savingText={`${t("Saving")}…`}
|
|
danger
|
|
>
|
|
<Trans
|
|
defaults="New users will first need to be invited to create an account. <em>Default role</em> and <em>Allowed domains</em> will no longer apply."
|
|
values={{
|
|
authenticationMethods: team.signinMethods,
|
|
}}
|
|
components={{
|
|
em: <strong />,
|
|
}}
|
|
/>
|
|
</ConfirmationDialog>
|
|
),
|
|
});
|
|
} else {
|
|
await saveData(newData);
|
|
}
|
|
},
|
|
[data, saveData, t, dialogs, team.signinMethods]
|
|
);
|
|
|
|
return (
|
|
<Scene title={t("Security")} icon={<ShieldIcon />}>
|
|
<Heading>{t("Security")}</Heading>
|
|
<Text as="p" type="secondary">
|
|
<Trans>
|
|
Settings that impact the access, security, and content of your
|
|
workspace.
|
|
</Trans>
|
|
</Text>
|
|
|
|
<SettingsSection title={t("Invites")}>
|
|
<SettingRow
|
|
label={t("Allow users to send invites")}
|
|
name={TeamPreference.MembersCanInvite}
|
|
description={t(
|
|
"Allow editors to invite other people to the workspace"
|
|
)}
|
|
>
|
|
<Switch
|
|
id={TeamPreference.MembersCanInvite}
|
|
checked={team.getPreference(TeamPreference.MembersCanInvite)}
|
|
onChange={handleMembersCanInviteChange}
|
|
/>
|
|
</SettingRow>
|
|
{isCloudHosted && (
|
|
<SettingRow
|
|
label={t("Require invites")}
|
|
name="inviteRequired"
|
|
description={t(
|
|
"Require members to be invited to the workspace before they can create an account using SSO."
|
|
)}
|
|
>
|
|
<Switch
|
|
id="inviteRequired"
|
|
checked={data.inviteRequired}
|
|
onChange={handleInviteRequiredChange}
|
|
/>
|
|
</SettingRow>
|
|
)}
|
|
|
|
{!data.inviteRequired && (
|
|
<SettingRow
|
|
label={t("Default role")}
|
|
name="defaultUserRole"
|
|
description={t(
|
|
"The default user role for new accounts. Changing this setting does not affect existing user accounts."
|
|
)}
|
|
>
|
|
<InputSelect
|
|
value={data.defaultUserRole}
|
|
options={userRoleOptions}
|
|
onChange={handleDefaultRoleChange}
|
|
label={t("Default role")}
|
|
labelHidden
|
|
short
|
|
/>
|
|
</SettingRow>
|
|
)}
|
|
</SettingsSection>
|
|
|
|
<SettingsSection title={t("Behavior")}>
|
|
<SettingRow
|
|
label={t("Public document sharing")}
|
|
name="sharing"
|
|
description={t(
|
|
"When enabled, documents can be shared publicly on the internet by any member of the workspace"
|
|
)}
|
|
>
|
|
<Switch
|
|
id="sharing"
|
|
checked={data.sharing}
|
|
onChange={handleSharingChange}
|
|
/>
|
|
</SettingRow>
|
|
{can.setDefaultShareExpiry && (
|
|
<SettingRow
|
|
label={t("Default link expiration")}
|
|
name={TeamPreference.DefaultShareExpiryDays}
|
|
description={t(
|
|
"New public links will expire after this period. Existing links are not affected."
|
|
)}
|
|
>
|
|
<InputSelect
|
|
value={String(
|
|
team.getPreference(TeamPreference.DefaultShareExpiryDays)
|
|
)}
|
|
options={defaultShareExpiryOptions}
|
|
onChange={handleDefaultShareExpiryChange}
|
|
label={t("Default link expiration")}
|
|
labelHidden
|
|
short
|
|
/>
|
|
</SettingRow>
|
|
)}
|
|
<SettingRow
|
|
label={t("Viewer document exports")}
|
|
name={TeamPreference.ViewersCanExport}
|
|
description={t(
|
|
"When enabled, viewers can see download options for documents"
|
|
)}
|
|
>
|
|
<Switch
|
|
id={TeamPreference.ViewersCanExport}
|
|
checked={team.getPreference(TeamPreference.ViewersCanExport)}
|
|
onChange={handleViewersCanExportChange}
|
|
/>
|
|
</SettingRow>
|
|
<SettingRow
|
|
label={t("Users can delete account")}
|
|
name={TeamPreference.MembersCanDeleteAccount}
|
|
description={t(
|
|
"When enabled, users can delete their own account from the workspace"
|
|
)}
|
|
>
|
|
<Switch
|
|
id={TeamPreference.MembersCanDeleteAccount}
|
|
checked={team.getPreference(TeamPreference.MembersCanDeleteAccount)}
|
|
onChange={handleMembersCanDeleteAccountChange}
|
|
/>
|
|
</SettingRow>
|
|
<SettingRow
|
|
label={t("Email address visibility")}
|
|
name={TeamPreference.EmailDisplay}
|
|
description={t(
|
|
"Controls who can see user email addresses in the workspace"
|
|
)}
|
|
>
|
|
<InputSelect
|
|
value={team.getPreference(TeamPreference.EmailDisplay) as string}
|
|
options={emailDisplayOptions}
|
|
onChange={handleEmailDisplayChange}
|
|
label={t("Email address visibility")}
|
|
labelHidden
|
|
short
|
|
/>
|
|
</SettingRow>
|
|
<SettingRow
|
|
label={t("Commenting")}
|
|
name={TeamPreference.Commenting}
|
|
description={t("Controls who can add comments to documents")}
|
|
>
|
|
<InputSelect
|
|
value={
|
|
team.getPreference(TeamPreference.Commenting) ||
|
|
CommentingAccess.Members
|
|
}
|
|
options={commentingOptions}
|
|
onChange={handleCommentingChange}
|
|
label={t("Commenting")}
|
|
labelHidden
|
|
short
|
|
/>
|
|
</SettingRow>
|
|
<SettingRow
|
|
label={t("Personal documents")}
|
|
name={TeamPreference.PersonalDocs}
|
|
description={t(
|
|
"Allow editors to create personal documents that are only visible to themselves and the people they share them with"
|
|
)}
|
|
>
|
|
<Switch
|
|
id={TeamPreference.PersonalDocs}
|
|
checked={team.getPreference(TeamPreference.PersonalDocs)}
|
|
onChange={handlePersonalDocsChange}
|
|
/>
|
|
</SettingRow>
|
|
<SettingRow
|
|
label={t("Collection creation")}
|
|
name="memberCollectionCreate"
|
|
description={t(
|
|
"Allow editors to create new collections within the workspace"
|
|
)}
|
|
>
|
|
<Switch
|
|
id="memberCollectionCreate"
|
|
checked={data.memberCollectionCreate}
|
|
onChange={handleMemberCollectionCreateChange}
|
|
/>
|
|
</SettingRow>
|
|
{isCloudHosted && (
|
|
<SettingRow
|
|
label={t("Workspace creation")}
|
|
name="memberTeamCreate"
|
|
description={t("Allow editors to create new workspaces")}
|
|
>
|
|
<Switch
|
|
id="memberTeamCreate"
|
|
checked={data.memberTeamCreate}
|
|
onChange={handleMemberTeamCreateChange}
|
|
/>
|
|
</SettingRow>
|
|
)}
|
|
</SettingsSection>
|
|
</Scene>
|
|
);
|
|
}
|
|
|
|
export default observer(Security);
|