mirror of
1
Fork 0

Minor fix for #2530

This commit is contained in:
Unknwon 2016-02-04 13:03:34 -05:00
parent 739d5aa1d3
commit ddf9fa06c7
2 changed files with 32 additions and 31 deletions

View File

@ -9,8 +9,8 @@ import (
"fmt" "fmt"
"os" "os"
"strings" "strings"
"strconv"
"github.com/Unknwon/com"
"github.com/go-xorm/xorm" "github.com/go-xorm/xorm"
) )
@ -1054,17 +1054,17 @@ func RemoveOrgRepo(orgID, repoID int64) error {
// that the user with the given userID has access to. // that the user with the given userID has access to.
func (org *User) GetUserRepositories(userID int64) (err error) { func (org *User) GetUserRepositories(userID int64) (err error) {
teams := make([]*Team, 0, 10) teams := make([]*Team, 0, 10)
if err := x.Cols("`team`.id"). if err = x.Cols("`team`.id").
Where("`team_user`.org_id=?", org.Id). Where("`team_user`.org_id=?", org.Id).
And("`team_user`.uid=?", userID). And("`team_user`.uid=?", userID).
Join("INNER", "`team_user`", "`team_user`.team_id=`team`.id"). Join("INNER", "`team_user`", "`team_user`.team_id=`team`.id").
Find(&teams); err != nil { Find(&teams); err != nil {
return fmt.Errorf("getUserRepositories: get teams: %v", err) return fmt.Errorf("GetUserRepositories: get teams: %v", err)
} }
var teamIDs []string teamIDs := make([]string, len(teams))
for _, team := range teams { for i := range teams {
teamIDs = append(teamIDs, strconv.FormatInt(team.ID, 10)) teamIDs[i] = com.ToStr(teams[i].ID)
} }
if len(teamIDs) == 0 { if len(teamIDs) == 0 {
// user has no team but "IN ()" is invalid SQL // user has no team but "IN ()" is invalid SQL
@ -1075,33 +1075,35 @@ func (org *User) GetUserRepositories(userID int64) (err error) {
// As a workaround, we have to build the IN statement on our own, until this is fixed. // As a workaround, we have to build the IN statement on our own, until this is fixed.
// https://github.com/go-xorm/xorm/issues/342 // https://github.com/go-xorm/xorm/issues/342
if err := x.Cols("`repository`.*"). if err = x.Cols("`repository`.*").
Join("INNER", "`team_repo`", "`team_repo`.repo_id=`repository`.id"). Join("INNER", "`team_repo`", "`team_repo`.repo_id=`repository`.id").
Where("`repository`.owner_id=?", org.Id). Where("`repository`.owner_id=?", org.Id).
And("`repository`.is_private=?", false). And("`repository`.is_private=?", false).
Or("`team_repo`.team_id=(?)", strings.Join(teamIDs, ",")). Or("`team_repo`.team_id=(?)", strings.Join(teamIDs, ",")).
GroupBy("`repository`.id"). GroupBy("`repository`.id").
Find(&org.Repos); err != nil { Find(&org.Repos); err != nil {
return fmt.Errorf("getUserRepositories: get repositories: %v", err) return fmt.Errorf("GetUserRepositories: get repositories: %v", err)
} }
// FIXME: should I change this value inside method,
// or only in location of caller where it's really needed?
org.NumRepos = len(org.Repos) org.NumRepos = len(org.Repos)
return nil
return
} }
// GetTeams returns all teams that belong to organization, // GetTeams returns all teams that belong to organization,
// and that the user has joined. // and that the user has joined.
func (org *User) GetUserTeams(userID int64) (err error) { func (org *User) GetUserTeams(userID int64) error {
if err := x.Cols("`team`.*"). if err := x.Cols("`team`.*").
Where("`team_user`.org_id=?", org.Id). Where("`team_user`.org_id=?", org.Id).
And("`team_user`.uid=?", userID). And("`team_user`.uid=?", userID).
Join("INNER", "`team_user`", "`team_user`.team_id=`team`.id"). Join("INNER", "`team_user`", "`team_user`.team_id=`team`.id").
Find(&org.Teams); err != nil { Find(&org.Teams); err != nil {
return fmt.Errorf("getUserTeams: %v", err) return fmt.Errorf("GetUserTeams: %v", err)
} }
// FIXME: should I change this value inside method,
// or only in location of caller where it's really needed?
org.NumTeams = len(org.Teams) org.NumTeams = len(org.Teams)
return nil
return
} }

View File

@ -105,8 +105,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
if len(teamName) > 0 { if len(teamName) > 0 {
teamExists := false teamExists := false
for _, team := range org.Teams { for _, team := range org.Teams {
if team.LowerName == strings.ToLower(teamName) {
if strings.ToLower(team.Name) == strings.ToLower(teamName) {
teamExists = true teamExists = true
ctx.Org.Team = team ctx.Org.Team = team
ctx.Org.IsTeamMember = true ctx.Org.IsTeamMember = true