MM-21357: Use typed constant for channel types (#17928)
* MM-21357: Use typed constant for channel types https://mattermost.atlassian.net/browse/MM-21357 ```release-note - Introduced a new type ChannelType for all channel types. - Updated the Client4.UpdateChannelPrivacy method to ChannelType. ``` * Address review comments ```release-note NONE ``` * telemetry fix ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
Claudio Costa
родитель
4968657651
Коммит
da7d71ccf7
@@ -725,7 +725,7 @@ func (a *App) postChannelPrivacyMessage(c *request.Context, user *model.User, ch
|
||||
authorUsername = systemBot.Username
|
||||
}
|
||||
|
||||
message := (map[string]string{
|
||||
message := (map[model.ChannelType]string{
|
||||
model.ChannelTypeOpen: i18n.T("api.channel.change_channel_privacy.private_to_public"),
|
||||
model.ChannelTypePrivate: i18n.T("api.channel.change_channel_privacy.public_to_private"),
|
||||
})[channel.Type]
|
||||
@@ -1080,7 +1080,7 @@ func (a *App) PatchChannelModerationsForChannel(channel *model.Channel, channelM
|
||||
return buildChannelModerations(channel.Type, memberRole, guestRole, higherScopedMemberRole, higherScopedGuestRole), nil
|
||||
}
|
||||
|
||||
func buildChannelModerations(channelType string, memberRole *model.Role, guestRole *model.Role, higherScopedMemberRole *model.Role, higherScopedGuestRole *model.Role) []*model.ChannelModeration {
|
||||
func buildChannelModerations(channelType model.ChannelType, memberRole *model.Role, guestRole *model.Role, higherScopedMemberRole *model.Role, higherScopedGuestRole *model.Role) []*model.ChannelModeration {
|
||||
var memberPermissions, guestPermissions, higherScopedMemberPermissions, higherScopedGuestPermissions map[string]bool
|
||||
if memberRole != nil {
|
||||
memberPermissions = memberRole.GetChannelModeratedPermissions(channelType)
|
||||
|
||||
@@ -316,7 +316,7 @@ func (th *TestHelper) CreatePrivateChannel(team *model.Team) *model.Channel {
|
||||
return th.createChannel(team, model.ChannelTypePrivate)
|
||||
}
|
||||
|
||||
func (th *TestHelper) createChannel(team *model.Team, channelType string, options ...ChannelOption) *model.Channel {
|
||||
func (th *TestHelper) createChannel(team *model.Team, channelType model.ChannelType, options ...ChannelOption) *model.Channel {
|
||||
id := model.NewId()
|
||||
|
||||
channel := &model.Channel{
|
||||
|
||||
@@ -610,10 +610,11 @@ func TestImportImportChannel(t *testing.T) {
|
||||
require.NoError(t, nErr, "Failed to get team count.")
|
||||
|
||||
// Do an invalid channel in dry-run mode.
|
||||
chanOpen := model.ChannelTypeOpen
|
||||
data := ChannelImportData{
|
||||
Team: &teamName,
|
||||
DisplayName: ptrStr("Display Name"),
|
||||
Type: ptrStr("O"),
|
||||
Type: &chanOpen,
|
||||
Header: ptrStr("Channe Header"),
|
||||
Purpose: ptrStr("Channel Purpose"),
|
||||
Scheme: &scheme1.Name,
|
||||
@@ -678,8 +679,9 @@ func TestImportImportChannel(t *testing.T) {
|
||||
assert.Equal(t, scheme1.Id, *channel.SchemeId)
|
||||
|
||||
// Alter all the fields of that channel.
|
||||
cTypePr := model.ChannelTypePrivate
|
||||
data.DisplayName = ptrStr("Chaned Disp Name")
|
||||
data.Type = ptrStr(model.ChannelTypePrivate)
|
||||
data.Type = &cTypePr
|
||||
data.Header = ptrStr("New Header")
|
||||
data.Purpose = ptrStr("New Purpose")
|
||||
data.Scheme = &scheme2.Name
|
||||
@@ -874,11 +876,12 @@ func TestImportImportUser(t *testing.T) {
|
||||
require.Nil(t, appErr, "Failed to get team from database.")
|
||||
|
||||
channelName := model.NewId()
|
||||
chanTypeOpen := model.ChannelTypeOpen
|
||||
th.App.importChannel(th.Context, &ChannelImportData{
|
||||
Team: &teamName,
|
||||
Name: &channelName,
|
||||
DisplayName: ptrStr("Display Name"),
|
||||
Type: ptrStr("O"),
|
||||
Type: &chanTypeOpen,
|
||||
}, false)
|
||||
channel, appErr := th.App.GetChannelByName(channelName, team.Id, false)
|
||||
require.Nil(t, appErr, "Failed to get channel from database.")
|
||||
@@ -1396,7 +1399,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
Team: &teamName,
|
||||
Name: ptrStr(model.NewId()),
|
||||
DisplayName: ptrStr("Display Name"),
|
||||
Type: ptrStr("O"),
|
||||
Type: &chanTypeOpen,
|
||||
Header: ptrStr("Channe Header"),
|
||||
Purpose: ptrStr("Channel Purpose"),
|
||||
}
|
||||
@@ -1939,11 +1942,12 @@ func TestImportimportMultiplePostLines(t *testing.T) {
|
||||
|
||||
// Create a Channel.
|
||||
channelName := model.NewId()
|
||||
chanTypeOpen := model.ChannelTypeOpen
|
||||
th.App.importChannel(th.Context, &ChannelImportData{
|
||||
Team: &teamName,
|
||||
Name: &channelName,
|
||||
DisplayName: ptrStr("Display Name"),
|
||||
Type: ptrStr("O"),
|
||||
Type: &chanTypeOpen,
|
||||
}, false)
|
||||
channel, err := th.App.GetChannelByName(channelName, team.Id, false)
|
||||
require.Nil(t, err, "Failed to get channel from database.")
|
||||
@@ -2418,7 +2422,7 @@ func TestImportimportMultiplePostLines(t *testing.T) {
|
||||
Team: &teamName2,
|
||||
Name: &channelName,
|
||||
DisplayName: ptrStr("Display Name"),
|
||||
Type: ptrStr("O"),
|
||||
Type: &chanTypeOpen,
|
||||
}, false)
|
||||
_, err = th.App.GetChannelByName(channelName, team2.Id, false)
|
||||
require.Nil(t, err, "Failed to get channel from database.")
|
||||
@@ -2477,11 +2481,12 @@ func TestImportImportPost(t *testing.T) {
|
||||
|
||||
// Create a Channel.
|
||||
channelName := model.NewId()
|
||||
chanTypeOpen := model.ChannelTypeOpen
|
||||
th.App.importChannel(th.Context, &ChannelImportData{
|
||||
Team: &teamName,
|
||||
Name: &channelName,
|
||||
DisplayName: ptrStr("Display Name"),
|
||||
Type: ptrStr("O"),
|
||||
Type: &chanTypeOpen,
|
||||
}, false)
|
||||
channel, appErr := th.App.GetChannelByName(channelName, team.Id, false)
|
||||
require.Nil(t, appErr, "Failed to get channel from database.")
|
||||
@@ -3920,11 +3925,12 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) {
|
||||
|
||||
// Create a Channel.
|
||||
channelName := model.NewId()
|
||||
chanTypeOpen := model.ChannelTypeOpen
|
||||
th.App.importChannel(th.Context, &ChannelImportData{
|
||||
Team: &teamName,
|
||||
Name: &channelName,
|
||||
DisplayName: ptrStr("Display Name"),
|
||||
Type: ptrStr("O"),
|
||||
Type: &chanTypeOpen,
|
||||
}, false)
|
||||
_, appErr = th.App.GetChannelByName(channelName, team.Id, false)
|
||||
require.Nil(t, appErr, "Failed to get channel from database.")
|
||||
@@ -4195,11 +4201,12 @@ func TestZippedImportPostAndRepliesWithAttachments(t *testing.T) {
|
||||
|
||||
// Create a Channel.
|
||||
channelName := model.NewId()
|
||||
chanTypeOpen := model.ChannelTypeOpen
|
||||
th.App.importChannel(th.Context, &ChannelImportData{
|
||||
Team: &teamName,
|
||||
Name: &channelName,
|
||||
DisplayName: ptrStr("Display Name"),
|
||||
Type: ptrStr("O"),
|
||||
Type: &chanTypeOpen,
|
||||
}, false)
|
||||
_, appErr = th.App.GetChannelByName(channelName, team.Id, false)
|
||||
require.Nil(t, appErr, "Failed to get channel from database.")
|
||||
|
||||
@@ -70,7 +70,7 @@ func AssertAllPostsCount(t *testing.T, a *App, initialCount int64, change int64,
|
||||
require.Equal(t, initialCount+change, result, "Did not find the expected number of posts.")
|
||||
}
|
||||
|
||||
func AssertChannelCount(t *testing.T, a *App, channelType string, expectedCount int64) {
|
||||
func AssertChannelCount(t *testing.T, a *App, channelType model.ChannelType, expectedCount int64) {
|
||||
count, err := a.Srv().Store.Channel().AnalyticsTypeCount("", channelType)
|
||||
require.Equalf(t, expectedCount, count, "Channel count of type: %v. Expected: %v, Got: %v", channelType, expectedCount, count)
|
||||
require.NoError(t, err, "Failed to get channel count.")
|
||||
|
||||
@@ -34,13 +34,13 @@ type TeamImportData struct {
|
||||
}
|
||||
|
||||
type ChannelImportData struct {
|
||||
Team *string `json:"team"`
|
||||
Name *string `json:"name"`
|
||||
DisplayName *string `json:"display_name"`
|
||||
Type *string `json:"type"`
|
||||
Header *string `json:"header,omitempty"`
|
||||
Purpose *string `json:"purpose,omitempty"`
|
||||
Scheme *string `json:"scheme,omitempty"`
|
||||
Team *string `json:"team"`
|
||||
Name *string `json:"name"`
|
||||
DisplayName *string `json:"display_name"`
|
||||
Type *model.ChannelType `json:"type"`
|
||||
Header *string `json:"header,omitempty"`
|
||||
Purpose *string `json:"purpose,omitempty"`
|
||||
Scheme *string `json:"scheme,omitempty"`
|
||||
}
|
||||
|
||||
type UserImportData struct {
|
||||
|
||||
@@ -357,11 +357,12 @@ func TestImportValidateTeamImportData(t *testing.T) {
|
||||
func TestImportValidateChannelImportData(t *testing.T) {
|
||||
|
||||
// Test with minimum required valid properties.
|
||||
chanTypeOpen := model.ChannelTypeOpen
|
||||
data := ChannelImportData{
|
||||
Team: ptrStr("teamname"),
|
||||
Name: ptrStr("channelname"),
|
||||
DisplayName: ptrStr("Display Name"),
|
||||
Type: ptrStr("O"),
|
||||
Type: &chanTypeOpen,
|
||||
}
|
||||
err := validateChannelImportData(&data)
|
||||
require.Nil(t, err, "Validation failed but should have been valid.")
|
||||
@@ -370,7 +371,7 @@ func TestImportValidateChannelImportData(t *testing.T) {
|
||||
data = ChannelImportData{
|
||||
Name: ptrStr("channelname"),
|
||||
DisplayName: ptrStr("Display Name"),
|
||||
Type: ptrStr("O"),
|
||||
Type: &chanTypeOpen,
|
||||
}
|
||||
err = validateChannelImportData(&data)
|
||||
require.NotNil(t, err, "Should have failed due to missing team.")
|
||||
@@ -379,7 +380,7 @@ func TestImportValidateChannelImportData(t *testing.T) {
|
||||
data = ChannelImportData{
|
||||
Team: ptrStr("teamname"),
|
||||
DisplayName: ptrStr("Display Name"),
|
||||
Type: ptrStr("O"),
|
||||
Type: &chanTypeOpen,
|
||||
}
|
||||
err = validateChannelImportData(&data)
|
||||
require.NotNil(t, err, "Should have failed due to missing name.")
|
||||
@@ -400,7 +401,7 @@ func TestImportValidateChannelImportData(t *testing.T) {
|
||||
data = ChannelImportData{
|
||||
Team: ptrStr("teamname"),
|
||||
Name: ptrStr("channelname"),
|
||||
Type: ptrStr("O"),
|
||||
Type: &chanTypeOpen,
|
||||
}
|
||||
err = validateChannelImportData(&data)
|
||||
require.NotNil(t, err, "Should have failed due to missing display_name.")
|
||||
@@ -422,11 +423,13 @@ func TestImportValidateChannelImportData(t *testing.T) {
|
||||
err = validateChannelImportData(&data)
|
||||
require.NotNil(t, err, "Should have failed due to missing type.")
|
||||
|
||||
data.Type = ptrStr("A")
|
||||
invalidType := model.ChannelType("A")
|
||||
data.Type = &invalidType
|
||||
err = validateChannelImportData(&data)
|
||||
require.NotNil(t, err, "Should have failed due to invalid type.")
|
||||
|
||||
data.Type = ptrStr("P")
|
||||
chanTypePr := model.ChannelTypePrivate
|
||||
data.Type = &chanTypePr
|
||||
err = validateChannelImportData(&data)
|
||||
require.Nil(t, err, "Should have succeeded with valid type.")
|
||||
|
||||
@@ -435,7 +438,7 @@ func TestImportValidateChannelImportData(t *testing.T) {
|
||||
Team: ptrStr("teamname"),
|
||||
Name: ptrStr("channelname"),
|
||||
DisplayName: ptrStr("Display Name"),
|
||||
Type: ptrStr("O"),
|
||||
Type: &chanTypeOpen,
|
||||
Header: ptrStr("Channel Header Here"),
|
||||
Purpose: ptrStr("Channel Purpose Here"),
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ func (a *App) sendPushNotification(notification *PostNotification, user *model.U
|
||||
}
|
||||
|
||||
func (a *App) getPushNotificationMessage(contentsConfig, postMessage string, explicitMention, channelWideMention,
|
||||
hasFiles bool, senderName, channelType, replyToThreadType string, userLocale i18n.TranslateFunc) string {
|
||||
hasFiles bool, senderName string, channelType model.ChannelType, replyToThreadType string, userLocale i18n.TranslateFunc) string {
|
||||
|
||||
// If the post only has images then push an appropriate message
|
||||
if postMessage == "" && hasFiles {
|
||||
|
||||
@@ -573,7 +573,7 @@ func TestGetPushNotificationMessage(t *testing.T) {
|
||||
replyToThreadType string
|
||||
Locale string
|
||||
PushNotificationContents string
|
||||
ChannelType string
|
||||
ChannelType model.ChannelType
|
||||
|
||||
ExpectedMessage string
|
||||
}{
|
||||
|
||||
@@ -19,7 +19,7 @@ type AutoChannelCreator struct {
|
||||
DisplayNameCharset string
|
||||
NameLen utils.Range
|
||||
NameCharset string
|
||||
ChannelType string
|
||||
ChannelType model.ChannelType
|
||||
}
|
||||
|
||||
func NewAutoChannelCreator(a *app.App, team *model.Team, userID string) *AutoChannelCreator {
|
||||
|
||||
@@ -247,7 +247,7 @@ func (th *TestHelper) createPrivateChannel(team *model.Team) *model.Channel {
|
||||
return th.createChannel(team, model.ChannelTypePrivate)
|
||||
}
|
||||
|
||||
func (th *TestHelper) createChannel(team *model.Team, channelType string, options ...ChannelOption) *model.Channel {
|
||||
func (th *TestHelper) createChannel(team *model.Team, channelType model.ChannelType, options ...ChannelOption) *model.Channel {
|
||||
id := model.NewId()
|
||||
|
||||
channel := &model.Channel{
|
||||
@@ -288,7 +288,7 @@ func (th *TestHelper) createChannel(team *model.Team, channelType string, option
|
||||
return channel
|
||||
}
|
||||
|
||||
func (th *TestHelper) createChannelWithAnotherUser(team *model.Team, channelType, userID string) *model.Channel {
|
||||
func (th *TestHelper) createChannelWithAnotherUser(team *model.Team, channelType model.ChannelType, userID string) *model.Channel {
|
||||
id := model.NewId()
|
||||
|
||||
channel := &model.Channel{
|
||||
|
||||
Ссылка в новой задаче
Block a user