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
```
Этот коммит содержится в:
Agniva De Sarker
2021-07-20 12:45:26 +05:30
коммит произвёл Claudio Costa
родитель 4968657651
Коммит da7d71ccf7
37 изменённых файлов: 114 добавлений и 101 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@@ -11,7 +11,7 @@ type MessageExport struct {
ChannelId *string
ChannelName *string
ChannelDisplayName *string
ChannelType *string
ChannelType *ChannelType
UserId *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
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 {

Просмотреть файл

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

Просмотреть файл

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