[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
@@ -251,9 +251,6 @@ func (s SqlTeamStore) Get(id string) store.StoreChannel {
|
||||
}
|
||||
|
||||
team := obj.(*model.Team)
|
||||
if len(team.InviteId) == 0 {
|
||||
team.InviteId = team.Id
|
||||
}
|
||||
|
||||
result.Data = team
|
||||
})
|
||||
@@ -263,15 +260,11 @@ func (s SqlTeamStore) GetByInviteId(inviteId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
team := model.Team{}
|
||||
|
||||
if err := s.GetReplica().SelectOne(&team, "SELECT * FROM Teams WHERE Id = :InviteId OR InviteId = :InviteId", map[string]interface{}{"InviteId": inviteId}); err != nil {
|
||||
if err := s.GetReplica().SelectOne(&team, "SELECT * FROM Teams WHERE InviteId = :InviteId", map[string]interface{}{"InviteId": inviteId}); err != nil {
|
||||
result.Err = model.NewAppError("SqlTeamStore.GetByInviteId", "store.sql_team.get_by_invite_id.finding.app_error", nil, "inviteId="+inviteId+", "+err.Error(), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
if len(team.InviteId) == 0 {
|
||||
team.InviteId = team.Id
|
||||
}
|
||||
|
||||
if len(inviteId) == 0 || team.InviteId != inviteId {
|
||||
result.Err = model.NewAppError("SqlTeamStore.GetByInviteId", "store.sql_team.get_by_invite_id.find.app_error", nil, "inviteId="+inviteId, http.StatusNotFound)
|
||||
return
|
||||
@@ -290,10 +283,6 @@ func (s SqlTeamStore) GetByName(name string) store.StoreChannel {
|
||||
return
|
||||
}
|
||||
|
||||
if len(team.InviteId) == 0 {
|
||||
team.InviteId = team.Id
|
||||
}
|
||||
|
||||
result.Data = &team
|
||||
})
|
||||
}
|
||||
@@ -358,12 +347,6 @@ func (s SqlTeamStore) GetAll() store.StoreChannel {
|
||||
return
|
||||
}
|
||||
|
||||
for _, team := range data {
|
||||
if len(team.InviteId) == 0 {
|
||||
team.InviteId = team.Id
|
||||
}
|
||||
}
|
||||
|
||||
result.Data = data
|
||||
})
|
||||
}
|
||||
@@ -376,12 +359,6 @@ func (s SqlTeamStore) GetAllPage(offset int, limit int) store.StoreChannel {
|
||||
return
|
||||
}
|
||||
|
||||
for _, team := range data {
|
||||
if len(team.InviteId) == 0 {
|
||||
team.InviteId = team.Id
|
||||
}
|
||||
}
|
||||
|
||||
result.Data = data
|
||||
})
|
||||
}
|
||||
@@ -394,12 +371,6 @@ func (s SqlTeamStore) GetTeamsByUserId(userId string) store.StoreChannel {
|
||||
return
|
||||
}
|
||||
|
||||
for _, team := range data {
|
||||
if len(team.InviteId) == 0 {
|
||||
team.InviteId = team.Id
|
||||
}
|
||||
}
|
||||
|
||||
result.Data = data
|
||||
})
|
||||
}
|
||||
@@ -418,12 +389,6 @@ func (s SqlTeamStore) GetAllPrivateTeamListing() store.StoreChannel {
|
||||
return
|
||||
}
|
||||
|
||||
for _, team := range data {
|
||||
if len(team.InviteId) == 0 {
|
||||
team.InviteId = team.Id
|
||||
}
|
||||
}
|
||||
|
||||
result.Data = data
|
||||
})
|
||||
}
|
||||
@@ -442,12 +407,6 @@ func (s SqlTeamStore) GetAllPrivateTeamPageListing(offset int, limit int) store.
|
||||
return
|
||||
}
|
||||
|
||||
for _, team := range data {
|
||||
if len(team.InviteId) == 0 {
|
||||
team.InviteId = team.Id
|
||||
}
|
||||
}
|
||||
|
||||
result.Data = data
|
||||
})
|
||||
}
|
||||
@@ -466,12 +425,6 @@ func (s SqlTeamStore) GetAllTeamListing() store.StoreChannel {
|
||||
return
|
||||
}
|
||||
|
||||
for _, team := range data {
|
||||
if len(team.InviteId) == 0 {
|
||||
team.InviteId = team.Id
|
||||
}
|
||||
}
|
||||
|
||||
result.Data = data
|
||||
})
|
||||
}
|
||||
@@ -490,12 +443,6 @@ func (s SqlTeamStore) GetAllTeamPageListing(offset int, limit int) store.StoreCh
|
||||
return
|
||||
}
|
||||
|
||||
for _, team := range data {
|
||||
if len(team.InviteId) == 0 {
|
||||
team.InviteId = team.Id
|
||||
}
|
||||
}
|
||||
|
||||
result.Data = data
|
||||
})
|
||||
}
|
||||
@@ -999,12 +946,6 @@ func (s SqlTeamStore) GetAllForExportAfter(limit int, afterId string) store.Stor
|
||||
return
|
||||
}
|
||||
|
||||
for _, team := range data {
|
||||
if len(team.InviteId) == 0 {
|
||||
team.InviteId = team.Id
|
||||
}
|
||||
}
|
||||
|
||||
result.Data = data
|
||||
})
|
||||
}
|
||||
|
||||
@@ -61,8 +61,9 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
EXIT_VERSION_SAVE = 1003
|
||||
EXIT_THEME_MIGRATION = 1004
|
||||
EXIT_VERSION_SAVE = 1003
|
||||
EXIT_THEME_MIGRATION = 1004
|
||||
EXIT_TEAM_INVITEID_MIGRATION_FAILED = 1006
|
||||
)
|
||||
|
||||
// UpgradeDatabase attempts to migrate the schema to the latest supported version.
|
||||
@@ -660,6 +661,19 @@ func UpgradeDatabaseToVersion511(sqlStore SqlStore) {
|
||||
// TODO: Uncomment following condition when version 5.11.0 is released
|
||||
// if shouldPerformUpgrade(sqlStore, VERSION_5_10_0, VERSION_5_11_0) {
|
||||
|
||||
// Enforce all teams have an InviteID set
|
||||
var teams []*model.Team
|
||||
if _, err := sqlStore.GetReplica().Select(&teams, "SELECT * FROM Teams WHERE InviteId = ''"); err != nil {
|
||||
mlog.Error("Error fetching Teams without InviteID: " + err.Error())
|
||||
} else {
|
||||
for _, team := range teams {
|
||||
team.InviteId = model.NewId()
|
||||
if _, err := sqlStore.Team().Update(team); err != nil {
|
||||
mlog.Error("Error updating Team InviteIDs: " + err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// saveSchemaVersion(sqlStore, VERSION_5_11_0)
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -393,7 +393,9 @@ func testTeamStoreGetByInviteId(t *testing.T, ss store.Store) {
|
||||
o1.Type = model.TEAM_OPEN
|
||||
o1.InviteId = model.NewId()
|
||||
|
||||
if err := (<-ss.Team().Save(&o1)).Err; err != nil {
|
||||
save1 := <-ss.Team().Save(&o1)
|
||||
|
||||
if err := save1.Err; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -403,11 +405,7 @@ func testTeamStoreGetByInviteId(t *testing.T, ss store.Store) {
|
||||
o2.Email = MakeEmail()
|
||||
o2.Type = model.TEAM_OPEN
|
||||
|
||||
if err := (<-ss.Team().Save(&o2)).Err; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if r1 := <-ss.Team().GetByInviteId(o1.InviteId); r1.Err != nil {
|
||||
if r1 := <-ss.Team().GetByInviteId(save1.Data.(*model.Team).InviteId); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
} else {
|
||||
if r1.Data.(*model.Team).ToJson() != o1.ToJson() {
|
||||
@@ -415,18 +413,6 @@ func testTeamStoreGetByInviteId(t *testing.T, ss store.Store) {
|
||||
}
|
||||
}
|
||||
|
||||
o2.InviteId = ""
|
||||
_, err := ss.Team().Update(&o2)
|
||||
require.Nil(t, err)
|
||||
|
||||
if r1 := <-ss.Team().GetByInviteId(o2.Id); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
} else {
|
||||
if r1.Data.(*model.Team).Id != o2.Id {
|
||||
t.Fatal("invalid returned team")
|
||||
}
|
||||
}
|
||||
|
||||
if err := (<-ss.Team().GetByInviteId("")).Err; err == nil {
|
||||
t.Fatal("Missing id should have failed")
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user