diff options
Diffstat (limited to 'models/org_team.go')
-rw-r--r-- | models/org_team.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/models/org_team.go b/models/org_team.go index ad11431a49..53c1ec34d8 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -40,6 +40,14 @@ func (t *Team) getUnits(e Engine) (err error) { return err } +// GetUnitNames returns the team units names +func (t *Team) GetUnitNames() (res []string) { + for _, u := range t.Units { + res = append(res, Units[u.Type].NameKey) + } + return +} + // HasWriteAccess returns true if team has at least write level access mode. func (t *Team) HasWriteAccess() bool { return t.Authorize >= AccessModeWrite @@ -367,6 +375,24 @@ func UpdateTeam(t *Team, authChanged bool) (err error) { return fmt.Errorf("update: %v", err) } + // update units for team + if len(t.Units) > 0 { + for _, unit := range t.Units { + unit.TeamID = t.ID + } + // Delete team-unit. + if _, err := sess. + Where("team_id=?", t.ID). + Delete(new(TeamUnit)); err != nil { + return err + } + + if _, err = sess.Insert(&t.Units); err != nil { + sess.Rollback() + return err + } + } + // Update access for team members if needed. if authChanged { if err = t.getRepositories(sess); err != nil { |