Browse Source

Work on #274

pull/275/head
Unknown 11 years ago
parent
commit
fd5412ec47
  1. 6
      models/org.go
  2. 51
      models/repo.go

6
models/org.go

@ -6,6 +6,7 @@ package models
import ( import (
"errors" "errors"
"os"
"strings" "strings"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
@ -97,6 +98,11 @@ func CreateOrganization(org, owner *User) (*User, error) {
return nil, err return nil, err
} }
if err = os.MkdirAll(UserPath(org.Name), os.ModePerm); err != nil {
sess.Rollback()
return nil, err
}
// Create default owner team. // Create default owner team.
t := &Team{ t := &Team{
OrgId: org.Id, OrgId: org.Id,

51
models/repo.go

@ -626,46 +626,25 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) (err error) {
return err return err
} }
// Update accesses.
/*accesses := make([]Access, 0, 10)
if err = x.Find(&accesses, &Access{RepoName: u.LowerName + "/" + repo.LowerName}); err != nil {
return err
}*/
sess := x.NewSession() sess := x.NewSession()
defer sess.Close() defer sess.Close()
if err = sess.Begin(); err != nil { if err = sess.Begin(); err != nil {
return err return err
} }
access := &Access{ if _, err = sess.Where("repo_name = ?", u.LowerName+"/"+repo.LowerName).
RepoName: newUser.LowerName + "/" + repo.LowerName, And("user_name = ?", u.LowerName).Update(&Access{UserName: newUser.LowerName}); err != nil {
}
sess.Where("repo_name = ?", u.LowerName+"/"+repo.LowerName)
_, err = sess.And("user_name = ?", u.LowerName).Update(&Access{UserName: newUser.LowerName})
if err != nil {
sess.Rollback() sess.Rollback()
return err return err
} }
_, err = sess.Where("repo_name = ?", u.LowerName+"/"+repo.LowerName).Update(access) if _, err = sess.Where("repo_name = ?", u.LowerName+"/"+repo.LowerName).Update(&Access{
if err != nil { RepoName: newUser.LowerName + "/" + repo.LowerName,
}); err != nil {
sess.Rollback() sess.Rollback()
return err return err
} }
/*
for i := range accesses {
accesses[i].RepoName = newUser.LowerName + "/" + repo.LowerName
if accesses[i].UserName == u.LowerName {
accesses[i].UserName = newUser.LowerName
}
if err = UpdateAccessWithSession(sess, &accesses[i]); err != nil {
return err
}
}*/
// Update repository. // Update repository.
repo.OwnerId = newUser.Id repo.OwnerId = newUser.Id
if _, err := sess.Id(repo.Id).Update(repo); err != nil { if _, err := sess.Id(repo.Id).Update(repo); err != nil {
@ -686,26 +665,28 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) (err error) {
return err return err
} }
// Add watch of new owner to repository. // Change repository directory name.
if !IsWatching(newUser.Id, repo.Id) { if err = os.Rename(RepoPath(u.Name, repo.Name), RepoPath(newUser.Name, repo.Name)); err != nil {
if err = WatchRepo(newUser.Id, repo.Id, true); err != nil {
sess.Rollback() sess.Rollback()
return err return err
} }
if err = sess.Commit(); err != nil {
return err
} }
if err = TransferRepoAction(u, newUser, repo); err != nil { // Add watch of new owner to repository.
sess.Rollback() if !IsWatching(newUser.Id, repo.Id) {
if err = WatchRepo(newUser.Id, repo.Id, true); err != nil {
return err return err
} }
}
// Change repository directory name. if err = TransferRepoAction(u, newUser, repo); err != nil {
if err = os.Rename(RepoPath(u.Name, repo.Name), RepoPath(newUser.Name, repo.Name)); err != nil {
sess.Rollback()
return err return err
} }
return sess.Commit() return nil
} }
// ChangeRepositoryName changes all corresponding setting from old repository name to new one. // ChangeRepositoryName changes all corresponding setting from old repository name to new one.

Loading…
Cancel
Save