diff options
author | slene <vslene@gmail.com> | 2014-03-17 14:36:28 +0800 |
---|---|---|
committer | slene <vslene@gmail.com> | 2014-03-17 14:36:28 +0800 |
commit | 3a2eee08278a71320140129ec29c8586264d9968 (patch) | |
tree | d49f49ba19b70334667eecd785482b111987fc2e /routers | |
parent | d64a8e8d3aa5f1dc606860c0950a8b7dbebf944c (diff) | |
download | gitea-3a2eee08278a71320140129ec29c8586264d9968.tar.gz gitea-3a2eee08278a71320140129ec29c8586264d9968.zip |
fix repo setting and delete repo
Diffstat (limited to 'routers')
-rw-r--r-- | routers/repo/repo.go | 54 | ||||
-rw-r--r-- | routers/repo/single.go | 3 |
2 files changed, 22 insertions, 35 deletions
diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 116c199b7d..edd8862794 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -20,49 +20,35 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) { return } - if ctx.HasError() { - ctx.Render.HTML(200, "repo/create", ctx.Data) + if _, err := models.CreateRepository(ctx.User, + form.RepoName, form.Description, form.Language, form.License, + form.Visibility == "private", form.InitReadme == "on"); err == nil { + ctx.Render.Redirect("/"+ctx.User.Name+"/"+form.RepoName, 302) return - } - - // TODO: access check - - user, err := models.GetUserById(form.UserId) - if err != nil { - if err.Error() == models.ErrUserNotExist.Error() { - ctx.RenderWithErr("User does not exist", "repo/create", &form) - return - } - } - - if err == nil { - if _, err = models.CreateRepository(user, - form.RepoName, form.Description, form.Language, form.License, - form.Visibility == "private", form.InitReadme == "on"); err == nil { - ctx.Render.Redirect("/"+user.Name+"/"+form.RepoName, 302) - return - } - } - - if err.Error() == models.ErrRepoAlreadyExist.Error() { + } else if err == models.ErrRepoAlreadyExist { ctx.RenderWithErr("Repository name has already been used", "repo/create", &form) return } - - ctx.Handle(200, "repo.Create", err) } -func Delete(ctx *middleware.Context, form auth.DeleteRepoForm) { - ctx.Data["Title"] = "Delete repository" - - if ctx.Req.Method == "GET" { - ctx.Render.HTML(200, "repo/delete", ctx.Data) +func SettingPost(ctx *middleware.Context) { + if !ctx.Repo.IsOwner { + ctx.Render.Error(404) return } - if err := models.DeleteRepository(form.UserId, form.RepoId, form.UserName); err != nil { - ctx.Handle(200, "repo.Delete", err) - return + switch ctx.Query("action") { + case "delete": + if len(ctx.Repo.Repository.Name) == 0 || ctx.Repo.Repository.Name != ctx.Query("repository") { + ctx.Data["ErrorMsg"] = "Please make sure you entered repository name is correct." + ctx.Render.HTML(200, "repo/setting", ctx.Data) + return + } + + if err := models.DeleteRepository(ctx.User.Id, ctx.Repo.Repository.Id, ctx.User.LowerName); err != nil { + ctx.Handle(200, "repo.Delete", err) + return + } } ctx.Render.Redirect("/", 302) diff --git a/routers/repo/single.go b/routers/repo/single.go index c4189ad6d0..fdc4e6e7f8 100644 --- a/routers/repo/single.go +++ b/routers/repo/single.go @@ -65,7 +65,8 @@ func Single(ctx *middleware.Context, params martini.Params) { } func Setting(ctx *middleware.Context, params martini.Params) { - if !ctx.Repo.IsValid { + if !ctx.Repo.IsOwner { + ctx.Render.Error(404) return } |