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

Delete subscription upon disconnecting user #42

Merged
merged 10 commits into from
Mar 31, 2020
25 changes: 25 additions & 0 deletions server/mscalendar/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
m.Logger.Errorf("failed to delete remote subscription %s. %s", eventSubscriptionID, err.Error())
}
}

return m.Store.DeleteUser(mattermostUserID)
}

Expand Down