diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2018-11-12 01:43:56 +0800 |
---|---|---|
committer | techknowlogick <hello@techknowlogick.com> | 2018-11-11 12:43:56 -0500 |
commit | 8670decafbf00291c3a2d203925b5d73a49e78a6 (patch) | |
tree | 4b0ad790433c1a4f603c0997d12421234d200a0a /models | |
parent | 297e619074d8578866d207b44f00771d0bfc0bc0 (diff) | |
download | gitea-8670decafbf00291c3a2d203925b5d73a49e78a6.tar.gz gitea-8670decafbf00291c3a2d203925b5d73a49e78a6.zip |
Fix create team, update team missing units (#5188) (#5313)
Diffstat (limited to 'models')
-rw-r--r-- | models/org_team.go | 26 | ||||
-rw-r--r-- | models/unit.go | 17 |
2 files changed, 43 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 { diff --git a/models/unit.go b/models/unit.go index 1d26359528..9619232cf4 100644 --- a/models/unit.go +++ b/models/unit.go @@ -4,6 +4,10 @@ package models +import ( + "strings" +) + // UnitType is Unit's Type type UnitType int @@ -137,3 +141,16 @@ var ( UnitTypeExternalWiki: UnitExternalWiki, } ) + +// FindUnitTypes give the unit key name and return unit +func FindUnitTypes(nameKeys ...string) (res []UnitType) { + for _, key := range nameKeys { + for t, u := range Units { + if strings.EqualFold(key, u.NameKey) { + res = append(res, t) + break + } + } + } + return +} |