From 263d4093260707c6249eecb52ad52a0205e61351 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sat, 4 Oct 2014 17:15:22 -0400 Subject: Basic xss prevention --- gogs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gogs.go') diff --git a/gogs.go b/gogs.go index 289ad191..12f142ab 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.4.1003 Beta" +const APP_VER = "0.5.4.1004 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) -- cgit v1.2.3 From 91e5c24a314170490139d661a921d94b8ab0555b Mon Sep 17 00:00:00 2001 From: Unknwon Date: Mon, 6 Oct 2014 10:36:16 -0400 Subject: Fix #522 --- gogs.go | 2 +- modules/auth/repo_form.go | 2 +- templates/.VERSION | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'gogs.go') diff --git a/gogs.go b/gogs.go index 12f142ab..c0f1d1e2 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.4.1004 Beta" +const APP_VER = "0.5.4.1005 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go index 233f7b10..df5b8b69 100644 --- a/modules/auth/repo_form.go +++ b/modules/auth/repo_form.go @@ -102,7 +102,7 @@ func (f *NewSlackHookForm) Validate(ctx *macaron.Context, errs *binding.Errors, // \/ \/ \/ type CreateIssueForm struct { - IssueName string `form:"title" binding:"Required;MaxSize(50)"` + IssueName string `form:"title" binding:"Required;MaxSize(255)"` MilestoneId int64 `form:"milestoneid"` AssigneeId int64 `form:"assigneeid"` Labels string `form:"labels"` diff --git a/templates/.VERSION b/templates/.VERSION index 776ae02a..7760f35b 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.4.1004 Beta \ No newline at end of file +0.5.4.1005 Beta \ No newline at end of file -- cgit v1.2.3 From 64c68220d203cb07be001184cde4b35d4b503344 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Mon, 6 Oct 2014 17:50:00 -0400 Subject: Fix #264 --- README.md | 4 +- README_ZH.md | 4 +- cmd/web.go | 6 ++ conf/app.ini | 2 + conf/locale/locale_en-US.ini | 6 ++ conf/locale/locale_zh-CN.ini | 6 ++ gogs.go | 2 +- modules/git/hooks.go | 111 ++++++++++++++++++++++++++++++ modules/git/utils.go | 21 ++++++ modules/middleware/repo.go | 10 +++ modules/setting/setting.go | 2 + public/ng/css/ui.css | 4 ++ public/ng/less/ui/form.less | 23 +++---- routers/repo/setting.go | 54 +++++++++++++++ templates/.VERSION | 2 +- templates/repo/settings/githook_edit.tmpl | 41 +++++++++++ templates/repo/settings/githooks.tmpl | 37 ++++++++++ templates/repo/settings/nav.tmpl | 1 + 18 files changed, 317 insertions(+), 19 deletions(-) create mode 100644 modules/git/hooks.go create mode 100644 templates/repo/settings/githook_edit.tmpl create mode 100644 templates/repo/settings/githooks.tmpl (limited to 'gogs.go') diff --git a/README.md b/README.md index b7ff264e..826d9b9e 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Gogs(Go Git Service) is a painless self-hosted Git Service written in Go. ![Demo](https://gowalker.org/public/gogs_demo.gif) -##### Current version: 0.5.4 Beta +##### Current version: 0.5.5 Beta ### NOTICES @@ -44,7 +44,7 @@ The goal of this project is to make the easiest, fastest and most painless way t - Slack webhook integration - Supports MySQL, PostgreSQL and SQLite3 - Social account login(GitHub, Google, QQ, Weibo) -- Multi-language support(English, Chinese, Germany, French etc.) +- Multi-language support(English, Chinese, Germany, French, Dutch etc.) ## System Requirements diff --git a/README_ZH.md b/README_ZH.md index d704053f..3da3b6be 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个基于 Go 语言的自助 Git 服务。 ![Demo](https://gowalker.org/public/gogs_demo.gif) -##### 当前版本:0.5.4 Beta +##### 当前版本:0.5.5 Beta ## 开发目的 @@ -35,7 +35,7 @@ Gogs 的目标是打造一个最简单、最快速和最轻松的方式搭建自 - Slack Web 钩子集成 - 支持 MySQL、PostgreSQL 以及 SQLite3 数据库 - 社交帐号登录(GitHub、Google、QQ、微博) -- 多语言支持(英文、简体中文、德语、法语等等) +- 多语言支持(英文、简体中文、德语、法语、荷兰语等等) ## 系统要求 diff --git a/cmd/web.go b/cmd/web.go index 72a58bc9..810e36d3 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -313,6 +313,12 @@ func runWeb(*cli.Context) { r.Get("/hooks/:id", repo.WebHooksEdit) r.Post("/hooks/gogs/:id", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksEditPost) r.Post("/hooks/slack/:id", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksEditPost) + + m.Group("/hooks/git", func(r *macaron.Router) { + r.Get("", repo.GitHooks) + r.Get("/:name", repo.GitHooksEdit) + r.Post("/:name", repo.GitHooksEditPost) + }, middleware.GitHookService()) }) }, reqSignIn, middleware.RepoAssignment(true), reqTrueOwner) diff --git a/conf/app.ini b/conf/app.ini index 224f45dd..1ea92e9f 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -70,6 +70,8 @@ ENABLE_CACHE_AVATAR = false ENABLE_NOTIFY_MAIL = false ; More detail: https://github.com/gogits/gogs/issues/165 ENABLE_REVERSE_PROXY_AUTHENTICATION = false +; Repository Git hooks +ENABLE_GIT_HOOKS = false [webhook] ; Cron task interval in minutes diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index 8e68fb98..4fc8c359 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -287,6 +287,7 @@ settings = Settings settings.options = Options settings.collaboration = Collaboration settings.hooks = Webhooks +settings.githooks = Git Hooks settings.deploy_keys = Deploy Keys settings.basic_settings = Basic Settings settings.danger_zone = Danger Zone @@ -310,6 +311,11 @@ settings.add_collaborator_success = New collaborator has been added. settings.remove_collaborator_success = Collaborator has been removed. settings.add_webhook = Add Webhook settings.hooks_desc = Webhooks allow external services to be notified when certain events happen on Gogs. When the specified events happen, we'll send a POST request to each of the URLs you provide. Learn more in our Webhooks Guide. +settings.githooks_desc = Git Hooks are powered by Git itself, you can edit files of supported hooks in the list below to apply custom operations. +settings.githook_edit_desc = If hook is not active, sample content will be presented. Leave content to be blank will disable this hook. +settings.githook_name = Hook Name +settings.githook_content = Hook Content +settings.update_githook = Update Hook settings.remove_hook_success = Webhook has been removed. settings.add_webhook_desc = We’ll send a POST request to the URL below with details of any subscribed events. You can also specify which data format you'd like to receive (JSON, x-www-form-urlencoded, etc). More information can be found in Webhooks Guide. settings.payload_url = Payload URL diff --git a/conf/locale/locale_zh-CN.ini b/conf/locale/locale_zh-CN.ini index 360bf4bc..dc454848 100644 --- a/conf/locale/locale_zh-CN.ini +++ b/conf/locale/locale_zh-CN.ini @@ -287,6 +287,7 @@ settings = 仓库设置 settings.options = 基本设置 settings.collaboration = 管理协作者 settings.hooks = 管理 Web 钩子 +settings.githooks = 管理 Git 钩子 settings.deploy_keys = 管理部署密钥 settings.basic_settings = 基本设置 settings.danger_zone = 危险操作区 @@ -312,6 +313,11 @@ settings.add_webhook = 添加 Web 钩子 settings.hooks_desc = Web 钩子允许您设定在 Gogs 上发生指定事件时对指定 URL 发送 POST 通知。查看 Webhooks 文档 获取更多信息。 settings.remove_hook_success = Web 钩子删除成功! settings.add_webhook_desc = 我们会通过 POST 请求将订阅事件信息发送至向指定 URL 地址。您可以设置不同的数据接收方式(JSON 或 x-www-form-urlencoded)。 请查阅 Webhooks 文档 获取更多信息。 +settings.githooks_desc = Git 钩子是由 Git 本身提供的功能,以下为 Gogs 所支持的钩子列表。 +settings.githook_edit_desc = 如果钩子未启动,则会显示样例文件中的内容。如果想要删除某个钩子,则提交空白文本即可。 +settings.githook_name = 钩子名称 +settings.githook_content = 钩子文本 +settings.update_githook = 更新钩子设置 settings.payload_url = 推送地址 settings.content_type = 数据格式 settings.secret = 密钥文本 diff --git a/gogs.go b/gogs.go index c0f1d1e2..43705061 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.4.1005 Beta" +const APP_VER = "0.5.5.1006 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/modules/git/hooks.go b/modules/git/hooks.go new file mode 100644 index 00000000..b8d15e5e --- /dev/null +++ b/modules/git/hooks.go @@ -0,0 +1,111 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "errors" + "io/ioutil" + "os" + "path" + "strings" +) + +// hookNames is a list of Git hooks' name that are supported. +var hookNames = []string{ + "pre-applypatch", + "applypatch-msg", + "prepare-commit-msg", + "commit-msg", + "pre-commit", + "pre-rebase", + "post-commit", + "post-receive", + "post-update", +} + +var ( + ErrNotValidHook = errors.New("not a valid Git hook") +) + +// IsValidHookName returns true if given name is a valid Git hook. +func IsValidHookName(name string) bool { + for _, hn := range hookNames { + if hn == name { + return true + } + } + return false +} + +// Hook represents a Git hook. +type Hook struct { + name string + IsActive bool // Indicates whether repository has this hook. + Content string // Content of hook if it's active. + Sample string // Sample content from Git. + path string // Hook file path. +} + +// GetHook returns a Git hook by given name and repository. +func GetHook(repoPath, name string) (*Hook, error) { + if !IsValidHookName(name) { + return nil, ErrNotValidHook + } + h := &Hook{ + name: name, + path: path.Join(repoPath, "hooks", name), + } + if isFile(h.path) { + data, err := ioutil.ReadFile(h.path) + if err != nil { + return nil, err + } + h.IsActive = true + h.Content = string(data) + } else if isFile(h.path + ".sample") { + data, err := ioutil.ReadFile(h.path + ".sample") + if err != nil { + return nil, err + } + h.Sample = string(data) + } + return h, nil +} + +func (h *Hook) Name() string { + return h.name +} + +// Update updates hook settings. +func (h *Hook) Update() error { + if len(strings.TrimSpace(h.Content)) == 0 { + return os.Remove(h.path) + } + return ioutil.WriteFile(h.path, []byte(h.Content), os.ModePerm) +} + +// ListHooks returns a list of Git hooks of given repository. +func ListHooks(repoPath string) (_ []*Hook, err error) { + if !isDir(path.Join(repoPath, "hooks")) { + return nil, errors.New("hooks path does not exist") + } + + hooks := make([]*Hook, len(hookNames)) + for i, name := range hookNames { + hooks[i], err = GetHook(repoPath, name) + if err != nil { + return nil, err + } + } + return hooks, nil +} + +func (repo *Repository) GetHook(name string) (*Hook, error) { + return GetHook(repo.Path, name) +} + +func (repo *Repository) Hooks() ([]*Hook, error) { + return ListHooks(repo.Path) +} diff --git a/modules/git/utils.go b/modules/git/utils.go index 26eef231..6abbca55 100644 --- a/modules/git/utils.go +++ b/modules/git/utils.go @@ -7,6 +7,7 @@ package git import ( "bytes" "container/list" + "os" "path/filepath" "strings" ) @@ -46,3 +47,23 @@ func RefEndName(refStr string) string { func filepathFromSHA1(rootdir, sha1 string) string { return filepath.Join(rootdir, "objects", sha1[:2], sha1[2:]) } + +// isDir returns true if given path is a directory, +// or returns false when it's a file or does not exist. +func isDir(dir string) bool { + f, e := os.Stat(dir) + if e != nil { + return false + } + return f.IsDir() +} + +// isFile returns true if given path is a file, +// or returns false when it's a directory or does not exist. +func isFile(filePath string) bool { + f, e := os.Stat(filePath) + if e != nil { + return false + } + return !f.IsDir() +} diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index c6250f6d..78af58ea 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -308,3 +308,13 @@ func RequireTrueOwner() macaron.Handler { } } } + +// GitHookService checks if repsitory Git hooks service has been enabled. +func GitHookService() macaron.Handler { + return func(ctx *Context) { + if !setting.Service.EnableGitHooks { + ctx.Handle(404, "GitHookService", nil) + return + } + } +} diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 67e48108..b8fc4dec 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -275,6 +275,7 @@ var Service struct { LdapAuth bool ActiveCodeLives int ResetPwdCodeLives int + EnableGitHooks bool } func newService() { @@ -284,6 +285,7 @@ func newService() { Service.RequireSignInView = Cfg.MustBool("service", "REQUIRE_SIGNIN_VIEW") Service.EnableCacheAvatar = Cfg.MustBool("service", "ENABLE_CACHE_AVATAR") Service.EnableReverseProxyAuth = Cfg.MustBool("service", "ENABLE_REVERSE_PROXY_AUTHENTICATION") + Service.EnableGitHooks = Cfg.MustBool("service", "ENABLE_GIT_HOOKS") } var logLevels = map[string]string{ diff --git a/public/ng/css/ui.css b/public/ng/css/ui.css index 9c3c8ded..3ea6fcd4 100644 --- a/public/ng/css/ui.css +++ b/public/ng/css/ui.css @@ -480,6 +480,10 @@ dt { .ipt-large { font-size: 14.4px; } +.ipt-textarea { + height: auto !important; + width: auto; +} .ipt-disabled, input[disabled] { background-color: #f2f2f2 !important; diff --git a/public/ng/less/ui/form.less b/public/ng/less/ui/form.less index 4a681994..b3de4273 100644 --- a/public/ng/less/ui/form.less +++ b/public/ng/less/ui/form.less @@ -116,25 +116,24 @@ } // input form elements - .ipt { - &:focus { - border-color: @iptFocusBorderColor; - } + &:focus { + border-color: @iptFocusBorderColor; + } } - .ipt-radius { - border-radius: .25em; + border-radius: .25em; } - .ipt-small { - font-size: .8*@baseFontSize; + font-size: .8*@baseFontSize; } - .ipt-large { - font-size: 1.2*@baseFontSize; + font-size: 1.2*@baseFontSize; +} +.ipt-textarea { + height: auto !important; + width: auto; } - .ipt-disabled, input[disabled] { background-color: @iptDisabledColor !important; @@ -144,14 +143,12 @@ input[disabled] { color: #888; cursor: not-allowed; } - .ipt-readonly, input[readonly] { &:focus { background-color: @iptDisabledColor !important; } } - .ipt-error { border-color: @iptErrorBorderColor !important; background-color: @iptErrorFocusColor !important; diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 48089787..0e58029e 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -16,6 +16,7 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/git" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/middleware" @@ -26,6 +27,8 @@ const ( SETTINGS_OPTIONS base.TplName = "repo/settings/options" COLLABORATION base.TplName = "repo/settings/collaboration" HOOKS base.TplName = "repo/settings/hooks" + GITHOOKS base.TplName = "repo/settings/githooks" + GITHOOK_EDIT base.TplName = "repo/settings/githook_edit" HOOK_NEW base.TplName = "repo/settings/hook_new" ORG_HOOK_NEW base.TplName = "org/settings/hook_new" ) @@ -591,3 +594,54 @@ func getOrgRepoCtx(ctx *middleware.Context) (*OrgRepoCtx, error) { return &OrgRepoCtx{}, errors.New("Unable to set OrgRepo context") } } + +func GitHooks(ctx *middleware.Context) { + ctx.Data["Title"] = ctx.Tr("repo.settings") + ctx.Data["PageIsSettingsGitHooks"] = true + + hooks, err := ctx.Repo.GitRepo.Hooks() + if err != nil { + ctx.Handle(500, "Hooks", err) + return + } + ctx.Data["Hooks"] = hooks + + ctx.HTML(200, GITHOOKS) +} + +func GitHooksEdit(ctx *middleware.Context) { + ctx.Data["Title"] = ctx.Tr("repo.settings") + ctx.Data["PageIsSettingsGitHooks"] = true + + name := ctx.Params(":name") + hook, err := ctx.Repo.GitRepo.GetHook(name) + if err != nil { + if err == git.ErrNotValidHook { + ctx.Handle(404, "GetHook", err) + } else { + ctx.Handle(500, "GetHook", err) + } + return + } + ctx.Data["Hook"] = hook + ctx.HTML(200, GITHOOK_EDIT) +} + +func GitHooksEditPost(ctx *middleware.Context) { + name := ctx.Params(":name") + hook, err := ctx.Repo.GitRepo.GetHook(name) + if err != nil { + if err == git.ErrNotValidHook { + ctx.Handle(404, "GetHook", err) + } else { + ctx.Handle(500, "GetHook", err) + } + return + } + hook.Content = ctx.Query("content") + if err = hook.Update(); err != nil { + ctx.Handle(500, "hook.Update", err) + return + } + ctx.Redirect(ctx.Repo.RepoLink + "/settings/hooks/git") +} diff --git a/templates/.VERSION b/templates/.VERSION index 7760f35b..e551dcfe 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.4.1005 Beta \ No newline at end of file +0.5.5.1006 Beta \ No newline at end of file diff --git a/templates/repo/settings/githook_edit.tmpl b/templates/repo/settings/githook_edit.tmpl new file mode 100644 index 00000000..23fc26e3 --- /dev/null +++ b/templates/repo/settings/githook_edit.tmpl @@ -0,0 +1,41 @@ +{{template "ng/base/head" .}} +{{template "ng/base/header" .}} +
+ {{template "repo/header" .}} +
+
+ {{template "repo/settings/nav" .}} +
+
+ {{template "ng/base/alert" .}} +
+
+
+ {{.i18n.Tr "repo.settings.githooks"}} +
+
+ {{.CsrfTokenHtml}} +
{{.i18n.Tr "repo.settings.githook_edit_desc"}}
+ {{with .Hook}} +
+ + +
+
+ + +
+
+ + +
+ {{end}} +
+
+
+
+
+
+
+
+{{template "ng/base/footer" .}} \ No newline at end of file diff --git a/templates/repo/settings/githooks.tmpl b/templates/repo/settings/githooks.tmpl new file mode 100644 index 00000000..a059b0e7 --- /dev/null +++ b/templates/repo/settings/githooks.tmpl @@ -0,0 +1,37 @@ +{{template "ng/base/head" .}} +{{template "ng/base/header" .}} +
+ {{template "repo/header" .}} +
+
+ {{template "repo/settings/nav" .}} +
+
+ {{template "ng/base/alert" .}} +
+
+
+ {{.i18n.Tr "repo.settings.githooks"}} +
+
    +
  • {{.i18n.Tr "repo.settings.githooks_desc" | Str2html}}
  • + {{range .Hooks}} +
  • + {{if .IsActive}} + + {{else}} + + {{end}} + {{.Name}} + +
  • + {{end}} +
+
+
+
+
+
+
+
+{{template "ng/base/footer" .}} \ No newline at end of file diff --git a/templates/repo/settings/nav.tmpl b/templates/repo/settings/nav.tmpl index ef0765fe..16128f01 100644 --- a/templates/repo/settings/nav.tmpl +++ b/templates/repo/settings/nav.tmpl @@ -5,6 +5,7 @@
  • {{.i18n.Tr "repo.settings.options"}}
  • {{.i18n.Tr "repo.settings.collaboration"}}
  • {{.i18n.Tr "repo.settings.hooks"}}
  • +
  • {{.i18n.Tr "repo.settings.githooks"}}
  • -- cgit v1.2.3 From fc18741cc78acbb6fac5cf89fa5ae7034178c5ca Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 7 Oct 2014 07:02:53 -0400 Subject: Fix #524 --- .bra.toml | 4 ++-- .gobuild.yml | 4 ++-- cmd/cert.go | 2 ++ cmd/cert_stub.go | 34 ++++++++++++++++++++++++++++++++++ gogs.go | 2 +- templates/.VERSION | 2 +- 6 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 cmd/cert_stub.go (limited to 'gogs.go') diff --git a/.bra.toml b/.bra.toml index a5fcdf6e..df2e10e6 100644 --- a/.bra.toml +++ b/.bra.toml @@ -11,7 +11,7 @@ watch_dirs = [ watch_exts = [".go", ".ini"] build_delay = 1500 cmds = [ - ["go", "install", "-tags", "sqlite"], - ["go", "build", "-tags", "sqlite"], + ["go", "install", "-tags", "sqlite cert"], + ["go", "build", "-tags", "sqlite cert"], ["./gogs", "web"] ] \ No newline at end of file diff --git a/.gobuild.yml b/.gobuild.yml index 77633fa0..3a2f361d 100644 --- a/.gobuild.yml +++ b/.gobuild.yml @@ -16,6 +16,6 @@ settings: then go install -v else - go get -v -tags "sqlite redis memcache" github.com/gogits/gogs - go install -v -tags "sqlite redis memcache" + go get -v -tags "sqlite redis memcache cert" github.com/gogits/gogs + go install -v -tags "sqlite redis memcache cert" fi diff --git a/cmd/cert.go b/cmd/cert.go index b693b7d9..631c4c68 100644 --- a/cmd/cert.go +++ b/cmd/cert.go @@ -1,3 +1,5 @@ +// +build cert + // Copyright 2009 The Go Authors. All rights reserved. // Copyright 2014 The Gogs Authors. All rights reserved. // Use of this source code is governed by a MIT-style diff --git a/cmd/cert_stub.go b/cmd/cert_stub.go new file mode 100644 index 00000000..2029f4cb --- /dev/null +++ b/cmd/cert_stub.go @@ -0,0 +1,34 @@ +// +build !cert + +// Copyright 2009 The Go Authors. All rights reserved. +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. +package cmd + +import ( + "fmt" + "time" + + "github.com/codegangsta/cli" +) + +var CmdCert = cli.Command{ + Name: "cert", + Usage: "Generate self-signed certificate", + Description: `Generate a self-signed X.509 certificate for a TLS server. +Outputs to 'cert.pem' and 'key.pem' and will overwrite existing files.`, + Action: runCert, + Flags: []cli.Flag{ + cli.StringFlag{"host", "", "Comma-separated hostnames and IPs to generate a certificate for", ""}, + cli.StringFlag{"ecdsa-curve", "", "ECDSA curve to use to generate a key. Valid values are P224, P256, P384, P521", ""}, + cli.IntFlag{"rsa-bits", 2048, "Size of RSA key to generate. Ignored if --ecdsa-curve is set", ""}, + cli.StringFlag{"start-date", "", "Creation date formatted as Jan 1 15:04:05 2011", ""}, + cli.DurationFlag{"duration", 365 * 24 * time.Hour, "Duration that certificate is valid for", ""}, + cli.BoolFlag{"ca", "whether this cert should be its own Certificate Authority", ""}, + }, +} + +func runCert(ctx *cli.Context) { + fmt.Println("Command cert not available, please use build tags 'cert' to rebuild.") +} diff --git a/gogs.go b/gogs.go index 43705061..b1e46096 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.5.1006 Beta" +const APP_VER = "0.5.5.1007 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/templates/.VERSION b/templates/.VERSION index e551dcfe..999f683b 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.5.1006 Beta \ No newline at end of file +0.5.5.1007 Beta \ No newline at end of file -- cgit v1.2.3 From 1aa76bd27913e40780aa66fe6b6c1158e20b7bef Mon Sep 17 00:00:00 2001 From: Unknwon Date: Wed, 8 Oct 2014 18:29:18 -0400 Subject: Fix #532, add system notice --- cmd/web.go | 5 ++++ conf/locale/locale_en-US.ini | 8 ++++++ conf/locale/locale_zh-CN.ini | 8 ++++++ gogs.go | 2 +- models/admin.go | 64 ++++++++++++++++++++++++++++++++++++++++++++ models/models.go | 10 +++---- models/repo.go | 9 +++++-- routers/admin/notice.go | 46 +++++++++++++++++++++++++++++++ routers/admin/users.go | 4 +-- templates/.VERSION | 2 +- templates/admin/nav.tmpl | 1 + templates/admin/notice.tmpl | 54 +++++++++++++++++++++++++++++++++++++ 12 files changed, 202 insertions(+), 11 deletions(-) create mode 100644 models/admin.go create mode 100644 routers/admin/notice.go create mode 100644 templates/admin/notice.tmpl (limited to 'gogs.go') diff --git a/cmd/web.go b/cmd/web.go index 201eb48f..9f2ec8b8 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -243,6 +243,11 @@ func runWeb(*cli.Context) { r.Post("/:authid", bindIgnErr(auth.AuthenticationForm{}), admin.EditAuthSourcePost) r.Post("/:authid/delete", admin.DeleteAuthSource) }) + + m.Group("/notices", func(r *macaron.Router) { + r.Get("", admin.Notices) + r.Get("/:id:int/delete", admin.DeleteNotice) + }) }, adminReq) m.Get("/:username", ignSignIn, user.Profile) diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index 4fc8c359..15262e63 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -416,6 +416,7 @@ organizations = Organizations repositories = Repositories authentication = Authentications config = Configuration +notices = System Notices monitor = Monitoring prev = Prev. next = Next @@ -593,6 +594,13 @@ monitor.desc = Description monitor.start = Start Time monitor.execute_time = Execution Time +notices.system_notice_list = System Notices +notices.type = Type +notices.type_1 = Repository +notices.desc = Description +notices.op = Op. +notices.delete_success = System notice has been successfully deleted. + [action] create_repo = created repository %s commit_repo = pushed to %s at %s diff --git a/conf/locale/locale_zh-CN.ini b/conf/locale/locale_zh-CN.ini index dc454848..8a343d4c 100644 --- a/conf/locale/locale_zh-CN.ini +++ b/conf/locale/locale_zh-CN.ini @@ -416,6 +416,7 @@ organizations = 组织管理 repositories = 仓库管理 authentication = 授权认证管理 config = 应用配置管理 +notices = 系统提示管理 monitor = 应用监控面板 prev = 上一页 next = 下一页 @@ -593,6 +594,13 @@ monitor.desc = 进程描述 monitor.start = 开始时间 monitor.execute_time = 已执行时间 +notices.system_notice_list = 系统提示管理 +notices.type = 提示类型 +notices.type_1 = 仓库 +notices.desc = 描述 +notices.op = 操作 +notices.delete_success = 系统提示删除成功! + [action] create_repo = 创建了仓库 %s commit_repo = 推送了 %s 分支的代码到 %s diff --git a/gogs.go b/gogs.go index b1e46096..250333f3 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.5.1007 Beta" +const APP_VER = "0.5.5.1008 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/admin.go b/models/admin.go new file mode 100644 index 00000000..493cc7af --- /dev/null +++ b/models/admin.go @@ -0,0 +1,64 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package models + +import ( + "time" + + "github.com/Unknwon/com" +) + +type NoticeType int + +const ( + NOTICE_REPOSITORY NoticeType = iota + 1 +) + +// Notice represents a system notice for admin. +type Notice struct { + Id int64 + Type NoticeType + Description string `xorm:"TEXT"` + Created time.Time `xorm:"CREATED"` +} + +// TrStr returns a translation format string. +func (n *Notice) TrStr() string { + return "admin.notices.type_" + com.ToStr(n.Type) +} + +// CreateNotice creates new system notice. +func CreateNotice(tp NoticeType, desc string) error { + n := &Notice{ + Type: tp, + Description: desc, + } + _, err := x.Insert(n) + return err +} + +// CreateRepositoryNotice creates new system notice with type NOTICE_REPOSITORY. +func CreateRepositoryNotice(desc string) error { + return CreateNotice(NOTICE_REPOSITORY, desc) +} + +// CountNotices returns number of notices. +func CountNotices() int64 { + count, _ := x.Count(new(Notice)) + return count +} + +// GetNotices returns given number of notices with offset. +func GetNotices(num, offset int) ([]*Notice, error) { + notices := make([]*Notice, 0, num) + err := x.Limit(num, offset).Desc("id").Find(¬ices) + return notices, err +} + +// DeleteNotice deletes a system notice by given ID. +func DeleteNotice(id int64) error { + _, err := x.Id(id).Delete(new(Notice)) + return err +} diff --git a/models/models.go b/models/models.go index 570df0c1..35eb4c96 100644 --- a/models/models.go +++ b/models/models.go @@ -32,12 +32,12 @@ var ( ) func init() { - tables = append(tables, new(User), new(PublicKey), + tables = append(tables, new(User), new(PublicKey), new(Follow), new(Oauth2), new(Repository), new(Watch), new(Star), new(Action), new(Access), - new(Issue), new(Comment), new(Oauth2), new(Follow), - new(Mirror), new(Release), new(LoginSource), new(Webhook), new(IssueUser), - new(Milestone), new(Label), new(HookTask), new(Team), new(OrgUser), new(TeamUser), - new(UpdateTask), new(Attachment)) + new(Issue), new(Comment), new(Attachment), new(IssueUser), new(Label), new(Milestone), + new(Mirror), new(Release), new(LoginSource), new(Webhook), + new(UpdateTask), new(HookTask), new(Team), new(OrgUser), new(TeamUser), + new(Notice)) } func LoadModelsConfig() { diff --git a/models/repo.go b/models/repo.go index 8e29b335..3a26c88f 100644 --- a/models/repo.go +++ b/models/repo.go @@ -934,9 +934,14 @@ func DeleteRepository(uid, repoId int64, userName string) error { sess.Rollback() return err } + + // Remove repository files. if err = os.RemoveAll(RepoPath(userName, repo.Name)); err != nil { - sess.Rollback() - return err + desc := fmt.Sprintf("Fail to delete repository files(%s/%s): %v", userName, repo.Name, err) + log.Warn(desc) + if err = CreateRepositoryNotice(desc); err != nil { + log.Error(4, "Fail to add notice: %v", err) + } } return sess.Commit() } diff --git a/routers/admin/notice.go b/routers/admin/notice.go new file mode 100644 index 00000000..b4319463 --- /dev/null +++ b/routers/admin/notice.go @@ -0,0 +1,46 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package admin + +import ( + "github.com/Unknwon/com" + + "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/log" + "github.com/gogits/gogs/modules/middleware" +) + +const ( + NOTICES base.TplName = "admin/notice" +) + +func Notices(ctx *middleware.Context) { + ctx.Data["Title"] = ctx.Tr("admin.notices") + ctx.Data["PageIsAdmin"] = true + ctx.Data["PageIsAdminNotices"] = true + + pageNum := 50 + p := pagination(ctx, models.CountNotices(), pageNum) + + notices, err := models.GetNotices(pageNum, (p-1)*pageNum) + if err != nil { + ctx.Handle(500, "GetNotices", err) + return + } + ctx.Data["Notices"] = notices + ctx.HTML(200, NOTICES) +} + +func DeleteNotice(ctx *middleware.Context) { + id := com.StrTo(ctx.Params(":id")).MustInt64() + if err := models.DeleteNotice(id); err != nil { + ctx.Handle(500, "DeleteNotice", err) + return + } + log.Trace("System notice deleted by admin(%s): %d", ctx.User.Name, id) + ctx.Flash.Success(ctx.Tr("admin.notices.delete_success")) + ctx.Redirect("/admin/notices") +} diff --git a/routers/admin/users.go b/routers/admin/users.go index fc3b0cbc..e5cd364f 100644 --- a/routers/admin/users.go +++ b/routers/admin/users.go @@ -48,12 +48,12 @@ func Users(ctx *middleware.Context) { pageNum := 50 p := pagination(ctx, models.CountUsers(), pageNum) - var err error - ctx.Data["Users"], err = models.GetUsers(pageNum, (p-1)*pageNum) + users, err := models.GetUsers(pageNum, (p-1)*pageNum) if err != nil { ctx.Handle(500, "GetUsers", err) return } + ctx.Data["Users"] = users ctx.HTML(200, USERS) } diff --git a/templates/.VERSION b/templates/.VERSION index 999f683b..194ec580 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.5.1007 Beta \ No newline at end of file +0.5.5.1008 Beta \ No newline at end of file diff --git a/templates/admin/nav.tmpl b/templates/admin/nav.tmpl index e294cd92..49c4b72c 100644 --- a/templates/admin/nav.tmpl +++ b/templates/admin/nav.tmpl @@ -8,6 +8,7 @@
  • {{.i18n.Tr "admin.repositories"}}
  • {{.i18n.Tr "admin.authentication"}}
  • {{.i18n.Tr "admin.config"}}
  • +
  • {{.i18n.Tr "admin.notices"}}
  • {{.i18n.Tr "admin.monitor"}}
  • diff --git a/templates/admin/notice.tmpl b/templates/admin/notice.tmpl new file mode 100644 index 00000000..b3abbb6b --- /dev/null +++ b/templates/admin/notice.tmpl @@ -0,0 +1,54 @@ +{{template "ng/base/head" .}} +{{template "ng/base/header" .}} +
    +
    +
    + {{template "admin/nav" .}} +
    +
    + {{template "ng/base/alert" .}} +
    +
    +
    + {{.i18n.Tr "admin.notices.system_notice_list"}} +
    +
    +
    + + + + + + + + + + + + {{range .Notices}} + + + + + + + + {{end}} + +
    Id{{.i18n.Tr "admin.notices.type"}}{{.i18n.Tr "admin.notices.desc"}}{{.i18n.Tr "admin.users.created"}}{{.i18n.Tr "admin.notices.op"}}
    {{.Id}}{{$.i18n.Tr .TrStr}}{{.Description}}{{.Created}}
    + {{if or .LastPageNum .NextPageNum}} + + {{end}} +
    +
    +
    +
    +
    +
    +
    +
    +
    +{{template "ng/base/footer" .}} \ No newline at end of file -- cgit v1.2.3 From 39931f8e001af113d3ea0905a79f152fb93f70ec Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 9 Oct 2014 18:08:07 -0400 Subject: Allow mail with self-signed certificates --- gogs.go | 2 +- modules/mailer/mailer.go | 53 ++++++++++++++++++++++++++++++++++++++++++++++-- templates/.VERSION | 2 +- 3 files changed, 53 insertions(+), 4 deletions(-) (limited to 'gogs.go') diff --git a/gogs.go b/gogs.go index 250333f3..f3825622 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.5.1008 Beta" +const APP_VER = "0.5.5.1009 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/modules/mailer/mailer.go b/modules/mailer/mailer.go index 6397ccc4..758792a3 100644 --- a/modules/mailer/mailer.go +++ b/modules/mailer/mailer.go @@ -5,7 +5,9 @@ package mailer import ( + "crypto/tls" "fmt" + "net" "net/smtp" "strings" @@ -64,6 +66,53 @@ func processMailQueue() { } } +// sendMail allows mail with self-signed certificates. +func sendMail(hostAddressWithPort string, auth smtp.Auth, from string, recipients []string, msgContent []byte) error { + client, err := smtp.Dial(hostAddressWithPort) + if err != nil { + return err + } + + host, _, _ := net.SplitHostPort(hostAddressWithPort) + tlsConn := &tls.Config{ + InsecureSkipVerify: true, + ServerName: host, + } + if err = client.StartTLS(tlsConn); err != nil { + return err + } + + if auth != nil { + if err = client.Auth(auth); err != nil { + return err + } + } + + if err = client.Mail(from); err != nil { + return err + } + + for _, rec := range recipients { + if err = client.Rcpt(rec); err != nil { + return err + } + } + + w, err := client.Data() + if err != nil { + return err + } + if _, err = w.Write([]byte(msgContent)); err != nil { + return err + } + + if err = w.Close(); err != nil { + return err + } + + return client.Quit() +} + // Direct Send mail message func Send(msg *Message) (int, error) { log.Trace("Sending mails to: %s", strings.Join(msg.To, "; ")) @@ -85,7 +134,7 @@ func Send(msg *Message) (int, error) { num := 0 for _, to := range msg.To { body := []byte("To: " + to + "\r\n" + content) - err := smtp.SendMail(setting.MailService.Host, auth, msg.From, []string{to}, body) + err := sendMail(setting.MailService.Host, auth, msg.From, []string{to}, body) if err != nil { return num, err } @@ -96,7 +145,7 @@ func Send(msg *Message) (int, error) { body := []byte("To: " + strings.Join(msg.To, ";") + "\r\n" + content) // send to multiple emails in one message - err := smtp.SendMail(setting.MailService.Host, auth, msg.From, msg.To, body) + err := sendMail(setting.MailService.Host, auth, msg.From, msg.To, body) if err != nil { return 0, err } else { diff --git a/templates/.VERSION b/templates/.VERSION index 194ec580..35a9c242 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.5.1008 Beta \ No newline at end of file +0.5.5.1009 Beta \ No newline at end of file -- cgit v1.2.3 From d78abd356186e5bfe841f5c70d9b907f5c288920 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 10 Oct 2014 03:28:21 -0400 Subject: Mirror fix on admin/orgs paging --- gogs.go | 2 +- routers/admin/orgs.go | 2 +- routers/admin/users.go | 6 +++--- templates/.VERSION | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'gogs.go') diff --git a/gogs.go b/gogs.go index f3825622..05fcd2cd 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.5.1009 Beta" +const APP_VER = "0.5.5.1010 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/routers/admin/orgs.go b/routers/admin/orgs.go index e813e474..54d7af5c 100644 --- a/routers/admin/orgs.go +++ b/routers/admin/orgs.go @@ -25,7 +25,7 @@ func Organizations(ctx *middleware.Context) { var err error ctx.Data["Orgs"], err = models.GetOrganizations(pageNum, (p-1)*pageNum) if err != nil { - ctx.Handle(500, "GetUsers", err) + ctx.Handle(500, "GetOrganizations", err) return } ctx.HTML(200, ORGS) diff --git a/routers/admin/users.go b/routers/admin/users.go index e5cd364f..c9adf2d8 100644 --- a/routers/admin/users.go +++ b/routers/admin/users.go @@ -24,14 +24,14 @@ const ( ) func pagination(ctx *middleware.Context, count int64, pageNum int) int { - p := com.StrTo(ctx.Query("p")).MustInt() + p := ctx.QueryInt("p") if p < 1 { p = 1 } curCount := int64((p-1)*pageNum + pageNum) - if curCount > count { + if curCount >= count { p = int(count) / pageNum - } else if count > curCount { + } else { ctx.Data["NextPageNum"] = p + 1 } if p > 1 { diff --git a/templates/.VERSION b/templates/.VERSION index 35a9c242..d62a81b6 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.5.1009 Beta \ No newline at end of file +0.5.5.1010 Beta \ No newline at end of file -- cgit v1.2.3 From 963354c5d7e78eb9fed447ab9b9984420573649c Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sat, 11 Oct 2014 18:02:48 -0400 Subject: Add raw, history file button, and other mirror fixes --- README.md | 1 + README_ZH.md | 17 +++++++------- conf/locale/locale_en-US.ini | 3 +++ conf/locale/locale_zh-CN.ini | 3 +++ gogs.go | 2 +- models/repo.go | 2 +- models/user.go | 2 +- modules/middleware/context.go | 6 ----- public/ng/css/ui.css | 3 +++ public/ng/less/ui/form.less | 3 +++ routers/repo/commit.go | 4 +++- routers/repo/view.go | 2 +- templates/.VERSION | 2 +- templates/admin/monitor.tmpl | 2 +- templates/repo/home.tmpl | 6 ++--- templates/repo/single.tmpl | 40 -------------------------------- templates/repo/single_bare.tmpl | 40 -------------------------------- templates/repo/single_file.tmpl | 51 ----------------------------------------- templates/repo/single_list.tmpl | 51 ----------------------------------------- templates/repo/view_file.tmpl | 16 +++++++++---- templates/repo/view_list.tmpl | 4 ++-- 21 files changed, 48 insertions(+), 212 deletions(-) delete mode 100644 templates/repo/single.tmpl delete mode 100644 templates/repo/single_bare.tmpl delete mode 100644 templates/repo/single_file.tmpl delete mode 100644 templates/repo/single_list.tmpl (limited to 'gogs.go') diff --git a/README.md b/README.md index 44c62649..b6dd1ea5 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ The goal of this project is to make the easiest, fastest and most painless way t - Create/migrate/mirror/delete/watch/rename/transfer public/private repository - Repository viewer/release/issue tracker - Repository and Organization level webhooks +- Repository Git hooks - Add/remove repository collaborators - Gravatar and cache support - Mail service(register, issue) diff --git a/README_ZH.md b/README_ZH.md index 9581faf7..a8cefa44 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -24,14 +24,15 @@ Gogs 的目标是打造一个最简单、最快速和最轻松的方式搭建自 - 支持 SSH/HTTP(S) 协议 - 支持 SMTP/LDAP/反向代理 用户认证 - 支持反向代理子路径 -- 注册/删除/重命名 用户 -- 创建/管理/删除 组织以及团队管理功能 -- 创建/迁移/镜像/删除/关注/重命名/转移 公开/私有 仓库 -- 仓库 浏览/发布/工单管理 -- 仓库和组织级别 Web 钩子 -- 添加/删除 仓库协作者 -- Gravatar 以及缓存支持 -- 邮件服务(注册、Issue) +- 支持 注册/删除/重命名 用户 +- 支持 创建/管理/删除 组织以及团队管理功能 +- 支持 创建/迁移/镜像/删除/关注/重命名/转移 公开/私有 仓库 +- 支持仓库 浏览/发布/工单管理 +- 支持仓库和组织级别 Web 钩子 +- 支持仓库 Git 钩子 +- 支持 添加/删除 仓库协作者 +- 支持 Gravatar 以及本地缓存 +- 支持邮件服务(注册、Issue) - 管理员面板 - Slack Web 钩子集成 - 支持 MySQL、PostgreSQL 以及 SQLite3 数据库 diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index 7452fb73..e0a50665 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -273,6 +273,9 @@ tags = Tags issues = Issues commits = Commits releases = Releases +file_raw = Raw +file_history = History +file_view_raw = View Raw commits.commits = Commits commits.search = Search commits diff --git a/conf/locale/locale_zh-CN.ini b/conf/locale/locale_zh-CN.ini index aeed4756..c704ad20 100644 --- a/conf/locale/locale_zh-CN.ini +++ b/conf/locale/locale_zh-CN.ini @@ -273,6 +273,9 @@ tags = 标签列表 issues = 工单管理 commits = 提交历史 releases = 版本发布 +file_raw = 原始文件 +file_history = 文件历史 +file_view_raw = 查看原始文件 commits.commits = 次代码提交 commits.search = 搜索提交历史 diff --git a/gogs.go b/gogs.go index 05fcd2cd..85a5626c 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.5.1010 Beta" +const APP_VER = "0.5.5.1011 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/repo.go b/models/repo.go index c3329951..419d034c 100644 --- a/models/repo.go +++ b/models/repo.go @@ -663,7 +663,7 @@ func RepoPath(userName, repoName string) string { func TransferOwnership(u *User, newOwner string, repo *Repository) error { newUser, err := GetUserByName(newOwner) if err != nil { - return err + return fmt.Errorf("fail to get new owner(%s): %v", newOwner, err) } // Check if new owner has repository with same name. diff --git a/models/user.go b/models/user.go index ee8f8586..dc9b052c 100644 --- a/models/user.go +++ b/models/user.go @@ -488,7 +488,7 @@ func GetUserByName(name string) (*User, error) { return user, nil } -// GetUserEmailsByNames returns a slice of e-mails corresponds to names. +// GetUserEmailsByNames returns a list of e-mails corresponds to names. func GetUserEmailsByNames(names []string) []string { mails := make([]string, 0, len(names)) for _, name := range names { diff --git a/modules/middleware/context.go b/modules/middleware/context.go index 1d9f5738..86e98c90 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -75,12 +75,6 @@ type Context struct { } } -// Query querys form parameter. -func (ctx *Context) Query(name string) string { - ctx.Req.ParseForm() - return ctx.Req.Form.Get(name) -} - // HasError returns true if error occurs in form validation. func (ctx *Context) HasApiError() bool { hasErr, ok := ctx.Data["HasError"] diff --git a/public/ng/css/ui.css b/public/ng/css/ui.css index cc1a277f..5aa1490f 100644 --- a/public/ng/css/ui.css +++ b/public/ng/css/ui.css @@ -457,6 +457,9 @@ dt { box-sizing: content-box; text-align: center; } +.btn-comb { + margin-left: -1px; +} .btn-disabled { opacity: .6; cursor: not-allowed; diff --git a/public/ng/less/ui/form.less b/public/ng/less/ui/form.less index b3de4273..6e33e606 100644 --- a/public/ng/less/ui/form.less +++ b/public/ng/less/ui/form.less @@ -102,6 +102,9 @@ box-sizing: content-box; text-align: center; } +.btn-comb { + margin-left: -1px; +} .btn-disabled { opacity: .6; diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 4c5bcf0c..b2c2e0f9 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -276,13 +276,15 @@ func FileHistory(ctx *middleware.Context) { nextPage = 0 } - ctx.Data["Commits"], err = ctx.Repo.GitRepo.CommitsByFileAndRange( + commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange( branchName, fileName, page) if err != nil { ctx.Handle(500, "repo.FileHistory(CommitsByRange)", err) return } + commits = models.ValidateCommitsWithEmails(commits) + ctx.Data["Commits"] = commits ctx.Data["Username"] = userName ctx.Data["Reponame"] = repoName ctx.Data["FileName"] = fileName diff --git a/routers/repo/view.go b/routers/repo/view.go index ba76a6ad..26fa0b4c 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -166,7 +166,7 @@ func Home(ctx *middleware.Context) { } if readmeFile != nil { - ctx.Data["ReadmeInHome"] = true + ctx.Data["ReadmeInList"] = true ctx.Data["ReadmeExist"] = true if dataRc, err := readmeFile.Data(); err != nil { ctx.Handle(404, "repo.SinglereadmeFile.LookupBlob", err) diff --git a/templates/.VERSION b/templates/.VERSION index d62a81b6..3f42d63c 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.5.1010 Beta \ No newline at end of file +0.5.5.1011 Beta \ No newline at end of file diff --git a/templates/admin/monitor.tmpl b/templates/admin/monitor.tmpl index 5da8f48e..a7942e09 100644 --- a/templates/admin/monitor.tmpl +++ b/templates/admin/monitor.tmpl @@ -58,7 +58,7 @@ {{.Pid}} {{.Description}} {{.Start}} - {{TimeSince .Start .i18n.Lang}} + {{TimeSince .Start $.Lang}} {{end}} diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index e7d4c45d..49bf1fd1 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -54,16 +54,16 @@ {{end}} {{end}} - + {{if .IsFile}} {{template "repo/view_file" .}} diff --git a/templates/repo/single.tmpl b/templates/repo/single.tmpl deleted file mode 100644 index d640fb00..00000000 --- a/templates/repo/single.tmpl +++ /dev/null @@ -1,40 +0,0 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -{{template "repo/nav" .}} -{{template "repo/toolbar" .}} -
    -
    -
    - {{ $n := len .Treenames}} - {{if not .IsFile}}{{end}} - - {{ $l := Subtract $n 1}} - -
    - {{if .IsFile}} - {{template "repo/single_file" .}} - {{else}} - {{template "repo/single_list" .}} - {{end}} -
    -
    -{{template "base/footer" .}} diff --git a/templates/repo/single_bare.tmpl b/templates/repo/single_bare.tmpl deleted file mode 100644 index f2b19561..00000000 --- a/templates/repo/single_bare.tmpl +++ /dev/null @@ -1,40 +0,0 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -{{template "repo/nav" .}} -{{template "repo/toolbar" .}} -
    -
    -
    -
    -

    Quick Guide

    -
    -
    -

    Clone this repository

    -
    - - - - - - - - -
    -

    We recommend every repository include a README, LICENSE, and .gitignore.

    -
    -

    Create a new repository on the command line

    -
    touch README.md
    -git init
    -git add README.md
    -git commit -m "first commit"
    -git remote add origin 
    -git push -u origin master
    -
    -

    Push an existing repository from the command line

    -
    git remote add origin 
    -git push -u origin master
    -
    -
    -
    -
    -{{template "base/footer" .}} diff --git a/templates/repo/single_file.tmpl b/templates/repo/single_file.tmpl deleted file mode 100644 index 0ce04e13..00000000 --- a/templates/repo/single_file.tmpl +++ /dev/null @@ -1,51 +0,0 @@ -
    -
    - {{if .ReadmeExist}} - - {{if .ReadmeInSingle}} - {{.FileName}} - {{else}} - {{.FileName}} {{FileSize .FileSize}} - {{end}} - {{else}} - - {{.FileName}} {{FileSize .FileSize}} - {{end}} - {{if not .ReadmeInSingle}} -
    - - Raw - - History - -
    - {{end}} -
    - - {{if not .FileIsText}} -
    - {{if .IsImageFile}} - - {{else}} - View Raw - {{end}} -
    - {{else}} - {{if .ReadmeExist}} -
    - {{.FileContent|str2html}} -
    - {{else}} -
    - - - - - - - -
    {{.FileContent}}
    -
    - {{end}} - {{end}} -
    diff --git a/templates/repo/single_list.tmpl b/templates/repo/single_list.tmpl deleted file mode 100644 index 03511a80..00000000 --- a/templates/repo/single_list.tmpl +++ /dev/null @@ -1,51 +0,0 @@ -
    - -
    - {{.LastCommit.Author.Name}} {{TimeSince .LastCommit.Author.When}} -
    - - - - - - - - - - - {{if .HasParentPath}} - - - - - - - {{end}} - {{range $item := .Files}} - {{$entry := index $item 0}} - {{$commit := index $item 1}} - - - - - - - {{end}} - - -
    -{{if .ReadmeExist}} - {{template "repo/single_file" .}} -{{end}} diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index 228d10cd..4e2d4fc6 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -2,15 +2,23 @@

    {{if .ReadmeExist}} - {{if .ReadmeInHome}} + {{if .ReadmeInList}} {{.FileName}} {{else}} {{.FileName}}{{FileSize .FileSize}} {{end}} {{else}} - - {{.FileName}}{{FileSize .FileSize}} + + {{.FileName}}{{FileSize .FileSize}} {{end}} + {{if not .ReadmeInList}} + + + + + + + {{end}}

    {{if .ReadmeExist}} @@ -20,7 +28,7 @@ {{if .IsImageFile}} {{else}} - View Raw + {{.i18n.Tr "repo.file_view_raw"}} {{end}}
    {{else if .FileSize}} diff --git a/templates/repo/view_list.tmpl b/templates/repo/view_list.tmpl index e6c43d9e..032b9e0f 100644 --- a/templates/repo/view_list.tmpl +++ b/templates/repo/view_list.tmpl @@ -10,7 +10,7 @@ {{ShortSha .LastCommit.Id.String}} {{.LastCommit.Summary}} - {{TimeSince .LastCommit.Author.When .i18n.Lang}} + {{TimeSince .LastCommit.Author.When $.Lang}} @@ -45,7 +45,7 @@ {{$commit.Summary}} - {{TimeSince $commit.Committer.When $.i18n.Lang}} + {{TimeSince $commit.Committer.When $.Lang}} {{end}} -- cgit v1.2.3 From 451f328a4cd651259bf173f99a37cd0feb866e32 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Mon, 13 Oct 2014 03:07:47 -0400 Subject: Fix #457 and fix #557 --- gogs.go | 2 +- public/ng/css/gogs.css | 6 ++---- public/ng/less/gogs/repository.less | 12 +++++------- templates/.VERSION | 2 +- 4 files changed, 9 insertions(+), 13 deletions(-) (limited to 'gogs.go') diff --git a/gogs.go b/gogs.go index 85a5626c..e0ecec25 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.5.1011 Beta" +const APP_VER = "0.5.5.1013 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/public/ng/css/gogs.css b/public/ng/css/gogs.css index 6c8211c7..52a503cc 100644 --- a/public/ng/css/gogs.css +++ b/public/ng/css/gogs.css @@ -1402,12 +1402,10 @@ The register and sign-in page style } .code-view .lines-num span { font-family: Monaco, Menlo, Consolas, "Courier New", monospace; - line-height: 18px; - padding: 0 8px 0 10px; + line-height: 1.6; + padding: 0 10px; cursor: pointer; display: block; - margin-top: 2px; - font-size: 12px; } .code-view .lines-code > pre { border: none; diff --git a/public/ng/less/gogs/repository.less b/public/ng/less/gogs/repository.less index 717c0d0e..423aeeb6 100644 --- a/public/ng/less/gogs/repository.less +++ b/public/ng/less/gogs/repository.less @@ -444,13 +444,11 @@ background: #f5f5f5; width: 1%; span { - font-family: Monaco, Menlo, Consolas, "Courier New", monospace; - line-height: 18px; - padding: 0 8px 0 10px; - cursor: pointer; - display: block; - margin-top: 2px; - font-size: 12px; + font-family: Monaco,Menlo,Consolas,"Courier New",monospace; + line-height: 1.6; + padding: 0 10px; + cursor: pointer; + display: block; } } .lines-code > pre { diff --git a/templates/.VERSION b/templates/.VERSION index 3f42d63c..6955a871 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.5.1011 Beta \ No newline at end of file +0.5.5.1013 Beta \ No newline at end of file -- cgit v1.2.3