diff options
author | Ethan Koenig <etk39@cornell.edu> | 2017-02-22 20:36:15 -0500 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-02-23 09:36:15 +0800 |
commit | 4f3880ff151fcbda019a1a9467bc39da621fbe07 (patch) | |
tree | a64d3b0740fd34ee55a9c4a55b04bb8aa1d023db /models/org_team.go | |
parent | d181113b82a29c035e92dc00c8385dbe41e5688b (diff) | |
download | gitea-4f3880ff151fcbda019a1a9467bc39da621fbe07.tar.gz gitea-4f3880ff151fcbda019a1a9467bc39da621fbe07.zip |
Bug fixes and unit tests for org_team (#1016)
Diffstat (limited to 'models/org_team.go')
-rw-r--r-- | models/org_team.go | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/models/org_team.go b/models/org_team.go index dfdffa70b2..55a539643b 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -36,7 +36,7 @@ func (t *Team) IsMember(userID int64) bool { return IsTeamMember(t.OrgID, t.ID, userID) } -func (t *Team) getRepositories(e Engine) (err error) { +func (t *Team) getRepositories(e Engine) error { return e.Join("INNER", "team_repo", "repository.id = team_repo.repo_id"). Where("team_repo.team_id=?", t.ID).Find(&t.Repos) } @@ -183,16 +183,13 @@ func (t *Team) RemoveRepository(repoID int64) error { } // IsUsableTeamName tests if a name could be as team name -func IsUsableTeamName(name string) (err error) { - var reservedTeamNames = []string{"new"} - - for i := range reservedTeamNames { - if name == reservedTeamNames[i] { - return ErrNameReserved{name} - } +func IsUsableTeamName(name string) error { + switch name { + case "new": + return ErrNameReserved{name} + default: + return nil } - - return nil } // NewTeam creates a record of new team. @@ -313,7 +310,7 @@ func UpdateTeam(t *Team, authChanged bool) (err error) { // Update access for team members if needed. if authChanged { if err = t.getRepositories(sess); err != nil { - return fmt.Errorf("getRepositories:%v", err) + return fmt.Errorf("getRepositories: %v", err) } for _, repo := range t.Repos { @@ -352,6 +349,13 @@ func DeleteTeam(t *Team) error { } } + // Delete team-repo + if _, err = sess. + Where("team_id=?", t.ID). + Delete(new(TeamRepo)); err != nil { + return err + } + // Delete team-user. if _, err = sess. Where("org_id=?", org.ID). @@ -624,11 +628,6 @@ func addTeamRepo(e Engine, orgID, teamID, repoID int64) error { return err } -// AddTeamRepo adds new repository relation to team. -func AddTeamRepo(orgID, teamID, repoID int64) error { - return addTeamRepo(x, orgID, teamID, repoID) -} - func removeTeamRepo(e Engine, teamID, repoID int64) error { _, err := e.Delete(&TeamRepo{ TeamID: teamID, @@ -636,8 +635,3 @@ func removeTeamRepo(e Engine, teamID, repoID int64) error { }) return err } - -// RemoveTeamRepo deletes repository relation to team. -func RemoveTeamRepo(teamID, repoID int64) error { - return removeTeamRepo(x, teamID, repoID) -} |