diff options
author | Unknown <joe2010xtmf@163.com> | 2014-03-17 04:33:59 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-03-17 04:33:59 -0400 |
commit | 5c3054c3b7387df56db8c193db7c662802fb4a50 (patch) | |
tree | 35721683878c4f6ae36cddf444bd55b099434f1e | |
parent | cf9fa06eae68cea08c3f2fb28644a80bb08be2c3 (diff) | |
parent | 24d91ecda8c819a33f326ff724559456bcae6d71 (diff) | |
download | gitea-5c3054c3b7387df56db8c193db7c662802fb4a50.tar.gz gitea-5c3054c3b7387df56db8c193db7c662802fb4a50.zip |
Merge branch 'master' of github.com:gogits/gogs
-rw-r--r-- | models/repo.go | 3 | ||||
-rw-r--r-- | modules/auth/repo.go | 7 | ||||
-rwxr-xr-x | public/css/gogs.css | 12 | ||||
-rw-r--r-- | public/js/app.js | 35 | ||||
-rw-r--r-- | routers/repo/repo.go | 54 | ||||
-rw-r--r-- | routers/repo/single.go | 3 | ||||
-rw-r--r-- | templates/base/footer.tmpl | 21 | ||||
-rw-r--r-- | templates/repo/delete.tmpl | 12 | ||||
-rw-r--r-- | templates/repo/setting.tmpl | 68 | ||||
-rw-r--r-- | templates/user/dashboard.tmpl | 2 | ||||
-rw-r--r-- | templates/user/delete.tmpl | 2 | ||||
-rw-r--r-- | templates/user/notification.tmpl | 2 | ||||
-rw-r--r-- | templates/user/password.tmpl | 2 | ||||
-rw-r--r-- | templates/user/profile.tmpl | 2 | ||||
-rw-r--r-- | templates/user/publickey.tmpl | 2 | ||||
-rw-r--r-- | templates/user/security.tmpl | 2 | ||||
-rw-r--r-- | templates/user/setting.tmpl | 2 | ||||
-rw-r--r-- | templates/user/signin.tmpl | 2 | ||||
-rw-r--r-- | templates/user/signup.tmpl | 2 | ||||
-rw-r--r-- | web.go | 5 |
20 files changed, 124 insertions, 116 deletions
diff --git a/models/repo.go b/models/repo.go index cfca3583f8..3b35f49753 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 ac1b6b699b..2cc93744ce 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 f98cf7a184..3d0a31e6f5 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 94e38cc134..58633718fc 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 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 75eb112503..d1ad36d45b 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 09466e9e9a..841af680bd 100644 --- a/templates/base/footer.tmpl +++ b/templates/base/footer.tmpl @@ -1,19 +1,12 @@ -<script> - $(function(){ - initCore();{{if .PageIsSignUp}} - initRegister();{{end}}{{if .PageIsUserSetting}} - initUserSetting();{{end}} - }); -</script> - <div class="wrapper-push"></div> +<div class="wrapper-push"></div> </div> <footer id="footer"> - <div class="container footer-wrap"> - <p> - © 2014 Gogs · ver {{AppVer}} · <i class="fa fa-github"></i><a target="_blank" href="https://github.com/gogits/gogs">GitHub</a> - </p> - <p class="desc"></p> - </div> + <div class="container footer-wrap"> + <p>© 2014 Gogs · ver {{AppVer}} · + <i class="fa fa-github"></i><a target="_blank" href="https://github.com/gogits/gogs">GitHub</a> + </p> + <p class="desc"></p> + </div> </footer> </body> </html>
\ No newline at end of file diff --git a/templates/repo/delete.tmpl b/templates/repo/delete.tmpl deleted file mode 100644 index 0b95c3fb18..0000000000 --- a/templates/repo/delete.tmpl +++ /dev/null @@ -1,12 +0,0 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -<div class="container"> - <form action="/repo/delete" method="post" class="form-horizontal"> - <div class="form-group"> - <div class="col-md-offset-4 col-md-3"> - <button type="submit" class="btn btn-danger">Delete repository</button> - </div> - </div> - </form> -</div> -{{template "base/footer" .}}
\ No newline at end of file diff --git a/templates/repo/setting.tmpl b/templates/repo/setting.tmpl index 225e229429..06f0ed4d50 100644 --- a/templates/repo/setting.tmpl +++ b/templates/repo/setting.tmpl @@ -4,30 +4,60 @@ {{template "repo/toolbar" .}} <div id="gogs-body" class="container"> <div id="gogs-user-setting-nav" class="col-md-3"> - <h4>Repository Settings</h4> <ul class="list-group" data-init="tabs"> - <li class="list-group-item"><a href="#options" data-toggle="tab">Options</a></li> - <!--<li class="list-group-item" data-toggle="tab"><a href="#">Collaborators</a></li> - <li class="list-group-item" data-toggle="tab"><a href="#">Notifications</a></li>--> - <li class="list-group-item"><a href="#delete" data-toggle="tab">Delete</a></li> + <li class="list-group-item active"><a href="/{{.Owner.Name}}/{{.Repository.Name}}/settings">Options</a></li> + <!--<li class="list-group-item"><a href="#">Collaborators</a></li> + <li class="list-group-item"><a href="#">Notifications</a></li>--> </ul> </div> - <div id="gogs-repo-setting-container" class="col-md-9 tab-content"> - <div id="options" class="tab-pane"> - <h4>Repository Options</h4> + <div id="gogs-repo-setting-container" class="col-md-9"> + {{if .ErrorMsg}}<p class="alert alert-danger">{{.ErrorMsg}}</p>{{end}} + <div class="panel panel-default"> + <div class="panel-heading"> + Repository Options + </div> + <div class="panel-body"> + + </div> </div> - <div id="delete" class="tab-pane"> - <h4>Delete Repository</h4> - <p class="alert alert-warning">Unexpected bad things will happen if you don't read this!</p> - <p>This action <strong>CANNOT</strong> be undone. This will delete the repository, wiki, issues, and comments permanently. </p> + <div class="panel panel-warning"> + <div class="panel-heading"> + Danger Zone + </div> + <div class="panel-body"> + <button type="button" class="btn btn-default pull-right" href="#delete-repository-modal" data-toggle="modal"> + Delete this repository + </button> + <dd> + <dt>Delete this repository.</dt> + <dl>Once you delete a repository, there is no going back. Please be certain.</dl> + </dd> - <form action="/repo/delete" method="post"> - <input type="hidden" name="userId" value="{{.Owner.Id}}"/> - <input type="hidden" name="userName" value="{{.Owner.Name}}"/> - <input type="hidden" name="repoId" value="{{.Repository.Id}}"/> - <hr/> - <button class="btn btn-danger btn-lg">I understand the consequences, delete this repository</button> - </form> + <div class="modal fade" id="delete-repository-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> + <div class="modal-dialog"> + <form action="/{{.Owner.Name}}/{{.Repository.Name}}/settings" method="post" class="modal-content"> + <input type="hidden" name="action" value="delete"> + + <div class="modal-header"> + <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> + <h4 class="modal-title" id="myModalLabel">Delete repository</h4> + </div> + + <div class="modal-body"> + <div class="form-group"> + <label>Please enter your repository name "<strong class="text-danger">{{.Repository.Name}}</strong>"</label> + <input name="repository" class="form-control" type="text" placeholder="Type your repository name" required="required"> + </div> + </div> + + <div class="modal-footer"> + <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> + <button class="btn btn-danger btn-lg">I understand the consequences, delete this repository</button> + </div> + </form> + </div> + </div> + </div> </div> </div> </div> diff --git a/templates/user/dashboard.tmpl b/templates/user/dashboard.tmpl index 547e8ab556..c528185c01 100644 --- a/templates/user/dashboard.tmpl +++ b/templates/user/dashboard.tmpl @@ -11,7 +11,7 @@ <h3>News Feed</h3> </div> </div> -<div id="gogs-body" class="container"> +<div id="gogs-body" class="container" data-page="user"> {{if .HasInfo}}<div class="alert alert-info">{{.InfoMsg}}</div>{{end}} <div id="gogs-feed-left" class="col-md-8"> <ul class="list-unstyled activity-list"> diff --git a/templates/user/delete.tmpl b/templates/user/delete.tmpl index a116787c80..397ea8cc09 100644 --- a/templates/user/delete.tmpl +++ b/templates/user/delete.tmpl @@ -1,6 +1,6 @@ {{template "base/head" .}} {{template "base/navbar" .}} -<div id="gogs-body" class="container"> +<div id="gogs-body" class="container" data-page="user"> <div id="gogs-user-setting-nav" class="col-md-3"> <h4>Account Setting</h4> <ul class="list-group"> diff --git a/templates/user/notification.tmpl b/templates/user/notification.tmpl index c1abc46fb0..ecb3fa856c 100644 --- a/templates/user/notification.tmpl +++ b/templates/user/notification.tmpl @@ -1,6 +1,6 @@ {{template "base/head" .}} {{template "base/navbar" .}} -<div id="gogs-body" class="container"> +<div id="gogs-body" class="container" data-page="user"> <div id="gogs-user-setting-nav" class="col-md-3"> <h4>Account Setting</h4> <ul class="list-group"> diff --git a/templates/user/password.tmpl b/templates/user/password.tmpl index a8b1e21e04..532a57cb0f 100644 --- a/templates/user/password.tmpl +++ b/templates/user/password.tmpl @@ -1,6 +1,6 @@ {{template "base/head" .}} {{template "base/navbar" .}} -<div id="gogs-body" class="container"> +<div id="gogs-body" class="container" data-page="user"> <div id="gogs-user-setting-nav" class="col-md-3"> <h4>Account Setting</h4> <ul class="list-group"> diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 24ae76fef8..8dca29ffe3 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -1,6 +1,6 @@ {{template "base/head" .}} {{template "base/navbar" .}} -<div id="gogs-body" class="container"> +<div id="gogs-body" class="container" data-page="user"> <div id="gogs-user-profile" class="col-md-3"> <div class="profile-avatar text-center"> <a href="{{.Owner.HomeLink}}" class="center-block" data-toggle="tooltip" data-placement="bottom" title="Change Avatar"> diff --git a/templates/user/publickey.tmpl b/templates/user/publickey.tmpl index 104575d488..ef5879b54d 100644 --- a/templates/user/publickey.tmpl +++ b/templates/user/publickey.tmpl @@ -1,6 +1,6 @@ {{template "base/head" .}} {{template "base/navbar" .}} -<div id="gogs-body" class="container"> +<div id="gogs-body" class="container" data-page="user"> <div id="gogs-user-setting-nav" class="col-md-3"> <h4>Account Setting</h4> <ul class="list-group"> diff --git a/templates/user/security.tmpl b/templates/user/security.tmpl index 37cd5872aa..cf51127d2c 100644 --- a/templates/user/security.tmpl +++ b/templates/user/security.tmpl @@ -1,6 +1,6 @@ {{template "base/head" .}} {{template "base/navbar" .}} -<div id="gogs-body" class="container"> +<div id="gogs-body" class="container" data-page="user"> <div id="gogs-user-setting-nav" class="col-md-3"> <h4>Account Setting</h4> <ul class="list-group"> diff --git a/templates/user/setting.tmpl b/templates/user/setting.tmpl index edbeeb22a9..d6a6094f3f 100644 --- a/templates/user/setting.tmpl +++ b/templates/user/setting.tmpl @@ -1,6 +1,6 @@ {{template "base/head" .}} {{template "base/navbar" .}} -<div id="gogs-body" class="container"> +<div id="gogs-body" class="container" data-page="user"> <div id="gogs-user-setting-nav" class="col-md-3"> <h4>Account Setting</h4> <ul class="list-group"> diff --git a/templates/user/signin.tmpl b/templates/user/signin.tmpl index 3aefefdcf1..e60cedec88 100644 --- a/templates/user/signin.tmpl +++ b/templates/user/signin.tmpl @@ -1,6 +1,6 @@ {{template "base/head" .}} {{template "base/navbar" .}} -<div class="container" id="gogs-body"> +<div class="container" id="gogs-body" data-page="user-signin"> <form action="/user/login" method="post" class="form-horizontal gogs-card" id="gogs-login-card"> <h3>Log in</h3> <div class="alert alert-danger form-error{{if .HasError}}{{else}} hidden{{end}}">{{.ErrorMsg}}</div> diff --git a/templates/user/signup.tmpl b/templates/user/signup.tmpl index 2f1e82c730..187364de8f 100644 --- a/templates/user/signup.tmpl +++ b/templates/user/signup.tmpl @@ -1,6 +1,6 @@ {{template "base/head" .}} {{template "base/navbar" .}} -<div class="container" id="gogs-body"> +<div class="container" id="gogs-body" data-page="user-signup"> <form action="/user/sign_up" method="post" class="form-horizontal gogs-card" id="gogs-login-card"> <h3>Sign Up</h3> <div class="alert alert-danger form-error{{if .HasError}}{{else}} hidden{{end}}">{{.ErrorMsg}}</div> @@ -68,11 +68,12 @@ func runWeb(*cli.Context) { m.Get("/user/:username", middleware.SignInRequire(false), user.Profile) m.Any("/repo/create", middleware.SignInRequire(true), binding.BindIgnErr(auth.CreateRepoForm{}), repo.Create) - m.Any("/repo/delete", middleware.SignInRequire(true), binding.Bind(auth.DeleteRepoForm{}), repo.Delete) m.Get("/help", routers.Help) - m.Get("/:username/:reponame/settings", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Setting) + m.Post("/:username/:reponame/settings", middleware.SignInRequire(true), middleware.RepoAssignment(true), repo.SettingPost) + m.Get("/:username/:reponame/settings", middleware.SignInRequire(true), middleware.RepoAssignment(true), repo.Setting) + m.Get("/:username/:reponame/commits", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Commits) m.Get("/:username/:reponame/issues", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Issues) m.Get("/:username/:reponame/pulls", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Pulls) |