aboutsummaryrefslogtreecommitdiffstats
path: root/models/org_team.go
diff options
context:
space:
mode:
authorEthan Koenig <etk39@cornell.edu>2017-03-14 20:51:46 -0400
committerLunny Xiao <xiaolunwen@gmail.com>2017-03-15 08:51:46 +0800
commitec0ae5d50c59315a3c597b1cf24d4c5508c718e5 (patch)
tree6f4d6f826dd9866f9b39b66522ec629555700de2 /models/org_team.go
parent7d8f9d1c46e38681f2a4033a7da811ab7562d953 (diff)
downloadgitea-ec0ae5d50c59315a3c597b1cf24d4c5508c718e5.tar.gz
gitea-ec0ae5d50c59315a3c597b1cf24d4c5508c718e5.zip
Refactor and fix incorrect comment (#1247)
Diffstat (limited to 'models/org_team.go')
-rw-r--r--models/org_team.go34
1 files changed, 20 insertions, 14 deletions
diff --git a/models/org_team.go b/models/org_team.go
index 84282da83c..db25e61547 100644
--- a/models/org_team.go
+++ b/models/org_team.go
@@ -139,18 +139,19 @@ func (t *Team) removeRepository(e Engine, repo *Repository, recalculate bool) (e
}
}
- if err = t.getMembers(e); err != nil {
- return fmt.Errorf("get team members: %v", err)
+ teamUsers, err := getTeamUsersByTeamID(e, t.ID)
+ if err != nil {
+ return fmt.Errorf("getTeamUsersByTeamID: %v", err)
}
- for _, u := range t.Members {
- has, err := hasAccess(e, u, repo, AccessModeRead)
+ for _, teamUser:= range teamUsers {
+ has, err := hasAccess(e, teamUser.UID, repo, AccessModeRead)
if err != nil {
return err
} else if has {
continue
}
- if err = watchRepo(e, u.ID, repo.ID, false); err != nil {
+ if err = watchRepo(e, teamUser.UID, repo.ID, false); err != nil {
return err
}
}
@@ -399,20 +400,25 @@ func IsTeamMember(orgID, teamID, userID int64) bool {
return isTeamMember(x, orgID, teamID, userID)
}
-func getTeamMembers(e Engine, teamID int64) (_ []*User, err error) {
+func getTeamUsersByTeamID(e Engine, teamID int64) ([]*TeamUser, error) {
teamUsers := make([]*TeamUser, 0, 10)
- if err = e.
+ return teamUsers, e.
Where("team_id=?", teamID).
- Find(&teamUsers); err != nil {
+ Find(&teamUsers)
+}
+
+func getTeamMembers(e Engine, teamID int64) (_ []*User, err error) {
+ teamUsers, err := getTeamUsersByTeamID(e, teamID)
+ if err != nil {
return nil, fmt.Errorf("get team-users: %v", err)
}
- members := make([]*User, 0, len(teamUsers))
- for i := range teamUsers {
- member := new(User)
- if _, err = e.Id(teamUsers[i].UID).Get(member); err != nil {
- return nil, fmt.Errorf("get user '%d': %v", teamUsers[i].UID, err)
+ members := make([]*User, len(teamUsers))
+ for i, teamUser := range teamUsers {
+ member, err := getUserByID(e, teamUser.UID)
+ if err != nil {
+ return nil, fmt.Errorf("get user '%d': %v", teamUser.UID, err)
}
- members = append(members, member)
+ members[i] = member
}
return members, nil
}