mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-31 20:02:09 +00:00
Fix bug on transfer repo
This commit is contained in:
parent
57d48fb6a2
commit
f69761563b
10 changed files with 45 additions and 21 deletions
|
@ -351,8 +351,8 @@ func NewRepoAction(u *User, repo *Repository) (err error) {
|
|||
// TransferRepoAction adds new action for transfering repository.
|
||||
func TransferRepoAction(u, newUser *User, repo *Repository) (err error) {
|
||||
if err = NotifyWatchers(&Action{ActUserId: u.Id, ActUserName: u.Name, ActEmail: u.Email,
|
||||
OpType: TRANSFER_REPO, RepoId: repo.Id, RepoUserName: repo.Owner.Name,
|
||||
RepoName: repo.Name, Content: newUser.Name,
|
||||
OpType: TRANSFER_REPO, RepoId: repo.Id, RepoUserName: newUser.Name,
|
||||
RepoName: repo.Name,
|
||||
IsPrivate: repo.IsPrivate}); err != nil {
|
||||
log.Error(4, "NotifyWatchers: %d/%s", u.Id, repo.Name)
|
||||
return err
|
||||
|
|
|
@ -669,15 +669,23 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if _, err = sess.Where("repo_name = ?", u.LowerName+"/"+repo.LowerName).
|
||||
And("user_name = ?", u.LowerName).Update(&Access{UserName: newUser.LowerName}); err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
curRepoLink := path.Join(u.LowerName, repo.LowerName)
|
||||
// Delete all access first if current owner is an organization.
|
||||
if u.IsOrganization() {
|
||||
if _, err = sess.Where("repo_name=?", curRepoLink).Delete(new(Access)); err != nil {
|
||||
sess.Rollback()
|
||||
return fmt.Errorf("fail to delete current accesses: %v", err)
|
||||
}
|
||||
} else {
|
||||
if _, err = sess.Where("repo_name=?", curRepoLink).And("user_name=?", u.LowerName).
|
||||
Update(&Access{UserName: newUser.LowerName}); err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if _, err = sess.Where("repo_name = ?", u.LowerName+"/"+repo.LowerName).Update(&Access{
|
||||
RepoName: newUser.LowerName + "/" + repo.LowerName,
|
||||
}); err != nil {
|
||||
if _, err = sess.Where("repo_name=?", curRepoLink).
|
||||
Update(&Access{RepoName: path.Join(newUser.LowerName, repo.LowerName)}); err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
}
|
||||
|
@ -700,12 +708,12 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) error {
|
|||
return err
|
||||
}
|
||||
|
||||
mode := WRITABLE
|
||||
if repo.IsMirror {
|
||||
mode = READABLE
|
||||
}
|
||||
// New owner is organization.
|
||||
if newUser.IsOrganization() {
|
||||
mode := WRITABLE
|
||||
if repo.IsMirror {
|
||||
mode = READABLE
|
||||
}
|
||||
access := &Access{
|
||||
RepoName: path.Join(newUser.LowerName, repo.LowerName),
|
||||
Mode: mode,
|
||||
|
@ -737,6 +745,16 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) error {
|
|||
sess.Rollback()
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
access := &Access{
|
||||
RepoName: path.Join(newUser.LowerName, repo.LowerName),
|
||||
UserName: newUser.LowerName,
|
||||
Mode: mode,
|
||||
}
|
||||
if _, err = sess.Insert(access); err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Change repository directory name.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue