diff --git a/api4/apitestlib.go b/api4/apitestlib.go index debd8b82ab3..8f87184c8a1 100644 --- a/api4/apitestlib.go +++ b/api4/apitestlib.go @@ -636,11 +636,11 @@ func (th *TestHelper) CreatePrivateChannel() *model.Channel { return th.CreateChannelWithClient(th.Client, model.ChannelTypePrivate) } -func (th *TestHelper) CreateChannelWithClient(client *model.Client4, channelType string) *model.Channel { +func (th *TestHelper) CreateChannelWithClient(client *model.Client4, channelType model.ChannelType) *model.Channel { return th.CreateChannelWithClientAndTeam(client, channelType, th.BasicTeam.Id) } -func (th *TestHelper) CreateChannelWithClientAndTeam(client *model.Client4, channelType string, teamId string) *model.Channel { +func (th *TestHelper) CreateChannelWithClientAndTeam(client *model.Client4, channelType model.ChannelType, teamId string) *model.Channel { id := model.NewId() channel := &model.Channel{ diff --git a/api4/channel.go b/api4/channel.go index 13890ab9ae4..8dcdeb2b287 100644 --- a/api4/channel.go +++ b/api4/channel.go @@ -283,7 +283,7 @@ func updateChannelPrivacy(c *Context, w http.ResponseWriter, r *http.Request) { props := model.StringInterfaceFromJson(r.Body) privacy, ok := props["privacy"].(string) - if !ok || (privacy != model.ChannelTypeOpen && privacy != model.ChannelTypePrivate) { + if !ok || (model.ChannelType(privacy) != model.ChannelTypeOpen && model.ChannelType(privacy) != model.ChannelTypePrivate) { c.SetInvalidParam("privacy") return } @@ -299,17 +299,17 @@ func updateChannelPrivacy(c *Context, w http.ResponseWriter, r *http.Request) { auditRec.AddMeta("channel", channel) auditRec.AddMeta("new_type", privacy) - if privacy == model.ChannelTypeOpen && !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), c.Params.ChannelId, model.PermissionConvertPrivateChannelToPublic) { + if model.ChannelType(privacy) == model.ChannelTypeOpen && !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), c.Params.ChannelId, model.PermissionConvertPrivateChannelToPublic) { c.SetPermissionError(model.PermissionConvertPrivateChannelToPublic) return } - if privacy == model.ChannelTypePrivate && !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), c.Params.ChannelId, model.PermissionConvertPublicChannelToPrivate) { + if model.ChannelType(privacy) == model.ChannelTypePrivate && !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), c.Params.ChannelId, model.PermissionConvertPublicChannelToPrivate) { c.SetPermissionError(model.PermissionConvertPublicChannelToPrivate) return } - if channel.Name == model.DefaultChannelName && privacy == model.ChannelTypePrivate { + if channel.Name == model.DefaultChannelName && model.ChannelType(privacy) == model.ChannelTypePrivate { c.Err = model.NewAppError("updateChannelPrivacy", "api.channel.update_channel_privacy.default_channel_error", nil, "", http.StatusBadRequest) return } @@ -321,7 +321,7 @@ func updateChannelPrivacy(c *Context, w http.ResponseWriter, r *http.Request) { } auditRec.AddMeta("user", user) - channel.Type = privacy + channel.Type = model.ChannelType(privacy) updatedChannel, err := c.App.UpdateChannelPrivacy(c.AppContext, channel, user) if err != nil { diff --git a/api4/channel_local.go b/api4/channel_local.go index c196a239dfc..15bd5657916 100644 --- a/api4/channel_local.go +++ b/api4/channel_local.go @@ -68,7 +68,7 @@ func localUpdateChannelPrivacy(c *Context, w http.ResponseWriter, r *http.Reques props := model.StringInterfaceFromJson(r.Body) privacy, ok := props["privacy"].(string) - if !ok || (privacy != model.ChannelTypeOpen && privacy != model.ChannelTypePrivate) { + if !ok || (model.ChannelType(privacy) != model.ChannelTypeOpen && model.ChannelType(privacy) != model.ChannelTypePrivate) { c.SetInvalidParam("privacy") return } @@ -84,11 +84,11 @@ func localUpdateChannelPrivacy(c *Context, w http.ResponseWriter, r *http.Reques auditRec.AddMeta("channel", channel) auditRec.AddMeta("new_type", privacy) - if channel.Name == model.DefaultChannelName && privacy == model.ChannelTypePrivate { + if channel.Name == model.DefaultChannelName && model.ChannelType(privacy) == model.ChannelTypePrivate { c.Err = model.NewAppError("updateChannelPrivacy", "api.channel.update_channel_privacy.default_channel_error", nil, "", http.StatusBadRequest) return } - channel.Type = privacy + channel.Type = model.ChannelType(privacy) updatedChannel, err := c.App.UpdateChannelPrivacy(c.AppContext, channel, nil) if err != nil { diff --git a/api4/channel_test.go b/api4/channel_test.go index be7079b7831..0c128c738a3 100644 --- a/api4/channel_test.go +++ b/api4/channel_test.go @@ -1850,7 +1850,7 @@ func TestUpdateChannelPrivacy(t *testing.T) { type testTable []struct { name string channel *model.Channel - expectedPrivacy string + expectedPrivacy model.ChannelType } t.Run("Should get a forbidden response if not logged in", func(t *testing.T) { diff --git a/app/channel.go b/app/channel.go index 1b7e87d69f1..7a6c3dccb2f 100644 --- a/app/channel.go +++ b/app/channel.go @@ -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) diff --git a/app/helper_test.go b/app/helper_test.go index 64374a40eaf..ae3666cb898 100644 --- a/app/helper_test.go +++ b/app/helper_test.go @@ -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{ diff --git a/app/import_functions_test.go b/app/import_functions_test.go index 67a86808ba9..a3e432e0c0d 100644 --- a/app/import_functions_test.go +++ b/app/import_functions_test.go @@ -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.") diff --git a/app/import_test.go b/app/import_test.go index e8bfbc2975a..c1bdd96faf1 100644 --- a/app/import_test.go +++ b/app/import_test.go @@ -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.") diff --git a/app/import_types.go b/app/import_types.go index 0d165e03efa..c53381bd110 100644 --- a/app/import_types.go +++ b/app/import_types.go @@ -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 { diff --git a/app/import_validators_test.go b/app/import_validators_test.go index 3e54c731889..cd4fc57c513 100644 --- a/app/import_validators_test.go +++ b/app/import_validators_test.go @@ -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"), } diff --git a/app/notification_push.go b/app/notification_push.go index 9624cf42bc4..96c6b787231 100644 --- a/app/notification_push.go +++ b/app/notification_push.go @@ -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 { diff --git a/app/notification_push_test.go b/app/notification_push_test.go index 24d963649fc..8cff678853d 100644 --- a/app/notification_push_test.go +++ b/app/notification_push_test.go @@ -573,7 +573,7 @@ func TestGetPushNotificationMessage(t *testing.T) { replyToThreadType string Locale string PushNotificationContents string - ChannelType string + ChannelType model.ChannelType ExpectedMessage string }{ diff --git a/app/slashcommands/auto_channels.go b/app/slashcommands/auto_channels.go index e5f479d0f90..cbc10cbe94e 100644 --- a/app/slashcommands/auto_channels.go +++ b/app/slashcommands/auto_channels.go @@ -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 { diff --git a/app/slashcommands/helper_test.go b/app/slashcommands/helper_test.go index 2af5049b131..3248701abe9 100644 --- a/app/slashcommands/helper_test.go +++ b/app/slashcommands/helper_test.go @@ -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{ diff --git a/cmd/mattermost/commands/sampledata.go b/cmd/mattermost/commands/sampledata.go index 5595933c157..367ac2d31de 100644 --- a/cmd/mattermost/commands/sampledata.go +++ b/cmd/mattermost/commands/sampledata.go @@ -617,9 +617,9 @@ func createChannel(idx int, teamName string) app.LineImportData { purpose = purpose[0:250] } - channelType := "P" + channelType := model.ChannelTypePrivate if rand.Intn(2) == 0 { - channelType = "O" + channelType = model.ChannelTypeOpen } channel := app.ChannelImportData{ diff --git a/migrations/helper_test.go b/migrations/helper_test.go index ff34d7b1519..9c36edb3506 100644 --- a/migrations/helper_test.go +++ b/migrations/helper_test.go @@ -159,7 +159,7 @@ func (th *TestHelper) CreateChannel(team *model.Team) *model.Channel { return th.createChannel(team, model.ChannelTypeOpen) } -func (th *TestHelper) createChannel(team *model.Team, channelType string) *model.Channel { +func (th *TestHelper) createChannel(team *model.Team, channelType model.ChannelType) *model.Channel { id := model.NewId() channel := &model.Channel{ diff --git a/model/auditconv.go b/model/auditconv.go index b3cf60629ae..38b4381e9f6 100644 --- a/model/auditconv.go +++ b/model/auditconv.go @@ -60,7 +60,7 @@ func AuditModelTypeConv(val interface{}) (newVal interface{}, converted bool) { type auditChannel struct { ID string Name string - Type string + Type ChannelType } // newAuditChannel creates a simplified representation of Channel for output to audit log. @@ -77,7 +77,7 @@ func newAuditChannel(c *Channel) auditChannel { func (c auditChannel) MarshalJSONObject(enc *gojay.Encoder) { enc.StringKey("id", c.ID) enc.StringKey("name", c.Name) - enc.StringKey("type", c.Type) + enc.StringKey("type", string(c.Type)) } func (c auditChannel) IsNil() bool { diff --git a/model/channel.go b/model/channel.go index 761e2a173ac..e8b3aeaede8 100644 --- a/model/channel.go +++ b/model/channel.go @@ -14,11 +14,13 @@ import ( "unicode/utf8" ) +type ChannelType string + const ( - ChannelTypeOpen = "O" - ChannelTypePrivate = "P" - ChannelTypeDirect = "D" - ChannelTypeGroup = "G" + ChannelTypeOpen ChannelType = "O" + ChannelTypePrivate ChannelType = "P" + ChannelTypeDirect ChannelType = "D" + ChannelTypeGroup ChannelType = "G" ChannelGroupMaxUsers = 8 ChannelGroupMinUsers = 3 @@ -40,7 +42,7 @@ type Channel struct { UpdateAt int64 `json:"update_at"` DeleteAt int64 `json:"delete_at"` TeamId string `json:"team_id"` - Type string `json:"type"` + Type ChannelType `json:"type"` DisplayName string `json:"display_name"` Name string `json:"name"` Header string `json:"header"` diff --git a/model/client4.go b/model/client4.go index dd5eb305b97..526acd1e6ee 100644 --- a/model/client4.go +++ b/model/client4.go @@ -2453,8 +2453,8 @@ func (c *Client4) ConvertChannelToPrivate(channelId string) (*Channel, *Response } // UpdateChannelPrivacy updates channel privacy -func (c *Client4) UpdateChannelPrivacy(channelId string, privacy string) (*Channel, *Response) { - requestBody := map[string]string{"privacy": privacy} +func (c *Client4) UpdateChannelPrivacy(channelId string, privacy ChannelType) (*Channel, *Response) { + requestBody := map[string]string{"privacy": string(privacy)} r, err := c.DoApiPut(c.GetChannelRoute(channelId)+"/privacy", MapToJson(requestBody)) if err != nil { return nil, BuildErrorResponse(r, err) diff --git a/model/message_export.go b/model/message_export.go index f94d861f8b1..92eca9d66e7 100644 --- a/model/message_export.go +++ b/model/message_export.go @@ -11,7 +11,7 @@ type MessageExport struct { ChannelId *string ChannelName *string ChannelDisplayName *string - ChannelType *string + ChannelType *ChannelType UserId *string UserEmail *string diff --git a/model/role.go b/model/role.go index 6bce22e205a..99bc623a205 100644 --- a/model/role.go +++ b/model/role.go @@ -554,7 +554,7 @@ func ChannelModeratedPermissionsChangedByPatch(role *Role, patch *RolePatch) []s } // GetChannelModeratedPermissions returns a map of channel moderated permissions that the role has access to -func (r *Role) GetChannelModeratedPermissions(channelType string) map[string]bool { +func (r *Role) GetChannelModeratedPermissions(channelType ChannelType) map[string]bool { moderatedPermissions := make(map[string]bool) for _, permission := range r.Permissions { if _, found := ChannelModeratedPermissionsMap[permission]; !found { diff --git a/model/role_test.go b/model/role_test.go index 562b3112e80..431a3286f19 100644 --- a/model/role_test.go +++ b/model/role_test.go @@ -231,7 +231,7 @@ func TestGetChannelModeratedPermissions(t *testing.T) { tests := []struct { Name string Permissions []string - ChannelType string + ChannelType ChannelType Expected map[string]bool }{ { diff --git a/model/shared_channel.go b/model/shared_channel.go index 9172629f7c5..0e44c1f8af9 100644 --- a/model/shared_channel.go +++ b/model/shared_channel.go @@ -16,19 +16,19 @@ import ( // If "home" is false, then the shared channel is homed remotely, and "RemoteId" // field points to the remote cluster connection in "RemoteClusters" table. type SharedChannel struct { - ChannelId string `json:"id"` - TeamId string `json:"team_id"` - Home bool `json:"home"` - ReadOnly bool `json:"readonly"` - ShareName string `json:"name"` - ShareDisplayName string `json:"display_name"` - SharePurpose string `json:"purpose"` - ShareHeader string `json:"header"` - CreatorId string `json:"creator_id"` - CreateAt int64 `json:"create_at"` - UpdateAt int64 `json:"update_at"` - RemoteId string `json:"remote_id,omitempty"` // if not "home" - Type string `db:"-"` + ChannelId string `json:"id"` + TeamId string `json:"team_id"` + Home bool `json:"home"` + ReadOnly bool `json:"readonly"` + ShareName string `json:"name"` + ShareDisplayName string `json:"display_name"` + SharePurpose string `json:"purpose"` + ShareHeader string `json:"header"` + CreatorId string `json:"creator_id"` + CreateAt int64 `json:"create_at"` + UpdateAt int64 `json:"update_at"` + RemoteId string `json:"remote_id,omitempty"` // if not "home" + Type ChannelType `db:"-"` } func (sc *SharedChannel) ToJson() string { diff --git a/services/sharedchannel/channelinvite.go b/services/sharedchannel/channelinvite.go index 0115aaf9faf..c17f0fc7f4a 100644 --- a/services/sharedchannel/channelinvite.go +++ b/services/sharedchannel/channelinvite.go @@ -17,15 +17,15 @@ import ( // channelInviteMsg represents an invitation for a remote cluster to start sharing a channel. type channelInviteMsg struct { - ChannelId string `json:"channel_id"` - TeamId string `json:"team_id"` - ReadOnly bool `json:"read_only"` - Name string `json:"name"` - DisplayName string `json:"display_name"` - Header string `json:"header"` - Purpose string `json:"purpose"` - Type string `json:"type"` - DirectParticipantIDs []string `json:"direct_participant_ids"` + ChannelId string `json:"channel_id"` + TeamId string `json:"team_id"` + ReadOnly bool `json:"read_only"` + Name string `json:"name"` + DisplayName string `json:"display_name"` + Header string `json:"header"` + Purpose string `json:"purpose"` + Type model.ChannelType `json:"type"` + DirectParticipantIDs []string `json:"direct_participant_ids"` } type InviteOption func(msg *channelInviteMsg) diff --git a/services/slackimport/parsers.go b/services/slackimport/parsers.go index 12984d86214..95d0cc7fdb7 100644 --- a/services/slackimport/parsers.go +++ b/services/slackimport/parsers.go @@ -7,10 +7,11 @@ import ( "encoding/json" "io" + "github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/shared/mlog" ) -func slackParseChannels(data io.Reader, channelType string) ([]slackChannel, error) { +func slackParseChannels(data io.Reader, channelType model.ChannelType) ([]slackChannel, error) { decoder := json.NewDecoder(data) var channels []slackChannel diff --git a/services/slackimport/slackimport.go b/services/slackimport/slackimport.go index cbafc89e854..6d6a5342348 100644 --- a/services/slackimport/slackimport.go +++ b/services/slackimport/slackimport.go @@ -31,7 +31,7 @@ type slackChannel struct { Members []string `json:"members"` Purpose slackChannelSub `json:"purpose"` Topic slackChannelSub `json:"topic"` - Type string + Type model.ChannelType } type slackChannelSub struct { diff --git a/services/telemetry/telemetry_test.go b/services/telemetry/telemetry_test.go index c6b237e126f..d026154d17e 100644 --- a/services/telemetry/telemetry_test.go +++ b/services/telemetry/telemetry_test.go @@ -101,9 +101,9 @@ func initializeMocks(cfg *model.Config) (*mocks.ServerIface, *storeMocks.Store, teamStore.On("GroupSyncedTeamCount").Return(int64(16), nil) channelStore := storeMocks.ChannelStore{} - channelStore.On("AnalyticsTypeCount", "", "O").Return(int64(25), nil) - channelStore.On("AnalyticsTypeCount", "", "P").Return(int64(26), nil) - channelStore.On("AnalyticsTypeCount", "", "D").Return(int64(27), nil) + channelStore.On("AnalyticsTypeCount", "", model.ChannelTypeOpen).Return(int64(25), nil) + channelStore.On("AnalyticsTypeCount", "", model.ChannelTypePrivate).Return(int64(26), nil) + channelStore.On("AnalyticsTypeCount", "", model.ChannelTypeDirect).Return(int64(27), nil) channelStore.On("AnalyticsDeletedTypeCount", "", "O").Return(int64(22), nil) channelStore.On("AnalyticsDeletedTypeCount", "", "P").Return(int64(23), nil) channelStore.On("GroupSyncedChannelCount").Return(int64(17), nil) diff --git a/store/opentracinglayer/opentracinglayer.go b/store/opentracinglayer/opentracinglayer.go index 843ae538411..b287efdf629 100644 --- a/store/opentracinglayer/opentracinglayer.go +++ b/store/opentracinglayer/opentracinglayer.go @@ -552,7 +552,7 @@ func (s *OpenTracingLayerChannelStore) AnalyticsDeletedTypeCount(teamID string, return result, err } -func (s *OpenTracingLayerChannelStore) AnalyticsTypeCount(teamID string, channelType string) (int64, error) { +func (s *OpenTracingLayerChannelStore) AnalyticsTypeCount(teamID string, channelType model.ChannelType) (int64, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.AnalyticsTypeCount") s.Root.Store.SetContext(newCtx) diff --git a/store/retrylayer/retrylayer.go b/store/retrylayer/retrylayer.go index 15f6fceab21..f50e525f665 100644 --- a/store/retrylayer/retrylayer.go +++ b/store/retrylayer/retrylayer.go @@ -588,7 +588,7 @@ func (s *RetryLayerChannelStore) AnalyticsDeletedTypeCount(teamID string, channe } -func (s *RetryLayerChannelStore) AnalyticsTypeCount(teamID string, channelType string) (int64, error) { +func (s *RetryLayerChannelStore) AnalyticsTypeCount(teamID string, channelType model.ChannelType) (int64, error) { tries := 0 for { diff --git a/store/searchtest/helper.go b/store/searchtest/helper.go index 109721ee05b..a608d7f510d 100644 --- a/store/searchtest/helper.go +++ b/store/searchtest/helper.go @@ -239,7 +239,7 @@ func (th *SearchTestHelper) deleteBot(botID string) error { return nil } -func (th *SearchTestHelper) createChannel(teamID, name, displayName, purpose, channelType string, deleted bool) (*model.Channel, error) { +func (th *SearchTestHelper) createChannel(teamID, name, displayName, purpose string, channelType model.ChannelType, deleted bool) (*model.Channel, error) { channel, err := th.Store.Channel().Save(&model.Channel{ TeamId: teamID, DisplayName: displayName, diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go index 9258c74384d..577a47bb1e0 100644 --- a/store/sqlstore/channel_store.go +++ b/store/sqlstore/channel_store.go @@ -1043,7 +1043,7 @@ func (s SqlChannelStore) getAllChannelsQuery(opts store.ChannelSearchOpts, forCo query := s.getQueryBuilder(). Select(selectStr). From("Channels AS c"). - Where(sq.Eq{"c.Type": []string{model.ChannelTypePrivate, model.ChannelTypeOpen}}) + Where(sq.Eq{"c.Type": []model.ChannelType{model.ChannelTypePrivate, model.ChannelTypeOpen}}) if !forCount { query = query.Join("Teams ON Teams.Id = c.TeamId") @@ -2376,7 +2376,7 @@ func (s SqlChannelStore) GetForPost(postId string) (*model.Channel, error) { return channel, nil } -func (s SqlChannelStore) AnalyticsTypeCount(teamId string, channelType string) (int64, error) { +func (s SqlChannelStore) AnalyticsTypeCount(teamId string, channelType model.ChannelType) (int64, error) { query := "SELECT COUNT(Id) AS Value FROM Channels WHERE Type = :ChannelType" if teamId != "" { diff --git a/store/sqlstore/channel_store_categories.go b/store/sqlstore/channel_store_categories.go index 982defd5efb..122c9b9c978 100644 --- a/store/sqlstore/channel_store_categories.go +++ b/store/sqlstore/channel_store_categories.go @@ -378,11 +378,11 @@ func (s SqlChannelStore) completePopulatingCategoryChannelsT(db dbSelecter, cate var channelTypeFilter sq.Sqlizer if category.Type == model.SidebarCategoryDirectMessages { // any DM/GM channels that aren't in any category should be returned as part of the Direct Messages category - channelTypeFilter = sq.Eq{"Channels.Type": []string{model.ChannelTypeDirect, model.ChannelTypeGroup}} + channelTypeFilter = sq.Eq{"Channels.Type": []model.ChannelType{model.ChannelTypeDirect, model.ChannelTypeGroup}} } else if category.Type == model.SidebarCategoryChannels { // any public/private channels that are on the current team and aren't in any category should be returned as part of the Channels category channelTypeFilter = sq.And{ - sq.Eq{"Channels.Type": []string{model.ChannelTypeOpen, model.ChannelTypePrivate}}, + sq.Eq{"Channels.Type": []model.ChannelType{model.ChannelTypeOpen, model.ChannelTypePrivate}}, sq.Eq{"Channels.TeamId": category.TeamId}, } } diff --git a/store/sqlstore/integrity.go b/store/sqlstore/integrity.go index 0ea4004a8fb..a9de499f1e1 100644 --- a/store/sqlstore/integrity.go +++ b/store/sqlstore/integrity.go @@ -215,7 +215,7 @@ func checkTeamsChannelsIntegrity(ss *SqlStore) model.IntegrityCheckResult { parentIdAttr: "TeamId", childName: "Channels", childIdAttr: "Id", - filter: sq.NotEq{"CT.Type": []string{model.ChannelTypeDirect, model.ChannelTypeGroup}}, + filter: sq.NotEq{"CT.Type": []model.ChannelType{model.ChannelTypeDirect, model.ChannelTypeGroup}}, }) res2 := checkParentChildIntegrity(ss, relationalCheckConfig{ parentName: "Teams", @@ -223,7 +223,7 @@ func checkTeamsChannelsIntegrity(ss *SqlStore) model.IntegrityCheckResult { childName: "Channels", childIdAttr: "Id", canParentIdBeEmpty: true, - filter: sq.Eq{"CT.Type": []string{model.ChannelTypeDirect, model.ChannelTypeGroup}}, + filter: sq.Eq{"CT.Type": []model.ChannelType{model.ChannelTypeDirect, model.ChannelTypeGroup}}, }) data1 := res1.Data.(model.RelationalIntegrityCheckData) data2 := res2.Data.(model.RelationalIntegrityCheckData) diff --git a/store/store.go b/store/store.go index 83a487410ac..a84ec086f63 100644 --- a/store/store.go +++ b/store/store.go @@ -220,7 +220,7 @@ type ChannelStore interface { UpdateLastViewedAtPost(unreadPost *model.Post, userID string, mentionCount, mentionCountRoot int, updateThreads bool, setUnreadCountRoot bool) (*model.ChannelUnreadAt, error) CountPostsAfter(channelID string, timestamp int64, userID string) (int, int, error) IncrementMentionCount(channelID string, userID string, updateThreads, isRoot bool) error - AnalyticsTypeCount(teamID string, channelType string) (int64, error) + AnalyticsTypeCount(teamID string, channelType model.ChannelType) (int64, error) GetMembersForUser(teamID string, userID string) (*model.ChannelMembers, error) GetMembersForUserWithPagination(teamID, userID string, page, perPage int) (*model.ChannelMembers, error) AutocompleteInTeam(teamID string, term string, includeDeleted bool) (*model.ChannelList, error) diff --git a/store/storetest/group_store.go b/store/storetest/group_store.go index 187966a21fe..de8885f81ae 100644 --- a/store/storetest/group_store.go +++ b/store/storetest/group_store.go @@ -3942,7 +3942,7 @@ func groupTestAdminRoleGroupsForSyncableMemberTeam(t *testing.T, ss store.Store) team := &model.Team{ DisplayName: "A Name", Name: "zz" + model.NewId(), - Type: model.ChannelTypeOpen, + Type: model.TeamOpen, } team, nErr := ss.Team().Save(team) require.NoError(t, nErr) @@ -4045,7 +4045,7 @@ func groupTestPermittedSyncableAdminsTeam(t *testing.T, ss store.Store) { team := &model.Team{ DisplayName: "A Name", Name: "zz" + model.NewId(), - Type: model.ChannelTypeOpen, + Type: model.TeamOpen, } team, nErr := ss.Team().Save(team) require.NoError(t, nErr) diff --git a/store/storetest/mocks/ChannelStore.go b/store/storetest/mocks/ChannelStore.go index d5c28df42e5..e446d7697ab 100644 --- a/store/storetest/mocks/ChannelStore.go +++ b/store/storetest/mocks/ChannelStore.go @@ -40,18 +40,18 @@ func (_m *ChannelStore) AnalyticsDeletedTypeCount(teamID string, channelType str } // AnalyticsTypeCount provides a mock function with given fields: teamID, channelType -func (_m *ChannelStore) AnalyticsTypeCount(teamID string, channelType string) (int64, error) { +func (_m *ChannelStore) AnalyticsTypeCount(teamID string, channelType model.ChannelType) (int64, error) { ret := _m.Called(teamID, channelType) var r0 int64 - if rf, ok := ret.Get(0).(func(string, string) int64); ok { + if rf, ok := ret.Get(0).(func(string, model.ChannelType) int64); ok { r0 = rf(teamID, channelType) } else { r0 = ret.Get(0).(int64) } var r1 error - if rf, ok := ret.Get(1).(func(string, string) error); ok { + if rf, ok := ret.Get(1).(func(string, model.ChannelType) error); ok { r1 = rf(teamID, channelType) } else { r1 = ret.Error(1) diff --git a/store/timerlayer/timerlayer.go b/store/timerlayer/timerlayer.go index 40cccb3038e..d1ad3039670 100644 --- a/store/timerlayer/timerlayer.go +++ b/store/timerlayer/timerlayer.go @@ -534,7 +534,7 @@ func (s *TimerLayerChannelStore) AnalyticsDeletedTypeCount(teamID string, channe return result, err } -func (s *TimerLayerChannelStore) AnalyticsTypeCount(teamID string, channelType string) (int64, error) { +func (s *TimerLayerChannelStore) AnalyticsTypeCount(teamID string, channelType model.ChannelType) (int64, error) { start := timemodule.Now() result, err := s.ChannelStore.AnalyticsTypeCount(teamID, channelType)