|
|
|
@ -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,11 +156,14 @@ 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 |
|
|
|
|
} |
|
|
|
@ -204,12 +188,15 @@ func (repo *Repository) recalculateTeamAccesses(e Engine, ignTeamID int64) (err |
|
|
|
|
accessMap[m.Id] = maxAccessMode(accessMap[m.Id], t.Authorize) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return repo.refreshAccesses(e, accessMap) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|