[MM-13671] Rework Team InviteId Creation and Updates (#10536)

* Add regenerate invite ID endpoint; Dont allow inviteID updates via other methods; Remove unrequired checks in get handler

* Fix tests; Dont accept TeamId as invite ID

* Ensure all teams have an InviteID set

* Custom Selector to get empty teams; dont crash when inviteid set fails

* Remote InviteId from TeamPatch

* Add missing translation

* Translation string order

* Use sync store

* gofmt
Этот коммит содержится в:
Daniel Schalla
2019-04-25 23:09:38 +02:00
коммит произвёл GitHub
родитель ec95793b90
Коммит f7982216e4
11 изменённых файлов: 109 добавлений и 99 удалений

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

@@ -1577,6 +1577,16 @@ func (c *Client4) PatchTeam(teamId string, patch *TeamPatch) (*Team, *Response)
return TeamFromJson(r.Body), BuildResponse(r)
}
// RegenerateTeamInviteId requests a new invite ID to be generated.
func (c *Client4) RegenerateTeamInviteId(teamId string) (*Team, *Response) {
r, err := c.DoApiPost(c.GetTeamRoute(teamId)+"/regenerate_invite_id", "")
if err != nil {
return nil, BuildErrorResponse(r, err)
}
defer closeBody(r)
return TeamFromJson(r.Body), BuildResponse(r)
}
// SoftDeleteTeam deletes the team softly (archive only, not permanent delete).
func (c *Client4) SoftDeleteTeam(teamId string) (bool, *Response) {
r, err := c.DoApiDelete(c.GetTeamRoute(teamId))

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

@@ -49,7 +49,6 @@ type TeamPatch struct {
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"`
}
@@ -153,6 +152,10 @@ func (o *Team) IsValid() *AppError {
return NewAppError("Team.IsValid", "model.team.is_valid.description.app_error", nil, "id="+o.Id, http.StatusBadRequest)
}
if len(o.InviteId) == 0 {
return NewAppError("Team.IsValid", "model.team.is_valid.invite_id.app_error", nil, "id="+o.Id, http.StatusBadRequest)
}
if IsReservedTeamName(o.Name) {
return NewAppError("Team.IsValid", "model.team.is_valid.reserved.app_error", nil, "id="+o.Id, http.StatusBadRequest)
}
@@ -268,10 +271,6 @@ func (t *Team) Patch(patch *TeamPatch) {
t.AllowedDomains = *patch.AllowedDomains
}
if patch.InviteId != nil {
t.InviteId = *patch.InviteId
}
if patch.AllowOpenInvite != nil {
t.AllowOpenInvite = *patch.AllowOpenInvite
}

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

@@ -59,6 +59,7 @@ func TestTeamIsValid(t *testing.T) {
o.Name = "zzzzz"
o.Type = TEAM_OPEN
o.InviteId = NewId()
if err := o.IsValid(); err != nil {
t.Fatal(err)
}
@@ -137,7 +138,6 @@ func TestTeamPatch(t *testing.T) {
Description: new(string),
CompanyName: new(string),
AllowedDomains: new(string),
InviteId: new(string),
AllowOpenInvite: new(bool),
GroupConstrained: new(bool),
}
@@ -146,7 +146,6 @@ func TestTeamPatch(t *testing.T) {
*p.Description = NewId()
*p.CompanyName = NewId()
*p.AllowedDomains = NewId()
*p.InviteId = NewId()
*p.AllowOpenInvite = true
*p.GroupConstrained = true
@@ -165,9 +164,6 @@ func TestTeamPatch(t *testing.T) {
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")
}