#1458: Authorities were messed up when using mysql database
This commit is contained in:
parent
70e0153b93
commit
ff35a37769
5 changed files with 30 additions and 45 deletions
2
gogs.go
2
gogs.go
|
@ -17,7 +17,7 @@ import (
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.6.6.0827 Beta"
|
const APP_VER = "0.6.6.0828 Beta"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
|
|
@ -145,25 +145,6 @@ func (repo *Repository) refreshCollaboratorAccesses(e Engine, accessMap map[int6
|
||||||
for _, c := range collaborators {
|
for _, c := range collaborators {
|
||||||
accessMap[c.Id] = ACCESS_MODE_WRITE
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,34 +156,36 @@ func (repo *Repository) recalculateTeamAccesses(e Engine, ignTeamID int64) (err
|
||||||
|
|
||||||
if err = repo.getOwner(e); err != nil {
|
if err = repo.getOwner(e); err != nil {
|
||||||
return err
|
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 {
|
if err = repo.refreshCollaboratorAccesses(e, accessMap); err != nil {
|
||||||
return fmt.Errorf("refreshCollaboratorAccesses: %v", err)
|
return fmt.Errorf("refreshCollaboratorAccesses: %v", err)
|
||||||
}
|
}
|
||||||
if repo.Owner.IsOrganization() {
|
|
||||||
if err = repo.Owner.getTeams(e); err != nil {
|
if err = repo.Owner.getTeams(e); err != nil {
|
||||||
return err
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, t := range repo.Owner.Teams {
|
||||||
|
if t.ID == ignTeamID {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, t := range repo.Owner.Teams {
|
// Owner team gets owner access, and skip for teams that do not
|
||||||
if t.ID == ignTeamID {
|
// have relations with repository.
|
||||||
continue
|
if t.IsOwnerTeam() {
|
||||||
}
|
t.Authorize = ACCESS_MODE_OWNER
|
||||||
|
} else if !t.hasRepository(e, repo.ID) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// Owner team gets owner access, and skip for teams that do not
|
if err = t.getMembers(e); err != nil {
|
||||||
// have relations with repository.
|
return fmt.Errorf("getMembers '%d': %v", t.ID, err)
|
||||||
if t.IsOwnerTeam() {
|
}
|
||||||
t.Authorize = ACCESS_MODE_OWNER
|
for _, m := range t.Members {
|
||||||
} else if !t.hasRepository(e, repo.ID) {
|
accessMap[m.Id] = maxAccessMode(accessMap[m.Id], t.Authorize)
|
||||||
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 {
|
func (repo *Repository) recalculateAccesses(e Engine) error {
|
||||||
|
if repo.Owner.IsOrganization() {
|
||||||
|
return repo.recalculateTeamAccesses(e, 0)
|
||||||
|
}
|
||||||
|
|
||||||
accessMap := make(map[int64]AccessMode, 20)
|
accessMap := make(map[int64]AccessMode, 20)
|
||||||
if err := repo.refreshCollaboratorAccesses(e, accessMap); err != nil {
|
if err := repo.refreshCollaboratorAccesses(e, accessMap); err != nil {
|
||||||
return fmt.Errorf("refreshCollaboratorAccesses: %v", err)
|
return fmt.Errorf("refreshCollaboratorAccesses: %v", err)
|
||||||
|
|
|
@ -483,7 +483,7 @@ func (t *Team) hasRepository(e Engine, repoID int64) bool {
|
||||||
|
|
||||||
// HasRepository returns true if given repository belong to team.
|
// HasRepository returns true if given repository belong to team.
|
||||||
func (t *Team) HasRepository(repoID int64) bool {
|
func (t *Team) HasRepository(repoID int64) bool {
|
||||||
return HasTeamRepo(t.OrgID, t.ID, repoID)
|
return t.hasRepository(x, repoID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Team) addRepository(e Engine, repo *Repository) (err error) {
|
func (t *Team) addRepository(e Engine, repo *Repository) (err error) {
|
||||||
|
|
|
@ -39,8 +39,6 @@ func checkRunMode() {
|
||||||
macaron.Env = macaron.PROD
|
macaron.Env = macaron.PROD
|
||||||
macaron.ColorLog = false
|
macaron.ColorLog = false
|
||||||
setting.ProdMode = true
|
setting.ProdMode = true
|
||||||
case "test":
|
|
||||||
macaron.Env = macaron.TEST
|
|
||||||
}
|
}
|
||||||
log.Info("Run Mode: %s", strings.Title(macaron.Env))
|
log.Info("Run Mode: %s", strings.Title(macaron.Env))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0.6.6.0827 Beta
|
0.6.6.0828 Beta
|
Reference in a new issue