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.
This commit is contained in:
Martin Kraft
2019-03-18 10:50:32 -04:00
committed by Jesús Espino
parent 683f215bd9
commit 16a9489bbb
5 changed files with 108 additions and 42 deletions

View File

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

View File

@@ -37,11 +37,12 @@ func TestChannelCopy(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.DisplayName = NewId()
*p.Header = NewId()
*p.Purpose = NewId()
*p.GroupConstrained = true
o := Channel{Id: NewId(), Name: NewId()}
o.Patch(p)
@@ -58,6 +59,9 @@ func TestChannelPatch(t *testing.T) {
if *p.Purpose != o.Purpose {
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) {

View File

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

View File

@@ -130,3 +130,48 @@ func TestCleanTeamName(t *testing.T) {
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)
}
}

View File

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