summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWendell Sun <iwendellsun@gmail.com>2018-02-24 02:02:45 +0800
committerLauris BH <lauris@nix.lv>2018-02-23 20:02:45 +0200
commit4a0ce6896b4ed938626361a81aab163213df2cec (patch)
treeddab624326f64ba8d6e023b35e68cb1bf492d266
parentd87fb0a6fd6154ac7810c27b02bcbfc52e850460 (diff)
downloadgitea-4a0ce6896b4ed938626361a81aab163213df2cec.tar.gz
gitea-4a0ce6896b4ed938626361a81aab163213df2cec.zip
Fix remove team member issue (#3566) (#3570)
Signed-off-by: Wendell Sun <iwendellsun@gmail.com>
-rw-r--r--models/org.go22
-rw-r--r--models/org_team.go14
2 files changed, 27 insertions, 9 deletions
diff --git a/models/org.go b/models/org.go
index 095265a12e..ed0d583067 100644
--- a/models/org.go
+++ b/models/org.go
@@ -436,8 +436,7 @@ func AddOrgUser(orgID, uid int64) error {
return sess.Commit()
}
-// RemoveOrgUser removes user from given organization.
-func RemoveOrgUser(orgID, userID int64) error {
+func removeOrgUser(sess *xorm.Session, orgID, userID int64) error {
ou := new(OrgUser)
has, err := x.
@@ -473,12 +472,6 @@ func RemoveOrgUser(orgID, userID int64) error {
}
}
- sess := x.NewSession()
- defer sess.Close()
- if err := sess.Begin(); err != nil {
- return err
- }
-
if _, err := sess.ID(ou.ID).Delete(ou); err != nil {
return err
} else if _, err = sess.Exec("UPDATE `user` SET num_members=num_members-1 WHERE id=?", orgID); err != nil {
@@ -520,6 +513,19 @@ func RemoveOrgUser(orgID, userID int64) error {
}
}
+ return nil
+}
+
+// RemoveOrgUser removes user from given organization.
+func RemoveOrgUser(orgID, userID int64) error {
+ sess := x.NewSession()
+ defer sess.Close()
+ if err := sess.Begin(); err != nil {
+ return err
+ }
+ if err := removeOrgUser(sess, orgID, userID); err != nil {
+ return err
+ }
return sess.Commit()
}
diff --git a/models/org_team.go b/models/org_team.go
index 941b7ed2a1..9d8a031418 100644
--- a/models/org_team.go
+++ b/models/org_team.go
@@ -10,6 +10,8 @@ import (
"strings"
"code.gitea.io/gitea/modules/log"
+
+ "github.com/go-xorm/xorm"
)
const ownerTeamName = "Owners"
@@ -521,7 +523,7 @@ func AddTeamMember(team *Team, userID int64) error {
return sess.Commit()
}
-func removeTeamMember(e Engine, team *Team, userID int64) error {
+func removeTeamMember(e *xorm.Session, team *Team, userID int64) error {
isMember, err := isTeamMember(e, team.OrgID, team.ID, userID)
if err != nil || !isMember {
return err
@@ -558,6 +560,16 @@ func removeTeamMember(e Engine, team *Team, userID int64) error {
}
}
+ // Check if the user is a member of any team in the organization.
+ if count, err := e.Count(&TeamUser{
+ UID: userID,
+ OrgID: team.OrgID,
+ }); err != nil {
+ return err
+ } else if count == 0 {
+ return removeOrgUser(e, team.OrgID, userID)
+ }
+
return nil
}