diff --git a/modules/setting/config.go b/modules/setting/config.go index 1391c37799..b09bbb0390 100644 --- a/modules/setting/config.go +++ b/modules/setting/config.go @@ -54,41 +54,16 @@ type RepositoryStruct struct { GitGuideRemoteName *config.Value[string] } -const ( - InstanceNoticeLevelInfo = "info" - InstanceNoticeLevelSuccess = "success" - InstanceNoticeLevelWarning = "warning" - InstanceNoticeLevelDanger = "danger" -) - type InstanceNotice struct { Enabled bool Message string - Level string StartTime int64 EndTime int64 } func DefaultInstanceNotice() InstanceNotice { - return InstanceNotice{ - Level: InstanceNoticeLevelInfo, - } -} - -func IsValidInstanceNoticeLevel(level string) bool { - switch level { - case InstanceNoticeLevelInfo, InstanceNoticeLevelSuccess, InstanceNoticeLevelWarning, InstanceNoticeLevelDanger: - return true - default: - return false - } -} - -func (n *InstanceNotice) Normalize() { - if !IsValidInstanceNoticeLevel(n.Level) { - n.Level = InstanceNoticeLevelInfo - } + return InstanceNotice{} } func (n *InstanceNotice) IsActive(now int64) bool { @@ -105,9 +80,7 @@ func (n *InstanceNotice) IsActive(now int64) bool { } func GetInstanceNotice(ctx context.Context) InstanceNotice { - notice := Config().InstanceNotice.Banner.Value(ctx) - notice.Normalize() - return notice + return Config().InstanceNotice.Banner.Value(ctx) } type InstanceNoticeStruct struct { diff --git a/options/locale/locale_en-US.json b/options/locale/locale_en-US.json index dd89976193..536616a54d 100644 --- a/options/locale/locale_en-US.json +++ b/options/locale/locale_en-US.json @@ -3283,11 +3283,6 @@ "admin.config.instance_notice.message": "Message", "admin.config.instance_notice.message_placeholder": "This message supports Markdown.", "admin.config.instance_notice.message_required": "Message is required when the banner is enabled.", - "admin.config.instance_notice.level": "Level", - "admin.config.instance_notice.level.info": "Info", - "admin.config.instance_notice.level.success": "Success", - "admin.config.instance_notice.level.warning": "Warning", - "admin.config.instance_notice.level.danger": "Danger", "admin.config.instance_notice.message_too_long": "Message must be at most %d characters.", "admin.config.instance_notice.start_time": "Start time", "admin.config.instance_notice.end_time": "End time", diff --git a/routers/web/admin/config.go b/routers/web/admin/config.go index b81af78ae6..05d6a110ff 100644 --- a/routers/web/admin/config.go +++ b/routers/web/admin/config.go @@ -213,7 +213,6 @@ func parseDatetimeLocalValue(raw string) (int64, error) { func SetInstanceNotice(ctx *context.Context) { saveInstanceNotice := func(instanceNotice setting.InstanceNotice) { - instanceNotice.Normalize() marshaled, err := json.Marshal(instanceNotice) if err != nil { ctx.ServerError("Marshal", err) @@ -240,7 +239,6 @@ func SetInstanceNotice(ctx *context.Context) { enabled := ctx.FormBool("enabled") message := strings.TrimSpace(ctx.FormString("message")) - level := strings.TrimSpace(ctx.FormString("level")) startTime, err := parseDatetimeLocalValue(strings.TrimSpace(ctx.FormString("start_time"))) if err != nil { ctx.Flash.Error(ctx.Tr("admin.config.instance_notice.invalid_time")) @@ -253,9 +251,6 @@ func SetInstanceNotice(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + "/-/admin/config#instance-notice") return } - if !setting.IsValidInstanceNoticeLevel(level) { - level = setting.InstanceNoticeLevelInfo - } if enabled && message == "" { ctx.Flash.Error(ctx.Tr("admin.config.instance_notice.message_required")) ctx.Redirect(setting.AppSubURL + "/-/admin/config#instance-notice") @@ -275,7 +270,6 @@ func SetInstanceNotice(ctx *context.Context) { instanceNotice := setting.InstanceNotice{ Enabled: enabled, Message: message, - Level: level, StartTime: startTime, EndTime: endTime, } diff --git a/tests/integration/instance_notice_test.go b/tests/integration/instance_notice_test.go index 1d8f4941fc..e9b3b41c0a 100644 --- a/tests/integration/instance_notice_test.go +++ b/tests/integration/instance_notice_test.go @@ -26,7 +26,6 @@ func TestInstanceNoticeVisibility(t *testing.T) { setInstanceNoticeForTest(t, setting.InstanceNotice{ Enabled: true, Message: "Planned **upgrade** in progress.", - Level: setting.InstanceNoticeLevelWarning, }) t.Run("AnonymousUserSeesBanner", func(t *testing.T) { @@ -60,7 +59,6 @@ func TestInstanceNoticeTimeWindow(t *testing.T) { setInstanceNoticeForTest(t, setting.InstanceNotice{ Enabled: true, Message: "Future banner", - Level: setting.InstanceNoticeLevelInfo, StartTime: now + 3600, EndTime: now + 7200, }) @@ -71,7 +69,6 @@ func TestInstanceNoticeTimeWindow(t *testing.T) { setInstanceNoticeForTest(t, setting.InstanceNotice{ Enabled: true, Message: "Expired banner", - Level: setting.InstanceNoticeLevelInfo, StartTime: now - 7200, EndTime: now - 3600, }) @@ -88,25 +85,21 @@ func TestInstanceNoticeAdminCRUD(t *testing.T) { req := NewRequestWithValues(t, "POST", "/-/admin/config/instance_notice", map[string]string{ "enabled": "true", "message": "Admin set banner", - "level": "danger", }) adminSession.MakeRequest(t, req, http.StatusSeeOther) notice := setting.GetInstanceNotice(t.Context()) assert.True(t, notice.Enabled) assert.Equal(t, "Admin set banner", notice.Message) - assert.Equal(t, setting.InstanceNoticeLevelDanger, notice.Level) req = NewRequestWithValues(t, "POST", "/-/admin/config/instance_notice", map[string]string{ "enabled": "true", "message": strings.Repeat("a", 2001), - "level": "warning", }) adminSession.MakeRequest(t, req, http.StatusSeeOther) notice = setting.GetInstanceNotice(t.Context()) assert.Equal(t, "Admin set banner", notice.Message) - assert.Equal(t, setting.InstanceNoticeLevelDanger, notice.Level) req = NewRequestWithValues(t, "POST", "/-/admin/config/instance_notice", map[string]string{ "action": "delete",