diff --git a/models/repo.go b/models/repo.go index cfca3583f..3b35f4975 100644 --- a/models/repo.go +++ b/models/repo.go @@ -307,6 +307,9 @@ func DeleteRepository(userId, repoId int64, userName string) (err error) { } session := orm.NewSession() + if err = session.Begin(); err != nil { + return err + } if _, err = session.Delete(&Repository{Id: repoId}); err != nil { session.Rollback() return err diff --git a/modules/auth/repo.go b/modules/auth/repo.go index ac1b6b699..2cc93744c 100644 --- a/modules/auth/repo.go +++ b/modules/auth/repo.go @@ -17,7 +17,6 @@ import ( ) type CreateRepoForm struct { - UserId int64 `form:"userId"` RepoName string `form:"repo" binding:"Required;AlphaDash"` Visibility string `form:"visibility"` Description string `form:"desc" binding:"MaxSize(100)"` @@ -52,9 +51,3 @@ func (f *CreateRepoForm) Validate(errors *binding.Errors, req *http.Request, con validate(errors, data, f) } - -type DeleteRepoForm struct { - UserId int64 `form:"userId" binding:"Required"` - UserName string `form:"userName" binding:"Required"` - RepoId int64 `form:"repoId" binding:"Required"` -} diff --git a/public/css/gogs.css b/public/css/gogs.css index f98cf7a18..3d0a31e6f 100755 --- a/public/css/gogs.css +++ b/public/css/gogs.css @@ -51,7 +51,6 @@ html, body { .gogs-masthead { background-color: #428bca; box-shadow: inset 0 -2px 5px rgba(0, 0, 0, .1); - padding: 0 16px; margin: 0; } @@ -133,6 +132,11 @@ html, body { padding: 5px 0; margin-left: 10px; height: 28px; + float: right; +} + +#gogs-nav-signin{ + float: right; } #gogs-nav-out .fa { @@ -349,10 +353,6 @@ html, body { /* #gogs-feed */ -#gogs-feed-left { - padding-left: 0; -} - #gogs-feed-right .repo-panel .panel-heading .btn { margin-top: -4px; } @@ -635,7 +635,7 @@ html, body { } #footer .footer-wrap { - padding: 20px 0; + padding: 20px 15px; } #footer a { diff --git a/public/js/app.js b/public/js/app.js index 94e38cc13..58633718f 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -43,7 +43,15 @@ var Gogits = { Gogits.initTabs = function () { var $tabs = $('[data-init=tabs]'); $tabs.find("li:eq(0) a").tab("show"); + }; + + // render markdown + Gogits.renderMarkdown = function () { + var $pre = $('.markdown').find('pre > code').parent(); + $pre.addClass("prettyprint"); + prettyPrint(); } + })(jQuery); // ajax utils @@ -70,6 +78,7 @@ function initCore() { Gogits.initTooltips(); Gogits.initTabs(); Gogits.initModals(); + Gogits.renderMarkdown(); } function initRegister() { @@ -98,14 +107,14 @@ function initRegister() { }); } -function initUserSetting(){ +function initUserSetting() { $('#gogs-ssh-keys .delete').confirmation({ singleton: true, - onConfirm: function(e, $this){ - Gogits.ajaxDelete("",{"id":$this.data("del")},function(json){ - if(json.ok){ + onConfirm: function (e, $this) { + Gogits.ajaxDelete("", {"id": $this.data("del")}, function (json) { + if (json.ok) { window.location.reload(); - }else{ + } else { alert(json.err); } }); @@ -113,11 +122,15 @@ function initUserSetting(){ }); } -;(function($){ - // on Dom Ready - $(function(){ - var $pre = $('.markdown').find('pre > code').parent(); - $pre.addClass("prettyprint"); - prettyPrint(); +(function ($) { + $(function () { + initCore(); + var body = $("#gogs-body"); + if (body.data("page") == "user-signup") { + initRegister(); + } + if (body.data("page") == "user") { + initUserSetting(); + } }); })(jQuery); diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 116c199b7..edd886279 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 75eb11250..d1ad36d45 100644 --- a/routers/repo/single.go +++ b/routers/repo/single.go @@ -78,7 +78,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 } diff --git a/templates/base/footer.tmpl b/templates/base/footer.tmpl index 09466e9e9..841af680b 100644 --- a/templates/base/footer.tmpl +++ b/templates/base/footer.tmpl @@ -1,19 +1,12 @@ - -
+