From 2ef1cfe1ea58c48d17fff1a78ea5e509107e92ae Mon Sep 17 00:00:00 2001 From: Dmitry Verkhoturov Date: Fri, 18 Feb 2022 22:48:30 +0100 Subject: [PATCH] fix logic of detecting deprecated notify type params --- backend/app/cmd/server.go | 10 +++++----- backend/app/cmd/server_test.go | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/backend/app/cmd/server.go b/backend/app/cmd/server.go index 454267c1d..8e74f956a 100644 --- a/backend/app/cmd/server.go +++ b/backend/app/cmd/server.go @@ -358,9 +358,9 @@ func (s *ServerCommand) HandleDeprecatedFlags() (result []DeprecatedFlag) { s.ImageProxy.HTTP2HTTPS = s.LegacyImageProxy result = append(result, DeprecatedFlag{Old: "img-proxy", New: "image-proxy.http2https", Version: "1.5"}) } - if len(s.Notify.Type) != 0 && // explicitly empty, would likely never happen due to "none" default - !(len(s.Notify.Type) == 1 && contains("none", s.Notify.Type)) && // ignore default, "none" notify type - (len(s.Notify.Users) != 0 || len(s.Notify.Admins) != 0) { // new notify param(s) are used, safe to ignore the old one + if !contains("none", s.Notify.Type) && + contains("none", s.Notify.Users) && + contains("none", s.Notify.Admins) { // if new notify param(s) are used, safe to ignore the old one s.handleDeprecatedNotifications() result = append(result, DeprecatedFlag{Old: "notify.type", New: "notify.(users|admins)", Version: "1.9"}) } @@ -404,8 +404,8 @@ func (s *ServerCommand) findDeprecatedFlagsCollisions() (result []DeprecatedFlag if s.Auth.Email.TimeOut != emailDefaultTimout && s.SMTP.TimeOut != emailDefaultTimout && s.Auth.Email.TimeOut != s.SMTP.TimeOut { result = append(result, DeprecatedFlag{Old: "auth.email.timeout", New: "smtp.timeout", Collision: true}) } - if !(len(s.Notify.Type) == 1 && contains("none", s.Notify.Type)) && // default, "none" notify type - (len(s.Notify.Users) != 0 || len(s.Notify.Admins) != 0) { // new notify param(s) are used, old ones will be ignored + if !contains("none", s.Notify.Type) && + (!contains("none", s.Notify.Users) || !contains("none", s.Notify.Admins)) { result = append(result, DeprecatedFlag{Old: "notify.type", New: "notify.(users|admins)", Collision: true}) } if stringsSetAndDifferent(s.Notify.Telegram.Token, s.Telegram.Token) { diff --git a/backend/app/cmd/server_test.go b/backend/app/cmd/server_test.go index 47db9612e..9214bb72b 100644 --- a/backend/app/cmd/server_test.go +++ b/backend/app/cmd/server_test.go @@ -412,6 +412,8 @@ func TestServerApp_DeprecatedArgs(t *testing.T) { "test", "--notify.type=email", "--notify.type=telegram", + "--notify.users=none", + "--notify.admins=none", "--img-proxy", "--notify.email.notify_admin", "--auth.email.host=smtp.example.org", @@ -446,7 +448,6 @@ func TestServerApp_DeprecatedArgs(t *testing.T) { {Old: "img-proxy", New: "image-proxy.http2https", Version: "1.5"}, {Old: "notify.email.notify_admin", New: "notify.admins=email", Version: "1.9"}, {Old: "notify.type", New: "notify.(users|admins)", Version: "1.9"}, - {Old: "notify.type", New: "notify.(users|admins)", Collision: true}, {Old: "notify.telegram.token", New: "telegram.token", Version: "1.9"}, {Old: "notify.telegram.timeout", New: "telegram.timeout", Version: "1.9"}, {Old: "notify.telegram.api", Version: "1.9"}, @@ -479,6 +480,7 @@ func TestServerApp_DeprecatedArgsCollisions(t *testing.T) { "--smtp.timeout=20s", "--notify.type=telegram", "--notify.users=telegram", + "--notify.admins=none", "--notify.telegram.token=abcd", "--telegram.token=dcba", "--notify.telegram.timeout=3m",