summaryrefslogtreecommitdiffstats
path: root/routers/repo/repo.go
diff options
context:
space:
mode:
authorUnknwon <joe2010xtmf@163.com>2014-07-26 02:28:04 -0400
committerUnknwon <joe2010xtmf@163.com>2014-07-26 02:28:04 -0400
commit5c4bc3c848fb4bd46ad5ceeacd82cdfa8f2b5635 (patch)
tree213666141efaf773c4411d41482387f1250068f8 /routers/repo/repo.go
parent3f38ff6c09f0497980ad13fda9803907cee6d612 (diff)
downloadgitea-5c4bc3c848fb4bd46ad5ceeacd82cdfa8f2b5635.tar.gz
gitea-5c4bc3c848fb4bd46ad5ceeacd82cdfa8f2b5635.zip
Huge updates!!!!! Be careful to merge!!!!
Diffstat (limited to 'routers/repo/repo.go')
-rw-r--r--routers/repo/repo.go184
1 files changed, 93 insertions, 91 deletions
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index d1e196a0bd..8de1e0936e 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -5,8 +5,10 @@
package repo
import (
+ "fmt"
"os"
"path"
+ "strings"
"github.com/Unknwon/com"
@@ -34,22 +36,22 @@ func Create(ctx *middleware.Context) {
ctx.Data["Licenses"] = models.Licenses
ctxUser := ctx.User
- // orgId := com.StrTo(ctx.Query("org")).MustInt64()
- // if orgId > 0 {
- // org, err := models.GetUserById(orgId)
- // if err != nil && err != models.ErrUserNotExist {
- // ctx.Handle(500, "home.Dashboard(GetUserById)", err)
- // return
- // }
- // ctxUser = org
- // }
+ orgId := com.StrTo(ctx.Query("org")).MustInt64()
+ if orgId > 0 {
+ org, err := models.GetUserById(orgId)
+ if err != nil && err != models.ErrUserNotExist {
+ ctx.Handle(500, "home.Dashboard(GetUserById)", err)
+ return
+ }
+ ctxUser = org
+ }
ctx.Data["ContextUser"] = ctxUser
- // if err := ctx.User.GetOrganizations(); err != nil {
- // ctx.Handle(500, "home.Dashboard(GetOrganizations)", err)
- // return
- // }
- // ctx.Data["AllUsers"] = append([]*models.User{ctx.User}, ctx.User.Orgs...)
+ if err := ctx.User.GetOrganizations(); err != nil {
+ ctx.Handle(500, "home.Dashboard(GetOrganizations)", err)
+ return
+ }
+ ctx.Data["AllUsers"] = append([]*models.User{ctx.User}, ctx.User.Orgs...)
ctx.HTML(200, CREATE)
}
@@ -62,22 +64,22 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) {
ctx.Data["Licenses"] = models.Licenses
ctxUser := ctx.User
- // orgId := com.StrTo(ctx.Query("org")).MustInt64()
- // if orgId > 0 {
- // org, err := models.GetUserById(orgId)
- // if err != nil && err != models.ErrUserNotExist {
- // ctx.Handle(500, "home.Dashboard(GetUserById)", err)
- // return
- // }
- // ctxUser = org
- // }
+ orgId := com.StrTo(ctx.Query("org")).MustInt64()
+ if orgId > 0 {
+ org, err := models.GetUserById(orgId)
+ if err != nil && err != models.ErrUserNotExist {
+ ctx.Handle(500, "home.Dashboard(GetUserById)", err)
+ return
+ }
+ ctxUser = org
+ }
ctx.Data["ContextUser"] = ctxUser
- // if err := ctx.User.GetOrganizations(); err != nil {
- // ctx.Handle(500, "home.CreatePost(GetOrganizations)", err)
- // return
- // }
- // ctx.Data["Orgs"] = ctx.User.Orgs
+ if err := ctx.User.GetOrganizations(); err != nil {
+ ctx.Handle(500, "home.CreatePost(GetOrganizations)", err)
+ return
+ }
+ ctx.Data["Orgs"] = ctx.User.Orgs
if ctx.HasError() {
ctx.HTML(200, CREATE)
@@ -127,78 +129,78 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) {
ctx.Handle(500, "CreateRepository", err)
}
-// func Migrate(ctx *middleware.Context) {
-// ctx.Data["Title"] = "Migrate repository"
-// ctx.Data["PageIsNewRepo"] = true
+func Migrate(ctx *middleware.Context) {
+ ctx.Data["Title"] = "Migrate repository"
+ 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
+ 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)
+}
-// func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) {
-// ctx.Data["Title"] = "Migrate repository"
-// ctx.Data["PageIsNewRepo"] = true
+func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) {
+ ctx.Data["Title"] = "Migrate repository"
+ 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 err := ctx.User.GetOrganizations(); err != nil {
+ ctx.Handle(500, "home.MigratePost(GetOrganizations)", err)
+ return
+ }
+ ctx.Data["Orgs"] = ctx.User.Orgs
-// if ctx.HasError() {
-// ctx.HTML(200, MIGRATE)
-// return
-// }
+ if ctx.HasError() {
+ ctx.HTML(200, MIGRATE)
+ 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
-// }
-// }
+ 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",
-// form.AuthUserName, form.AuthPasswd), "@", "%40", -1)
-// url := strings.Replace(form.Url, "://", authStr+"@", 1)
-// repo, err := models.MigrateRepository(u, form.RepoName, form.Description, form.Private,
-// form.Mirror, url)
-// if err == nil {
-// log.Trace("%s Repository migrated: %s/%s", ctx.Req.RequestURI, u.LowerName, form.RepoName)
-// ctx.Redirect("/" + u.Name + "/" + form.RepoName)
-// return
-// } else if err == models.ErrRepoAlreadyExist {
-// ctx.RenderWithErr("Repository name has already been used", MIGRATE, &form)
-// return
-// } else if err == models.ErrRepoNameIllegal {
-// ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), MIGRATE, &form)
-// return
-// }
+ authStr := strings.Replace(fmt.Sprintf("://%s:%s",
+ form.AuthUserName, form.AuthPasswd), "@", "%40", -1)
+ url := strings.Replace(form.Url, "://", authStr+"@", 1)
+ repo, err := models.MigrateRepository(u, form.RepoName, form.Description, form.Private,
+ form.Mirror, url)
+ if err == nil {
+ log.Trace("%s Repository migrated: %s/%s", ctx.Req.RequestURI, u.LowerName, form.RepoName)
+ ctx.Redirect("/" + u.Name + "/" + form.RepoName)
+ return
+ } else if err == models.ErrRepoAlreadyExist {
+ ctx.RenderWithErr("Repository name has already been used", MIGRATE, &form)
+ return
+ } else if err == models.ErrRepoNameIllegal {
+ ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), MIGRATE, &form)
+ return
+ }
-// if repo != nil {
-// if errDelete := models.DeleteRepository(u.Id, repo.Id, u.Name); errDelete != nil {
-// log.Error("repo.MigratePost(DeleteRepository): %v", errDelete)
-// }
-// }
+ if repo != nil {
+ if errDelete := models.DeleteRepository(u.Id, repo.Id, u.Name); errDelete != nil {
+ log.Error(4, "DeleteRepository: %v", errDelete)
+ }
+ }
-// if strings.Contains(err.Error(), "Authentication failed") {
-// ctx.RenderWithErr(err.Error(), MIGRATE, &form)
-// return
-// }
-// ctx.Handle(500, "repo.Migrate(MigrateRepository)", err)
-// }
+ if strings.Contains(err.Error(), "Authentication failed") {
+ ctx.RenderWithErr(err.Error(), MIGRATE, &form)
+ return
+ }
+ ctx.Handle(500, "MigrateRepository", err)
+}
// func Action(ctx *middleware.Context, params martini.Params) {
// var err error