summaryrefslogtreecommitdiffstats
path: root/models/access.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-08-28 13:51:15 +0800
committerUnknwon <u@gogs.io>2015-08-28 13:51:15 +0800
commitff35a37769cbf60cd1522eb05411adbf965c9950 (patch)
treec8f500294dd65813fd2d9becab1c076f92d424f3 /models/access.go
parent70e0153b939a2446bf1d8e459a1b965660463585 (diff)
downloadgitea-ff35a37769cbf60cd1522eb05411adbf965c9950.tar.gz
gitea-ff35a37769cbf60cd1522eb05411adbf965c9950.zip
#1458: Authorities were messed up when using mysql database
Diffstat (limited to 'models/access.go')
-rw-r--r--models/access.go67
1 files changed, 27 insertions, 40 deletions
diff --git a/models/access.go b/models/access.go
index 917f1c280d..fe8bf2c17e 100644
--- a/models/access.go
+++ b/models/access.go
@@ -145,25 +145,6 @@ func (repo *Repository) refreshCollaboratorAccesses(e Engine, accessMap map[int6
for _, c := range collaborators {
accessMap[c.Id] = ACCESS_MODE_WRITE
}
-
- // Adds team members access.
- if repo.Owner.IsOrganization() {
- if err = repo.Owner.GetTeams(); err != nil {
- return fmt.Errorf("GetTeams: %v", err)
- }
- for _, t := range repo.Owner.Teams {
- if err = t.GetMembers(); err != nil {
- return fmt.Errorf("GetMembers: %v", err)
- }
- for _, m := range t.Members {
- if t.IsOwnerTeam() {
- accessMap[m.Id] = ACCESS_MODE_OWNER
- } else {
- accessMap[m.Id] = maxAccessMode(accessMap[m.Id], t.Authorize)
- }
- }
- }
- }
return nil
}
@@ -175,34 +156,36 @@ func (repo *Repository) recalculateTeamAccesses(e Engine, ignTeamID int64) (err
if err = repo.getOwner(e); err != nil {
return err
+ } else if !repo.Owner.IsOrganization() {
+ return fmt.Errorf("owner is not an organization: %d", repo.OwnerID)
}
+
if err = repo.refreshCollaboratorAccesses(e, accessMap); err != nil {
return fmt.Errorf("refreshCollaboratorAccesses: %v", err)
}
- if repo.Owner.IsOrganization() {
- if err = repo.Owner.getTeams(e); err != nil {
- return err
- }
- for _, t := range repo.Owner.Teams {
- if t.ID == ignTeamID {
- continue
- }
+ if err = repo.Owner.getTeams(e); err != nil {
+ return err
+ }
- // 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
- }
+ for _, t := range repo.Owner.Teams {
+ if t.ID == ignTeamID {
+ continue
+ }
- if err = t.getMembers(e); err != nil {
- return fmt.Errorf("getMembers '%d': %v", t.ID, err)
- }
- for _, m := range t.Members {
- accessMap[m.Id] = maxAccessMode(accessMap[m.Id], t.Authorize)
- }
+ // 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 {
+ return fmt.Errorf("getMembers '%d': %v", t.ID, err)
+ }
+ for _, m := range t.Members {
+ accessMap[m.Id] = maxAccessMode(accessMap[m.Id], t.Authorize)
}
}
@@ -210,6 +193,10 @@ func (repo *Repository) recalculateTeamAccesses(e Engine, ignTeamID int64) (err
}
func (repo *Repository) recalculateAccesses(e Engine) error {
+ if repo.Owner.IsOrganization() {
+ return repo.recalculateTeamAccesses(e, 0)
+ }
+
accessMap := make(map[int64]AccessMode, 20)
if err := repo.refreshCollaboratorAccesses(e, accessMap); err != nil {
return fmt.Errorf("refreshCollaboratorAccesses: %v", err)