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 (
"crypto/sha1"
"database/sql"
"encoding/hex"
"encoding/json"
"io"
@@ -51,6 +52,7 @@ type Channel struct {
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 {
@@ -65,6 +67,7 @@ type ChannelPatch struct {
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() {

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

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

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

@@ -4,6 +4,7 @@
package model
import (
"database/sql"
"encoding/json"
"fmt"
"io"
@@ -41,6 +42,7 @@ type Team struct {
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 {
@@ -50,6 +52,7 @@ type TeamPatch struct {
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 {

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

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

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

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