diff options
author | Unknwon <u@gogs.io> | 2015-03-24 18:14:04 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-03-24 18:14:04 -0400 |
commit | 6f81c05dde2def51c30a97f65f901ae45c971e05 (patch) | |
tree | d05c93bf9c941e8b3aac98a40ca854285e472020 /models | |
parent | ab6b2881412bbb039f0bf6a829586b434f4bd65b (diff) | |
download | gitea-6f81c05dde2def51c30a97f65f901ae45c971e05.tar.gz gitea-6f81c05dde2def51c30a97f65f901ae45c971e05.zip |
#1143 Team member access lost when adding repository collaborator
- fix bug when add a repo to team, all other team members gets access as well
Diffstat (limited to 'models')
-rw-r--r-- | models/access.go | 5 | ||||
-rw-r--r-- | models/repo.go | 15 |
2 files changed, 18 insertions, 2 deletions
diff --git a/models/access.go b/models/access.go index ea2f7f7b4b..dd856afb71 100644 --- a/models/access.go +++ b/models/access.go @@ -170,8 +170,13 @@ func (repo *Repository) recalculateTeamAccesses(e Engine, ignTeamID int64) (err if t.ID == ignTeamID { continue } + + // Owner team gets owner access, and skip for teams that do not + // have relations with repository. if t.IsOwnerTeam() { t.Authorize = ACCESS_MODE_OWNER + } else if !t.hasRepository(e, repo.Id) { + continue } if err = t.getMembers(e); err != nil { diff --git a/models/repo.go b/models/repo.go index cfab329bab..73b635d240 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1107,6 +1107,10 @@ func (repo *Repository) AddCollaborator(u *User) error { return nil } + if err = repo.GetOwner(); err != nil { + return fmt.Errorf("GetOwner: %v", err) + } + sess := x.NewSession() defer sessionRelease(sess) if err = sess.Begin(); err != nil { @@ -1115,8 +1119,15 @@ func (repo *Repository) AddCollaborator(u *User) error { if _, err = sess.InsertOne(collaboration); err != nil { return err - } else if err = repo.recalculateAccesses(sess); err != nil { - return err + } + + if repo.Owner.IsOrganization() { + err = repo.recalculateTeamAccesses(sess, 0) + } else { + err = repo.recalculateAccesses(sess) + } + if err != nil { + return fmt.Errorf("recalculateAccesses 'team=%v': %v", repo.Owner.IsOrganization(), err) } return sess.Commit() |