From fea430b63adf18e55917681552976686b8b08aae Mon Sep 17 00:00:00 2001 From: Matthew Dorner Date: Tue, 3 Mar 2020 02:07:37 -0600 Subject: [PATCH 1/5] Delete subscription upon disconnecting user --- server/mscalendar/user.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/server/mscalendar/user.go b/server/mscalendar/user.go index d7ccd520..8f615c3f 100644 --- a/server/mscalendar/user.go +++ b/server/mscalendar/user.go @@ -94,6 +94,31 @@ func (user *User) Markdown() string { } func (m *mscalendar) DisconnectUser(mattermostUserID string) error { + err := m.Filter( + withClient, + ) + if err != nil { + return err + } + + storedUser, err := m.Store.LoadUser(mattermostUserID) + if err != nil { + return err + } + + eventSubscriptionID := storedUser.Settings.EventSubscriptionID + if eventSubscriptionID != "" { + err = m.Store.DeleteUserSubscription(storedUser, eventSubscriptionID) + if err != nil && err != store.ErrNotFound { + return errors.WithMessagef(err, "failed to delete subscription %s", eventSubscriptionID) + } + + err = m.client.DeleteSubscription(eventSubscriptionID) + if err != nil { + return errors.WithMessagef(err, "failed to delete subscription %s", eventSubscriptionID) + } + } + return m.Store.DeleteUser(mattermostUserID) } From e78b458bc9c49d5a76a9848821e9a64167cb3ea7 Mon Sep 17 00:00:00 2001 From: Matthew Dorner Date: Tue, 3 Mar 2020 02:26:43 -0600 Subject: [PATCH 2/5] Don't return err if remote deletion fails --- server/mscalendar/user.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/server/mscalendar/user.go b/server/mscalendar/user.go index 8f615c3f..9deb5476 100644 --- a/server/mscalendar/user.go +++ b/server/mscalendar/user.go @@ -113,10 +113,9 @@ func (m *mscalendar) DisconnectUser(mattermostUserID string) error { return errors.WithMessagef(err, "failed to delete subscription %s", eventSubscriptionID) } - err = m.client.DeleteSubscription(eventSubscriptionID) - if err != nil { - return errors.WithMessagef(err, "failed to delete subscription %s", eventSubscriptionID) - } + m.client.DeleteSubscription(eventSubscriptionID) + } else { + fmt.Println("there was no storedUser.Settings.EventSubscriptionID") } return m.Store.DeleteUser(mattermostUserID) From a7f18230eccd1aaeaa82e37b2412453f680f5050 Mon Sep 17 00:00:00 2001 From: Matthew Dorner Date: Tue, 3 Mar 2020 04:42:35 -0600 Subject: [PATCH 3/5] Remove debug statement --- server/mscalendar/user.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/server/mscalendar/user.go b/server/mscalendar/user.go index 9deb5476..64dd9051 100644 --- a/server/mscalendar/user.go +++ b/server/mscalendar/user.go @@ -114,8 +114,6 @@ func (m *mscalendar) DisconnectUser(mattermostUserID string) error { } m.client.DeleteSubscription(eventSubscriptionID) - } else { - fmt.Println("there was no storedUser.Settings.EventSubscriptionID") } return m.Store.DeleteUser(mattermostUserID) From 57c0a5260a4e0cf2d6552bf43e978c64337e4999 Mon Sep 17 00:00:00 2001 From: Matthew Dorner Date: Thu, 5 Mar 2020 16:13:37 -0600 Subject: [PATCH 4/5] Log error if remote sub deletion fails --- server/mscalendar/user.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/mscalendar/user.go b/server/mscalendar/user.go index 64dd9051..3804c377 100644 --- a/server/mscalendar/user.go +++ b/server/mscalendar/user.go @@ -113,7 +113,10 @@ func (m *mscalendar) DisconnectUser(mattermostUserID string) error { return errors.WithMessagef(err, "failed to delete subscription %s", eventSubscriptionID) } - m.client.DeleteSubscription(eventSubscriptionID) + err = m.client.DeleteSubscription(eventSubscriptionID) + if err != nil { + m.Logger.Errorf("failed to delete remote subscription %s. %s", eventSubscriptionID, err.Error()) + } } return m.Store.DeleteUser(mattermostUserID) From 324c448ededd817f509aafbb4b0515824438ea24 Mon Sep 17 00:00:00 2001 From: Matthew Dorner Date: Sun, 29 Mar 2020 08:18:53 -0500 Subject: [PATCH 5/5] Delete Daily Summary Settings --- server/mscalendar/user.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/mscalendar/user.go b/server/mscalendar/user.go index 3804c377..58b8bc9e 100644 --- a/server/mscalendar/user.go +++ b/server/mscalendar/user.go @@ -119,7 +119,17 @@ func (m *mscalendar) DisconnectUser(mattermostUserID string) error { } } - return m.Store.DeleteUser(mattermostUserID) + err = m.Store.DeleteUser(mattermostUserID) + if err != nil { + return err + } + + err = m.Store.DeleteDailySummarySettings(mattermostUserID) + if err != nil { + return err + } + + return nil } func (m *mscalendar) GetRemoteUser(mattermostUserID string) (*remote.User, error) {