aboutsummaryrefslogtreecommitdiffstats
path: root/models/org_team.go
diff options
context:
space:
mode:
authorEthan Koenig <ethantkoenig@gmail.com>2017-12-20 23:43:26 -0800
committerLauris BH <lauris@nix.lv>2017-12-21 09:43:26 +0200
commit515cdaa85d6087d91a61ebe74fae39e0c4bdf1c4 (patch)
tree3a7143fc376af4402ca9008876be3afdc0c18efc /models/org_team.go
parent529482135c8e9304dd7cdf08772eaba61d903894 (diff)
downloadgitea-515cdaa85d6087d91a61ebe74fae39e0c4bdf1c4.tar.gz
gitea-515cdaa85d6087d91a61ebe74fae39e0c4bdf1c4.zip
Fix ignored errors when checking if organization, team member (#3177)
Diffstat (limited to 'models/org_team.go')
-rw-r--r--models/org_team.go31
1 files changed, 20 insertions, 11 deletions
diff --git a/models/org_team.go b/models/org_team.go
index dcbf073837..1e3bc27071 100644
--- a/models/org_team.go
+++ b/models/org_team.go
@@ -8,6 +8,8 @@ import (
"errors"
"fmt"
"strings"
+
+ "code.gitea.io/gitea/modules/log"
)
const ownerTeamName = "Owners"
@@ -47,7 +49,12 @@ func (t *Team) IsOwnerTeam() bool {
// IsMember returns true if given user is a member of team.
func (t *Team) IsMember(userID int64) bool {
- return IsTeamMember(t.OrgID, t.ID, userID)
+ isMember, err := IsTeamMember(t.OrgID, t.ID, userID)
+ if err != nil {
+ log.Error(4, "IsMember: %v", err)
+ return false
+ }
+ return isMember
}
func (t *Team) getRepositories(e Engine) error {
@@ -413,17 +420,17 @@ type TeamUser struct {
UID int64 `xorm:"UNIQUE(s)"`
}
-func isTeamMember(e Engine, orgID, teamID, userID int64) bool {
- has, _ := e.
+func isTeamMember(e Engine, orgID, teamID, userID int64) (bool, error) {
+ return e.
Where("org_id=?", orgID).
And("team_id=?", teamID).
And("uid=?", userID).
- Get(new(TeamUser))
- return has
+ Table("team_user").
+ Exist()
}
// IsTeamMember returns true if given user is a member of team.
-func IsTeamMember(orgID, teamID, userID int64) bool {
+func IsTeamMember(orgID, teamID, userID int64) (bool, error) {
return isTeamMember(x, orgID, teamID, userID)
}
@@ -471,8 +478,9 @@ func GetUserTeams(orgID, userID int64) ([]*Team, error) {
// AddTeamMember adds new membership of given team to given organization,
// the user will have membership to given organization automatically when needed.
func AddTeamMember(team *Team, userID int64) error {
- if IsTeamMember(team.OrgID, team.ID, userID) {
- return nil
+ isAlreadyMember, err := IsTeamMember(team.OrgID, team.ID, userID)
+ if err != nil || isAlreadyMember {
+ return err
}
if err := AddOrgUser(team.OrgID, userID); err != nil {
@@ -529,8 +537,9 @@ func AddTeamMember(team *Team, userID int64) error {
}
func removeTeamMember(e Engine, team *Team, userID int64) error {
- if !isTeamMember(e, team.OrgID, team.ID, userID) {
- return nil
+ isMember, err := isTeamMember(e, team.OrgID, team.ID, userID)
+ if err != nil || !isMember {
+ return err
}
// Check if the user to delete is the last member in owner team.
@@ -566,7 +575,7 @@ func removeTeamMember(e Engine, team *Team, userID int64) error {
// This must exist.
ou := new(OrgUser)
- _, err := e.
+ _, err = e.
Where("uid = ?", userID).
And("org_id = ?", team.OrgID).
Get(ou)