MM-57824: Export/import custom status (#27361)

https://mattermost.atlassian.net/browse/MM-57824
```release-note
NONE
```

Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
Agniva De Sarker 2024-07-08 09:41:25 +05:30 committed by GitHub
parent b596430920
commit db45c0132e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 52 additions and 1 deletions

View File

@ -469,6 +469,11 @@ func (a *App) exportAllUsers(ctx request.CTX, job *model.Job, writer io.Writer,
userLine.User.NotifyProps = a.buildUserNotifyProps(user.NotifyProps) userLine.User.NotifyProps = a.buildUserNotifyProps(user.NotifyProps)
// Adding custom status
if cs := user.GetCustomStatus(); cs != nil {
userLine.User.CustomStatus = cs
}
// Do the Team Memberships. // Do the Team Memberships.
members, err := a.buildUserTeamAndChannelMemberships(ctx, user.Id, includeArchivedChannels) members, err := a.buildUserTeamAndChannelMemberships(ctx, user.Id, includeArchivedChannels)
if err != nil { if err != nil {

View File

@ -10,6 +10,7 @@ import (
"path/filepath" "path/filepath"
"sort" "sort"
"testing" "testing"
"time"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -574,6 +575,40 @@ func TestExportPostWithProps(t *testing.T) {
assert.Contains(t, posts[1].Props["attachments"].([]any)[0], "footer") assert.Contains(t, posts[1].Props["attachments"].([]any)[0], "footer")
} }
func TestExportUserCustomStatus(t *testing.T) {
th1 := Setup(t).InitBasic()
cs := &model.CustomStatus{
Emoji: "palm_tree",
Text: "on a vacation",
Duration: "this_week",
ExpiresAt: time.Now().Add(24 * time.Hour),
}
appErr := th1.App.SetCustomStatus(th1.Context, th1.BasicUser.Id, cs)
require.Nil(t, appErr)
uname := th1.BasicUser.Username
var b bytes.Buffer
appErr = th1.App.BulkExport(th1.Context, &b, "somePath", nil, model.BulkExportOpts{})
require.Nil(t, appErr)
th1.TearDown()
th2 := Setup(t)
defer th2.TearDown()
appErr, i := th2.App.BulkImport(th2.Context, &b, nil, false, 1)
require.Nil(t, appErr)
assert.Equal(t, 0, i)
gotUser, err := th2.Server.Store().User().GetByUsername(uname)
require.NoError(t, err)
gotCs := gotUser.GetCustomStatus()
require.Equal(t, cs.Emoji, gotCs.Emoji)
require.Equal(t, cs.Text, gotCs.Text)
}
func TestExportDMPostWithSelf(t *testing.T) { func TestExportDMPostWithSelf(t *testing.T) {
th1 := Setup(t).InitBasic() th1 := Setup(t).InitBasic()

View File

@ -536,6 +536,12 @@ func (a *App) importUser(rctx request.CTX, data *imports.UserImportData, dryRun
} }
} }
if data.CustomStatus != nil {
if err := user.SetCustomStatus(data.CustomStatus); err != nil {
return model.NewAppError("importUser", "app.import.custom_status.error", nil, "", http.StatusBadRequest).Wrap(err)
}
}
var savedUser *model.User var savedUser *model.User
var err error var err error
if user.Id == "" { if user.Id == "" {

View File

@ -86,6 +86,7 @@ type UserImportData struct {
EmailInterval *string `json:"email_interval,omitempty"` EmailInterval *string `json:"email_interval,omitempty"`
NotifyProps *UserNotifyPropsImportData `json:"notify_props,omitempty"` NotifyProps *UserNotifyPropsImportData `json:"notify_props,omitempty"`
CustomStatus *model.CustomStatus `json:"custom_status,omitempty"`
} }
type UserNotifyPropsImportData struct { type UserNotifyPropsImportData struct {

View File

@ -5122,6 +5122,10 @@
"id": "app.import.bulk_import.unsupported_version.error", "id": "app.import.bulk_import.unsupported_version.error",
"translation": "Incorrect or missing version in the data import file. Make sure version is the first object in your import file and try again." "translation": "Incorrect or missing version in the data import file. Make sure version is the first object in your import file and try again."
}, },
{
"id": "app.import.custom_status.error",
"translation": "Unable to set custom status."
},
{ {
"id": "app.import.emoji.bad_file.error", "id": "app.import.emoji.bad_file.error",
"translation": "Error reading import emoji image file. Emoji with name: \"{{.EmojiName}}\"" "translation": "Error reading import emoji image file. Emoji with name: \"{{.EmojiName}}\""