Merge branch 'master' of github.com:gogits/gogs

This commit is contained in:
Unknown 2014-03-17 04:33:59 -04:00
commit 5c3054c3b7
20 changed files with 124 additions and 116 deletions

View file

@ -307,6 +307,9 @@ func DeleteRepository(userId, repoId int64, userName string) (err error) {
} }
session := orm.NewSession() session := orm.NewSession()
if err = session.Begin(); err != nil {
return err
}
if _, err = session.Delete(&Repository{Id: repoId}); err != nil { if _, err = session.Delete(&Repository{Id: repoId}); err != nil {
session.Rollback() session.Rollback()
return err return err

View file

@ -17,7 +17,6 @@ import (
) )
type CreateRepoForm struct { type CreateRepoForm struct {
UserId int64 `form:"userId"`
RepoName string `form:"repo" binding:"Required;AlphaDash"` RepoName string `form:"repo" binding:"Required;AlphaDash"`
Visibility string `form:"visibility"` Visibility string `form:"visibility"`
Description string `form:"desc" binding:"MaxSize(100)"` 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) 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"`
}

View file

@ -51,7 +51,6 @@ html, body {
.gogs-masthead { .gogs-masthead {
background-color: #428bca; background-color: #428bca;
box-shadow: inset 0 -2px 5px rgba(0, 0, 0, .1); box-shadow: inset 0 -2px 5px rgba(0, 0, 0, .1);
padding: 0 16px;
margin: 0; margin: 0;
} }
@ -133,6 +132,11 @@ html, body {
padding: 5px 0; padding: 5px 0;
margin-left: 10px; margin-left: 10px;
height: 28px; height: 28px;
float: right;
}
#gogs-nav-signin{
float: right;
} }
#gogs-nav-out .fa { #gogs-nav-out .fa {
@ -349,10 +353,6 @@ html, body {
/* #gogs-feed */ /* #gogs-feed */
#gogs-feed-left {
padding-left: 0;
}
#gogs-feed-right .repo-panel .panel-heading .btn { #gogs-feed-right .repo-panel .panel-heading .btn {
margin-top: -4px; margin-top: -4px;
} }
@ -635,7 +635,7 @@ html, body {
} }
#footer .footer-wrap { #footer .footer-wrap {
padding: 20px 0; padding: 20px 15px;
} }
#footer a { #footer a {

View file

@ -43,7 +43,15 @@ var Gogits = {
Gogits.initTabs = function () { Gogits.initTabs = function () {
var $tabs = $('[data-init=tabs]'); var $tabs = $('[data-init=tabs]');
$tabs.find("li:eq(0) a").tab("show"); $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); })(jQuery);
// ajax utils // ajax utils
@ -70,6 +78,7 @@ function initCore() {
Gogits.initTooltips(); Gogits.initTooltips();
Gogits.initTabs(); Gogits.initTabs();
Gogits.initModals(); Gogits.initModals();
Gogits.renderMarkdown();
} }
function initRegister() { function initRegister() {
@ -113,11 +122,15 @@ function initUserSetting(){
}); });
} }
;(function($){ (function ($) {
// on Dom Ready
$(function () { $(function () {
var $pre = $('.markdown').find('pre > code').parent(); initCore();
$pre.addClass("prettyprint"); var body = $("#gogs-body");
prettyPrint(); if (body.data("page") == "user-signup") {
initRegister();
}
if (body.data("page") == "user") {
initUserSetting();
}
}); });
})(jQuery); })(jQuery);

View file

@ -20,50 +20,36 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) {
return return
} }
if ctx.HasError() { if _, err := models.CreateRepository(ctx.User,
ctx.Render.HTML(200, "repo/create", ctx.Data)
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.RepoName, form.Description, form.Language, form.License,
form.Visibility == "private", form.InitReadme == "on"); err == nil { form.Visibility == "private", form.InitReadme == "on"); err == nil {
ctx.Render.Redirect("/"+user.Name+"/"+form.RepoName, 302) ctx.Render.Redirect("/"+ctx.User.Name+"/"+form.RepoName, 302)
return return
} } else if err == models.ErrRepoAlreadyExist {
}
if err.Error() == models.ErrRepoAlreadyExist.Error() {
ctx.RenderWithErr("Repository name has already been used", "repo/create", &form) ctx.RenderWithErr("Repository name has already been used", "repo/create", &form)
return return
} }
ctx.Handle(200, "repo.Create", err)
} }
func Delete(ctx *middleware.Context, form auth.DeleteRepoForm) { func SettingPost(ctx *middleware.Context) {
ctx.Data["Title"] = "Delete repository" if !ctx.Repo.IsOwner {
ctx.Render.Error(404)
if ctx.Req.Method == "GET" {
ctx.Render.HTML(200, "repo/delete", ctx.Data)
return return
} }
if err := models.DeleteRepository(form.UserId, form.RepoId, form.UserName); err != nil { 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) ctx.Handle(200, "repo.Delete", err)
return return
} }
}
ctx.Render.Redirect("/", 302) ctx.Render.Redirect("/", 302)
} }

View file

@ -78,7 +78,8 @@ func Single(ctx *middleware.Context, params martini.Params) {
} }
func Setting(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 return
} }

View file

@ -1,16 +1,9 @@
<script>
$(function(){
initCore();{{if .PageIsSignUp}}
initRegister();{{end}}{{if .PageIsUserSetting}}
initUserSetting();{{end}}
});
</script>
<div class="wrapper-push"></div> <div class="wrapper-push"></div>
</div> </div>
<footer id="footer"> <footer id="footer">
<div class="container footer-wrap"> <div class="container footer-wrap">
<p> <p>© 2014 Gogs · ver {{AppVer}} ·
© 2014 Gogs · ver {{AppVer}} · <i class="fa fa-github"></i><a target="_blank" href="https://github.com/gogits/gogs">GitHub</a> <i class="fa fa-github"></i><a target="_blank" href="https://github.com/gogits/gogs">GitHub</a>
</p> </p>
<p class="desc"></p> <p class="desc"></p>
</div> </div>

View file

@ -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" .}}

View file

@ -4,31 +4,61 @@
{{template "repo/toolbar" .}} {{template "repo/toolbar" .}}
<div id="gogs-body" class="container"> <div id="gogs-body" class="container">
<div id="gogs-user-setting-nav" class="col-md-3"> <div id="gogs-user-setting-nav" class="col-md-3">
<h4>Repository Settings</h4>
<ul class="list-group" data-init="tabs"> <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 active"><a href="/{{.Owner.Name}}/{{.Repository.Name}}/settings">Options</a></li>
<!--<li class="list-group-item" data-toggle="tab"><a href="#">Collaborators</a></li> <!--<li class="list-group-item"><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="#">Notifications</a></li>-->
<li class="list-group-item"><a href="#delete" data-toggle="tab">Delete</a></li>
</ul> </ul>
</div> </div>
<div id="gogs-repo-setting-container" class="col-md-9 tab-content"> <div id="gogs-repo-setting-container" class="col-md-9">
<div id="options" class="tab-pane"> {{if .ErrorMsg}}<p class="alert alert-danger">{{.ErrorMsg}}</p>{{end}}
<h4>Repository Options</h4> <div class="panel panel-default">
<div class="panel-heading">
Repository Options
</div> </div>
<div id="delete" class="tab-pane"> <div class="panel-body">
<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>
<form action="/repo/delete" method="post"> </div>
<input type="hidden" name="userId" value="{{.Owner.Id}}"/> </div>
<input type="hidden" name="userName" value="{{.Owner.Name}}"/> <div class="panel panel-warning">
<input type="hidden" name="repoId" value="{{.Repository.Id}}"/> <div class="panel-heading">
<hr/> 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>
<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">&times;</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> <button class="btn btn-danger btn-lg">I understand the consequences, delete this repository</button>
</div>
</form> </form>
</div> </div>
</div> </div>
</div> </div>
</div>
</div>
</div>
{{template "base/footer" .}} {{template "base/footer" .}}

View file

@ -11,7 +11,7 @@
<h3>News Feed</h3> <h3>News Feed</h3>
</div> </div>
</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}} {{if .HasInfo}}<div class="alert alert-info">{{.InfoMsg}}</div>{{end}}
<div id="gogs-feed-left" class="col-md-8"> <div id="gogs-feed-left" class="col-md-8">
<ul class="list-unstyled activity-list"> <ul class="list-unstyled activity-list">

View file

@ -1,6 +1,6 @@
{{template "base/head" .}} {{template "base/head" .}}
{{template "base/navbar" .}} {{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"> <div id="gogs-user-setting-nav" class="col-md-3">
<h4>Account Setting</h4> <h4>Account Setting</h4>
<ul class="list-group"> <ul class="list-group">

View file

@ -1,6 +1,6 @@
{{template "base/head" .}} {{template "base/head" .}}
{{template "base/navbar" .}} {{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"> <div id="gogs-user-setting-nav" class="col-md-3">
<h4>Account Setting</h4> <h4>Account Setting</h4>
<ul class="list-group"> <ul class="list-group">

View file

@ -1,6 +1,6 @@
{{template "base/head" .}} {{template "base/head" .}}
{{template "base/navbar" .}} {{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"> <div id="gogs-user-setting-nav" class="col-md-3">
<h4>Account Setting</h4> <h4>Account Setting</h4>
<ul class="list-group"> <ul class="list-group">

View file

@ -1,6 +1,6 @@
{{template "base/head" .}} {{template "base/head" .}}
{{template "base/navbar" .}} {{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 id="gogs-user-profile" class="col-md-3">
<div class="profile-avatar text-center"> <div class="profile-avatar text-center">
<a href="{{.Owner.HomeLink}}" class="center-block" data-toggle="tooltip" data-placement="bottom" title="Change Avatar"> <a href="{{.Owner.HomeLink}}" class="center-block" data-toggle="tooltip" data-placement="bottom" title="Change Avatar">

View file

@ -1,6 +1,6 @@
{{template "base/head" .}} {{template "base/head" .}}
{{template "base/navbar" .}} {{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"> <div id="gogs-user-setting-nav" class="col-md-3">
<h4>Account Setting</h4> <h4>Account Setting</h4>
<ul class="list-group"> <ul class="list-group">

View file

@ -1,6 +1,6 @@
{{template "base/head" .}} {{template "base/head" .}}
{{template "base/navbar" .}} {{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"> <div id="gogs-user-setting-nav" class="col-md-3">
<h4>Account Setting</h4> <h4>Account Setting</h4>
<ul class="list-group"> <ul class="list-group">

View file

@ -1,6 +1,6 @@
{{template "base/head" .}} {{template "base/head" .}}
{{template "base/navbar" .}} {{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"> <div id="gogs-user-setting-nav" class="col-md-3">
<h4>Account Setting</h4> <h4>Account Setting</h4>
<ul class="list-group"> <ul class="list-group">

View file

@ -1,6 +1,6 @@
{{template "base/head" .}} {{template "base/head" .}}
{{template "base/navbar" .}} {{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"> <form action="/user/login" method="post" class="form-horizontal gogs-card" id="gogs-login-card">
<h3>Log in</h3> <h3>Log in</h3>
<div class="alert alert-danger form-error{{if .HasError}}{{else}} hidden{{end}}">{{.ErrorMsg}}</div> <div class="alert alert-danger form-error{{if .HasError}}{{else}} hidden{{end}}">{{.ErrorMsg}}</div>

View file

@ -1,6 +1,6 @@
{{template "base/head" .}} {{template "base/head" .}}
{{template "base/navbar" .}} {{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"> <form action="/user/sign_up" method="post" class="form-horizontal gogs-card" id="gogs-login-card">
<h3>Sign Up</h3> <h3>Sign Up</h3>
<div class="alert alert-danger form-error{{if .HasError}}{{else}} hidden{{end}}">{{.ErrorMsg}}</div> <div class="alert alert-danger form-error{{if .HasError}}{{else}} hidden{{end}}">{{.ErrorMsg}}</div>

5
web.go
View file

@ -68,11 +68,12 @@ func runWeb(*cli.Context) {
m.Get("/user/:username", middleware.SignInRequire(false), user.Profile) 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/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("/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/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/issues", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Issues)
m.Get("/:username/:reponame/pulls", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Pulls) m.Get("/:username/:reponame/pulls", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Pulls)