1
1
mirror of https://github.com/go-gitea/gitea synced 2024-11-10 12:14:25 +00:00

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"
)
const APP_VER = "0.5.13.0211 Beta"
const APP_VER = "0.5.14.0213 Beta"
func init() {
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
}
func (repo *Repository) HasAccess(u *User) bool {
has, _ := HasAccess(u, repo, ACCESS_MODE_READ)
return has
}
func (repo *Repository) IsOwnedBy(u *User) bool {
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 {
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?
// 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 {
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.
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() {
// Update owner team info and count.
t, err := u.getOwnerTeam(sess)
if err != nil {
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)
}
}
t.RepoIds += "$" + com.ToStr(repo.Id) + "|"
t.NumRepos++
if _, err = sess.Id(t.Id).AllCols().Update(t); err != nil {
return nil, err
}
} else {
if err = watchRepo(sess, u.Id, repo.Id, true); err != nil {
return nil, fmt.Errorf("watch repository 2: %v", err)
@ -746,21 +743,11 @@ func DeleteRepository(uid, repoId int64, userName string) error {
}
sess := x.NewSession()
defer sess.Close()
defer sessionRelease(sess)
if err = sess.Begin(); err != nil {
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() {
idStr := "$" + com.ToStr(repoId) + "|"
for _, t := range org.Teams {
@ -770,34 +757,26 @@ func DeleteRepository(uid, repoId int64, userName string) error {
t.NumRepos--
t.RepoIds = strings.Replace(t.RepoIds, idStr, "", 1)
if _, err = sess.Id(t.Id).AllCols().Update(t); err != nil {
sess.Rollback()
return err
}
}
}
if _, err := sess.Delete(&Action{RepoId: repo.Id}); err != nil {
sess.Rollback()
if _, err = sess.Delete(&Repository{Id: repoId}); err != nil {
return err
}
if _, err = sess.Delete(&Watch{RepoId: repoId}); err != nil {
sess.Rollback()
} else if _, err := sess.Delete(&Access{RepoID: repo.Id}); err != nil {
return err
}
if _, err = sess.Delete(&Mirror{RepoId: repoId}); err != nil {
sess.Rollback()
} else if _, err := sess.Delete(&Action{RepoId: repo.Id}); err != nil {
return err
}
if _, err = sess.Delete(&IssueUser{RepoId: repoId}); err != nil {
sess.Rollback()
} else if _, err = sess.Delete(&Watch{RepoId: repoId}); err != nil {
return err
}
if _, err = sess.Delete(&Milestone{RepoId: repoId}); err != nil {
sess.Rollback()
} else if _, err = sess.Delete(&Mirror{RepoId: repoId}); err != nil {
return err
}
if _, err = sess.Delete(&Release{RepoId: repoId}); err != nil {
sess.Rollback()
} else if _, err = sess.Delete(&IssueUser{RepoId: repoId}); err != nil {
return err
} else if _, err = sess.Delete(&Milestone{RepoId: repoId}); err != nil {
return err
} else if _, err = sess.Delete(&Release{RepoId: repoId}); err != nil {
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 {
issue := bean.(*Issue)
if _, err = sess.Delete(&Comment{IssueId: issue.Id}); err != nil {
sess.Rollback()
return err
}
return nil
}); err != nil {
sess.Rollback()
return err
}
if _, err = sess.Delete(&Issue{RepoId: repoId}); err != nil {
sess.Rollback()
return err
}
if repo.IsFork {
if _, err = sess.Exec("UPDATE `repository` SET num_forks = num_forks - 1 WHERE id = ?", repo.ForkId); err != nil {
sess.Rollback()
return err
}
}
if _, err = sess.Exec("UPDATE `user` SET num_repos = num_repos - 1 WHERE id = ?", uid); err != nil {
sess.Rollback()
return err
}
@ -839,6 +813,7 @@ func DeleteRepository(uid, repoId int64, userName string) error {
log.Error(4, "Fail to add notice: %v", err)
}
}
return sess.Commit()
}
@ -1331,38 +1306,30 @@ func ForkRepository(u *User, oldRepo *Repository, name, desc string) (*Repositor
if err = repo.recalculateAccesses(sess); err != nil {
return nil, err
}
var t *Team // Owner team.
if _, err = sess.Exec("UPDATE `user` SET num_repos = num_repos + 1 WHERE id = ?", u.Id); err != nil {
} else 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.
if u.IsOrganization() {
// Update owner team info and count.
t, err := u.getOwnerTeam(sess)
if err != nil {
return nil, fmt.Errorf("get owner team: %v", err)
} else if err = t.getMembers(sess); err != nil {
return nil, fmt.Errorf("get team members: %v", err)
}
for _, u := range t.Members {
if err = watchRepo(sess, u.Id, repo.Id, true); err != nil {
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
}
}
if u.IsOrganization() {
t, err := u.getOwnerTeam(sess)
if err != nil {
return nil, fmt.Errorf("get owner team: %v", err)
} else {
if err = t.getMembers(sess); err != nil {
return nil, fmt.Errorf("get team members: %v", err)
} else {
for _, u := range t.Members {
if err = watchRepo(sess, u.Id, repo.Id, true); err != nil {
return nil, fmt.Errorf("watch repository: %v", err)
}
}
}
}
} else {
if err = watchRepo(sess, u.Id, repo.Id, true); err != nil {
return nil, fmt.Errorf("watch repository 2: %v", err)

View File

@ -29,7 +29,7 @@ func ApiRepoAssignment() macaron.Handler {
)
// 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
} else {
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
if ctx.IsSigned && u.LowerName == strings.ToLower(userName) {
if ctx.IsSigned && ctx.User.LowerName == strings.ToLower(userName) {
u = ctx.User
} else {
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.IsAdmin = mode >= models.ACCESS_MODE_READ
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.

View File

@ -1 +1 @@
0.5.13.0211 Beta
0.5.14.0213 Beta

View File

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

View File

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