|
|
@ -53,7 +53,7 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { |
|
|
|
ctx.Data["Licenses"] = models.Licenses |
|
|
|
ctx.Data["Licenses"] = models.Licenses |
|
|
|
|
|
|
|
|
|
|
|
if err := ctx.User.GetOrganizations(); err != nil { |
|
|
|
if err := ctx.User.GetOrganizations(); err != nil { |
|
|
|
ctx.Handle(500, "home.Dashboard(GetOrganizations)", err) |
|
|
|
ctx.Handle(500, "home.CreatePost(GetOrganizations)", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Data["Orgs"] = ctx.User.Orgs |
|
|
|
ctx.Data["Orgs"] = ctx.User.Orgs |
|
|
@ -70,9 +70,9 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { |
|
|
|
u, err = models.GetUserById(form.Uid) |
|
|
|
u, err = models.GetUserById(form.Uid) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
if err == models.ErrUserNotExist { |
|
|
|
if err == models.ErrUserNotExist { |
|
|
|
ctx.Handle(404, "home.Dashboard(GetUserById)", err) |
|
|
|
ctx.Handle(404, "home.CreatePost(GetUserById)", err) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ctx.Handle(500, "home.Dashboard(GetUserById)", err) |
|
|
|
ctx.Handle(500, "home.CreatePost(GetUserById)", err) |
|
|
|
} |
|
|
|
} |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -97,12 +97,19 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { |
|
|
|
log.Error("repo.CreatePost(DeleteRepository): %v", errDelete) |
|
|
|
log.Error("repo.CreatePost(DeleteRepository): %v", errDelete) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Handle(500, "repo.CreatePost", err) |
|
|
|
ctx.Handle(500, "repo.CreatePost(CreateRepository)", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func Migrate(ctx *middleware.Context) { |
|
|
|
func Migrate(ctx *middleware.Context) { |
|
|
|
ctx.Data["Title"] = "Migrate repository" |
|
|
|
ctx.Data["Title"] = "Migrate repository" |
|
|
|
ctx.Data["PageIsNewRepo"] = true |
|
|
|
ctx.Data["PageIsNewRepo"] = true |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := ctx.User.GetOrganizations(); err != nil { |
|
|
|
|
|
|
|
ctx.Handle(500, "home.Migrate(GetOrganizations)", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ctx.Data["Orgs"] = ctx.User.Orgs |
|
|
|
|
|
|
|
|
|
|
|
ctx.HTML(200, MIGRATE) |
|
|
|
ctx.HTML(200, MIGRATE) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -110,19 +117,40 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { |
|
|
|
ctx.Data["Title"] = "Migrate repository" |
|
|
|
ctx.Data["Title"] = "Migrate repository" |
|
|
|
ctx.Data["PageIsNewRepo"] = true |
|
|
|
ctx.Data["PageIsNewRepo"] = true |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := ctx.User.GetOrganizations(); err != nil { |
|
|
|
|
|
|
|
ctx.Handle(500, "home.MigratePost(GetOrganizations)", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ctx.Data["Orgs"] = ctx.User.Orgs |
|
|
|
|
|
|
|
|
|
|
|
if ctx.HasError() { |
|
|
|
if ctx.HasError() { |
|
|
|
ctx.HTML(200, MIGRATE) |
|
|
|
ctx.HTML(200, MIGRATE) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
u := ctx.User |
|
|
|
|
|
|
|
// Not equal means current user is an organization.
|
|
|
|
|
|
|
|
if u.Id != form.Uid { |
|
|
|
|
|
|
|
var err error |
|
|
|
|
|
|
|
u, err = models.GetUserById(form.Uid) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
if err == models.ErrUserNotExist { |
|
|
|
|
|
|
|
ctx.Handle(404, "home.MigratePost(GetUserById)", err) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
ctx.Handle(500, "home.MigratePost(GetUserById)", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
authStr := strings.Replace(fmt.Sprintf("://%s:%s", |
|
|
|
authStr := strings.Replace(fmt.Sprintf("://%s:%s", |
|
|
|
form.AuthUserName, form.AuthPasswd), "@", "%40", -1) |
|
|
|
form.AuthUserName, form.AuthPasswd), "@", "%40", -1) |
|
|
|
url := strings.Replace(form.Url, "://", authStr+"@", 1) |
|
|
|
url := strings.Replace(form.Url, "://", authStr+"@", 1) |
|
|
|
repo, err := models.MigrateRepository(ctx.User, form.RepoName, form.Description, form.Private, |
|
|
|
repo, err := models.MigrateRepository(u, form.RepoName, form.Description, form.Private, |
|
|
|
form.Mirror, url) |
|
|
|
form.Mirror, url) |
|
|
|
if err == nil { |
|
|
|
if err == nil { |
|
|
|
log.Trace("%s Repository migrated: %s/%s", ctx.Req.RequestURI, ctx.User.LowerName, form.RepoName) |
|
|
|
log.Trace("%s Repository migrated: %s/%s", ctx.Req.RequestURI, u.LowerName, form.RepoName) |
|
|
|
ctx.Redirect("/" + ctx.User.Name + "/" + form.RepoName) |
|
|
|
ctx.Redirect("/" + u.Name + "/" + form.RepoName) |
|
|
|
return |
|
|
|
return |
|
|
|
} else if err == models.ErrRepoAlreadyExist { |
|
|
|
} else if err == models.ErrRepoAlreadyExist { |
|
|
|
ctx.RenderWithErr("Repository name has already been used", MIGRATE, &form) |
|
|
|
ctx.RenderWithErr("Repository name has already been used", MIGRATE, &form) |
|
|
@ -133,7 +161,7 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if repo != nil { |
|
|
|
if repo != nil { |
|
|
|
if errDelete := models.DeleteRepository(ctx.User.Id, repo.Id, ctx.User.Name); errDelete != nil { |
|
|
|
if errDelete := models.DeleteRepository(u.Id, repo.Id, u.Name); errDelete != nil { |
|
|
|
log.Error("repo.MigratePost(DeleteRepository): %v", errDelete) |
|
|
|
log.Error("repo.MigratePost(DeleteRepository): %v", errDelete) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -142,7 +170,7 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { |
|
|
|
ctx.RenderWithErr(err.Error(), MIGRATE, &form) |
|
|
|
ctx.RenderWithErr(err.Error(), MIGRATE, &form) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Handle(500, "repo.Migrate", err) |
|
|
|
ctx.Handle(500, "repo.Migrate(MigrateRepository)", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func Single(ctx *middleware.Context, params martini.Params) { |
|
|
|
func Single(ctx *middleware.Context, params martini.Params) { |
|
|
|