Skip to content

Commit

Permalink
fix(edit): properly remove notify defaults that aren't overriden
Browse files Browse the repository at this point in the history
was treating default notify's that got their type from their id as having overriden values,
so saved them to the service on edit
  • Loading branch information
JosephKav committed May 7, 2024
1 parent f18c10b commit a49939d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 7 additions & 5 deletions service/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,10 @@ func removeDefaults(oldService *Service, newService *Service, d *Defaults) {
if len(defaultNotifys) != len(usingNotifys) {
notifyDefaults = false
} else {
// Check that the keys are the same
// Check that the Notify's haven't changed (still match the defaults)
for i, notify := range usingNotifys {
if defaultNotifys[i] != notify || newService.Notify[notify].String("") != oldService.Notify[notify].String("") {
// Name has changed or now has values that override the defaults
if defaultNotifys[i] != notify || newService.Notify[notify].String("") != fmt.Sprintf("type: %s\n", newService.Notify[notify].Type) {
notifyDefaults = false
break
}
Expand All @@ -406,7 +407,7 @@ func removeDefaults(oldService *Service, newService *Service, d *Defaults) {
if len(newService.Command) != len(d.Command) {
commandDefaults = false
} else {
// Check that the commands are the defaults
// Check that the Commands haven't changed (still match the defaults)
for i, command := range d.Command {
if newService.Command[i].FormattedString() != command.FormattedString() {
commandDefaults = false
Expand All @@ -428,9 +429,10 @@ func removeDefaults(oldService *Service, newService *Service, d *Defaults) {
if len(defaultWebHooks) != len(usingWebHooks) {
webhookDefaults = false
} else {
// Check that the keys are the same
// Check that the WebHooks haven't changed (still match the defaults)
for i, webhook := range usingWebHooks {
if defaultWebHooks[i] != webhook || newService.WebHook[webhook].String() != oldService.WebHook[webhook].String() {
// Name has changed or now has values that override the defaults
if defaultWebHooks[i] != webhook || newService.WebHook[webhook].String() != fmt.Sprintf("type: %s\n", newService.WebHook[webhook].Type) {
webhookDefaults = false
break
}
Expand Down
7 changes: 6 additions & 1 deletion service/new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3307,6 +3307,10 @@ func TestRemoveDefaults(t *testing.T) {
"foo": shoutrrr.New(
nil, "foo", nil, nil,
"gotify",
nil, nil, nil, nil),
"gotify": shoutrrr.New(
nil, "bar", nil, nil,
"gotify",
nil, nil, nil, nil)},
Command: command.Slice{{"ls", "-lah"}},
WebHook: webhook.Slice{
Expand All @@ -3319,7 +3323,8 @@ func TestRemoveDefaults(t *testing.T) {
wasUsingWebHookDefaults: true,
d: &Defaults{
Notify: map[string]struct{}{
"foo": {}},
"foo": {},
"gotify": {}},
Command: command.Slice{{"ls", "-lah"}},
WebHook: map[string]struct{}{
"bar": {}}},
Expand Down

0 comments on commit a49939d

Please sign in to comment.