[MM-59367] export: enable exporting thread followers for CRT (#27623)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3dc0e63c03
Коммит
d5cc2eb2f6
@@ -3,6 +3,8 @@
|
||||
|
||||
package model
|
||||
|
||||
import "net/http"
|
||||
|
||||
// Thread tracks the metadata associated with a root post and its reply posts.
|
||||
//
|
||||
// Note that Thread metadata does not exist until the first reply to a root post.
|
||||
@@ -126,3 +128,21 @@ type ThreadMembership struct {
|
||||
// threads with the mention count.
|
||||
UnreadMentions int64 `json:"unread_mentions"`
|
||||
}
|
||||
|
||||
func (o *ThreadMembership) IsValid() *AppError {
|
||||
if !IsValidId(o.PostId) {
|
||||
return NewAppError("ThreadMembership.IsValid", "model.thread.is_valid.post_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if !IsValidId(o.UserId) {
|
||||
return NewAppError("ThreadMembership.IsValid", "model.thread.is_valid.user_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type ThreadMembershipForExport struct {
|
||||
Username string `json:"user_name"`
|
||||
LastViewed int64 `json:"last_viewed"`
|
||||
UnreadMentions int64 `json:"unread_mentions"`
|
||||
}
|
||||
|
||||
39
server/public/model/thread_test.go
Обычный файл
39
server/public/model/thread_test.go
Обычный файл
@@ -0,0 +1,39 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestThreadMembershipIsValid(t *testing.T) {
|
||||
cases := map[string]struct {
|
||||
Member *ThreadMembership
|
||||
ShouldBeValid bool
|
||||
}{
|
||||
"valid member": {
|
||||
Member: &ThreadMembership{PostId: NewId(), UserId: NewId()},
|
||||
ShouldBeValid: true,
|
||||
},
|
||||
"empty post id": {
|
||||
Member: &ThreadMembership{PostId: "", UserId: NewId()},
|
||||
ShouldBeValid: false,
|
||||
},
|
||||
"empty user id": {
|
||||
Member: &ThreadMembership{PostId: NewId(), UserId: ""},
|
||||
ShouldBeValid: false,
|
||||
},
|
||||
"invalid post id": {
|
||||
Member: &ThreadMembership{PostId: "invalid", UserId: NewId()},
|
||||
ShouldBeValid: false,
|
||||
},
|
||||
}
|
||||
for name, tc := range cases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
require.Equal(t, tc.ShouldBeValid, (tc.Member.IsValid() == nil))
|
||||
})
|
||||
}
|
||||
}
|
||||
Ссылка в новой задаче
Block a user