feat(system): support for disabling public memos (#1003)

* feat(system): support for disabling public memos

* fix(web/editor): set visibility to private on disabled public memos

* feat(server/memo): find/check if public memos are disabled

* fix(server/memo): handle error for finding system error

* fix(server/memo): unmarshal visiblity when getting system settings

* chore(web): move side effect imports to end

* Update memo.go

---------

Co-authored-by: boojack <stevenlgtm@gmail.com>
This commit is contained in:
Christopher
2023-02-13 17:07:31 +01:00
committed by GitHub
parent 28405f6d24
commit 4641e89c17
12 changed files with 158 additions and 36 deletions

View File

@ -5,11 +5,14 @@ import { useGlobalStore } from "../../store/module";
import * as api from "../../helpers/api";
import toastHelper from "../Toast";
import showUpdateCustomizedProfileDialog from "../UpdateCustomizedProfileDialog";
import { useAppDispatch } from "../../store";
import { setGlobalState } from "../../store/reducer/global";
import "@/less/settings/system-section.less";
interface State {
dbSize: number;
allowSignUp: boolean;
disablePublicMemos: boolean;
additionalStyle: string;
additionalScript: string;
}
@ -32,8 +35,11 @@ const SystemSection = () => {
allowSignUp: systemStatus.allowSignUp,
additionalStyle: systemStatus.additionalStyle,
additionalScript: systemStatus.additionalScript,
disablePublicMemos: systemStatus.disablePublicMemos,
});
const dispatch = useAppDispatch();
useEffect(() => {
globalStore.fetchSystemStatus();
}, []);
@ -44,6 +50,7 @@ const SystemSection = () => {
allowSignUp: systemStatus.allowSignUp,
additionalStyle: systemStatus.additionalStyle,
additionalScript: systemStatus.additionalScript,
disablePublicMemos: systemStatus.disablePublicMemos,
});
}, [systemStatus]);
@ -100,6 +107,19 @@ const SystemSection = () => {
});
};
const handleDisablePublicMemosChanged = async (value: boolean) => {
setState({
...state,
disablePublicMemos: value,
});
// Update global store immediately as MemoEditor/Selector is dependent on this value.
dispatch(setGlobalState({ systemStatus: { ...systemStatus, disablePublicMemos: value } }));
await api.upsertSystemSetting({
name: "disablePublicMemos",
value: JSON.stringify(value),
});
};
const handleSaveAdditionalScript = async () => {
try {
await api.upsertSystemSetting({
@ -133,6 +153,10 @@ const SystemSection = () => {
<span className="normal-text">{t("setting.system-section.allow-user-signup")}</span>
<Switch checked={state.allowSignUp} onChange={(event) => handleAllowSignUpChanged(event.target.checked)} />
</div>
<div className="form-label">
<span className="normal-text">{t("setting.system-section.disable-public-memos")}</span>
<Switch checked={state.disablePublicMemos} onChange={(event) => handleDisablePublicMemosChanged(event.target.checked)} />
</div>
<div className="form-label">
<span className="normal-text">{t("setting.system-section.additional-style")}</span>
<Button onClick={handleSaveAdditionalStyle}>{t("common.save")}</Button>