MM-56082 Add PreferencesHaveChanged plugin hook (#25659)

* Add interface for PreferencesHaveChanged hook

* Add context to preference-related methods of App

* Implement PreferencesHaveChanged

* Re-add missing "fmt" import

* Update minimum server version for the new hook

* Remove pointers to be consistent with other preference APIs
This commit is contained in:
Harrison Healey
2024-01-03 12:25:53 -05:00
committed by GitHub
parent 18f0d8d88f
commit 502cd6ef7d
19 changed files with 226 additions and 64 deletions

View File

@@ -31,7 +31,7 @@ func getPreferences(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
preferences, err := c.App.GetPreferencesForUser(c.Params.UserId)
preferences, err := c.App.GetPreferencesForUser(c.AppContext, c.Params.UserId)
if err != nil {
c.Err = err
return
@@ -53,7 +53,7 @@ func getPreferencesByCategory(c *Context, w http.ResponseWriter, r *http.Request
return
}
preferences, err := c.App.GetPreferenceByCategoryForUser(c.Params.UserId, c.Params.Category)
preferences, err := c.App.GetPreferenceByCategoryForUser(c.AppContext, c.Params.UserId, c.Params.Category)
if err != nil {
c.Err = err
return
@@ -75,7 +75,7 @@ func getPreferenceByCategoryAndName(c *Context, w http.ResponseWriter, r *http.R
return
}
preferences, err := c.App.GetPreferenceByCategoryAndNameForUser(c.Params.UserId, c.Params.Category, c.Params.PreferenceName)
preferences, err := c.App.GetPreferenceByCategoryAndNameForUser(c.AppContext, c.Params.UserId, c.Params.Category, c.Params.PreferenceName)
if err != nil {
c.Err = err
return
@@ -125,7 +125,7 @@ func updatePreferences(c *Context, w http.ResponseWriter, r *http.Request) {
sanitizedPreferences = append(sanitizedPreferences, pref)
}
if err := c.App.UpdatePreferences(c.Params.UserId, sanitizedPreferences); err != nil {
if err := c.App.UpdatePreferences(c.AppContext, c.Params.UserId, sanitizedPreferences); err != nil {
c.Err = err
return
}
@@ -154,7 +154,7 @@ func deletePreferences(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if err := c.App.DeletePreferences(c.Params.UserId, preferences); err != nil {
if err := c.App.DeletePreferences(c.AppContext, c.Params.UserId, preferences); err != nil {
c.Err = err
return
}

View File

@@ -203,7 +203,7 @@ func removeUserRecentCustomStatus(c *Context, w http.ResponseWriter, r *http.Req
return
}
if err := c.App.RemoveRecentCustomStatus(c.Params.UserId, &recentCustomStatus); err != nil {
if err := c.App.RemoveRecentCustomStatus(c.AppContext, c.Params.UserId, &recentCustomStatus); err != nil {
c.Err = err
return
}

View File

@@ -3089,7 +3089,7 @@ func TestGetUsersInGroupByDisplayName(t *testing.T) {
Value: model.ShowUsername,
}
err = th.App.UpdatePreferences(th.SystemAdminUser.Id, model.Preferences{preference})
err = th.App.UpdatePreferences(th.Context, th.SystemAdminUser.Id, model.Preferences{preference})
assert.Nil(t, err)
t.Run("Returns users in group in right order for username", func(t *testing.T) {
@@ -3099,7 +3099,7 @@ func TestGetUsersInGroupByDisplayName(t *testing.T) {
})
preference.Value = model.ShowNicknameFullName
err = th.App.UpdatePreferences(th.SystemAdminUser.Id, model.Preferences{preference})
err = th.App.UpdatePreferences(th.Context, th.SystemAdminUser.Id, model.Preferences{preference})
assert.Nil(t, err)
t.Run("Returns users in group in right order for nickname", func(t *testing.T) {