[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
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ec95793b90
Коммит
f7982216e4
24
api4/team.go
24
api4/team.go
@@ -33,6 +33,7 @@ func (api *API) InitTeam() {
|
||||
api.BaseRoutes.Team.Handle("", api.ApiSessionRequired(deleteTeam)).Methods("DELETE")
|
||||
api.BaseRoutes.Team.Handle("/patch", api.ApiSessionRequired(patchTeam)).Methods("PUT")
|
||||
api.BaseRoutes.Team.Handle("/stats", api.ApiSessionRequired(getTeamStats)).Methods("GET")
|
||||
api.BaseRoutes.Team.Handle("/regenerate_invite_id", api.ApiSessionRequired(regenerateTeamInviteId)).Methods("POST")
|
||||
|
||||
api.BaseRoutes.Team.Handle("/image", api.ApiSessionRequiredTrustRequester(getTeamIcon)).Methods("GET")
|
||||
api.BaseRoutes.Team.Handle("/image", api.ApiSessionRequired(setTeamIcon)).Methods("POST")
|
||||
@@ -190,6 +191,29 @@ func patchTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(patchedTeam.ToJson()))
|
||||
}
|
||||
|
||||
func regenerateTeamInviteId(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.RequireTeamId()
|
||||
if c.Err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_TEAM)
|
||||
return
|
||||
}
|
||||
|
||||
patchedTeam, err := c.App.RegenerateTeamInviteId(c.Params.TeamId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
c.App.SanitizeTeam(c.App.Session, patchedTeam)
|
||||
|
||||
c.LogAudit("")
|
||||
w.Write([]byte(patchedTeam.ToJson()))
|
||||
}
|
||||
|
||||
func deleteTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.RequireTeamId()
|
||||
if c.Err != nil {
|
||||
|
||||
@@ -307,8 +307,8 @@ func TestUpdateTeam(t *testing.T) {
|
||||
uteam, resp = Client.UpdateTeam(team)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
if uteam.InviteId != "inviteid1" {
|
||||
t.Fatal("Update failed")
|
||||
if uteam.InviteId == "inviteid1" {
|
||||
t.Fatal("InviteID should not be updated")
|
||||
}
|
||||
|
||||
team.AllowedDomains = "domain"
|
||||
@@ -411,7 +411,6 @@ func TestPatchTeam(t *testing.T) {
|
||||
patch.DisplayName = model.NewString("Other name")
|
||||
patch.Description = model.NewString("Other description")
|
||||
patch.CompanyName = model.NewString("Other company name")
|
||||
patch.InviteId = model.NewString("inviteid1")
|
||||
patch.AllowOpenInvite = model.NewBool(true)
|
||||
|
||||
rteam, resp := Client.PatchTeam(team.Id, patch)
|
||||
@@ -426,8 +425,8 @@ func TestPatchTeam(t *testing.T) {
|
||||
if rteam.CompanyName != "Other company name" {
|
||||
t.Fatal("CompanyName did not update properly")
|
||||
}
|
||||
if rteam.InviteId != "inviteid1" {
|
||||
t.Fatal("InviteId did not update properly")
|
||||
if rteam.InviteId == "inviteid1" {
|
||||
t.Fatal("InviteId should not update")
|
||||
}
|
||||
if !rteam.AllowOpenInvite {
|
||||
t.Fatal("AllowOpenInvite did not update properly")
|
||||
@@ -504,6 +503,24 @@ func TestPatchTeamSanitization(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestRegenerateTeamInviteId(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
|
||||
team := &model.Team{DisplayName: "Name", Description: "Some description", CompanyName: "Some company name", AllowOpenInvite: false, InviteId: "inviteid0", Name: "z-z-" + model.NewId() + "a", Email: "success+" + model.NewId() + "@simulator.amazonses.com", Type: model.TEAM_OPEN}
|
||||
team, _ = Client.CreateTeam(team)
|
||||
|
||||
assert.NotEqual(t, team.InviteId, "")
|
||||
assert.NotEqual(t, team.InviteId, "inviteid0")
|
||||
|
||||
rteam, resp := Client.RegenerateTeamInviteId(team.Id)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
assert.NotEqual(t, team.InviteId, rteam.InviteId)
|
||||
assert.NotEqual(t, team.InviteId, "")
|
||||
}
|
||||
|
||||
func TestSoftDeleteTeam(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
@@ -283,8 +283,7 @@ func TestCreateUserWithInviteId(t *testing.T) {
|
||||
|
||||
inviteId := th.BasicTeam.InviteId
|
||||
|
||||
th.BasicTeam.InviteId = model.NewId()
|
||||
_, resp := th.SystemAdminClient.UpdateTeam(th.BasicTeam)
|
||||
_, resp := th.SystemAdminClient.RegenerateTeamInviteId(th.BasicTeam.Id)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
_, resp = th.Client.CreateUserWithInviteId(&user, inviteId)
|
||||
@@ -319,7 +318,9 @@ func TestCreateUserWithInviteId(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableOpenServer = false })
|
||||
|
||||
inviteId := th.BasicTeam.InviteId
|
||||
team, res := th.SystemAdminClient.RegenerateTeamInviteId(th.BasicTeam.Id)
|
||||
assert.Nil(t, res.Error)
|
||||
inviteId := team.InviteId
|
||||
|
||||
ruser, resp := th.Client.CreateUserWithInviteId(&user, inviteId)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
Ссылка в новой задаче
Block a user