summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-03-16 04:52:11 -0400
committerUnknwon <u@gogs.io>2015-03-16 04:52:11 -0400
commitfc6db829b2040227bb9dac6d243a9f94c5651154 (patch)
tree2933da30cc9b49919397999ebcb41485e49545ad
parent588f3215c6c4a82c7ad9cbd2cc6a5683d0ca3cc2 (diff)
downloadgitea-fc6db829b2040227bb9dac6d243a9f94c5651154.tar.gz
gitea-fc6db829b2040227bb9dac6d243a9f94c5651154.zip
fix read access team visibility of private repo
-rw-r--r--models/action.go2
-rw-r--r--models/repo.go44
-rw-r--r--routers/repo/repo.go2
-rw-r--r--routers/repo/setting.go3
4 files changed, 40 insertions, 11 deletions
diff --git a/models/action.go b/models/action.go
index f97ecfcde3..46ce44e26b 100644
--- a/models/action.go
+++ b/models/action.go
@@ -309,7 +309,7 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string,
return errors.New("action.CommitRepoAction(GetRepositoryByName): " + err.Error())
}
repo.IsBare = false
- if err = UpdateRepository(repo); err != nil {
+ if err = UpdateRepository(repo, false); err != nil {
return errors.New("action.CommitRepoAction(UpdateRepository): " + err.Error())
}
diff --git a/models/repo.go b/models/repo.go
index 2718970f18..e5d63c03fb 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -347,7 +347,7 @@ func MigrateRepository(u *User, name, desc string, private, mirror bool, url str
return repo, err
}
repo.IsMirror = true
- return repo, UpdateRepository(repo)
+ return repo, UpdateRepository(repo, false)
} else {
os.RemoveAll(repoPath)
}
@@ -362,7 +362,7 @@ func MigrateRepository(u *User, name, desc string, private, mirror bool, url str
return repo, fmt.Errorf("create update hook: %v", err)
}
- return repo, UpdateRepository(repo)
+ return repo, UpdateRepository(repo, false)
}
// extractGitBareZip extracts git-bare.zip to repository path.
@@ -501,7 +501,7 @@ func initRepository(e Engine, f string, u *User, repo *Repository, initReadme bo
}
repo.IsBare = true
repo.DefaultBranch = "master"
- return updateRepository(e, repo)
+ return updateRepository(e, repo, false)
}
// Apply changes and commit.
@@ -733,7 +733,7 @@ func ChangeRepositoryName(userName, oldRepoName, newRepoName string) (err error)
return os.Rename(RepoPath(userName, oldRepoName), RepoPath(userName, newRepoName))
}
-func updateRepository(e Engine, repo *Repository) error {
+func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err error) {
repo.LowerName = strings.ToLower(repo.Name)
if len(repo.Description) > 255 {
@@ -742,12 +742,40 @@ func updateRepository(e Engine, repo *Repository) error {
if len(repo.Website) > 255 {
repo.Website = repo.Website[:255]
}
- _, err := e.Id(repo.Id).AllCols().Update(repo)
- return err
+
+ if _, err = e.Id(repo.Id).AllCols().Update(repo); err != nil {
+ return fmt.Errorf("update: %v", err)
+ }
+
+ if visibilityChanged {
+ if err = repo.getOwner(e); err != nil {
+ return fmt.Errorf("getOwner: %v", err)
+ }
+ if !repo.Owner.IsOrganization() {
+ return nil
+ }
+
+ // Organization repository need to recalculate access table when visivility is changed.
+ if err = repo.recalculateTeamAccesses(e, 0); err != nil {
+ return fmt.Errorf("recalculateTeamAccesses: %v", err)
+ }
+ }
+
+ return nil
}
-func UpdateRepository(repo *Repository) error {
- return updateRepository(x, repo)
+func UpdateRepository(repo *Repository, visibilityChanged bool) (err error) {
+ sess := x.NewSession()
+ defer sessionRelease(sess)
+ if err = sess.Begin(); err != nil {
+ return err
+ }
+
+ if err = updateRepository(x, repo, visibilityChanged); err != nil {
+ return fmt.Errorf("updateRepository: %v", err)
+ }
+
+ return sess.Commit()
}
// DeleteRepository deletes a repository for a user or organization.
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index a70f31e614..8884bea3ab 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -356,7 +356,7 @@ func Action(ctx *middleware.Context) {
ctx.Repo.Repository.Description = ctx.Query("desc")
ctx.Repo.Repository.Website = ctx.Query("site")
- err = models.UpdateRepository(ctx.Repo.Repository)
+ err = models.UpdateRepository(ctx.Repo.Repository, false)
}
if err != nil {
diff --git a/routers/repo/setting.go b/routers/repo/setting.go
index 5b9b672c04..be21405bf6 100644
--- a/routers/repo/setting.go
+++ b/routers/repo/setting.go
@@ -78,8 +78,9 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) {
}
ctx.Repo.Repository.Description = form.Description
ctx.Repo.Repository.Website = form.Website
+ visibilityChanged := ctx.Repo.Repository.IsPrivate != form.Private
ctx.Repo.Repository.IsPrivate = form.Private
- if err := models.UpdateRepository(ctx.Repo.Repository); err != nil {
+ if err := models.UpdateRepository(ctx.Repo.Repository, visibilityChanged); err != nil {
ctx.Handle(404, "UpdateRepository", err)
return
}