diff --git a/models/repo.go b/models/repo.go index 83031c508c..933bb6c2a7 100644 --- a/models/repo.go +++ b/models/repo.go @@ -150,27 +150,56 @@ func getRepoAssignees(ctx context.Context, repo *repo_model.Repository) (_ []*us } e := db.GetEngine(ctx) - accesses := make([]*Access, 0, 10) - if err = e. + userIDs := make([]int64, 0, 10) + if err = e.Table("access"). Where("repo_id = ? AND mode >= ?", repo.ID, perm.AccessModeWrite). - Find(&accesses); err != nil { + Select("id"). + Find(&userIDs); err != nil { return nil, err } + additionalUserIDs := make([]int64, 0, 10) + if err = e.Table("team_user"). + Join("INNER", "team_repo", "`team_repo`.team_id = `team_user`.team_id"). + Join("INNER", "team_unit", "`team_unit`.team_id = `team_user`.team_id"). + Where("`team_repo`.repo_id = ? AND `team_unit`.access_mode >= ?", repo.ID, perm.AccessModeWrite). + Distinct("`team_user`.uid"). + Select("`team_user`.uid"). + Find(&additionalUserIDs); err != nil { + return nil, err + } + + uidMap := map[int64]bool{} + i := 0 + for _, uid := range userIDs { + if uidMap[uid] { + continue + } + uidMap[uid] = true + userIDs[i] = uid + i++ + } + userIDs = userIDs[:i] + userIDs = append(userIDs, additionalUserIDs...) + + for _, uid := range additionalUserIDs { + if uidMap[uid] { + continue + } + userIDs[i] = uid + i++ + } + userIDs = userIDs[:i] + // Leave a seat for owner itself to append later, but if owner is an organization // and just waste 1 unit is cheaper than re-allocate memory once. - users := make([]*user_model.User, 0, len(accesses)+1) - if len(accesses) > 0 { - userIDs := make([]int64, len(accesses)) - for i := 0; i < len(accesses); i++ { - userIDs[i] = accesses[i].UserID - } - + users := make([]*user_model.User, 0, len(userIDs)+1) + if len(userIDs) > 0 { if err = e.In("id", userIDs).Find(&users); err != nil { return nil, err } } - if !repo.Owner.IsOrganization() { + if !repo.Owner.IsOrganization() && !uidMap[repo.OwnerID] { users = append(users, repo.Owner) } diff --git a/routers/web/org/teams.go b/routers/web/org/teams.go index 9b0212e569..f6e09eb4c8 100644 --- a/routers/web/org/teams.go +++ b/routers/web/org/teams.go @@ -311,6 +311,7 @@ func TeamMembers(ctx *context.Context) { ctx.ServerError("GetMembers", err) return } + ctx.Data["Units"] = unit_model.Units ctx.HTML(http.StatusOK, tplTeamMembers) } @@ -323,6 +324,7 @@ func TeamRepositories(ctx *context.Context) { ctx.ServerError("GetRepositories", err) return } + ctx.Data["Units"] = unit_model.Units ctx.HTML(http.StatusOK, tplTeamRepositories) } diff --git a/templates/org/team/sidebar.tmpl b/templates/org/team/sidebar.tmpl index 6ea08740f7..2dec681b4c 100644 --- a/templates/org/team/sidebar.tmpl +++ b/templates/org/team/sidebar.tmpl @@ -25,31 +25,55 @@ {{.i18n.Tr "org.teams.no_desc"}} {{end}} - -
{{.i18n.Tr "units.unit"}} | +{{.i18n.Tr "org.team_permission_desc"}} | +
---|---|
{{$.i18n.Tr $unit.NameKey}} | +{{if eq ($.Team.UnitAccessMode $unit.Type) 0 -}} + {{$.i18n.Tr "org.teams.none_access"}} + {{- else if or (eq $.Team.ID 0) (eq ($.Team.UnitAccessMode $unit.Type) 1) -}} + {{$.i18n.Tr "org.teams.read_access"}} + {{- else if eq ($.Team.UnitAccessMode $unit.Type) 2 -}} + {{$.i18n.Tr "org.teams.write_access"}} + {{- end}} | +