summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-02-04 13:03:34 -0500
committerUnknwon <u@gogs.io>2016-02-04 13:03:34 -0500
commitddf9fa06c7725820176ae75ae0b7e85c25f2886b (patch)
treefeaef1756f9cf6b587bdade4109dd31722ad0726
parent739d5aa1d32229769acbdf53bd99222d13441b47 (diff)
downloadgitea-ddf9fa06c7725820176ae75ae0b7e85c25f2886b.tar.gz
gitea-ddf9fa06c7725820176ae75ae0b7e85c25f2886b.zip
Minor fix for #2530
-rw-r--r--models/org.go60
-rw-r--r--modules/middleware/org.go3
2 files changed, 32 insertions, 31 deletions
diff --git a/models/org.go b/models/org.go
index 6844445591..020284d8d2 100644
--- a/models/org.go
+++ b/models/org.go
@@ -9,8 +9,8 @@ import (
"fmt"
"os"
"strings"
- "strconv"
+ "github.com/Unknwon/com"
"github.com/go-xorm/xorm"
)
@@ -1054,54 +1054,56 @@ func RemoveOrgRepo(orgID, repoID int64) error {
// that the user with the given userID has access to.
func (org *User) GetUserRepositories(userID int64) (err error) {
teams := make([]*Team, 0, 10)
- if err := x.Cols("`team`.id").
- Where("`team_user`.org_id=?", org.Id).
- And("`team_user`.uid=?", userID).
- Join("INNER", "`team_user`", "`team_user`.team_id=`team`.id").
- Find(&teams); err != nil {
- return fmt.Errorf("getUserRepositories: get teams: %v", err)
+ if err = x.Cols("`team`.id").
+ Where("`team_user`.org_id=?", org.Id).
+ And("`team_user`.uid=?", userID).
+ Join("INNER", "`team_user`", "`team_user`.team_id=`team`.id").
+ Find(&teams); err != nil {
+ return fmt.Errorf("GetUserRepositories: get teams: %v", err)
}
- var teamIDs []string
- for _, team := range teams {
- teamIDs = append(teamIDs, strconv.FormatInt(team.ID, 10))
+ teamIDs := make([]string, len(teams))
+ for i := range teams {
+ teamIDs[i] = com.ToStr(teams[i].ID)
}
if len(teamIDs) == 0 {
// user has no team but "IN ()" is invalid SQL
- teamIDs = append(teamIDs, "-1") // there is no repo with id=-1
+ teamIDs = append(teamIDs, "-1") // there is no repo with id=-1
}
// Due to a bug in xorm using IN() together with OR() is impossible.
// 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
- if err := x.Cols("`repository`.*").
- Join("INNER", "`team_repo`", "`team_repo`.repo_id=`repository`.id").
- Where("`repository`.owner_id=?", org.Id).
- And("`repository`.is_private=?", false).
- Or("`team_repo`.team_id=(?)", strings.Join(teamIDs, ",")).
- GroupBy("`repository`.id").
- Find(&org.Repos); err != nil {
- return fmt.Errorf("getUserRepositories: get repositories: %v", err)
+ if err = x.Cols("`repository`.*").
+ Join("INNER", "`team_repo`", "`team_repo`.repo_id=`repository`.id").
+ Where("`repository`.owner_id=?", org.Id).
+ And("`repository`.is_private=?", false).
+ Or("`team_repo`.team_id=(?)", strings.Join(teamIDs, ",")).
+ GroupBy("`repository`.id").
+ Find(&org.Repos); err != nil {
+ 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)
-
- return
+ return nil
}
// GetTeams returns all teams that belong to organization,
// 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`.*").
- Where("`team_user`.org_id=?", org.Id).
- And("`team_user`.uid=?", userID).
- Join("INNER", "`team_user`", "`team_user`.team_id=`team`.id").
- Find(&org.Teams); err != nil {
- return fmt.Errorf("getUserTeams: %v", err)
+ Where("`team_user`.org_id=?", org.Id).
+ And("`team_user`.uid=?", userID).
+ Join("INNER", "`team_user`", "`team_user`.team_id=`team`.id").
+ Find(&org.Teams); err != nil {
+ 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)
-
- return
+ return nil
}
diff --git a/modules/middleware/org.go b/modules/middleware/org.go
index eb71020e69..e62e0b0b01 100644
--- a/modules/middleware/org.go
+++ b/modules/middleware/org.go
@@ -105,8 +105,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
if len(teamName) > 0 {
teamExists := false
for _, team := range org.Teams {
-
- if strings.ToLower(team.Name) == strings.ToLower(teamName) {
+ if team.LowerName == strings.ToLower(teamName) {
teamExists = true
ctx.Org.Team = team
ctx.Org.IsTeamMember = true