Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add ignore version upgrade setting #1491

Merged
merged 1 commit into from
Apr 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ type SystemStatus struct {
// System settings
// Allow sign up.
AllowSignUp bool `json:"allowSignUp"`
// Ignore upgrade
IgnoreUpgrade bool `json:"ignoreUpgrade"`
// Disable public memos.
DisablePublicMemos bool `json:"disablePublicMemos"`
// Additional style.
Expand Down
10 changes: 10 additions & 0 deletions api/system_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const (
SystemSettingSecretSessionName SystemSettingName = "secret-session"
// SystemSettingAllowSignUpName is the name of allow signup setting.
SystemSettingAllowSignUpName SystemSettingName = "allow-signup"
// SystemSettingIgnoreUpgradeName is the name of ignore upgrade.
SystemSettingIgnoreUpgradeName SystemSettingName = "ignore-upgrade"
// SystemSettingDisablePublicMemosName is the name of disable public memos setting.
SystemSettingDisablePublicMemosName SystemSettingName = "disable-public-memos"
// SystemSettingAdditionalStyleName is the name of additional style.
Expand Down Expand Up @@ -62,6 +64,8 @@ func (key SystemSettingName) String() string {
return "secret-session"
case SystemSettingAllowSignUpName:
return "allow-signup"
case SystemSettingIgnoreUpgradeName:
return "ignore-upgrade"
case SystemSettingDisablePublicMemosName:
return "disable-public-memos"
case SystemSettingAdditionalStyleName:
Expand Down Expand Up @@ -102,6 +106,12 @@ func (upsert SystemSettingUpsert) Validate() error {
if err != nil {
return fmt.Errorf("failed to unmarshal system setting allow signup value")
}
} else if upsert.Name == SystemSettingIgnoreUpgradeName {
value := false
err := json.Unmarshal([]byte(upsert.Value), &value)
if err != nil {
return fmt.Errorf("failed to unmarshal system setting ignore upgrade value")
}
} else if upsert.Name == SystemSettingDisablePublicMemosName {
value := false
err := json.Unmarshal([]byte(upsert.Value), &value)
Expand Down
3 changes: 3 additions & 0 deletions server/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
Profile: *s.Profile,
DBSize: 0,
AllowSignUp: false,
IgnoreUpgrade: false,
DisablePublicMemos: false,
AdditionalStyle: "",
AdditionalScript: "",
Expand Down Expand Up @@ -75,6 +76,8 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {

if systemSetting.Name == api.SystemSettingAllowSignUpName {
systemStatus.AllowSignUp = baseValue.(bool)
} else if systemSetting.Name == api.SystemSettingIgnoreUpgradeName {
systemStatus.IgnoreUpgrade = baseValue.(bool)
} else if systemSetting.Name == api.SystemSettingDisablePublicMemosName {
systemStatus.DisablePublicMemos = baseValue.(bool)
} else if systemSetting.Name == api.SystemSettingAdditionalStyleName {
Expand Down
17 changes: 17 additions & 0 deletions web/src/components/Settings/SystemSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "@/less/settings/system-section.less";
interface State {
dbSize: number;
allowSignUp: boolean;
ignoreUpgrade: boolean;
disablePublicMemos: boolean;
additionalStyle: string;
additionalScript: string;
Expand All @@ -31,6 +32,7 @@ const SystemSection = () => {
const [state, setState] = useState<State>({
dbSize: systemStatus.dbSize,
allowSignUp: systemStatus.allowSignUp,
ignoreUpgrade: systemStatus.ignoreUpgrade,
additionalStyle: systemStatus.additionalStyle,
additionalScript: systemStatus.additionalScript,
disablePublicMemos: systemStatus.disablePublicMemos,
Expand Down Expand Up @@ -75,6 +77,17 @@ const SystemSection = () => {
});
};

const handleIgnoreUpgradeChanged = async (value: boolean) => {
setState({
...state,
ignoreUpgrade: value,
});
await api.upsertSystemSetting({
name: "ignore-upgrade",
value: JSON.stringify(value),
});
};

const handleUpdateCustomizedProfileButtonClick = () => {
showUpdateCustomizedProfileDialog();
};
Expand Down Expand Up @@ -189,6 +202,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">Ignore version upgrade</span>
<Switch checked={state.ignoreUpgrade} onChange={(event) => handleIgnoreUpgradeChanged(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)} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface State {
show: boolean;
}

const UpdateVersionBanner: React.FC = () => {
const UpgradeVersionBanner: React.FC = () => {
const globalStore = useGlobalStore();
const profile = globalStore.state.systemStatus.profile;
const [state, setState] = useState<State>({
Expand All @@ -19,6 +19,10 @@ const UpdateVersionBanner: React.FC = () => {
});

useEffect(() => {
if (globalStore.state.systemStatus.ignoreUpgrade) {
return;
}

api.getRepoLatestTag().then((latestTag) => {
const { skippedVersion } = storage.get(["skippedVersion"]);
const latestVersion = latestTag.slice(1) || "0.0.0";
Expand Down Expand Up @@ -58,4 +62,4 @@ const UpdateVersionBanner: React.FC = () => {
);
};

export default UpdateVersionBanner;
export default UpgradeVersionBanner;
4 changes: 2 additions & 2 deletions web/src/layouts/Root.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Outlet } from "react-router-dom";
import Header from "@/components/Header";
import UpdateVersionBanner from "@/components/UpdateVersionBanner";
import UpgradeVersionBanner from "@/components/UpgradeVersionBanner";

function Root() {
return (
<div className="w-full min-h-full bg-zinc-100 dark:bg-zinc-800">
<div className="w-full h-auto flex flex-col justify-start items-center">
<UpdateVersionBanner />
<UpgradeVersionBanner />
</div>
<div className="w-full max-w-6xl mx-auto flex flex-row justify-center items-start">
<Header />
Expand Down
1 change: 1 addition & 0 deletions web/src/store/module/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const initialGlobalState = async () => {
appearance: "system" as Appearance,
systemStatus: {
allowSignUp: false,
ignoreUpgrade: false,
disablePublicMemos: false,
additionalStyle: "",
additionalScript: "",
Expand Down
1 change: 1 addition & 0 deletions web/src/store/reducer/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const globalSlice = createSlice({
},
dbSize: 0,
allowSignUp: false,
ignoreUpgrade: false,
disablePublicMemos: false,
additionalStyle: "",
additionalScript: "",
Expand Down
1 change: 1 addition & 0 deletions web/src/types/modules/system.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface SystemStatus {
dbSize: number;
// System settings
allowSignUp: boolean;
ignoreUpgrade: boolean;
disablePublicMemos: boolean;
additionalStyle: string;
additionalScript: string;
Expand Down