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
```
This commit is contained in:
Agniva De Sarker 2021-07-20 12:45:26 +05:30 committed by Claudio Costa
parent 4968657651
commit da7d71ccf7
37 changed files with 114 additions and 101 deletions

View file

@ -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{

View file

@ -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 {

View file

@ -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 {

View file

@ -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) {

View file

@ -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)

View file

@ -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{

View file

@ -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.")

View file

@ -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.")

View file

@ -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 {

View file

@ -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"),
}

View file

@ -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 {

View file

@ -573,7 +573,7 @@ func TestGetPushNotificationMessage(t *testing.T) {
replyToThreadType string
Locale string
PushNotificationContents string
ChannelType string
ChannelType model.ChannelType
ExpectedMessage string
}{

View file

@ -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 {

View file

@ -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{

View file

@ -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{

View file

@ -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{

View file

@ -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 {

View file

@ -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"`

View file

@ -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)

View file

@ -11,7 +11,7 @@ type MessageExport struct {
ChannelId *string
ChannelName *string
ChannelDisplayName *string
ChannelType *string
ChannelType *ChannelType
UserId *string
UserEmail *string

View file

@ -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 {

View file

@ -231,7 +231,7 @@ func TestGetChannelModeratedPermissions(t *testing.T) {
tests := []struct {
Name string
Permissions []string
ChannelType string
ChannelType ChannelType
Expected map[string]bool
}{
{

View file

@ -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 {

View file

@ -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)

View file

@ -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

View file

@ -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 {

View file

@ -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)

View file

@ -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)

View file

@ -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 {

View file

@ -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,

View file

@ -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 != "" {

View file

@ -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},
}
}

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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)