MM-14416: Adds new fields to Channels and Teams for use by LDAP groups removals. (#10450)

* MM-14416: Updates tests.

* MM-14416: Adds new fields to models and patches.

* MM-14416: Adds upgrade operations.

* MM-14416: Removes the 'is' from the new field names.

* MM-14416: Some fmting and removes API test change for now.

* MM-14416: Adds team patch test.

* MM-14416: Using sql.NullBool.

* MM-14416: Using sql.NullBool.
Этот коммит содержится в:
Martin Kraft
2019-03-18 10:50:32 -04:00
коммит произвёл Jesús Espino
родитель 683f215bd9
Коммит 16a9489bbb
5 изменённых файлов: 108 добавлений и 42 удалений

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

@@ -5,6 +5,7 @@ package model
import ( import (
"crypto/sha1" "crypto/sha1"
"database/sql"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"io" "io"
@@ -35,22 +36,23 @@ const (
) )
type Channel struct { type Channel struct {
Id string `json:"id"` Id string `json:"id"`
CreateAt int64 `json:"create_at"` CreateAt int64 `json:"create_at"`
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 string `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"`
Purpose string `json:"purpose"` Purpose string `json:"purpose"`
LastPostAt int64 `json:"last_post_at"` LastPostAt int64 `json:"last_post_at"`
TotalMsgCount int64 `json:"total_msg_count"` TotalMsgCount int64 `json:"total_msg_count"`
ExtraUpdateAt int64 `json:"extra_update_at"` ExtraUpdateAt int64 `json:"extra_update_at"`
CreatorId string `json:"creator_id"` CreatorId string `json:"creator_id"`
SchemeId *string `json:"scheme_id"` SchemeId *string `json:"scheme_id"`
Props map[string]interface{} `json:"props" db:"-"` Props map[string]interface{} `json:"props" db:"-"`
GroupConstrained sql.NullBool `json:"group_constrained"`
} }
type ChannelWithTeamData struct { type ChannelWithTeamData struct {
@@ -61,10 +63,11 @@ type ChannelWithTeamData struct {
} }
type ChannelPatch struct { type ChannelPatch struct {
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"`
Purpose *string `json:"purpose"` Purpose *string `json:"purpose"`
GroupConstrained *bool `json:"group_constrained"`
} }
type ChannelForExport struct { type ChannelForExport struct {
@@ -186,6 +189,10 @@ func (o *Channel) Patch(patch *ChannelPatch) {
if patch.Purpose != nil { if patch.Purpose != nil {
o.Purpose = *patch.Purpose o.Purpose = *patch.Purpose
} }
if patch.GroupConstrained != nil {
o.GroupConstrained.Bool = *patch.GroupConstrained
}
} }
func (o *Channel) MakeNonNil() { func (o *Channel) MakeNonNil() {

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

@@ -37,11 +37,12 @@ func TestChannelCopy(t *testing.T) {
} }
func TestChannelPatch(t *testing.T) { func TestChannelPatch(t *testing.T) {
p := &ChannelPatch{Name: new(string), DisplayName: new(string), Header: new(string), Purpose: new(string)} p := &ChannelPatch{Name: new(string), DisplayName: new(string), Header: new(string), Purpose: new(string), GroupConstrained: new(bool)}
*p.Name = NewId() *p.Name = NewId()
*p.DisplayName = NewId() *p.DisplayName = NewId()
*p.Header = NewId() *p.Header = NewId()
*p.Purpose = NewId() *p.Purpose = NewId()
*p.GroupConstrained = true
o := Channel{Id: NewId(), Name: NewId()} o := Channel{Id: NewId(), Name: NewId()}
o.Patch(p) o.Patch(p)
@@ -58,6 +59,9 @@ func TestChannelPatch(t *testing.T) {
if *p.Purpose != o.Purpose { if *p.Purpose != o.Purpose {
t.Fatal("do not match") t.Fatal("do not match")
} }
if *p.GroupConstrained != o.GroupConstrained.Bool {
t.Fatalf("expected %v got %v", *p.GroupConstrained, o.GroupConstrained.Bool)
}
} }
func TestChannelIsValid(t *testing.T) { func TestChannelIsValid(t *testing.T) {

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

@@ -4,6 +4,7 @@
package model package model
import ( import (
"database/sql"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
@@ -26,30 +27,32 @@ const (
) )
type Team struct { type Team struct {
Id string `json:"id"` Id string `json:"id"`
CreateAt int64 `json:"create_at"` CreateAt int64 `json:"create_at"`
UpdateAt int64 `json:"update_at"` UpdateAt int64 `json:"update_at"`
DeleteAt int64 `json:"delete_at"` DeleteAt int64 `json:"delete_at"`
DisplayName string `json:"display_name"` DisplayName string `json:"display_name"`
Name string `json:"name"` Name string `json:"name"`
Description string `json:"description"` Description string `json:"description"`
Email string `json:"email"` Email string `json:"email"`
Type string `json:"type"` Type string `json:"type"`
CompanyName string `json:"company_name"` CompanyName string `json:"company_name"`
AllowedDomains string `json:"allowed_domains"` AllowedDomains string `json:"allowed_domains"`
InviteId string `json:"invite_id"` InviteId string `json:"invite_id"`
AllowOpenInvite bool `json:"allow_open_invite"` AllowOpenInvite bool `json:"allow_open_invite"`
LastTeamIconUpdate int64 `json:"last_team_icon_update,omitempty"` LastTeamIconUpdate int64 `json:"last_team_icon_update,omitempty"`
SchemeId *string `json:"scheme_id"` SchemeId *string `json:"scheme_id"`
GroupConstrained sql.NullBool `json:"group_constrained"`
} }
type TeamPatch struct { type TeamPatch struct {
DisplayName *string `json:"display_name"` DisplayName *string `json:"display_name"`
Description *string `json:"description"` Description *string `json:"description"`
CompanyName *string `json:"company_name"` CompanyName *string `json:"company_name"`
AllowedDomains *string `json:"allowed_domains"` AllowedDomains *string `json:"allowed_domains"`
InviteId *string `json:"invite_id"` InviteId *string `json:"invite_id"`
AllowOpenInvite *bool `json:"allow_open_invite"` AllowOpenInvite *bool `json:"allow_open_invite"`
GroupConstrained *bool `json:"group_constrained"`
} }
type TeamForExport struct { type TeamForExport struct {
@@ -273,6 +276,10 @@ func (t *Team) Patch(patch *TeamPatch) {
if patch.AllowOpenInvite != nil { if patch.AllowOpenInvite != nil {
t.AllowOpenInvite = *patch.AllowOpenInvite t.AllowOpenInvite = *patch.AllowOpenInvite
} }
if patch.GroupConstrained != nil {
t.GroupConstrained.Bool = *patch.GroupConstrained
}
} }
func (t *TeamPatch) ToJson() string { func (t *TeamPatch) ToJson() string {

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

@@ -130,3 +130,48 @@ func TestCleanTeamName(t *testing.T) {
t.Fatal("didn't clean name properly") t.Fatal("didn't clean name properly")
} }
} }
func TestTeamPatch(t *testing.T) {
p := &TeamPatch{
DisplayName: new(string),
Description: new(string),
CompanyName: new(string),
AllowedDomains: new(string),
InviteId: new(string),
AllowOpenInvite: new(bool),
GroupConstrained: new(bool),
}
*p.DisplayName = NewId()
*p.Description = NewId()
*p.CompanyName = NewId()
*p.AllowedDomains = NewId()
*p.InviteId = NewId()
*p.AllowOpenInvite = true
*p.GroupConstrained = true
o := Team{Id: NewId()}
o.Patch(p)
if *p.DisplayName != o.DisplayName {
t.Fatal("DisplayName did not update")
}
if *p.Description != o.Description {
t.Fatal("Description did not update")
}
if *p.CompanyName != o.CompanyName {
t.Fatal("CompanyName did not update")
}
if *p.AllowedDomains != o.AllowedDomains {
t.Fatal("AllowedDomains did not update")
}
if *p.InviteId != o.InviteId {
t.Fatal("InviteId did not update")
}
if *p.AllowOpenInvite != o.AllowOpenInvite {
t.Fatal("AllowOpenInvite did not update")
}
if *p.GroupConstrained != o.GroupConstrained.Bool {
t.Fatalf("expected %v got %v", *p.GroupConstrained, o.GroupConstrained.Bool)
}
}

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

@@ -634,6 +634,9 @@ func UpgradeDatabaseToVersion510(sqlStore SqlStore) {
} }
} }
sqlStore.CreateColumnIfNotExistsNoDefault("Channels", "GroupConstrained", "tinyint(1)", "boolean")
sqlStore.CreateColumnIfNotExistsNoDefault("Teams", "GroupConstrained", "tinyint(1)", "boolean")
// saveSchemaVersion(sqlStore, VERSION_5_10_0) // saveSchemaVersion(sqlStore, VERSION_5_10_0)
// } // }
} }