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
@@ -636,11 +636,11 @@ func (th *TestHelper) CreatePrivateChannel() *model.Channel {
|
|||||||
return th.CreateChannelWithClient(th.Client, model.ChannelTypePrivate)
|
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)
|
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()
|
id := model.NewId()
|
||||||
|
|
||||||
channel := &model.Channel{
|
channel := &model.Channel{
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ func updateChannelPrivacy(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
props := model.StringInterfaceFromJson(r.Body)
|
props := model.StringInterfaceFromJson(r.Body)
|
||||||
privacy, ok := props["privacy"].(string)
|
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")
|
c.SetInvalidParam("privacy")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -299,17 +299,17 @@ func updateChannelPrivacy(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
auditRec.AddMeta("channel", channel)
|
auditRec.AddMeta("channel", channel)
|
||||||
auditRec.AddMeta("new_type", privacy)
|
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)
|
c.SetPermissionError(model.PermissionConvertPrivateChannelToPublic)
|
||||||
return
|
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)
|
c.SetPermissionError(model.PermissionConvertPublicChannelToPrivate)
|
||||||
return
|
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)
|
c.Err = model.NewAppError("updateChannelPrivacy", "api.channel.update_channel_privacy.default_channel_error", nil, "", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -321,7 +321,7 @@ func updateChannelPrivacy(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
auditRec.AddMeta("user", user)
|
auditRec.AddMeta("user", user)
|
||||||
|
|
||||||
channel.Type = privacy
|
channel.Type = model.ChannelType(privacy)
|
||||||
|
|
||||||
updatedChannel, err := c.App.UpdateChannelPrivacy(c.AppContext, channel, user)
|
updatedChannel, err := c.App.UpdateChannelPrivacy(c.AppContext, channel, user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ func localUpdateChannelPrivacy(c *Context, w http.ResponseWriter, r *http.Reques
|
|||||||
|
|
||||||
props := model.StringInterfaceFromJson(r.Body)
|
props := model.StringInterfaceFromJson(r.Body)
|
||||||
privacy, ok := props["privacy"].(string)
|
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")
|
c.SetInvalidParam("privacy")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -84,11 +84,11 @@ func localUpdateChannelPrivacy(c *Context, w http.ResponseWriter, r *http.Reques
|
|||||||
auditRec.AddMeta("channel", channel)
|
auditRec.AddMeta("channel", channel)
|
||||||
auditRec.AddMeta("new_type", privacy)
|
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)
|
c.Err = model.NewAppError("updateChannelPrivacy", "api.channel.update_channel_privacy.default_channel_error", nil, "", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
channel.Type = privacy
|
channel.Type = model.ChannelType(privacy)
|
||||||
|
|
||||||
updatedChannel, err := c.App.UpdateChannelPrivacy(c.AppContext, channel, nil)
|
updatedChannel, err := c.App.UpdateChannelPrivacy(c.AppContext, channel, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1850,7 +1850,7 @@ func TestUpdateChannelPrivacy(t *testing.T) {
|
|||||||
type testTable []struct {
|
type testTable []struct {
|
||||||
name string
|
name string
|
||||||
channel *model.Channel
|
channel *model.Channel
|
||||||
expectedPrivacy string
|
expectedPrivacy model.ChannelType
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("Should get a forbidden response if not logged in", func(t *testing.T) {
|
t.Run("Should get a forbidden response if not logged in", func(t *testing.T) {
|
||||||
|
|||||||
@@ -725,7 +725,7 @@ func (a *App) postChannelPrivacyMessage(c *request.Context, user *model.User, ch
|
|||||||
authorUsername = systemBot.Username
|
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.ChannelTypeOpen: i18n.T("api.channel.change_channel_privacy.private_to_public"),
|
||||||
model.ChannelTypePrivate: i18n.T("api.channel.change_channel_privacy.public_to_private"),
|
model.ChannelTypePrivate: i18n.T("api.channel.change_channel_privacy.public_to_private"),
|
||||||
})[channel.Type]
|
})[channel.Type]
|
||||||
@@ -1080,7 +1080,7 @@ func (a *App) PatchChannelModerationsForChannel(channel *model.Channel, channelM
|
|||||||
return buildChannelModerations(channel.Type, memberRole, guestRole, higherScopedMemberRole, higherScopedGuestRole), nil
|
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
|
var memberPermissions, guestPermissions, higherScopedMemberPermissions, higherScopedGuestPermissions map[string]bool
|
||||||
if memberRole != nil {
|
if memberRole != nil {
|
||||||
memberPermissions = memberRole.GetChannelModeratedPermissions(channelType)
|
memberPermissions = memberRole.GetChannelModeratedPermissions(channelType)
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ func (th *TestHelper) CreatePrivateChannel(team *model.Team) *model.Channel {
|
|||||||
return th.createChannel(team, model.ChannelTypePrivate)
|
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()
|
id := model.NewId()
|
||||||
|
|
||||||
channel := &model.Channel{
|
channel := &model.Channel{
|
||||||
|
|||||||
@@ -610,10 +610,11 @@ func TestImportImportChannel(t *testing.T) {
|
|||||||
require.NoError(t, nErr, "Failed to get team count.")
|
require.NoError(t, nErr, "Failed to get team count.")
|
||||||
|
|
||||||
// Do an invalid channel in dry-run mode.
|
// Do an invalid channel in dry-run mode.
|
||||||
|
chanOpen := model.ChannelTypeOpen
|
||||||
data := ChannelImportData{
|
data := ChannelImportData{
|
||||||
Team: &teamName,
|
Team: &teamName,
|
||||||
DisplayName: ptrStr("Display Name"),
|
DisplayName: ptrStr("Display Name"),
|
||||||
Type: ptrStr("O"),
|
Type: &chanOpen,
|
||||||
Header: ptrStr("Channe Header"),
|
Header: ptrStr("Channe Header"),
|
||||||
Purpose: ptrStr("Channel Purpose"),
|
Purpose: ptrStr("Channel Purpose"),
|
||||||
Scheme: &scheme1.Name,
|
Scheme: &scheme1.Name,
|
||||||
@@ -678,8 +679,9 @@ func TestImportImportChannel(t *testing.T) {
|
|||||||
assert.Equal(t, scheme1.Id, *channel.SchemeId)
|
assert.Equal(t, scheme1.Id, *channel.SchemeId)
|
||||||
|
|
||||||
// Alter all the fields of that channel.
|
// Alter all the fields of that channel.
|
||||||
|
cTypePr := model.ChannelTypePrivate
|
||||||
data.DisplayName = ptrStr("Chaned Disp Name")
|
data.DisplayName = ptrStr("Chaned Disp Name")
|
||||||
data.Type = ptrStr(model.ChannelTypePrivate)
|
data.Type = &cTypePr
|
||||||
data.Header = ptrStr("New Header")
|
data.Header = ptrStr("New Header")
|
||||||
data.Purpose = ptrStr("New Purpose")
|
data.Purpose = ptrStr("New Purpose")
|
||||||
data.Scheme = &scheme2.Name
|
data.Scheme = &scheme2.Name
|
||||||
@@ -874,11 +876,12 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
require.Nil(t, appErr, "Failed to get team from database.")
|
require.Nil(t, appErr, "Failed to get team from database.")
|
||||||
|
|
||||||
channelName := model.NewId()
|
channelName := model.NewId()
|
||||||
|
chanTypeOpen := model.ChannelTypeOpen
|
||||||
th.App.importChannel(th.Context, &ChannelImportData{
|
th.App.importChannel(th.Context, &ChannelImportData{
|
||||||
Team: &teamName,
|
Team: &teamName,
|
||||||
Name: &channelName,
|
Name: &channelName,
|
||||||
DisplayName: ptrStr("Display Name"),
|
DisplayName: ptrStr("Display Name"),
|
||||||
Type: ptrStr("O"),
|
Type: &chanTypeOpen,
|
||||||
}, false)
|
}, false)
|
||||||
channel, appErr := th.App.GetChannelByName(channelName, team.Id, false)
|
channel, appErr := th.App.GetChannelByName(channelName, team.Id, false)
|
||||||
require.Nil(t, appErr, "Failed to get channel from database.")
|
require.Nil(t, appErr, "Failed to get channel from database.")
|
||||||
@@ -1396,7 +1399,7 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
Team: &teamName,
|
Team: &teamName,
|
||||||
Name: ptrStr(model.NewId()),
|
Name: ptrStr(model.NewId()),
|
||||||
DisplayName: ptrStr("Display Name"),
|
DisplayName: ptrStr("Display Name"),
|
||||||
Type: ptrStr("O"),
|
Type: &chanTypeOpen,
|
||||||
Header: ptrStr("Channe Header"),
|
Header: ptrStr("Channe Header"),
|
||||||
Purpose: ptrStr("Channel Purpose"),
|
Purpose: ptrStr("Channel Purpose"),
|
||||||
}
|
}
|
||||||
@@ -1939,11 +1942,12 @@ func TestImportimportMultiplePostLines(t *testing.T) {
|
|||||||
|
|
||||||
// Create a Channel.
|
// Create a Channel.
|
||||||
channelName := model.NewId()
|
channelName := model.NewId()
|
||||||
|
chanTypeOpen := model.ChannelTypeOpen
|
||||||
th.App.importChannel(th.Context, &ChannelImportData{
|
th.App.importChannel(th.Context, &ChannelImportData{
|
||||||
Team: &teamName,
|
Team: &teamName,
|
||||||
Name: &channelName,
|
Name: &channelName,
|
||||||
DisplayName: ptrStr("Display Name"),
|
DisplayName: ptrStr("Display Name"),
|
||||||
Type: ptrStr("O"),
|
Type: &chanTypeOpen,
|
||||||
}, false)
|
}, false)
|
||||||
channel, err := th.App.GetChannelByName(channelName, team.Id, false)
|
channel, err := th.App.GetChannelByName(channelName, team.Id, false)
|
||||||
require.Nil(t, err, "Failed to get channel from database.")
|
require.Nil(t, err, "Failed to get channel from database.")
|
||||||
@@ -2418,7 +2422,7 @@ func TestImportimportMultiplePostLines(t *testing.T) {
|
|||||||
Team: &teamName2,
|
Team: &teamName2,
|
||||||
Name: &channelName,
|
Name: &channelName,
|
||||||
DisplayName: ptrStr("Display Name"),
|
DisplayName: ptrStr("Display Name"),
|
||||||
Type: ptrStr("O"),
|
Type: &chanTypeOpen,
|
||||||
}, false)
|
}, false)
|
||||||
_, err = th.App.GetChannelByName(channelName, team2.Id, false)
|
_, err = th.App.GetChannelByName(channelName, team2.Id, false)
|
||||||
require.Nil(t, err, "Failed to get channel from database.")
|
require.Nil(t, err, "Failed to get channel from database.")
|
||||||
@@ -2477,11 +2481,12 @@ func TestImportImportPost(t *testing.T) {
|
|||||||
|
|
||||||
// Create a Channel.
|
// Create a Channel.
|
||||||
channelName := model.NewId()
|
channelName := model.NewId()
|
||||||
|
chanTypeOpen := model.ChannelTypeOpen
|
||||||
th.App.importChannel(th.Context, &ChannelImportData{
|
th.App.importChannel(th.Context, &ChannelImportData{
|
||||||
Team: &teamName,
|
Team: &teamName,
|
||||||
Name: &channelName,
|
Name: &channelName,
|
||||||
DisplayName: ptrStr("Display Name"),
|
DisplayName: ptrStr("Display Name"),
|
||||||
Type: ptrStr("O"),
|
Type: &chanTypeOpen,
|
||||||
}, false)
|
}, false)
|
||||||
channel, appErr := th.App.GetChannelByName(channelName, team.Id, false)
|
channel, appErr := th.App.GetChannelByName(channelName, team.Id, false)
|
||||||
require.Nil(t, appErr, "Failed to get channel from database.")
|
require.Nil(t, appErr, "Failed to get channel from database.")
|
||||||
@@ -3920,11 +3925,12 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) {
|
|||||||
|
|
||||||
// Create a Channel.
|
// Create a Channel.
|
||||||
channelName := model.NewId()
|
channelName := model.NewId()
|
||||||
|
chanTypeOpen := model.ChannelTypeOpen
|
||||||
th.App.importChannel(th.Context, &ChannelImportData{
|
th.App.importChannel(th.Context, &ChannelImportData{
|
||||||
Team: &teamName,
|
Team: &teamName,
|
||||||
Name: &channelName,
|
Name: &channelName,
|
||||||
DisplayName: ptrStr("Display Name"),
|
DisplayName: ptrStr("Display Name"),
|
||||||
Type: ptrStr("O"),
|
Type: &chanTypeOpen,
|
||||||
}, false)
|
}, false)
|
||||||
_, appErr = th.App.GetChannelByName(channelName, team.Id, false)
|
_, appErr = th.App.GetChannelByName(channelName, team.Id, false)
|
||||||
require.Nil(t, appErr, "Failed to get channel from database.")
|
require.Nil(t, appErr, "Failed to get channel from database.")
|
||||||
@@ -4195,11 +4201,12 @@ func TestZippedImportPostAndRepliesWithAttachments(t *testing.T) {
|
|||||||
|
|
||||||
// Create a Channel.
|
// Create a Channel.
|
||||||
channelName := model.NewId()
|
channelName := model.NewId()
|
||||||
|
chanTypeOpen := model.ChannelTypeOpen
|
||||||
th.App.importChannel(th.Context, &ChannelImportData{
|
th.App.importChannel(th.Context, &ChannelImportData{
|
||||||
Team: &teamName,
|
Team: &teamName,
|
||||||
Name: &channelName,
|
Name: &channelName,
|
||||||
DisplayName: ptrStr("Display Name"),
|
DisplayName: ptrStr("Display Name"),
|
||||||
Type: ptrStr("O"),
|
Type: &chanTypeOpen,
|
||||||
}, false)
|
}, false)
|
||||||
_, appErr = th.App.GetChannelByName(channelName, team.Id, false)
|
_, appErr = th.App.GetChannelByName(channelName, team.Id, false)
|
||||||
require.Nil(t, appErr, "Failed to get channel from database.")
|
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.")
|
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)
|
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.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.")
|
require.NoError(t, err, "Failed to get channel count.")
|
||||||
|
|||||||
@@ -34,13 +34,13 @@ type TeamImportData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ChannelImportData struct {
|
type ChannelImportData struct {
|
||||||
Team *string `json:"team"`
|
Team *string `json:"team"`
|
||||||
Name *string `json:"name"`
|
Name *string `json:"name"`
|
||||||
DisplayName *string `json:"display_name"`
|
DisplayName *string `json:"display_name"`
|
||||||
Type *string `json:"type"`
|
Type *model.ChannelType `json:"type"`
|
||||||
Header *string `json:"header,omitempty"`
|
Header *string `json:"header,omitempty"`
|
||||||
Purpose *string `json:"purpose,omitempty"`
|
Purpose *string `json:"purpose,omitempty"`
|
||||||
Scheme *string `json:"scheme,omitempty"`
|
Scheme *string `json:"scheme,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserImportData struct {
|
type UserImportData struct {
|
||||||
|
|||||||
@@ -357,11 +357,12 @@ func TestImportValidateTeamImportData(t *testing.T) {
|
|||||||
func TestImportValidateChannelImportData(t *testing.T) {
|
func TestImportValidateChannelImportData(t *testing.T) {
|
||||||
|
|
||||||
// Test with minimum required valid properties.
|
// Test with minimum required valid properties.
|
||||||
|
chanTypeOpen := model.ChannelTypeOpen
|
||||||
data := ChannelImportData{
|
data := ChannelImportData{
|
||||||
Team: ptrStr("teamname"),
|
Team: ptrStr("teamname"),
|
||||||
Name: ptrStr("channelname"),
|
Name: ptrStr("channelname"),
|
||||||
DisplayName: ptrStr("Display Name"),
|
DisplayName: ptrStr("Display Name"),
|
||||||
Type: ptrStr("O"),
|
Type: &chanTypeOpen,
|
||||||
}
|
}
|
||||||
err := validateChannelImportData(&data)
|
err := validateChannelImportData(&data)
|
||||||
require.Nil(t, err, "Validation failed but should have been valid.")
|
require.Nil(t, err, "Validation failed but should have been valid.")
|
||||||
@@ -370,7 +371,7 @@ func TestImportValidateChannelImportData(t *testing.T) {
|
|||||||
data = ChannelImportData{
|
data = ChannelImportData{
|
||||||
Name: ptrStr("channelname"),
|
Name: ptrStr("channelname"),
|
||||||
DisplayName: ptrStr("Display Name"),
|
DisplayName: ptrStr("Display Name"),
|
||||||
Type: ptrStr("O"),
|
Type: &chanTypeOpen,
|
||||||
}
|
}
|
||||||
err = validateChannelImportData(&data)
|
err = validateChannelImportData(&data)
|
||||||
require.NotNil(t, err, "Should have failed due to missing team.")
|
require.NotNil(t, err, "Should have failed due to missing team.")
|
||||||
@@ -379,7 +380,7 @@ func TestImportValidateChannelImportData(t *testing.T) {
|
|||||||
data = ChannelImportData{
|
data = ChannelImportData{
|
||||||
Team: ptrStr("teamname"),
|
Team: ptrStr("teamname"),
|
||||||
DisplayName: ptrStr("Display Name"),
|
DisplayName: ptrStr("Display Name"),
|
||||||
Type: ptrStr("O"),
|
Type: &chanTypeOpen,
|
||||||
}
|
}
|
||||||
err = validateChannelImportData(&data)
|
err = validateChannelImportData(&data)
|
||||||
require.NotNil(t, err, "Should have failed due to missing name.")
|
require.NotNil(t, err, "Should have failed due to missing name.")
|
||||||
@@ -400,7 +401,7 @@ func TestImportValidateChannelImportData(t *testing.T) {
|
|||||||
data = ChannelImportData{
|
data = ChannelImportData{
|
||||||
Team: ptrStr("teamname"),
|
Team: ptrStr("teamname"),
|
||||||
Name: ptrStr("channelname"),
|
Name: ptrStr("channelname"),
|
||||||
Type: ptrStr("O"),
|
Type: &chanTypeOpen,
|
||||||
}
|
}
|
||||||
err = validateChannelImportData(&data)
|
err = validateChannelImportData(&data)
|
||||||
require.NotNil(t, err, "Should have failed due to missing display_name.")
|
require.NotNil(t, err, "Should have failed due to missing display_name.")
|
||||||
@@ -422,11 +423,13 @@ func TestImportValidateChannelImportData(t *testing.T) {
|
|||||||
err = validateChannelImportData(&data)
|
err = validateChannelImportData(&data)
|
||||||
require.NotNil(t, err, "Should have failed due to missing type.")
|
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)
|
err = validateChannelImportData(&data)
|
||||||
require.NotNil(t, err, "Should have failed due to invalid type.")
|
require.NotNil(t, err, "Should have failed due to invalid type.")
|
||||||
|
|
||||||
data.Type = ptrStr("P")
|
chanTypePr := model.ChannelTypePrivate
|
||||||
|
data.Type = &chanTypePr
|
||||||
err = validateChannelImportData(&data)
|
err = validateChannelImportData(&data)
|
||||||
require.Nil(t, err, "Should have succeeded with valid type.")
|
require.Nil(t, err, "Should have succeeded with valid type.")
|
||||||
|
|
||||||
@@ -435,7 +438,7 @@ func TestImportValidateChannelImportData(t *testing.T) {
|
|||||||
Team: ptrStr("teamname"),
|
Team: ptrStr("teamname"),
|
||||||
Name: ptrStr("channelname"),
|
Name: ptrStr("channelname"),
|
||||||
DisplayName: ptrStr("Display Name"),
|
DisplayName: ptrStr("Display Name"),
|
||||||
Type: ptrStr("O"),
|
Type: &chanTypeOpen,
|
||||||
Header: ptrStr("Channel Header Here"),
|
Header: ptrStr("Channel Header Here"),
|
||||||
Purpose: ptrStr("Channel Purpose 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,
|
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 the post only has images then push an appropriate message
|
||||||
if postMessage == "" && hasFiles {
|
if postMessage == "" && hasFiles {
|
||||||
|
|||||||
@@ -573,7 +573,7 @@ func TestGetPushNotificationMessage(t *testing.T) {
|
|||||||
replyToThreadType string
|
replyToThreadType string
|
||||||
Locale string
|
Locale string
|
||||||
PushNotificationContents string
|
PushNotificationContents string
|
||||||
ChannelType string
|
ChannelType model.ChannelType
|
||||||
|
|
||||||
ExpectedMessage string
|
ExpectedMessage string
|
||||||
}{
|
}{
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ type AutoChannelCreator struct {
|
|||||||
DisplayNameCharset string
|
DisplayNameCharset string
|
||||||
NameLen utils.Range
|
NameLen utils.Range
|
||||||
NameCharset string
|
NameCharset string
|
||||||
ChannelType string
|
ChannelType model.ChannelType
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAutoChannelCreator(a *app.App, team *model.Team, userID string) *AutoChannelCreator {
|
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)
|
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()
|
id := model.NewId()
|
||||||
|
|
||||||
channel := &model.Channel{
|
channel := &model.Channel{
|
||||||
@@ -288,7 +288,7 @@ func (th *TestHelper) createChannel(team *model.Team, channelType string, option
|
|||||||
return channel
|
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()
|
id := model.NewId()
|
||||||
|
|
||||||
channel := &model.Channel{
|
channel := &model.Channel{
|
||||||
|
|||||||
@@ -617,9 +617,9 @@ func createChannel(idx int, teamName string) app.LineImportData {
|
|||||||
purpose = purpose[0:250]
|
purpose = purpose[0:250]
|
||||||
}
|
}
|
||||||
|
|
||||||
channelType := "P"
|
channelType := model.ChannelTypePrivate
|
||||||
if rand.Intn(2) == 0 {
|
if rand.Intn(2) == 0 {
|
||||||
channelType = "O"
|
channelType = model.ChannelTypeOpen
|
||||||
}
|
}
|
||||||
|
|
||||||
channel := app.ChannelImportData{
|
channel := app.ChannelImportData{
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ func (th *TestHelper) CreateChannel(team *model.Team) *model.Channel {
|
|||||||
return th.createChannel(team, model.ChannelTypeOpen)
|
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()
|
id := model.NewId()
|
||||||
|
|
||||||
channel := &model.Channel{
|
channel := &model.Channel{
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func AuditModelTypeConv(val interface{}) (newVal interface{}, converted bool) {
|
|||||||
type auditChannel struct {
|
type auditChannel struct {
|
||||||
ID string
|
ID string
|
||||||
Name string
|
Name string
|
||||||
Type string
|
Type ChannelType
|
||||||
}
|
}
|
||||||
|
|
||||||
// newAuditChannel creates a simplified representation of Channel for output to audit log.
|
// 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) {
|
func (c auditChannel) MarshalJSONObject(enc *gojay.Encoder) {
|
||||||
enc.StringKey("id", c.ID)
|
enc.StringKey("id", c.ID)
|
||||||
enc.StringKey("name", c.Name)
|
enc.StringKey("name", c.Name)
|
||||||
enc.StringKey("type", c.Type)
|
enc.StringKey("type", string(c.Type))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c auditChannel) IsNil() bool {
|
func (c auditChannel) IsNil() bool {
|
||||||
|
|||||||
@@ -14,11 +14,13 @@ import (
|
|||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ChannelType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ChannelTypeOpen = "O"
|
ChannelTypeOpen ChannelType = "O"
|
||||||
ChannelTypePrivate = "P"
|
ChannelTypePrivate ChannelType = "P"
|
||||||
ChannelTypeDirect = "D"
|
ChannelTypeDirect ChannelType = "D"
|
||||||
ChannelTypeGroup = "G"
|
ChannelTypeGroup ChannelType = "G"
|
||||||
|
|
||||||
ChannelGroupMaxUsers = 8
|
ChannelGroupMaxUsers = 8
|
||||||
ChannelGroupMinUsers = 3
|
ChannelGroupMinUsers = 3
|
||||||
@@ -40,7 +42,7 @@ type Channel struct {
|
|||||||
UpdateAt int64 `json:"update_at"`
|
UpdateAt int64 `json:"update_at"`
|
||||||
DeleteAt int64 `json:"delete_at"`
|
DeleteAt int64 `json:"delete_at"`
|
||||||
TeamId string `json:"team_id"`
|
TeamId string `json:"team_id"`
|
||||||
Type string `json:"type"`
|
Type ChannelType `json:"type"`
|
||||||
DisplayName string `json:"display_name"`
|
DisplayName string `json:"display_name"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Header string `json:"header"`
|
Header string `json:"header"`
|
||||||
|
|||||||
@@ -2453,8 +2453,8 @@ func (c *Client4) ConvertChannelToPrivate(channelId string) (*Channel, *Response
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateChannelPrivacy updates channel privacy
|
// UpdateChannelPrivacy updates channel privacy
|
||||||
func (c *Client4) UpdateChannelPrivacy(channelId string, privacy string) (*Channel, *Response) {
|
func (c *Client4) UpdateChannelPrivacy(channelId string, privacy ChannelType) (*Channel, *Response) {
|
||||||
requestBody := map[string]string{"privacy": privacy}
|
requestBody := map[string]string{"privacy": string(privacy)}
|
||||||
r, err := c.DoApiPut(c.GetChannelRoute(channelId)+"/privacy", MapToJson(requestBody))
|
r, err := c.DoApiPut(c.GetChannelRoute(channelId)+"/privacy", MapToJson(requestBody))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, BuildErrorResponse(r, err)
|
return nil, BuildErrorResponse(r, err)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ type MessageExport struct {
|
|||||||
ChannelId *string
|
ChannelId *string
|
||||||
ChannelName *string
|
ChannelName *string
|
||||||
ChannelDisplayName *string
|
ChannelDisplayName *string
|
||||||
ChannelType *string
|
ChannelType *ChannelType
|
||||||
|
|
||||||
UserId *string
|
UserId *string
|
||||||
UserEmail *string
|
UserEmail *string
|
||||||
|
|||||||
@@ -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
|
// 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)
|
moderatedPermissions := make(map[string]bool)
|
||||||
for _, permission := range r.Permissions {
|
for _, permission := range r.Permissions {
|
||||||
if _, found := ChannelModeratedPermissionsMap[permission]; !found {
|
if _, found := ChannelModeratedPermissionsMap[permission]; !found {
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ func TestGetChannelModeratedPermissions(t *testing.T) {
|
|||||||
tests := []struct {
|
tests := []struct {
|
||||||
Name string
|
Name string
|
||||||
Permissions []string
|
Permissions []string
|
||||||
ChannelType string
|
ChannelType ChannelType
|
||||||
Expected map[string]bool
|
Expected map[string]bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,19 +16,19 @@ import (
|
|||||||
// If "home" is false, then the shared channel is homed remotely, and "RemoteId"
|
// If "home" is false, then the shared channel is homed remotely, and "RemoteId"
|
||||||
// field points to the remote cluster connection in "RemoteClusters" table.
|
// field points to the remote cluster connection in "RemoteClusters" table.
|
||||||
type SharedChannel struct {
|
type SharedChannel struct {
|
||||||
ChannelId string `json:"id"`
|
ChannelId string `json:"id"`
|
||||||
TeamId string `json:"team_id"`
|
TeamId string `json:"team_id"`
|
||||||
Home bool `json:"home"`
|
Home bool `json:"home"`
|
||||||
ReadOnly bool `json:"readonly"`
|
ReadOnly bool `json:"readonly"`
|
||||||
ShareName string `json:"name"`
|
ShareName string `json:"name"`
|
||||||
ShareDisplayName string `json:"display_name"`
|
ShareDisplayName string `json:"display_name"`
|
||||||
SharePurpose string `json:"purpose"`
|
SharePurpose string `json:"purpose"`
|
||||||
ShareHeader string `json:"header"`
|
ShareHeader string `json:"header"`
|
||||||
CreatorId string `json:"creator_id"`
|
CreatorId string `json:"creator_id"`
|
||||||
CreateAt int64 `json:"create_at"`
|
CreateAt int64 `json:"create_at"`
|
||||||
UpdateAt int64 `json:"update_at"`
|
UpdateAt int64 `json:"update_at"`
|
||||||
RemoteId string `json:"remote_id,omitempty"` // if not "home"
|
RemoteId string `json:"remote_id,omitempty"` // if not "home"
|
||||||
Type string `db:"-"`
|
Type ChannelType `db:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sc *SharedChannel) ToJson() string {
|
func (sc *SharedChannel) ToJson() string {
|
||||||
|
|||||||
@@ -17,15 +17,15 @@ import (
|
|||||||
|
|
||||||
// channelInviteMsg represents an invitation for a remote cluster to start sharing a channel.
|
// channelInviteMsg represents an invitation for a remote cluster to start sharing a channel.
|
||||||
type channelInviteMsg struct {
|
type channelInviteMsg struct {
|
||||||
ChannelId string `json:"channel_id"`
|
ChannelId string `json:"channel_id"`
|
||||||
TeamId string `json:"team_id"`
|
TeamId string `json:"team_id"`
|
||||||
ReadOnly bool `json:"read_only"`
|
ReadOnly bool `json:"read_only"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
DisplayName string `json:"display_name"`
|
DisplayName string `json:"display_name"`
|
||||||
Header string `json:"header"`
|
Header string `json:"header"`
|
||||||
Purpose string `json:"purpose"`
|
Purpose string `json:"purpose"`
|
||||||
Type string `json:"type"`
|
Type model.ChannelType `json:"type"`
|
||||||
DirectParticipantIDs []string `json:"direct_participant_ids"`
|
DirectParticipantIDs []string `json:"direct_participant_ids"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type InviteOption func(msg *channelInviteMsg)
|
type InviteOption func(msg *channelInviteMsg)
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
"github.com/mattermost/mattermost-server/v5/shared/mlog"
|
"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)
|
decoder := json.NewDecoder(data)
|
||||||
|
|
||||||
var channels []slackChannel
|
var channels []slackChannel
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ type slackChannel struct {
|
|||||||
Members []string `json:"members"`
|
Members []string `json:"members"`
|
||||||
Purpose slackChannelSub `json:"purpose"`
|
Purpose slackChannelSub `json:"purpose"`
|
||||||
Topic slackChannelSub `json:"topic"`
|
Topic slackChannelSub `json:"topic"`
|
||||||
Type string
|
Type model.ChannelType
|
||||||
}
|
}
|
||||||
|
|
||||||
type slackChannelSub struct {
|
type slackChannelSub struct {
|
||||||
|
|||||||
@@ -101,9 +101,9 @@ func initializeMocks(cfg *model.Config) (*mocks.ServerIface, *storeMocks.Store,
|
|||||||
teamStore.On("GroupSyncedTeamCount").Return(int64(16), nil)
|
teamStore.On("GroupSyncedTeamCount").Return(int64(16), nil)
|
||||||
|
|
||||||
channelStore := storeMocks.ChannelStore{}
|
channelStore := storeMocks.ChannelStore{}
|
||||||
channelStore.On("AnalyticsTypeCount", "", "O").Return(int64(25), nil)
|
channelStore.On("AnalyticsTypeCount", "", model.ChannelTypeOpen).Return(int64(25), nil)
|
||||||
channelStore.On("AnalyticsTypeCount", "", "P").Return(int64(26), nil)
|
channelStore.On("AnalyticsTypeCount", "", model.ChannelTypePrivate).Return(int64(26), nil)
|
||||||
channelStore.On("AnalyticsTypeCount", "", "D").Return(int64(27), nil)
|
channelStore.On("AnalyticsTypeCount", "", model.ChannelTypeDirect).Return(int64(27), nil)
|
||||||
channelStore.On("AnalyticsDeletedTypeCount", "", "O").Return(int64(22), nil)
|
channelStore.On("AnalyticsDeletedTypeCount", "", "O").Return(int64(22), nil)
|
||||||
channelStore.On("AnalyticsDeletedTypeCount", "", "P").Return(int64(23), nil)
|
channelStore.On("AnalyticsDeletedTypeCount", "", "P").Return(int64(23), nil)
|
||||||
channelStore.On("GroupSyncedChannelCount").Return(int64(17), nil)
|
channelStore.On("GroupSyncedChannelCount").Return(int64(17), nil)
|
||||||
|
|||||||
@@ -552,7 +552,7 @@ func (s *OpenTracingLayerChannelStore) AnalyticsDeletedTypeCount(teamID string,
|
|||||||
return result, err
|
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()
|
origCtx := s.Root.Store.Context()
|
||||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.AnalyticsTypeCount")
|
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.AnalyticsTypeCount")
|
||||||
s.Root.Store.SetContext(newCtx)
|
s.Root.Store.SetContext(newCtx)
|
||||||
|
|||||||
@@ -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
|
tries := 0
|
||||||
for {
|
for {
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ func (th *SearchTestHelper) deleteBot(botID string) error {
|
|||||||
return nil
|
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{
|
channel, err := th.Store.Channel().Save(&model.Channel{
|
||||||
TeamId: teamID,
|
TeamId: teamID,
|
||||||
DisplayName: displayName,
|
DisplayName: displayName,
|
||||||
|
|||||||
@@ -1043,7 +1043,7 @@ func (s SqlChannelStore) getAllChannelsQuery(opts store.ChannelSearchOpts, forCo
|
|||||||
query := s.getQueryBuilder().
|
query := s.getQueryBuilder().
|
||||||
Select(selectStr).
|
Select(selectStr).
|
||||||
From("Channels AS c").
|
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 {
|
if !forCount {
|
||||||
query = query.Join("Teams ON Teams.Id = c.TeamId")
|
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
|
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"
|
query := "SELECT COUNT(Id) AS Value FROM Channels WHERE Type = :ChannelType"
|
||||||
|
|
||||||
if teamId != "" {
|
if teamId != "" {
|
||||||
|
|||||||
@@ -378,11 +378,11 @@ func (s SqlChannelStore) completePopulatingCategoryChannelsT(db dbSelecter, cate
|
|||||||
var channelTypeFilter sq.Sqlizer
|
var channelTypeFilter sq.Sqlizer
|
||||||
if category.Type == model.SidebarCategoryDirectMessages {
|
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
|
// 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 {
|
} 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
|
// 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{
|
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},
|
sq.Eq{"Channels.TeamId": category.TeamId},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ func checkTeamsChannelsIntegrity(ss *SqlStore) model.IntegrityCheckResult {
|
|||||||
parentIdAttr: "TeamId",
|
parentIdAttr: "TeamId",
|
||||||
childName: "Channels",
|
childName: "Channels",
|
||||||
childIdAttr: "Id",
|
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{
|
res2 := checkParentChildIntegrity(ss, relationalCheckConfig{
|
||||||
parentName: "Teams",
|
parentName: "Teams",
|
||||||
@@ -223,7 +223,7 @@ func checkTeamsChannelsIntegrity(ss *SqlStore) model.IntegrityCheckResult {
|
|||||||
childName: "Channels",
|
childName: "Channels",
|
||||||
childIdAttr: "Id",
|
childIdAttr: "Id",
|
||||||
canParentIdBeEmpty: true,
|
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)
|
data1 := res1.Data.(model.RelationalIntegrityCheckData)
|
||||||
data2 := res2.Data.(model.RelationalIntegrityCheckData)
|
data2 := res2.Data.(model.RelationalIntegrityCheckData)
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ type ChannelStore interface {
|
|||||||
UpdateLastViewedAtPost(unreadPost *model.Post, userID string, mentionCount, mentionCountRoot int, updateThreads bool, setUnreadCountRoot bool) (*model.ChannelUnreadAt, error)
|
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)
|
CountPostsAfter(channelID string, timestamp int64, userID string) (int, int, error)
|
||||||
IncrementMentionCount(channelID string, userID string, updateThreads, isRoot bool) 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)
|
GetMembersForUser(teamID string, userID string) (*model.ChannelMembers, error)
|
||||||
GetMembersForUserWithPagination(teamID, userID string, page, perPage int) (*model.ChannelMembers, error)
|
GetMembersForUserWithPagination(teamID, userID string, page, perPage int) (*model.ChannelMembers, error)
|
||||||
AutocompleteInTeam(teamID string, term string, includeDeleted bool) (*model.ChannelList, error)
|
AutocompleteInTeam(teamID string, term string, includeDeleted bool) (*model.ChannelList, error)
|
||||||
|
|||||||
@@ -3942,7 +3942,7 @@ func groupTestAdminRoleGroupsForSyncableMemberTeam(t *testing.T, ss store.Store)
|
|||||||
team := &model.Team{
|
team := &model.Team{
|
||||||
DisplayName: "A Name",
|
DisplayName: "A Name",
|
||||||
Name: "zz" + model.NewId(),
|
Name: "zz" + model.NewId(),
|
||||||
Type: model.ChannelTypeOpen,
|
Type: model.TeamOpen,
|
||||||
}
|
}
|
||||||
team, nErr := ss.Team().Save(team)
|
team, nErr := ss.Team().Save(team)
|
||||||
require.NoError(t, nErr)
|
require.NoError(t, nErr)
|
||||||
@@ -4045,7 +4045,7 @@ func groupTestPermittedSyncableAdminsTeam(t *testing.T, ss store.Store) {
|
|||||||
team := &model.Team{
|
team := &model.Team{
|
||||||
DisplayName: "A Name",
|
DisplayName: "A Name",
|
||||||
Name: "zz" + model.NewId(),
|
Name: "zz" + model.NewId(),
|
||||||
Type: model.ChannelTypeOpen,
|
Type: model.TeamOpen,
|
||||||
}
|
}
|
||||||
team, nErr := ss.Team().Save(team)
|
team, nErr := ss.Team().Save(team)
|
||||||
require.NoError(t, nErr)
|
require.NoError(t, nErr)
|
||||||
|
|||||||
@@ -40,18 +40,18 @@ func (_m *ChannelStore) AnalyticsDeletedTypeCount(teamID string, channelType str
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AnalyticsTypeCount provides a mock function with given fields: teamID, channelType
|
// 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)
|
ret := _m.Called(teamID, channelType)
|
||||||
|
|
||||||
var r0 int64
|
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)
|
r0 = rf(teamID, channelType)
|
||||||
} else {
|
} else {
|
||||||
r0 = ret.Get(0).(int64)
|
r0 = ret.Get(0).(int64)
|
||||||
}
|
}
|
||||||
|
|
||||||
var r1 error
|
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)
|
r1 = rf(teamID, channelType)
|
||||||
} else {
|
} else {
|
||||||
r1 = ret.Error(1)
|
r1 = ret.Error(1)
|
||||||
|
|||||||
@@ -534,7 +534,7 @@ func (s *TimerLayerChannelStore) AnalyticsDeletedTypeCount(teamID string, channe
|
|||||||
return result, err
|
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()
|
start := timemodule.Now()
|
||||||
|
|
||||||
result, err := s.ChannelStore.AnalyticsTypeCount(teamID, channelType)
|
result, err := s.ChannelStore.AnalyticsTypeCount(teamID, channelType)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user