[MM-44954] Regenerate default avatar (#22871)

* Regenerate default profile picture if username has changed

- Only actions is profile picture has not been changed
- Adjusts ResetLastPictureUpdate store function to store
-curTime instead of 0
    - This is to support updating the default picture while still
    retaining the ability to discern a default image from a set one.
- Changes SetDefaultProfileImage to leverage UpdateDefaultProfileImage
- Test updates around updating user default profile pictures

* App interface updates

* Only display picture update date if non-negative

- Ensures we don't display negative timestamps (default images)
- Change ported for mono-repo changes

* Remove duplicate test assertion

---------

Co-authored-by: Nathan Geist <ngeist@spiria.com>
Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Nathan
2023-05-04 08:14:26 -06:00
коммит произвёл GitHub
родитель 349e5d4573
Коммит 670b0e4c9f
8 изменённых файлов: 105 добавлений и 18 удалений

Просмотреть файл

@@ -3664,9 +3664,16 @@ func TestSetDefaultProfileImage(t *testing.T) {
defer th.TearDown()
user := th.BasicUser
startTime := model.GetMillis()
time.Sleep(time.Millisecond)
_, err := th.Client.SetDefaultProfileImage(user.Id)
require.NoError(t, err)
iuser, getUserErr := th.App.GetUser(user.Id)
require.Nil(t, getUserErr)
assert.Less(t, iuser.LastPictureUpdate, -startTime, "LastPictureUpdate should be set to -(current time in milliseconds)")
resp, err := th.Client.SetDefaultProfileImage(model.NewId())
require.Error(t, err)
CheckForbiddenStatus(t, resp)
@@ -3684,12 +3691,14 @@ func TestSetDefaultProfileImage(t *testing.T) {
require.Fail(t, "Should have failed either forbidden or unauthorized")
}
time.Sleep(time.Millisecond)
_, err = th.SystemAdminClient.SetDefaultProfileImage(user.Id)
require.NoError(t, err)
ruser, appErr := th.App.GetUser(user.Id)
require.Nil(t, appErr)
assert.Equal(t, int64(0), ruser.LastPictureUpdate, "Picture should have reset to default")
assert.Less(t, ruser.LastPictureUpdate, iuser.LastPictureUpdate, "LastPictureUpdate should be updated to a lower negative number")
info := &model.FileInfo{Path: "users/" + user.Id + "/profile.png"}
err = th.cleanupTestFile(info)