fix mirror issues uncaught #941

This commit is contained in:
Unknwon 2015-02-13 02:14:57 -05:00
parent 6d0f3a07d4
commit 6b7d35eade
6 changed files with 50 additions and 80 deletions

View File

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.5.13.0211 Beta" const APP_VER = "0.5.14.0213 Beta"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

View File

@ -206,6 +206,11 @@ func (repo *Repository) RepoLink() (string, error) {
return setting.AppSubUrl + "/" + repo.Owner.Name + "/" + repo.Name, nil return setting.AppSubUrl + "/" + repo.Owner.Name + "/" + repo.Name, nil
} }
func (repo *Repository) HasAccess(u *User) bool {
has, _ := HasAccess(u, repo, ACCESS_MODE_READ)
return has
}
func (repo *Repository) IsOwnedBy(u *User) bool { func (repo *Repository) IsOwnedBy(u *User) bool {
return repo.OwnerId == u.Id return repo.OwnerId == u.Id
} }
@ -539,10 +544,10 @@ func CreateRepository(u *User, name, desc, lang, license string, private, mirror
if _, err = sess.Insert(repo); err != nil { if _, err = sess.Insert(repo); err != nil {
return nil, err return nil, err
} else if _, err = sess.Exec("UPDATE `user` SET num_repos = num_repos + 1 WHERE id = ?", u.Id); err != nil {
return nil, err
} }
var t *Team // Owner team.
// TODO fix code for mirrors? // TODO fix code for mirrors?
// Give access to all members in owner team. // Give access to all members in owner team.
@ -550,22 +555,8 @@ func CreateRepository(u *User, name, desc, lang, license string, private, mirror
if err = repo.recalculateAccesses(sess); err != nil { if err = repo.recalculateAccesses(sess); err != nil {
return nil, err return nil, err
} }
}
if _, err = sess.Exec("UPDATE `user` SET num_repos = num_repos + 1 WHERE id = ?", u.Id); err != nil {
return nil, err
}
// Update owner team info and count. // Update owner team info and count.
if u.IsOrganization() {
t.RepoIds += "$" + com.ToStr(repo.Id) + "|"
t.NumRepos++
if _, err = sess.Id(t.Id).AllCols().Update(t); err != nil {
return nil, err
}
}
if u.IsOrganization() {
t, err := u.getOwnerTeam(sess) t, err := u.getOwnerTeam(sess)
if err != nil { if err != nil {
return nil, fmt.Errorf("get owner team: %v", err) return nil, fmt.Errorf("get owner team: %v", err)
@ -578,6 +569,12 @@ func CreateRepository(u *User, name, desc, lang, license string, private, mirror
return nil, fmt.Errorf("watch repository: %v", err) return nil, fmt.Errorf("watch repository: %v", err)
} }
} }
t.RepoIds += "$" + com.ToStr(repo.Id) + "|"
t.NumRepos++
if _, err = sess.Id(t.Id).AllCols().Update(t); err != nil {
return nil, err
}
} else { } else {
if err = watchRepo(sess, u.Id, repo.Id, true); err != nil { if err = watchRepo(sess, u.Id, repo.Id, true); err != nil {
return nil, fmt.Errorf("watch repository 2: %v", err) return nil, fmt.Errorf("watch repository 2: %v", err)
@ -746,21 +743,11 @@ func DeleteRepository(uid, repoId int64, userName string) error {
} }
sess := x.NewSession() sess := x.NewSession()
defer sess.Close() defer sessionRelease(sess)
if err = sess.Begin(); err != nil { if err = sess.Begin(); err != nil {
return err return err
} }
if _, err = sess.Delete(&Repository{Id: repoId}); err != nil {
sess.Rollback()
return err
}
// Delete all access.
if _, err := sess.Delete(&Access{RepoID: repo.Id}); err != nil {
sess.Rollback()
return err
}
if org.IsOrganization() { if org.IsOrganization() {
idStr := "$" + com.ToStr(repoId) + "|" idStr := "$" + com.ToStr(repoId) + "|"
for _, t := range org.Teams { for _, t := range org.Teams {
@ -770,34 +757,26 @@ func DeleteRepository(uid, repoId int64, userName string) error {
t.NumRepos-- t.NumRepos--
t.RepoIds = strings.Replace(t.RepoIds, idStr, "", 1) t.RepoIds = strings.Replace(t.RepoIds, idStr, "", 1)
if _, err = sess.Id(t.Id).AllCols().Update(t); err != nil { if _, err = sess.Id(t.Id).AllCols().Update(t); err != nil {
sess.Rollback()
return err return err
} }
} }
} }
if _, err := sess.Delete(&Action{RepoId: repo.Id}); err != nil { if _, err = sess.Delete(&Repository{Id: repoId}); err != nil {
sess.Rollback()
return err return err
} } else if _, err := sess.Delete(&Access{RepoID: repo.Id}); err != nil {
if _, err = sess.Delete(&Watch{RepoId: repoId}); err != nil {
sess.Rollback()
return err return err
} } else if _, err := sess.Delete(&Action{RepoId: repo.Id}); err != nil {
if _, err = sess.Delete(&Mirror{RepoId: repoId}); err != nil {
sess.Rollback()
return err return err
} } else if _, err = sess.Delete(&Watch{RepoId: repoId}); err != nil {
if _, err = sess.Delete(&IssueUser{RepoId: repoId}); err != nil {
sess.Rollback()
return err return err
} } else if _, err = sess.Delete(&Mirror{RepoId: repoId}); err != nil {
if _, err = sess.Delete(&Milestone{RepoId: repoId}); err != nil {
sess.Rollback()
return err return err
} } else if _, err = sess.Delete(&IssueUser{RepoId: repoId}); err != nil {
if _, err = sess.Delete(&Release{RepoId: repoId}); err != nil { return err
sess.Rollback() } else if _, err = sess.Delete(&Milestone{RepoId: repoId}); err != nil {
return err
} else if _, err = sess.Delete(&Release{RepoId: repoId}); err != nil {
return err return err
} }
@ -805,29 +784,24 @@ func DeleteRepository(uid, repoId int64, userName string) error {
if err = x.Iterate(&Issue{RepoId: repoId}, func(idx int, bean interface{}) error { if err = x.Iterate(&Issue{RepoId: repoId}, func(idx int, bean interface{}) error {
issue := bean.(*Issue) issue := bean.(*Issue)
if _, err = sess.Delete(&Comment{IssueId: issue.Id}); err != nil { if _, err = sess.Delete(&Comment{IssueId: issue.Id}); err != nil {
sess.Rollback()
return err return err
} }
return nil return nil
}); err != nil { }); err != nil {
sess.Rollback()
return err return err
} }
if _, err = sess.Delete(&Issue{RepoId: repoId}); err != nil { if _, err = sess.Delete(&Issue{RepoId: repoId}); err != nil {
sess.Rollback()
return err return err
} }
if repo.IsFork { if repo.IsFork {
if _, err = sess.Exec("UPDATE `repository` SET num_forks = num_forks - 1 WHERE id = ?", repo.ForkId); err != nil { if _, err = sess.Exec("UPDATE `repository` SET num_forks = num_forks - 1 WHERE id = ?", repo.ForkId); err != nil {
sess.Rollback()
return err return err
} }
} }
if _, err = sess.Exec("UPDATE `user` SET num_repos = num_repos - 1 WHERE id = ?", uid); err != nil { if _, err = sess.Exec("UPDATE `user` SET num_repos = num_repos - 1 WHERE id = ?", uid); err != nil {
sess.Rollback()
return err return err
} }
@ -839,6 +813,7 @@ func DeleteRepository(uid, repoId int64, userName string) error {
log.Error(4, "Fail to add notice: %v", err) log.Error(4, "Fail to add notice: %v", err)
} }
} }
return sess.Commit() return sess.Commit()
} }
@ -1331,37 +1306,29 @@ func ForkRepository(u *User, oldRepo *Repository, name, desc string) (*Repositor
if err = repo.recalculateAccesses(sess); err != nil { if err = repo.recalculateAccesses(sess); err != nil {
return nil, err return nil, err
} } else if _, err = sess.Exec("UPDATE `user` SET num_repos = num_repos + 1 WHERE id = ?", u.Id); err != nil {
var t *Team // Owner team.
if _, err = sess.Exec("UPDATE `user` SET num_repos = num_repos + 1 WHERE id = ?", u.Id); err != nil {
return nil, err return nil, err
} }
if u.IsOrganization() {
// Update owner team info and count. // Update owner team info and count.
if u.IsOrganization() {
t.RepoIds += "$" + com.ToStr(repo.Id) + "|"
t.NumRepos++
if _, err = sess.Id(t.Id).AllCols().Update(t); err != nil {
return nil, err
}
}
if u.IsOrganization() {
t, err := u.getOwnerTeam(sess) t, err := u.getOwnerTeam(sess)
if err != nil { if err != nil {
return nil, fmt.Errorf("get owner team: %v", err) return nil, fmt.Errorf("get owner team: %v", err)
} else { } else if err = t.getMembers(sess); err != nil {
if err = t.getMembers(sess); err != nil {
return nil, fmt.Errorf("get team members: %v", err) return nil, fmt.Errorf("get team members: %v", err)
} else { }
for _, u := range t.Members { for _, u := range t.Members {
if err = watchRepo(sess, u.Id, repo.Id, true); err != nil { if err = watchRepo(sess, u.Id, repo.Id, true); err != nil {
return nil, fmt.Errorf("watch repository: %v", err) return nil, fmt.Errorf("watch repository: %v", err)
} }
} }
}
t.RepoIds += "$" + com.ToStr(repo.Id) + "|"
t.NumRepos++
if _, err = sess.Id(t.Id).AllCols().Update(t); err != nil {
return nil, err
} }
} else { } else {
if err = watchRepo(sess, u.Id, repo.Id, true); err != nil { if err = watchRepo(sess, u.Id, repo.Id, true); err != nil {

View File

@ -29,7 +29,7 @@ func ApiRepoAssignment() macaron.Handler {
) )
// Check if the user is the same as the repository owner. // Check if the user is the same as the repository owner.
if ctx.IsSigned && u.LowerName == strings.ToLower(userName) { if ctx.IsSigned && ctx.User.LowerName == strings.ToLower(userName) {
u = ctx.User u = ctx.User
} else { } else {
u, err = models.GetUserByName(userName) u, err = models.GetUserByName(userName)
@ -210,7 +210,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
} }
// Check if the user is the same as the repository owner // Check if the user is the same as the repository owner
if ctx.IsSigned && u.LowerName == strings.ToLower(userName) { if ctx.IsSigned && ctx.User.LowerName == strings.ToLower(userName) {
u = ctx.User u = ctx.User
} else { } else {
u, err = models.GetUserByName(userName) u, err = models.GetUserByName(userName)
@ -248,6 +248,9 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
ctx.Repo.IsOwner = mode >= models.ACCESS_MODE_WRITE ctx.Repo.IsOwner = mode >= models.ACCESS_MODE_WRITE
ctx.Repo.IsAdmin = mode >= models.ACCESS_MODE_READ ctx.Repo.IsAdmin = mode >= models.ACCESS_MODE_READ
ctx.Repo.IsTrueOwner = mode >= models.ACCESS_MODE_OWNER ctx.Repo.IsTrueOwner = mode >= models.ACCESS_MODE_OWNER
if !ctx.Repo.IsTrueOwner && ctx.Repo.Owner.IsOrganization() {
ctx.Repo.IsTrueOwner = ctx.Repo.Owner.IsOwnedBy(ctx.User.Id)
}
} }
// Check access. // Check access.

View File

@ -1 +1 @@
0.5.13.0211 Beta 0.5.14.0213 Beta

View File

@ -27,7 +27,7 @@
</div> </div>
<div id="org-repo-list"> <div id="org-repo-list">
{{range .Repos}} {{range .Repos}}
{{if .HasAccess $.SignedUser.Name}} {{if .HasAccess $.SignedUser}}
<div class="org-repo-item"> <div class="org-repo-item">
<ul class="org-repo-status right"> <ul class="org-repo-status right">
<li><i class="octicon octicon-star"></i> {{.NumStars}}</li> <li><i class="octicon octicon-star"></i> {{.NumStars}}</li>

View File

@ -74,7 +74,7 @@
<div class="tab-pane active"> <div class="tab-pane active">
<div id="org-repo-list"> <div id="org-repo-list">
{{range .Repos}} {{range .Repos}}
{{if or (not .IsPrivate) (.HasAccess $.SignedUserName)}} {{if or (not .IsPrivate) (.HasAccess $.SignedUser)}}
<div class="org-repo-item"> <div class="org-repo-item">
<ul class="org-repo-status right"> <ul class="org-repo-status right">
<li><i class="octicon octicon-star"></i> {{.NumStars}}</li> <li><i class="octicon octicon-star"></i> {{.NumStars}}</li>