From 2bce24068dc3c64ee5e501c48b7f080c48383970 Mon Sep 17 00:00:00 2001 From: Christopher Brickley Date: Sun, 24 Aug 2014 08:59:47 -0400 Subject: add Slack API webhook support --- models/action.go | 35 +++++++++++++---- models/slack.go | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ models/webhook.go | 86 ++++++++++++++++++++++++++++++---------- 3 files changed, 207 insertions(+), 28 deletions(-) create mode 100644 models/slack.go (limited to 'models') diff --git a/models/action.go b/models/action.go index b5f692c4..d536c84d 100644 --- a/models/action.go +++ b/models/action.go @@ -266,14 +266,33 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, continue } - p.Secret = w.Secret - CreateHookTask(&HookTask{ - Type: WEBHOOK, - Url: w.Url, - Payload: p, - ContentType: w.ContentType, - IsSsl: w.IsSsl, - }) + switch w.HookTaskType { + case SLACK: + { + s, err := GetSlackPayload(p, w.Meta) + if err != nil { + return errors.New("action.GetSlackPayload: " + err.Error()) + } + CreateHookTask(&HookTask{ + Type: w.HookTaskType, + Url: w.Url, + BasePayload: s, + ContentType: w.ContentType, + IsSsl: w.IsSsl, + }) + } + default: + { + p.Secret = w.Secret + CreateHookTask(&HookTask{ + Type: w.HookTaskType, + Url: w.Url, + BasePayload: p, + ContentType: w.ContentType, + IsSsl: w.IsSsl, + }) + } + } } return nil } diff --git a/models/slack.go b/models/slack.go new file mode 100644 index 00000000..0a557409 --- /dev/null +++ b/models/slack.go @@ -0,0 +1,114 @@ +// 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 ( + "encoding/json" + "errors" + "fmt" + "strings" +) + +const ( + SLACK_COLOR string = "#dd4b39" +) + +type Slack struct { + Domain string `json:"domain"` + Token string `json:"token"` + Channel string `json:"channel"` +} + +type SlackPayload struct { + Channel string `json:"channel"` + Text string `json:"text"` + Username string `json:"username"` + IconUrl string `json:"icon_url"` + UnfurlLinks int `json:"unfurl_links"` + LinkNames int `json:"link_names"` + Attachments []SlackAttachment `json:"attachments"` +} + +type SlackAttachment struct { + Color string `json:"color"` + Text string `json:"text"` +} + +func GetSlackURL(domain string, token string) string { + return fmt.Sprintf( + "https://%s.slack.com/services/hooks/incoming-webhook?token=%s", + domain, + token, + ) +} + +func (p SlackPayload) GetJSONPayload() ([]byte, error) { + data, err := json.Marshal(p) + if err != nil { + return []byte{}, err + } + return data, nil +} + +func GetSlackPayload(p *Payload, meta string) (*SlackPayload, error) { + slack := &Slack{} + slackPayload := &SlackPayload{} + if err := json.Unmarshal([]byte(meta), &slack); err != nil { + return slackPayload, errors.New("GetSlackPayload meta json:" + err.Error()) + } + + // TODO: handle different payload types: push, new branch, delete branch etc. + // when they are added to gogs. Only handles push now + return getSlackPushPayload(p, slack) +} + +func getSlackPushPayload(p *Payload, slack *Slack) (*SlackPayload, error) { + // n new commits + refSplit := strings.Split(p.Ref, "/") + branchName := refSplit[len(refSplit)-1] + var commitString string + + // TODO: add commit compare before/after link when gogs adds it + if len(p.Commits) == 1 { + commitString = "1 new commit" + } else { + commitString = fmt.Sprintf("%d new commits", len(p.Commits)) + } + + text := fmt.Sprintf("[%s:%s] %s pushed by %s", p.Repo.Name, branchName, commitString, p.Pusher.Name) + var attachmentText string + + // for each commit, generate attachment text + for i, commit := range p.Commits { + attachmentText += fmt.Sprintf("<%s|%s>: %s - %s", commit.Url, commit.Id[:7], SlackFormatter(commit.Message), commit.Author.Name) + // add linebreak to each commit but the last + if i < len(p.Commits)-1 { + attachmentText += "\n" + } + } + + slackAttachments := []SlackAttachment{{Color: SLACK_COLOR, Text: attachmentText}} + + return &SlackPayload{ + Channel: slack.Channel, + Text: text, + Username: "gogs", + IconUrl: "https://raw.githubusercontent.com/gogits/gogs/master/public/img/favicon.png", + UnfurlLinks: 0, + LinkNames: 0, + Attachments: slackAttachments, + }, nil +} + +// see: https://api.slack.com/docs/formatting +func SlackFormatter(s string) string { + // take only first line of commit + first := strings.Split(s, "\n")[0] + // replace & < > + first = strings.Replace(first, "&", "&", -1) + first = strings.Replace(first, "<", "<", -1) + first = strings.Replace(first, ">", ">", -1) + return first +} diff --git a/models/webhook.go b/models/webhook.go index ced79366..55ed4844 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -7,6 +7,7 @@ package models import ( "encoding/json" "errors" + "io/ioutil" "time" "github.com/gogits/gogs/modules/httplib" @@ -33,15 +34,17 @@ type HookEvent struct { // Webhook represents a web hook object. type Webhook struct { - Id int64 - RepoId int64 - Url string `xorm:"TEXT"` - ContentType HookContentType - Secret string `xorm:"TEXT"` - Events string `xorm:"TEXT"` - *HookEvent `xorm:"-"` - IsSsl bool - IsActive bool + Id int64 + RepoId int64 + Url string `xorm:"TEXT"` + ContentType HookContentType + Secret string `xorm:"TEXT"` + Events string `xorm:"TEXT"` + *HookEvent `xorm:"-"` + IsSsl bool + IsActive bool + HookTaskType HookTaskType + Meta string `xorm:"TEXT"` // store hook-specific attributes } // GetEvent handles conversion from Events to HookEvent. @@ -52,6 +55,14 @@ func (w *Webhook) GetEvent() { } } +func (w *Webhook) GetSlackHook() *Slack { + s := &Slack{} + if err := json.Unmarshal([]byte(w.Meta), s); err != nil { + log.Error(4, "webhook.GetSlackHook(%d): %v", w.Id, err) + } + return s +} + // UpdateEvent handles conversion from HookEvent to Events. func (w *Webhook) UpdateEvent() error { data, err := json.Marshal(w.HookEvent) @@ -119,8 +130,8 @@ func DeleteWebhook(hookId int64) error { type HookTaskType int const ( - WEBHOOK HookTaskType = iota + 1 - SERVICE + GOGS HookTaskType = iota + 1 + SLACK ) type HookEventType string @@ -152,6 +163,10 @@ type PayloadRepo struct { Private bool `json:"private"` } +type BasePayload interface { + GetJSONPayload() ([]byte, error) +} + // Payload represents a payload information of hook. type Payload struct { Secret string `json:"secret"` @@ -161,25 +176,33 @@ type Payload struct { Pusher *PayloadAuthor `json:"pusher"` } +func (p Payload) GetJSONPayload() ([]byte, error) { + data, err := json.Marshal(p) + if err != nil { + return []byte{}, err + } + return data, nil +} + // HookTask represents a hook task. type HookTask struct { Id int64 Uuid string Type HookTaskType Url string - *Payload `xorm:"-"` + BasePayload `xorm:"-"` PayloadContent string `xorm:"TEXT"` ContentType HookContentType EventType HookEventType IsSsl bool - IsDeliveried bool + IsDelivered bool IsSucceed bool } // CreateHookTask creates a new hook task, // it handles conversion from Payload to PayloadContent. func CreateHookTask(t *HookTask) error { - data, err := json.Marshal(t.Payload) + data, err := t.BasePayload.GetJSONPayload() if err != nil { return err } @@ -198,7 +221,7 @@ func UpdateHookTask(t *HookTask) error { // DeliverHooks checks and delivers undelivered hooks. func DeliverHooks() { timeout := time.Duration(setting.WebhookDeliverTimeout) * time.Second - x.Where("is_deliveried=?", false).Iterate(new(HookTask), + x.Where("is_delivered=?", false).Iterate(new(HookTask), func(idx int, bean interface{}) error { t := bean.(*HookTask) req := httplib.Post(t.Url).SetTimeout(timeout, timeout). @@ -212,13 +235,36 @@ func DeliverHooks() { req.Param("payload", t.PayloadContent) } - t.IsDeliveried = true + t.IsDelivered = true // TODO: record response. - if _, err := req.Response(); err != nil { - log.Error(4, "Delivery: %v", err) - } else { - t.IsSucceed = true + switch t.Type { + case GOGS: + { + if _, err := req.Response(); err != nil { + log.Error(4, "Delivery: %v", err) + } else { + t.IsSucceed = true + } + } + case SLACK: + { + if res, err := req.Response(); err != nil { + log.Error(4, "Delivery: %v", err) + } else { + defer res.Body.Close() + contents, err := ioutil.ReadAll(res.Body) + if err != nil { + log.Error(4, "%s", err) + } else { + if string(contents) != "ok" { + log.Error(4, "slack failed with: %s", string(contents)) + } else { + t.IsSucceed = true + } + } + } + } } if err := UpdateHookTask(t); err != nil { -- cgit v1.2.3 From 00a864e693434bce687f3f5145d8369583197b78 Mon Sep 17 00:00:00 2001 From: Christopher Brickley Date: Tue, 26 Aug 2014 08:20:18 -0400 Subject: add commit compare functionality --- cmd/web.go | 1 + models/action.go | 6 +++- models/git_diff.go | 25 ++++++++++----- models/slack.go | 14 ++++++--- models/update.go | 4 +-- models/webhook.go | 13 +++++--- public/css/gogs.css | 7 +++++ routers/repo/commit.go | 65 +++++++++++++++++++++++++++++++++++++-- templates/repo/commits.tmpl | 43 +------------------------- templates/repo/commits_table.tmpl | 42 +++++++++++++++++++++++++ templates/repo/diff.tmpl | 15 +++++++-- 11 files changed, 169 insertions(+), 66 deletions(-) create mode 100644 templates/repo/commits_table.tmpl (limited to 'models') diff --git a/cmd/web.go b/cmd/web.go index 275d3fb9..2199d4ca 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -342,6 +342,7 @@ func runWeb(*cli.Context) { r.Get("/commit/:branchname/*", repo.Diff) r.Get("/releases", repo.Releases) r.Get("/archive/*.*", repo.Download) + r.Get("/compare/:before([a-z0-9]+)...:after([a-z0-9]+)", repo.CompareDiff) }, ignSignIn, middleware.RepoAssignment(true, true)) m.Group("/:username", func(r *macaron.Router) { diff --git a/models/action.go b/models/action.go index d536c84d..5a8c3169 100644 --- a/models/action.go +++ b/models/action.go @@ -172,7 +172,7 @@ func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, com // CommitRepoAction adds new action for committing repository. func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, - repoId int64, repoUserName, repoName string, refFullName string, commit *base.PushCommits) error { + repoId int64, repoUserName, repoName string, refFullName string, commit *base.PushCommits, oldCommitId string, newCommitId string) error { opType := COMMIT_REPO // Check it's tag push or branch. @@ -226,6 +226,7 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, } repoLink := fmt.Sprintf("%s%s/%s", setting.AppUrl, repoUserName, repoName) + compareUrl := fmt.Sprintf("%s/compare/%s...%s", repoLink, oldCommitId, newCommitId) commits := make([]*PayloadCommit, len(commit.Commits)) for i, cmt := range commit.Commits { commits[i] = &PayloadCommit{ @@ -258,6 +259,9 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, Name: repo.Owner.LowerName, Email: repo.Owner.Email, }, + Before: oldCommitId, + After: newCommitId, + CompareUrl: compareUrl, } for _, w := range ws { diff --git a/models/git_diff.go b/models/git_diff.go index 4b4d1234..21a624de 100644 --- a/models/git_diff.go +++ b/models/git_diff.go @@ -175,25 +175,30 @@ func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) { return diff, nil } -func GetDiff(repoPath, commitid string) (*Diff, error) { +func GetDiffRange(repoPath, beforeCommitId string, afterCommitId string) (*Diff, error) { repo, err := git.OpenRepository(repoPath) if err != nil { return nil, err } - commit, err := repo.GetCommit(commitid) + commit, err := repo.GetCommit(afterCommitId) if err != nil { return nil, err } rd, wr := io.Pipe() var cmd *exec.Cmd - // First commit of repository. - if commit.ParentCount() == 0 { - cmd = exec.Command("git", "show", commitid) + // if "after" commit given + if beforeCommitId == "" { + // First commit of repository. + if commit.ParentCount() == 0 { + cmd = exec.Command("git", "show", afterCommitId) + } else { + c, _ := commit.Parent(0) + cmd = exec.Command("git", "diff", c.Id.String(), afterCommitId) + } } else { - c, _ := commit.Parent(0) - cmd = exec.Command("git", "diff", c.Id.String(), commitid) + cmd = exec.Command("git", "diff", beforeCommitId, afterCommitId) } cmd.Dir = repoPath cmd.Stdout = wr @@ -208,7 +213,7 @@ func GetDiff(repoPath, commitid string) (*Diff, error) { }() defer rd.Close() - desc := fmt.Sprintf("GetDiff(%s)", repoPath) + desc := fmt.Sprintf("GetDiffRange(%s)", repoPath) pid := process.Add(desc, cmd) go func() { // In case process became zombie. @@ -226,3 +231,7 @@ func GetDiff(repoPath, commitid string) (*Diff, error) { return ParsePatch(pid, cmd, rd) } + +func GetDiffCommit(repoPath, commitId string) (*Diff, error) { + return GetDiffRange(repoPath, "", commitId) +} diff --git a/models/slack.go b/models/slack.go index 0a557409..714b2f6c 100644 --- a/models/slack.go +++ b/models/slack.go @@ -70,19 +70,21 @@ func getSlackPushPayload(p *Payload, slack *Slack) (*SlackPayload, error) { branchName := refSplit[len(refSplit)-1] var commitString string - // TODO: add commit compare before/after link when gogs adds it if len(p.Commits) == 1 { commitString = "1 new commit" } else { commitString = fmt.Sprintf("%d new commits", len(p.Commits)) + commitString = SlackLinkFormatter(p.CompareUrl, commitString) } - text := fmt.Sprintf("[%s:%s] %s pushed by %s", p.Repo.Name, branchName, commitString, p.Pusher.Name) + repoLink := SlackLinkFormatter(p.Repo.Url, p.Repo.Name) + branchLink := SlackLinkFormatter(p.Repo.Url+"/src/"+branchName, branchName) + text := fmt.Sprintf("[%s:%s] %s pushed by %s", repoLink, branchLink, commitString, p.Pusher.Name) var attachmentText string // for each commit, generate attachment text for i, commit := range p.Commits { - attachmentText += fmt.Sprintf("<%s|%s>: %s - %s", commit.Url, commit.Id[:7], SlackFormatter(commit.Message), commit.Author.Name) + attachmentText += fmt.Sprintf("%s: %s - %s", SlackLinkFormatter(commit.Url, commit.Id[:7]), SlackTextFormatter(commit.Message), SlackTextFormatter(commit.Author.Name)) // add linebreak to each commit but the last if i < len(p.Commits)-1 { attachmentText += "\n" @@ -103,7 +105,7 @@ func getSlackPushPayload(p *Payload, slack *Slack) (*SlackPayload, error) { } // see: https://api.slack.com/docs/formatting -func SlackFormatter(s string) string { +func SlackTextFormatter(s string) string { // take only first line of commit first := strings.Split(s, "\n")[0] // replace & < > @@ -112,3 +114,7 @@ func SlackFormatter(s string) string { first = strings.Replace(first, ">", ">", -1) return first } + +func SlackLinkFormatter(url string, text string) string { + return fmt.Sprintf("<%s|%s>", url, SlackTextFormatter(text)) +} diff --git a/models/update.go b/models/update.go index 68a92ada..ec6a9790 100644 --- a/models/update.go +++ b/models/update.go @@ -101,7 +101,7 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName commit := &base.PushCommits{} if err = CommitRepoAction(userId, ru.Id, userName, actEmail, - repos.Id, repoUserName, repoName, refName, commit); err != nil { + repos.Id, repoUserName, repoName, refName, commit, oldCommitId, newCommitId); err != nil { log.GitLogger.Fatal(4, "runUpdate.models.CommitRepoAction: %s/%s:%v", repoUserName, repoName, err) } return err @@ -152,7 +152,7 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName //commits = append(commits, []string{lastCommit.Id().String(), lastCommit.Message()}) if err = CommitRepoAction(userId, ru.Id, userName, actEmail, - repos.Id, repoUserName, repoName, refName, &base.PushCommits{l.Len(), commits}); err != nil { + repos.Id, repoUserName, repoName, refName, &base.PushCommits{l.Len(), commits}, oldCommitId, newCommitId); err != nil { return fmt.Errorf("runUpdate.models.CommitRepoAction: %s/%s:%v", repoUserName, repoName, err) } return nil diff --git a/models/webhook.go b/models/webhook.go index 55ed4844..0b7b3a99 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -169,11 +169,14 @@ type BasePayload interface { // Payload represents a payload information of hook. type Payload struct { - Secret string `json:"secret"` - Ref string `json:"ref"` - Commits []*PayloadCommit `json:"commits"` - Repo *PayloadRepo `json:"repository"` - Pusher *PayloadAuthor `json:"pusher"` + Secret string `json:"secret"` + Ref string `json:"ref"` + Commits []*PayloadCommit `json:"commits"` + Repo *PayloadRepo `json:"repository"` + Pusher *PayloadAuthor `json:"pusher"` + Before string `json:"before"` + After string `json:"after"` + CompareUrl string `json:"compare_url"` } func (p Payload) GetJSONPayload() ([]byte, error) { diff --git a/public/css/gogs.css b/public/css/gogs.css index 2d30d062..0af09a3e 100755 --- a/public/css/gogs.css +++ b/public/css/gogs.css @@ -968,6 +968,13 @@ body { .guide-box .zclip { left: auto !important; } +div.compare div#commits { + margin-top: 5px; +} +div.compare div#commits h4 { + margin: 10px 0; + line-height: 1.1; +} .diff-head-box h4 { margin-top: 0; margin-bottom: 0; diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 6320123b..54acc85b 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -114,9 +114,9 @@ func Diff(ctx *middleware.Context) { commit := ctx.Repo.Commit - diff, err := models.GetDiff(models.RepoPath(userName, repoName), commitId) + diff, err := models.GetDiffCommit(models.RepoPath(userName, repoName), commitId) if err != nil { - ctx.Handle(404, "GetDiff", err) + ctx.Handle(404, "GetDiffCommit", err) return } @@ -162,6 +162,67 @@ func Diff(ctx *middleware.Context) { ctx.HTML(200, DIFF) } +func CompareDiff(ctx *middleware.Context) { + ctx.Data["IsRepoToolbarCommits"] = true + ctx.Data["IsDiffCompare"] = true + userName := ctx.Repo.Owner.Name + repoName := ctx.Repo.Repository.Name + beforeCommitId := ctx.Params(":before") + afterCommitId := ctx.Params(":after") + + commit, err := ctx.Repo.GitRepo.GetCommit(afterCommitId) + if err != nil { + ctx.Handle(404, "GetCommit", err) + return + } + + diff, err := models.GetDiffRange(models.RepoPath(userName, repoName), beforeCommitId, afterCommitId) + if err != nil { + ctx.Handle(404, "GetDiffRange", err) + return + } + + isImageFile := func(name string) bool { + blob, err := commit.GetBlobByPath(name) + if err != nil { + return false + } + + dataRc, err := blob.Data() + if err != nil { + return false + } + buf := make([]byte, 1024) + n, _ := dataRc.Read(buf) + if n > 0 { + buf = buf[:n] + } + _, isImage := base.IsImageFile(buf) + return isImage + } + + commits, err := commit.CommitsBeforeUntil(beforeCommitId) + if err != nil { + ctx.Handle(500, "CommitsBeforeUntil", err) + return + } + + ctx.Data["Commits"] = commits + ctx.Data["CommitCount"] = commits.Len() + ctx.Data["BeforeCommitId"] = beforeCommitId + ctx.Data["AfterCommitId"] = afterCommitId + ctx.Data["Username"] = userName + ctx.Data["Reponame"] = repoName + ctx.Data["IsImageFile"] = isImageFile + ctx.Data["Title"] = "Comparing " + base.ShortSha(beforeCommitId) + "..." + base.ShortSha(afterCommitId) + " · " + userName + "/" + repoName + ctx.Data["Commit"] = commit + ctx.Data["Diff"] = diff + ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0 + ctx.Data["SourcePath"] = "/" + path.Join(userName, repoName, "src", afterCommitId) + ctx.Data["RawPath"] = "/" + path.Join(userName, repoName, "raw", afterCommitId) + ctx.HTML(200, DIFF) +} + func FileHistory(ctx *middleware.Context) { ctx.Data["IsRepoToolbarCommits"] = true diff --git a/templates/repo/commits.tmpl b/templates/repo/commits.tmpl index 420e973a..e7518e98 100644 --- a/templates/repo/commits.tmpl +++ b/templates/repo/commits.tmpl @@ -3,47 +3,6 @@ {{template "repo/nav" .}} {{template "repo/toolbar" .}}
-
-
-
- -

{{.CommitCount}} Commits

-
- - - - - - - - - - - {{ $username := .Username}} - {{ $reponame := .Reponame}} - {{$r := List .Commits}} - {{range $r}} - - - - - - - {{end}} - - -
- {{if not .IsSearchPage}}{{end}} -
+ {{template "repo/commits_table" .}}
{{template "base/footer" .}} diff --git a/templates/repo/commits_table.tmpl b/templates/repo/commits_table.tmpl new file mode 100644 index 00000000..4612398a --- /dev/null +++ b/templates/repo/commits_table.tmpl @@ -0,0 +1,42 @@ +
+
+
+ +

{{.CommitCount}} Commits

+
+ + + + + + + + + + + {{ $username := .Username}} + {{ $reponame := .Reponame}} + {{$r := List .Commits}} + {{range $r}} + + + + + + + {{end}} + + +
+ {{if not .IsSearchPage}}{{end}} +
diff --git a/templates/repo/diff.tmpl b/templates/repo/diff.tmpl index 6adea045..78733450 100644 --- a/templates/repo/diff.tmpl +++ b/templates/repo/diff.tmpl @@ -3,7 +3,18 @@ {{template "repo/nav" .}}
+ {{if .IsDiffCompare }}
+ +
+ {{template "repo/commits_table" .}} +
+
+ {{else}} +
Browse Source

{{.Commit.Message}}

@@ -22,9 +33,9 @@ {{.Commit.Author.Name}} {{TimeSince .Commit.Author.When $.Lang}}

-
+
- + {{end}} {{if .DiffNotAvailable}}

Diff Data Not Available.

{{else}} -- cgit v1.2.3 From af0741da07ec190804fff2a84c3813fc62a1c3ba Mon Sep 17 00:00:00 2001 From: Christopher Brickley Date: Mon, 1 Sep 2014 19:19:56 -0400 Subject: handle initial commit for compareUrl --- models/action.go | 6 +++++- models/slack.go | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'models') diff --git a/models/action.go b/models/action.go index 5a8c3169..f739fc35 100644 --- a/models/action.go +++ b/models/action.go @@ -226,7 +226,11 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, } repoLink := fmt.Sprintf("%s%s/%s", setting.AppUrl, repoUserName, repoName) - compareUrl := fmt.Sprintf("%s/compare/%s...%s", repoLink, oldCommitId, newCommitId) + compareUrl := "" + // if not the first commit, set the compareUrl + if !strings.HasPrefix(oldCommitId, "0000000") { + compareUrl = fmt.Sprintf("%s/compare/%s...%s", repoLink, oldCommitId, newCommitId) + } commits := make([]*PayloadCommit, len(commit.Commits)) for i, cmt := range commit.Commits { commits[i] = &PayloadCommit{ diff --git a/models/slack.go b/models/slack.go index 714b2f6c..3dd40759 100644 --- a/models/slack.go +++ b/models/slack.go @@ -72,9 +72,14 @@ func getSlackPushPayload(p *Payload, slack *Slack) (*SlackPayload, error) { if len(p.Commits) == 1 { commitString = "1 new commit" + if p.CompareUrl != "" { + commitString = SlackLinkFormatter(p.CompareUrl, commitString) + } } else { commitString = fmt.Sprintf("%d new commits", len(p.Commits)) - commitString = SlackLinkFormatter(p.CompareUrl, commitString) + if p.CompareUrl != "" { + commitString = SlackLinkFormatter(p.CompareUrl, commitString) + } } repoLink := SlackLinkFormatter(p.Repo.Url, p.Repo.Name) -- cgit v1.2.3 From 1240fef0ca252f03c8cd67ef84d6fd48cd3cb76d Mon Sep 17 00:00:00 2001 From: lunnyxiao Date: Tue, 2 Sep 2014 11:57:06 +0800 Subject: bug fixed for migrate and fixed #141 --- models/repo.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'models') diff --git a/models/repo.go b/models/repo.go index 47036966..105e8eec 100644 --- a/models/repo.go +++ b/models/repo.go @@ -277,7 +277,7 @@ func MirrorUpdate() { // MigrateRepository migrates a existing repository from other project hosting. func MigrateRepository(u *User, name, desc string, private, mirror bool, url string) (*Repository, error) { - repo, err := CreateRepository(u, name, desc, "", "", private, mirror, false) + repo, err := CreateRepository(u, name, desc, "", "", private, true, false) if err != nil { return nil, err } @@ -307,8 +307,15 @@ func MigrateRepository(u *User, name, desc string, private, mirror bool, url str return repo, UpdateRepository(repo) } - // Clone from local repository. + // this command could for both migrate and mirror _, stderr, err := process.ExecTimeout(10*time.Minute, + fmt.Sprintf("MigrateRepository: %s", repoPath), + "git", "clone", "--mirror", "--bare", url, repoPath) + if err != nil { + return repo, errors.New("git clone: " + stderr) + } + // Clone from local repository. + /*_, stderr, err := process.ExecTimeout(10*time.Minute, fmt.Sprintf("MigrateRepository(git clone): %s", repoPath), "git", "clone", repoPath, tmpDir) if err != nil { @@ -327,7 +334,7 @@ func MigrateRepository(u *User, name, desc string, private, mirror bool, url str tmpDir, fmt.Sprintf("MigrateRepository(git push): %s", repoPath), "git", "push", "--tags", "origin", "refs/remotes/upstream/*:refs/heads/*"); err != nil { return repo, errors.New("git push: " + stderr) - } + }*/ return repo, UpdateRepository(repo) } -- cgit v1.2.3 From 830efc90da2895d65c3a2df32e7ef79cf2a8d556 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 2 Sep 2014 07:11:39 -0400 Subject: update docs and mirror bug fix --- CONTRIBUTING.md | 62 ++++++++++++++++++++++++++++++++++++++++++++---------- README.md | 3 ++- README_ZH.md | 1 + gogs.go | 2 +- models/repo.go | 26 +++-------------------- templates/.VERSION | 2 +- 6 files changed, 59 insertions(+), 37 deletions(-) (limited to 'models') diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0a8b26f1..1917ae88 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,14 +1,54 @@ # Contributing to Gogs -> Thanks [drone](https://github.com/drone/drone) because this guidelines sheet is forked from its [CONTRIBUTING.md](https://github.com/drone/drone/blob/master/CONTRIBUTING.md). +> This guidelines sheet is forked from [CONTRIBUTING.md](https://github.com/drone/drone/blob/master/CONTRIBUTING.md). -Want to hack on Gogs? Awesome! Here are instructions to get you started. They are probably not perfect, please let us know if anything feels wrong or incomplete. +Gogs is not perfect and it has bugs, or incomplete features for rare cases. You're welcome to tell us or contribute some code. This document describles details about how can you contribute to Gogs project. ## Contribution guidelines -### Pull requests are always welcome +Depends on the situation, you will: -**ALL PULL REQUESTS MUST SEND TO `DEV` BRANCH** +- Find bug, create an issue +- Need more functionality, make a feature request +- Want to contribute code, open a pull request +- Run into issue, need help + +### Bug Report + +If you find or consider something is a bug, please create a issue on [GitHub](https://github.com/gogits/gogs/issues). To reduce unnecessary time wasting of interacting and waiting with team members, please use following form as template in the first place: + +``` +- **Bug Description**: +- **Gogs Version**: +- **Git Version**: +- **System Type**: +- **Error Log**: +- **Other information**: +``` + +Please take a moment to check that an issue on [GitHub](https://github.com/gogits/gogs/issues) doesn't already exist documenting your bug report or improvement proposal. If it does, it never hurts to add a quick "+1" or "I have this problem too". This will help prioritize the most common problems and requests. + +#### Bug Report Example + +- **Bug Description**: Crash when create repository with license| +- **Gogs Version**: `v0.4.9.0901` +- **Git Version**: `1.9.0` +- **System Type**: `Ubuntu 12.04` +- **Error Log**: + +``` +2014/09/01 07:21:49 [E] nil pointer +``` + +- **Other information**: Use SQLite3 as database + +### Feature Request + +There is no standard form of making a feature request, just try to describle the feature as clear as possible because team members may not have experience with the functionality you're talking about. + +### Pull Request + +Pull requests are always welcome, but note that **ALL PULL REQUESTS MUST SEND TO `DEV` BRANCH**. We are always thrilled to receive pull requests, and do our best to process them as fast as possible. Not sure if that typo is worth a pull request? Do it! We will appreciate it. @@ -16,16 +56,16 @@ If your pull request is not accepted on the first try, don't be discouraged! If We're trying very hard to keep Gogs lean and focused. We don't want it to do everything for everybody. This means that we might decide against incorporating a new feature. -### Discuss your design on the mailing list +### Ask For Help -We recommend discussing your plans [on the mailing list](https://groups.google.com/forum/#!forum/gogits) before starting to code - especially for more ambitious contributions. This gives other contributors a chance to point you in the right direction, give feedback on your design, and maybe point out if someone else is working on the same thing. +Before open any new issue, please check your problem on [Troubleshooting](http://gogs.io/docs/intro/troubleshooting.md) and [FAQs](http://gogs.io/docs/intro/faqs.html) pages. -We may close your pull request if not first discussed on the mailing list. We aren't doing this to be jerks. We are doing this to prevent people from spending large amounts of time on changes that may need to be designed or architected in a specific way, or may not align with the vision of the project. +## Things To Notice -### Create issues... +Please take a moment to check that an issue on [GitHub](https://github.com/gogits/gogs/issues) or card on [Trello](https://trello.com/b/uxAoeLUl/gogs-go-git-service) doesn't already exist documenting your bug report or improvement proposal. If it does, it never hurts to add a quick "+1" or "I have this problem too". This will help prioritize the most common problems and requests. -Any significant improvement should be documented as [a GitHub issue](https://github.com/gogits/gogs/issues) before anybody starts working on it. +### Discuss your design on the mailing list -### ...but check for existing issues first! +We recommend discussing your plans [on the mailing list](https://groups.google.com/forum/#!forum/gogits) before starting to code - especially for more ambitious contributions. This gives other contributors a chance to point you in the right direction, give feedback on your design, and maybe point out if someone else is working on the same thing. -Please take a moment to check that an issue or card on [Trello](https://trello.com/b/uxAoeLUl/gogs-go-git-service) doesn't already exist documenting your bug report or improvement proposal. If it does, it never hurts to add a quick "+1" or "I have this problem too". This will help prioritize the most common problems and requests. \ No newline at end of file +We may close your pull request if not first discussed on the mailing list. We aren't doing this to be jerks. We are doing this to prevent people from spending large amounts of time on changes that may need to be designed or architected in a specific way, or may not align with the vision of the project. \ No newline at end of file diff --git a/README.md b/README.md index 38e081f4..ddb8367e 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ The goal of this project is to make the easiest, fastest and most painless way t - Gravatar and cache support - Mail service(register, issue) - Administration panel +- Slack webhook integration - Supports MySQL, PostgreSQL and SQLite3 - Social account login(GitHub, Google, QQ, Weibo) - Multi-language support(English, Chinese, Germany etc.) @@ -69,7 +70,7 @@ There are 5 ways to install Gogs: - Usage and modification from [beego](http://beego.me) modules. - Thanks [lavachen](http://www.lavachen.cn/) and [Rocker](http://weibo.com/rocker1989) for designing Logo. - Thanks [gobuild.io](http://gobuild.io) for providing binary compile and download service. -- Great thanks to [Docker China](http://www.dockboard.org/) for providing [dockerfiles](https://github.com/gogits/gogs/tree/master/dockerfiles). +- Thanks [Docker China](http://www.dockboard.org/) for providing [dockerfiles](https://github.com/gogits/gogs/tree/master/dockerfiles). ## Contributors diff --git a/README_ZH.md b/README_ZH.md index b830d416..de982baf 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -31,6 +31,7 @@ Gogs 的目标是打造一个最简单、最快速和最轻松的方式搭建自 - Gravatar 以及缓存支持 - 邮件服务(注册、Issue) - 管理员面板 +- Slack Web 钩子集成 - 支持 MySQL、PostgreSQL 以及 SQLite3 数据库 - 社交帐号登录(GitHub、Google、QQ、微博) - 多语言支持(英文、简体中文、德语等等) diff --git a/gogs.go b/gogs.go index 1e2150b3..a1160190 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.4.9.0831 Beta" +const APP_VER = "0.4.9.0902 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/repo.go b/models/repo.go index 105e8eec..8f62fa17 100644 --- a/models/repo.go +++ b/models/repo.go @@ -277,7 +277,7 @@ func MirrorUpdate() { // MigrateRepository migrates a existing repository from other project hosting. func MigrateRepository(u *User, name, desc string, private, mirror bool, url string) (*Repository, error) { - repo, err := CreateRepository(u, name, desc, "", "", private, true, false) + repo, err := CreateRepository(u, name, desc, "", "", private, mirror, false) if err != nil { return nil, err } @@ -305,6 +305,8 @@ func MigrateRepository(u *User, name, desc string, private, mirror bool, url str } repo.IsMirror = true return repo, UpdateRepository(repo) + } else { + os.RemoveAll(repoPath) } // this command could for both migrate and mirror @@ -314,28 +316,6 @@ func MigrateRepository(u *User, name, desc string, private, mirror bool, url str if err != nil { return repo, errors.New("git clone: " + stderr) } - // Clone from local repository. - /*_, stderr, err := process.ExecTimeout(10*time.Minute, - fmt.Sprintf("MigrateRepository(git clone): %s", repoPath), - "git", "clone", repoPath, tmpDir) - if err != nil { - return repo, errors.New("git clone: " + stderr) - } - - // Add remote and fetch data. - if _, stderr, err = process.ExecDir(3*time.Minute, - tmpDir, fmt.Sprintf("MigrateRepository(git pull): %s", repoPath), - "git", "remote", "add", "-f", "--tags", "upstream", url); err != nil { - return repo, errors.New("git remote: " + stderr) - } - - // Push data to local repository. - if _, stderr, err = process.ExecDir(3*time.Minute, - tmpDir, fmt.Sprintf("MigrateRepository(git push): %s", repoPath), - "git", "push", "--tags", "origin", "refs/remotes/upstream/*:refs/heads/*"); err != nil { - return repo, errors.New("git push: " + stderr) - }*/ - return repo, UpdateRepository(repo) } diff --git a/templates/.VERSION b/templates/.VERSION index fb2403ad..5f3c5181 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.4.9.0831 Beta \ No newline at end of file +0.4.9.0902 Beta \ No newline at end of file -- cgit v1.2.3 From 9fc4ded369a90140a63e064371479f2ef4e4bc4f Mon Sep 17 00:00:00 2001 From: Tristan Storch Date: Thu, 4 Sep 2014 12:03:29 +0200 Subject: Standard git user.name and user.email if not set Git user.name and user.email will now be set to the standard values - Gogs - gogitservice@gmail.com if user.name is not set or empty. If user.name is set and user.email not, it will leave it this way. --- models/repo.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'models') diff --git a/models/repo.go b/models/repo.go index 8f62fa17..23d44a6b 100644 --- a/models/repo.go +++ b/models/repo.go @@ -99,20 +99,26 @@ func NewRepoContext() { log.Fatal(4, "Gogs requires Git version greater or equal to 1.8.0") } - // Check if server has basic git setting. - stdout, stderr, err := process.Exec("NewRepoContext(get setting)", "git", "config", "--get", "user.name") - if err != nil { - log.Fatal(4, "Fail to get git user.name: %s", stderr) - } else if err != nil || len(strings.TrimSpace(stdout)) == 0 { - if _, stderr, err = process.Exec("NewRepoContext(set email)", "git", "config", "--global", "user.email", "gogitservice@gmail.com"); err != nil { - log.Fatal(4, "Fail to set git user.email: %s", stderr) - } else if _, stderr, err = process.Exec("NewRepoContext(set name)", "git", "config", "--global", "user.name", "Gogs"); err != nil { - log.Fatal(4, "Fail to set git user.name: %s", stderr) + // Check if server has basic git setting and set if not. + if stdout, stderr, err := process.Exec("NewRepoContext(get setting)", "git", "config", "--get", "user.name"); err != nil || strings.TrimSpace(stdout) == "" { + // ExitError indicates user.name is not set + if _, ok := err.(*exec.ExitError); ok || strings.TrimSpace(stdout) == "" { + stndrdUserName := "Gogs" + stndrdUserEmail := "gogitservice@gmail.com" + if _, stderr, gerr := process.Exec("NewRepoContext(set name)", "git", "config", "--global", "user.name", stndrdUserName); gerr != nil { + log.Fatal(4, "Fail to set git user.name(%s): %s", gerr, stderr) + } + if _, stderr, gerr := process.Exec("NewRepoContext(set email)", "git", "config", "--global", "user.email", stndrdUserEmail); gerr != nil { + log.Fatal(4, "Fail to set git user.email(%s): %s", gerr, stderr) + } + log.Info("Git user.name and user.email set to %s <%s>", stndrdUserName, stndrdUserEmail) + } else { + log.Fatal(4, "Fail to get git user.name(%s): %s", err, stderr) } } // Set git some configurations. - if _, stderr, err = process.Exec("NewRepoContext(git config --global core.quotepath false)", + if _, stderr, err := process.Exec("NewRepoContext(git config --global core.quotepath false)", "git", "config", "--global", "core.quotepath", "false"); err != nil { log.Fatal(4, "Fail to execute 'git config --global core.quotepath false': %s", stderr) } -- cgit v1.2.3 From bdfdf3cacba75fe1c36f7a05096748c26f25a2f9 Mon Sep 17 00:00:00 2001 From: Tristan Storch Date: Thu, 4 Sep 2014 17:19:26 +0200 Subject: Code dedoublication in models/models.go Just some code dedoublication in models/models.go --- models/models.go | 44 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) (limited to 'models') diff --git a/models/models.go b/models/models.go index 4e2e08cf..5558ec00 100644 --- a/models/models.go +++ b/models/models.go @@ -55,11 +55,12 @@ func LoadModelsConfig() { DbCfg.Path = setting.Cfg.MustValue("database", "PATH", "data/gogs.db") } -func NewTestEngine(x *xorm.Engine) (err error) { +func getEngine() (*xorm.Engine, error) { + cnnstr := "" switch DbCfg.Type { case "mysql": - x, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8", - DbCfg.User, DbCfg.Pwd, DbCfg.Host, DbCfg.Name)) + cnnstr = fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8", + DbCfg.User, DbCfg.Pwd, DbCfg.Host, DbCfg.Name) case "postgres": var host, port = "127.0.0.1", "5432" fields := strings.Split(DbCfg.Host, ":") @@ -69,46 +70,31 @@ func NewTestEngine(x *xorm.Engine) (err error) { if len(fields) > 1 && len(strings.TrimSpace(fields[1])) > 0 { port = fields[1] } - cnnstr := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=%s", + cnnstr = fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=%s", DbCfg.User, DbCfg.Pwd, host, port, DbCfg.Name, DbCfg.SslMode) - x, err = xorm.NewEngine("postgres", cnnstr) case "sqlite3": if !EnableSQLite3 { - return fmt.Errorf("Unknown database type: %s", DbCfg.Type) + return nil, fmt.Errorf("Unknown database type: %s", DbCfg.Type) } os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm) - x, err = xorm.NewEngine("sqlite3", DbCfg.Path) + cnnstr = DbCfg.Path default: - return fmt.Errorf("Unknown database type: %s", DbCfg.Type) + return nil, fmt.Errorf("Unknown database type: %s", DbCfg.Type) } + return xorm.NewEngine(DbCfg.Type, cnnstr) +} + +func NewTestEngine(x *xorm.Engine) (err error) { + x, err = getEngine() if err != nil { return fmt.Errorf("models.init(fail to conntect database): %v", err) } + return x.Sync(tables...) } func SetEngine() (err error) { - switch DbCfg.Type { - case "mysql": - x, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8", - DbCfg.User, DbCfg.Pwd, DbCfg.Host, DbCfg.Name)) - case "postgres": - var host, port = "127.0.0.1", "5432" - fields := strings.Split(DbCfg.Host, ":") - if len(fields) > 0 && len(strings.TrimSpace(fields[0])) > 0 { - host = fields[0] - } - if len(fields) > 1 && len(strings.TrimSpace(fields[1])) > 0 { - port = fields[1] - } - x, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=%s", - DbCfg.User, DbCfg.Pwd, host, port, DbCfg.Name, DbCfg.SslMode)) - case "sqlite3": - os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm) - x, err = xorm.NewEngine("sqlite3", DbCfg.Path) - default: - return fmt.Errorf("Unknown database type: %s", DbCfg.Type) - } + x, err = getEngine() if err != nil { return fmt.Errorf("models.init(fail to conntect database): %v", err) } -- cgit v1.2.3 From 31d80118438729119b40fd863e54ee7ca903b18b Mon Sep 17 00:00:00 2001 From: Vyacheslav Bakhmutov Date: Fri, 5 Sep 2014 08:10:41 +0700 Subject: Set milestone content field to TEXT orm type --- models/issue.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'models') diff --git a/models/issue.go b/models/issue.go index 307ace81..f16c2e25 100644 --- a/models/issue.go +++ b/models/issue.go @@ -612,7 +612,7 @@ type Milestone struct { RepoId int64 `xorm:"INDEX"` Index int64 Name string - Content string + Content string `xorm:"TEXT"` RenderedContent string `xorm:"-"` IsClosed bool NumIssues int -- cgit v1.2.3 From 85c35a6b8bb7430568d375d1e792e1417bbd7f4b Mon Sep 17 00:00:00 2001 From: Christopher Brickley Date: Thu, 4 Sep 2014 07:17:00 -0400 Subject: add organization-level webhooks --- cmd/web.go | 7 +++++ conf/locale/locale_en-US.ini | 1 + models/action.go | 16 ++++++++-- models/webhook.go | 13 ++++++++ public/ng/js/gogs.js | 29 ++++++++++------- routers/org/setting.go | 28 +++++++++++++++++ routers/repo/setting.go | 56 ++++++++++++++++++++++++++++----- templates/org/settings/hook_new.tmpl | 37 ++++++++++++++++++++++ templates/org/settings/hooks.tmpl | 38 ++++++++++++++++++++++ templates/org/settings/nav.tmpl | 3 +- templates/repo/settings/hook_gogs.tmpl | 2 +- templates/repo/settings/hook_slack.tmpl | 2 +- 12 files changed, 208 insertions(+), 24 deletions(-) create mode 100644 templates/org/settings/hook_new.tmpl create mode 100644 templates/org/settings/hooks.tmpl (limited to 'models') diff --git a/cmd/web.go b/cmd/web.go index 57164683..f7b8d921 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -260,6 +260,13 @@ func runWeb(*cli.Context) { m.Group("/settings", func(r *macaron.Router) { r.Get("", org.Settings) r.Post("", bindIgnErr(auth.UpdateOrgSettingForm{}), org.SettingsPost) + r.Get("/hooks", org.SettingsHooks) + r.Get("/hooks/new", repo.WebHooksNew) + r.Post("/hooks/gogs/new", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksNewPost) + r.Post("/hooks/slack/new", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksNewPost) + 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) r.Route("/delete", "GET,POST", org.SettingsDelete) }) diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index 4f1acdcd..3969074e 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -270,6 +270,7 @@ settings.delete = Delete Organization settings.delete_account = Delete This Organization settings.delete_prompt = The operation will delete this organization permanently, and CANNOT be undone! settings.confirm_delete_account = Confirm Deletion +settings.hooks_desc = Add webhooks that will be triggered for all repositories under this organization. members.public = Public members.public_helper = make private diff --git a/models/action.go b/models/action.go index f739fc35..c0992dba 100644 --- a/models/action.go +++ b/models/action.go @@ -220,8 +220,20 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, ws, err := GetActiveWebhooksByRepoId(repoId) if err != nil { - return errors.New("action.CommitRepoAction(GetWebhooksByRepoId): " + err.Error()) - } else if len(ws) == 0 { + return errors.New("action.CommitRepoAction(GetActiveWebhooksByRepoId): " + err.Error()) + } + + // check if repo belongs to org and append additional webhooks + if repo.Owner.IsOrganization() { + // get hooks for org + orgws, err := GetActiveWebhooksByOrgId(repo.OwnerId) + if err != nil { + return errors.New("action.CommitRepoAction(GetActiveWebhooksByOrgId): " + err.Error()) + } + ws = append(ws, orgws...) + } + + if len(ws) == 0 { return nil } diff --git a/models/webhook.go b/models/webhook.go index 0b7b3a99..5acc83f5 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -45,6 +45,7 @@ type Webhook struct { IsActive bool HookTaskType HookTaskType Meta string `xorm:"TEXT"` // store hook-specific attributes + OrgId int64 } // GetEvent handles conversion from Events to HookEvent. @@ -120,6 +121,18 @@ func DeleteWebhook(hookId int64) error { return err } +// GetWebhooksByOrgId returns all webhooks for an organization. +func GetWebhooksByOrgId(orgId int64) (ws []*Webhook, err error) { + err = x.Find(&ws, &Webhook{OrgId: orgId}) + return ws, err +} + +// GetActiveWebhooksByOrgId returns all active webhooks for an organization. +func GetActiveWebhooksByOrgId(orgId int64) (ws []*Webhook, err error) { + err = x.Find(&ws, &Webhook{OrgId: orgId, IsActive: true}) + return ws, err +} + // ___ ___ __ ___________ __ // / | \ ____ ____ | | _\__ ___/____ _____| | __ // / ~ \/ _ \ / _ \| |/ / | | \__ \ / ___/ |/ / diff --git a/public/ng/js/gogs.js b/public/ng/js/gogs.js index c08a887a..c60a5cf6 100644 --- a/public/ng/js/gogs.js +++ b/public/ng/js/gogs.js @@ -349,17 +349,8 @@ function initRepo() { }) } -function initRepoSetting() { - // Options. - // Confirmation of changing repository name. - $('#repo-setting-form').submit(function (e) { - var $reponame = $('#repo_name'); - if (($reponame.data('repo-name') != $reponame.val()) && !confirm('Repository name has been changed, do you want to continue?')) { - e.preventDefault(); - return true; - } - }); - +// when user changes hook type, hide/show proper divs +function initHookTypeChange() { // web hook type change $('select#hook-type').on("change", function () { hookTypes = ['Gogs','Slack']; @@ -374,6 +365,20 @@ function initRepoSetting() { } }); }); +} + +function initRepoSetting() { + // Options. + // Confirmation of changing repository name. + $('#repo-setting-form').submit(function (e) { + var $reponame = $('#repo_name'); + if (($reponame.data('repo-name') != $reponame.val()) && !confirm('Repository name has been changed, do you want to continue?')) { + e.preventDefault(); + return true; + } + }); + + initHookTypeChange(); $('#transfer-button').click(function () { $('#transfer-form').show(); @@ -421,6 +426,8 @@ function initOrgSetting() { return true; } }); + + initHookTypeChange(); } function initInvite() { diff --git a/routers/org/setting.go b/routers/org/setting.go index 0ddf0065..f853ef0e 100644 --- a/routers/org/setting.go +++ b/routers/org/setting.go @@ -5,6 +5,7 @@ package org import ( + "github.com/Unknwon/com" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/base" @@ -15,6 +16,7 @@ import ( const ( SETTINGS_OPTIONS base.TplName = "org/settings/options" SETTINGS_DELETE base.TplName = "org/settings/delete" + SETTINGS_HOOKS base.TplName = "org/settings/hooks" ) func Settings(ctx *middleware.Context) { @@ -97,3 +99,29 @@ func SettingsDelete(ctx *middleware.Context) { ctx.HTML(200, SETTINGS_DELETE) } + +func SettingsHooks(ctx *middleware.Context) { + ctx.Data["Title"] = ctx.Tr("org.settings") + ctx.Data["PageIsSettingsHooks"] = true + + // Delete web hook. + remove := com.StrTo(ctx.Query("remove")).MustInt64() + if remove > 0 { + if err := models.DeleteWebhook(remove); err != nil { + ctx.Handle(500, "DeleteWebhook", err) + return + } + ctx.Flash.Success(ctx.Tr("repo.settings.remove_hook_success")) + ctx.Redirect(ctx.Org.OrgLink + "/settings/hooks") + return + } + + ws, err := models.GetWebhooksByOrgId(ctx.Org.Organization.Id) + if err != nil { + ctx.Handle(500, "GetWebhooksByOrgId", err) + return + } + + ctx.Data["Webhooks"] = ws + ctx.HTML(200, SETTINGS_HOOKS) +} diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 74567812..81747d43 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -6,6 +6,7 @@ package repo import ( "encoding/json" + "errors" "fmt" "strings" "time" @@ -26,6 +27,7 @@ const ( COLLABORATION base.TplName = "repo/settings/collaboration" HOOKS base.TplName = "repo/settings/hooks" HOOK_NEW base.TplName = "repo/settings/hook_new" + ORG_HOOK_NEW base.TplName = "org/settings/hook_new" ) func Settings(ctx *middleware.Context) { @@ -284,7 +286,14 @@ func WebHooksNew(ctx *middleware.Context) { ctx.Data["PageIsSettingsHooksNew"] = true ctx.Data["Webhook"] = models.Webhook{HookEvent: &models.HookEvent{}} renderHookTypes(ctx) - ctx.HTML(200, HOOK_NEW) + orgId, repoId, _ := getOrgRepoCtx(ctx) + if repoId > 0 { + ctx.HTML(200, HOOK_NEW) + } else if orgId > 0 { + ctx.HTML(200, ORG_HOOK_NEW) + } else { + ctx.Handle(500, "WebHooksEdit(DetermineContext)", errors.New("Can't determine hook context")) + } } func WebHooksNewPost(ctx *middleware.Context, form auth.NewWebhookForm) { @@ -293,6 +302,8 @@ func WebHooksNewPost(ctx *middleware.Context, form auth.NewWebhookForm) { ctx.Data["PageIsSettingsHooksNew"] = true ctx.Data["Webhook"] = models.Webhook{HookEvent: &models.HookEvent{}} + orgId, repoId, link := getOrgRepoCtx(ctx) + if ctx.HasError() { ctx.HTML(200, HOOK_NEW) return @@ -304,7 +315,7 @@ func WebHooksNewPost(ctx *middleware.Context, form auth.NewWebhookForm) { } w := &models.Webhook{ - RepoId: ctx.Repo.Repository.Id, + RepoId: repoId, Url: form.PayloadUrl, ContentType: ct, Secret: form.Secret, @@ -314,6 +325,7 @@ func WebHooksNewPost(ctx *middleware.Context, form auth.NewWebhookForm) { IsActive: form.Active, HookTaskType: models.GOGS, Meta: "", + OrgId: orgId, } if err := w.UpdateEvent(); err != nil { @@ -325,7 +337,7 @@ func WebHooksNewPost(ctx *middleware.Context, form auth.NewWebhookForm) { } ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) - ctx.Redirect(ctx.Repo.RepoLink + "/settings/hooks") + ctx.Redirect(link + "/settings/hooks") } func WebHooksEdit(ctx *middleware.Context) { @@ -363,7 +375,14 @@ func WebHooksEdit(ctx *middleware.Context) { } w.GetEvent() ctx.Data["Webhook"] = w - ctx.HTML(200, HOOK_NEW) + orgId, repoId, _ := getOrgRepoCtx(ctx) + if repoId > 0 { + ctx.HTML(200, HOOK_NEW) + } else if orgId > 0 { + ctx.HTML(200, ORG_HOOK_NEW) + } else { + ctx.Handle(500, "WebHooksEdit(DetermineContext)", errors.New("Can't determine hook context")) + } } func WebHooksEditPost(ctx *middleware.Context, form auth.NewWebhookForm) { @@ -413,9 +432,10 @@ func WebHooksEditPost(ctx *middleware.Context, form auth.NewWebhookForm) { ctx.Handle(500, "WebHooksEditPost", err) return } + _, _, link := getOrgRepoCtx(ctx) ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success")) - ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", ctx.Repo.RepoLink, hookId)) + ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", link, hookId)) } func SlackHooksNewPost(ctx *middleware.Context, form auth.NewSlackHookForm) { @@ -428,6 +448,7 @@ func SlackHooksNewPost(ctx *middleware.Context, form auth.NewSlackHookForm) { ctx.HTML(200, HOOK_NEW) return } + orgId, repoId, link := getOrgRepoCtx(ctx) meta, err := json.Marshal(&models.Slack{ Domain: form.Domain, @@ -440,7 +461,7 @@ func SlackHooksNewPost(ctx *middleware.Context, form auth.NewSlackHookForm) { } w := &models.Webhook{ - RepoId: ctx.Repo.Repository.Id, + RepoId: repoId, Url: models.GetSlackURL(form.Domain, form.Token), ContentType: models.JSON, Secret: "", @@ -450,6 +471,7 @@ func SlackHooksNewPost(ctx *middleware.Context, form auth.NewSlackHookForm) { IsActive: form.Active, HookTaskType: models.SLACK, Meta: string(meta), + OrgId: orgId, } if err := w.UpdateEvent(); err != nil { ctx.Handle(500, "UpdateEvent", err) @@ -460,7 +482,7 @@ func SlackHooksNewPost(ctx *middleware.Context, form auth.NewSlackHookForm) { } ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) - ctx.Redirect(ctx.Repo.RepoLink + "/settings/hooks") + ctx.Redirect(link + "/settings/hooks") } func SlackHooksEditPost(ctx *middleware.Context, form auth.NewSlackHookForm) { @@ -514,7 +536,25 @@ func SlackHooksEditPost(ctx *middleware.Context, form auth.NewSlackHookForm) { ctx.Handle(500, "SlackHooksEditPost", err) return } + _, _, link := getOrgRepoCtx(ctx) ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success")) - ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", ctx.Repo.RepoLink, hookId)) + ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", link, hookId)) +} + +func getOrgRepoCtx(ctx *middleware.Context) (int64, int64, string) { + orgId := int64(0) + repoId := int64(0) + link := "" + if _, ok := ctx.Data["RepoLink"]; ok { + repoId = ctx.Repo.Repository.Id + link = ctx.Repo.RepoLink + } + + if _, ok := ctx.Data["OrgLink"]; ok { + orgId = ctx.Org.Organization.Id + link = ctx.Org.OrgLink + } + + return orgId, repoId, link } diff --git a/templates/org/settings/hook_new.tmpl b/templates/org/settings/hook_new.tmpl new file mode 100644 index 00000000..6e7ee536 --- /dev/null +++ b/templates/org/settings/hook_new.tmpl @@ -0,0 +1,37 @@ +{{template "ng/base/head" .}} +{{template "ng/base/header" .}} +{{template "org/base/header" .}} +
+
+ {{template "org/settings/nav" .}} +
+
+ {{template "ng/base/alert" .}} +
+
+
+ {{if .PageIsSettingsHooksNew}}{{.i18n.Tr "repo.settings.add_webhook"}}{{else}}{{.i18n.Tr "repo.settings.update_webhook"}}{{end}} +
+ {{template "repo/settings/hook_types" .}} + {{template "repo/settings/hook_gogs" .}} + {{template "repo/settings/hook_slack" .}} +
+
+ {{if .PageIsSettingsHooksEdit}} +
+
+
+
+ {{.i18n.Tr "repo.settings.recent_deliveries"}} +
+
    +
  • Coming soon!
  • +
+
+
+ {{end}} +
+
+
+
+{{template "ng/base/footer" .}} diff --git a/templates/org/settings/hooks.tmpl b/templates/org/settings/hooks.tmpl new file mode 100644 index 00000000..713cfeb4 --- /dev/null +++ b/templates/org/settings/hooks.tmpl @@ -0,0 +1,38 @@ +{{template "ng/base/head" .}} +{{template "ng/base/header" .}} +{{template "org/base/header" .}} +
+
+ {{template "org/settings/nav" .}} +
+
+ {{template "ng/base/alert" .}} +
+
+
+ {{.i18n.Tr "repo.settings.add_webhook"}} + {{.i18n.Tr "repo.settings.hooks"}} +
+
    +
  • {{.i18n.Tr "org.settings.hooks_desc" | Str2html}}
  • + {{range .Webhooks}} +
  • + {{if .IsActive}} + + {{else}} + + {{end}} + {{.Url}} + + +
  • + {{end}} +
+
+
+
+
+
+
+
+{{template "ng/base/footer" .}} diff --git a/templates/org/settings/nav.tmpl b/templates/org/settings/nav.tmpl index 950569d6..954893c6 100644 --- a/templates/org/settings/nav.tmpl +++ b/templates/org/settings/nav.tmpl @@ -5,7 +5,8 @@ - \ No newline at end of file + diff --git a/templates/repo/settings/hook_gogs.tmpl b/templates/repo/settings/hook_gogs.tmpl index 35b58995..31a04ce0 100644 --- a/templates/repo/settings/hook_gogs.tmpl +++ b/templates/repo/settings/hook_gogs.tmpl @@ -1,5 +1,5 @@
-
+ {{.CsrfTokenHtml}}
{{.i18n.Tr "repo.settings.add_webhook_desc" | Str2html}}
diff --git a/templates/repo/settings/hook_slack.tmpl b/templates/repo/settings/hook_slack.tmpl index 50d28e2f..ed7a42e6 100644 --- a/templates/repo/settings/hook_slack.tmpl +++ b/templates/repo/settings/hook_slack.tmpl @@ -1,5 +1,5 @@
- + {{.CsrfTokenHtml}}
{{.i18n.Tr "repo.settings.add_slack_hook_desc" | Str2html}}
-- cgit v1.2.3 From ab7206d6b787645956b0279f729bd7b22cbed690 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 5 Sep 2014 17:28:09 -0400 Subject: Fix #348 --- README.md | 3 +- README_ZH.md | 3 +- cmd/web.go | 1 + conf/locale/locale_en-US.ini | 3 ++ conf/locale/locale_zh-CN.ini | 3 ++ gogs.go | 2 +- models/repo.go | 4 +- routers/home.go | 26 +++++++++- templates/.VERSION | 2 +- templates/explore/nav.tmpl | 8 ++++ templates/explore/repos.tmpl | 25 ++++++++++ templates/org/settings/options.tmpl | 96 ++++++++++++++++++------------------- templates/status/404.tmpl | 4 +- 13 files changed, 121 insertions(+), 59 deletions(-) create mode 100644 templates/explore/nav.tmpl create mode 100644 templates/explore/repos.tmpl (limited to 'models') diff --git a/README.md b/README.md index ddb8367e..689b0df4 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ There are 5 ways to install Gogs: - [Install from binary](http://gogs.io/docs/installation/install_from_binary.md): **STRONGLY RECOMMENDED** - [Install from source](http://gogs.io/docs/installation/install_from_source.md) - [Install from packages](http://gogs.io/docs/installation/install_from_packages.md) -- [Ship with Docker](https://github.com/gogits/gogs/tree/master/dockerfiles) +- [Ship with Docker](https://github.com/gogits/gogs/tree/master/docker) - [Install with Vagrant](https://github.com/geerlingguy/ansible-vagrant-examples/tree/master/gogs) ## Acknowledgments @@ -70,7 +70,6 @@ There are 5 ways to install Gogs: - Usage and modification from [beego](http://beego.me) modules. - Thanks [lavachen](http://www.lavachen.cn/) and [Rocker](http://weibo.com/rocker1989) for designing Logo. - Thanks [gobuild.io](http://gobuild.io) for providing binary compile and download service. -- Thanks [Docker China](http://www.dockboard.org/) for providing [dockerfiles](https://github.com/gogits/gogs/tree/master/dockerfiles). ## Contributors diff --git a/README_ZH.md b/README_ZH.md index de982baf..401c8186 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -50,7 +50,7 @@ Gogs 的目标是打造一个最简单、最快速和最轻松的方式搭建自 - [二进制安装](http://gogs.io/docs/installation/install_from_binary.md): **强烈推荐** - [源码安装](http://gogs.io/docs/installation/install_from_source.md) - [包管理安装](http://gogs.io/docs/installation/install_from_packages.md) -- [采用 Docker 部署](https://github.com/gogits/gogs/tree/master/dockerfiles) +- [采用 Docker 部署](https://github.com/gogits/gogs/tree/master/docker) - [通过 Vagrant 安装](https://github.com/geerlingguy/ansible-vagrant-examples/tree/master/gogs) ## 特别鸣谢 @@ -61,7 +61,6 @@ Gogs 的目标是打造一个最简单、最快速和最轻松的方式搭建自 - [martini](http://martini.codegangsta.io/) 的路由与中间件机制。 - 感谢 [gobuild.io](http://gobuild.io) 提供二进制编译与下载服务。 - 感谢 [lavachen](http://www.lavachen.cn/) 和 [Rocker](http://weibo.com/rocker1989) 设计的 Logo。 -- 感谢 [Docker 中文社区](http://www.dockboard.org/) 提供的 [dockerfiles](https://github.com/gogits/gogs/tree/master/dockerfiles)。 ## 贡献成员 diff --git a/cmd/web.go b/cmd/web.go index 57164683..cad1db33 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -124,6 +124,7 @@ func runWeb(*cli.Context) { // Routers. m.Get("/", ignSignIn, routers.Home) + m.Get("/explore", routers.Explore) m.Get("/install", bindIgnErr(auth.InstallForm{}), routers.Install) m.Post("/install", bindIgnErr(auth.InstallForm{}), routers.InstallPost) m.Group("", func(r *macaron.Router) { diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index 946d5604..e8329933 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -47,6 +47,9 @@ collaborative_repos = Collaborative Repositories my_orgs = My Organizations my_mirrors = My Mirrors +[explore] +repos = Repositories + [auth] create_new_account = Create New Account register_hepler_msg = Already have an account? Sign in now! diff --git a/conf/locale/locale_zh-CN.ini b/conf/locale/locale_zh-CN.ini index 55d22f23..a61a54ce 100644 --- a/conf/locale/locale_zh-CN.ini +++ b/conf/locale/locale_zh-CN.ini @@ -47,6 +47,9 @@ collaborative_repos = 参与协作的仓库 my_orgs = 我的组织 my_mirrors = 我的镜像 +[explore] +repos = 探索仓库 + [auth] create_new_account = 创建帐户 register_hepler_msg = 已经注册?立即登录! diff --git a/gogs.go b/gogs.go index a1160190..1c012d40 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.4.9.0902 Beta" +const APP_VER = "0.4.9.0905 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/repo.go b/models/repo.go index 23d44a6b..341e7e47 100644 --- a/models/repo.go +++ b/models/repo.go @@ -972,8 +972,8 @@ func GetRepositories(uid int64, private bool) ([]*Repository, error) { } // GetRecentUpdatedRepositories returns the list of repositories that are recently updated. -func GetRecentUpdatedRepositories() (repos []*Repository, err error) { - err = x.Where("is_private=?", false).Limit(5).Desc("updated").Find(&repos) +func GetRecentUpdatedRepositories(num int) (repos []*Repository, err error) { + err = x.Where("is_private=?", false).Limit(num).Desc("updated").Find(&repos) return repos, err } diff --git a/routers/home.go b/routers/home.go index 5ea3e2a0..36a4f50f 100644 --- a/routers/home.go +++ b/routers/home.go @@ -5,6 +5,9 @@ package routers import ( + "fmt" + + "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/setting" @@ -12,7 +15,8 @@ import ( ) const ( - HOME base.TplName = "home" + HOME base.TplName = "home" + EXPLORE_REPOS base.TplName = "explore/repos" ) func Home(ctx *middleware.Context) { @@ -42,6 +46,26 @@ func Home(ctx *middleware.Context) { ctx.HTML(200, HOME) } +func Explore(ctx *middleware.Context) { + ctx.Data["Title"] = ctx.Tr("explore") + ctx.Data["PageIsExploreRepositories"] = true + + repos, err := models.GetRecentUpdatedRepositories(20) + if err != nil { + ctx.Handle(500, "GetRecentUpdatedRepositories", err) + return + } + for _, repo := range repos { + if err = repo.GetOwner(); err != nil { + ctx.Handle(500, "GetOwner", fmt.Errorf("%d: %v", repo.Id, err)) + return + } + } + ctx.Data["Repos"] = repos + + ctx.HTML(200, EXPLORE_REPOS) +} + func NotFound(ctx *middleware.Context) { ctx.Data["Title"] = "Page Not Found" ctx.Handle(404, "home.NotFound", nil) diff --git a/templates/.VERSION b/templates/.VERSION index 5f3c5181..6e361299 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.4.9.0902 Beta \ No newline at end of file +0.4.9.0905 Beta \ No newline at end of file diff --git a/templates/explore/nav.tmpl b/templates/explore/nav.tmpl new file mode 100644 index 00000000..1310bccf --- /dev/null +++ b/templates/explore/nav.tmpl @@ -0,0 +1,8 @@ +
+

{{.i18n.Tr "explore"}}

+ +
\ No newline at end of file diff --git a/templates/explore/repos.tmpl b/templates/explore/repos.tmpl new file mode 100644 index 00000000..a1e3d408 --- /dev/null +++ b/templates/explore/repos.tmpl @@ -0,0 +1,25 @@ +{{template "ng/base/head" .}} +{{template "ng/base/header" .}} +
+
+ {{template "explore/nav" .}} +
+
+
+ {{range .Repos}} +
+
    +
  • {{.NumStars}}
  • +
  • {{.NumForks}}
  • +
+

{{.Name}}

+

{{.Description}}

+

{{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Updated $.i18n.Lang}}

+
+ {{end}} +
+
+
+
+
+{{template "ng/base/footer" .}} \ No newline at end of file diff --git a/templates/org/settings/options.tmpl b/templates/org/settings/options.tmpl index ae225a9c..14ea1b34 100644 --- a/templates/org/settings/options.tmpl +++ b/templates/org/settings/options.tmpl @@ -3,54 +3,54 @@ {{template "org/base/header" .}}
- {{template "org/settings/nav" .}} -
-
- {{template "ng/base/alert" .}} -
-
-
- {{.i18n.Tr "org.settings.options"}} -
- - {{.CsrfTokenHtml}} - -
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
- -
-
-
+ {{template "org/settings/nav" .}} +
+
+ {{template "ng/base/alert" .}} +
+
+
+ {{.i18n.Tr "org.settings.options"}} +
+
+ {{.CsrfTokenHtml}} + +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+
diff --git a/templates/status/404.tmpl b/templates/status/404.tmpl index 2d04b559..e024715e 100644 --- a/templates/status/404.tmpl +++ b/templates/status/404.tmpl @@ -1,11 +1,11 @@ {{template "ng/base/head" .}} {{template "ng/base/header" .}} -
+

404



Application Version: {{AppVer}}

If you think this is an error, please open an issue on GitHub.

-

We're currently working on 0.5 beta version, many pages may be missing at this time. Sorry for confusion!

+
{{template "ng/base/footer" .}} -- cgit v1.2.3 From d84d6dfdae93518936b33290e5cc9adeef876524 Mon Sep 17 00:00:00 2001 From: lunnyxiao Date: Mon, 8 Sep 2014 12:11:25 +0800 Subject: add showinfo for xorm --- models/models.go | 1 + 1 file changed, 1 insertion(+) (limited to 'models') diff --git a/models/models.go b/models/models.go index 5558ec00..247bcf2f 100644 --- a/models/models.go +++ b/models/models.go @@ -111,6 +111,7 @@ func SetEngine() (err error) { x.Logger = xorm.NewSimpleLogger(f) x.ShowSQL = true + x.ShowInfo = true x.ShowDebug = true x.ShowErr = true x.ShowWarn = true -- cgit v1.2.3 From 132590fab8c92fea1dc11faf6ffe3052c2350d91 Mon Sep 17 00:00:00 2001 From: Christopher Brickley Date: Tue, 9 Sep 2014 08:37:34 -0400 Subject: update specific hook_task, not all --- models/webhook.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'models') diff --git a/models/webhook.go b/models/webhook.go index 5acc83f5..6aac457b 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -230,7 +230,7 @@ func CreateHookTask(t *HookTask) error { // UpdateHookTask updates information of hook task. func UpdateHookTask(t *HookTask) error { - _, err := x.AllCols().Update(t) + _, err := x.Id(t.Id).AllCols().Update(t) return err } -- cgit v1.2.3 From 33659ed9a5d95f13a4b10c06ba1e7c12e23ad6f0 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 9 Sep 2014 10:17:35 -0400 Subject: Fix #452 --- gogs.go | 2 +- models/webhook.go | 4 ++-- templates/.VERSION | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'models') diff --git a/gogs.go b/gogs.go index 2ca0f9ad..02ae7fd2 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.0.0907 Beta" +const APP_VER = "0.5.0.0909 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/webhook.go b/models/webhook.go index 6aac457b..5c0e2179 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -99,7 +99,7 @@ func GetWebhookById(hookId int64) (*Webhook, error) { // GetActiveWebhooksByRepoId returns all active webhooks of repository. func GetActiveWebhooksByRepoId(repoId int64) (ws []*Webhook, err error) { - err = x.Find(&ws, &Webhook{RepoId: repoId, IsActive: true}) + err = x.Where("repo_id=?", repoId).And("is_active=?", true).Find(&ws) return ws, err } @@ -129,7 +129,7 @@ func GetWebhooksByOrgId(orgId int64) (ws []*Webhook, err error) { // GetActiveWebhooksByOrgId returns all active webhooks for an organization. func GetActiveWebhooksByOrgId(orgId int64) (ws []*Webhook, err error) { - err = x.Find(&ws, &Webhook{OrgId: orgId, IsActive: true}) + err = x.Where("org_id=?", orgId).And("is_active=?", true).Find(&ws) return ws, err } diff --git a/templates/.VERSION b/templates/.VERSION index ec831f10..b539e339 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.0.0907 Beta \ No newline at end of file +0.5.0.0909 Beta \ No newline at end of file -- cgit v1.2.3 From 52d15ddec81127855a9981029cb77d4ed2798e79 Mon Sep 17 00:00:00 2001 From: Christopher Brickley Date: Wed, 10 Sep 2014 08:53:16 -0400 Subject: deliver hooks immediately after commit --- models/action.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'models') diff --git a/models/action.go b/models/action.go index c0992dba..295a61cc 100644 --- a/models/action.go +++ b/models/action.go @@ -314,6 +314,8 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, } } } + + go DeliverHooks() return nil } -- cgit v1.2.3 From cfed11f092580ecf47cff43274c7cdd10d07bffd Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 12 Sep 2014 18:29:58 -0400 Subject: Bug: Transfer repository doesn't update the count --- conf/locale/locale_en-US.ini | 1 + conf/locale/locale_zh-CN.ini | 1 + gogs.go | 2 +- models/repo.go | 20 +++++++++++--------- routers/repo/setting.go | 6 +++++- templates/.VERSION | 2 +- templates/repo/view_file.tmpl | 2 +- 7 files changed, 21 insertions(+), 13 deletions(-) (limited to 'models') diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index ba9bef6d..2d69b48d 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -257,6 +257,7 @@ settings.site = Official Site settings.update_settings = Update Settings settings.transfer = Transfer Ownership settings.transfer_desc = Transfer this repo to another user or to an organization where you have admin rights. +settings.new_owner_has_same_repo = New owner already has a repository with same name. settings.delete = Delete This Repository settings.delete_desc = Once you delete a repository, there is no going back. Please be certain. settings.update_settings_success = Repository options has been successfully updated. diff --git a/conf/locale/locale_zh-CN.ini b/conf/locale/locale_zh-CN.ini index 7d10142e..2022361f 100644 --- a/conf/locale/locale_zh-CN.ini +++ b/conf/locale/locale_zh-CN.ini @@ -257,6 +257,7 @@ settings.site = 官方网站 settings.update_settings = 更新仓库设置 settings.transfer = 转移仓库所有权 settings.transfer_desc = 您可以将仓库转移至您拥有管理员权限的帐户或组织。 +settings.new_owner_has_same_repo = 新的仓库拥有者已经存在同名仓库! settings.delete = 删除本仓库 settings.delete_desc = 删除仓库操作不可逆转,请三思而后行。 settings.update_settings_success = 仓库设置更新成功! diff --git a/gogs.go b/gogs.go index d3aa4377..6f32b747 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.0.0910 Beta" +const APP_VER = "0.5.0.0912 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/repo.go b/models/repo.go index 341e7e47..25876872 100644 --- a/models/repo.go +++ b/models/repo.go @@ -644,12 +644,20 @@ func RepoPath(userName, repoName string) string { } // TransferOwnership transfers all corresponding setting from old user to new one. -func TransferOwnership(u *User, newOwner string, repo *Repository) (err error) { +func TransferOwnership(u *User, newOwner string, repo *Repository) error { newUser, err := GetUserByName(newOwner) if err != nil { return err } + // Check if new owner has repository with same name. + has, err := IsRepositoryExist(u, repo.Name) + if err != nil { + return err + } else if has { + return ErrRepoAlreadyExist + } + sess := x.NewSession() defer sess.Close() if err = sess.Begin(); err != nil { @@ -717,12 +725,6 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) (err error) { } } - if _, err = sess.Exec( - "UPDATE `user` SET num_repos = num_repos + 1 WHERE id = ?", u.Id); err != nil { - sess.Rollback() - return err - } - // Update owner team info and count. t.RepoIds += "$" + com.ToStr(repo.Id) + "|" t.NumRepos++ @@ -933,9 +935,9 @@ func GetRepositoryByRef(ref string) (*Repository, error) { } // GetRepositoryByName returns the repository by given name under user if exists. -func GetRepositoryByName(userId int64, repoName string) (*Repository, error) { +func GetRepositoryByName(uid int64, repoName string) (*Repository, error) { repo := &Repository{ - OwnerId: userId, + OwnerId: uid, LowerName: strings.ToLower(repoName), } has, err := x.Get(repo) diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 80a06449..2354fbc1 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -113,7 +113,11 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), SETTINGS_OPTIONS, nil) return } else if err = models.TransferOwnership(ctx.Repo.Owner, newOwner, ctx.Repo.Repository); err != nil { - ctx.Handle(500, "TransferOwnership", err) + if err == models.ErrRepoAlreadyExist { + ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), SETTINGS_OPTIONS, nil) + } else { + ctx.Handle(500, "TransferOwnership", err) + } return } log.Trace("Repository transfered: %s/%s -> %s", ctx.Repo.Owner.Name, ctx.Repo.Repository.Name, newOwner) diff --git a/templates/.VERSION b/templates/.VERSION index 18a13b3a..e53dedcb 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.0.0910 Beta \ No newline at end of file +0.5.0.0912 Beta \ No newline at end of file diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index fb05945b..96efcdac 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -14,7 +14,7 @@

{{if .ReadmeExist}} - {{.FileContent | Str2html}} + {{if .FileContent}}{{.FileContent | Str2html}}{{end}} {{else if not .IsFileText}}
{{if .IsImageFile}} -- cgit v1.2.3 From 1b7adf57e94aaccd2abc6c7288947e36bb311c0a Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 12 Sep 2014 18:58:24 -0400 Subject: fix https://github.com/go-xorm/xorm/issues/161 --- models/models.go | 2 +- models/webhook.go | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'models') diff --git a/models/models.go b/models/models.go index 247bcf2f..283a8f7a 100644 --- a/models/models.go +++ b/models/models.go @@ -77,7 +77,7 @@ func getEngine() (*xorm.Engine, error) { return nil, fmt.Errorf("Unknown database type: %s", DbCfg.Type) } os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm) - cnnstr = DbCfg.Path + cnnstr = "file:" + DbCfg.Path + "?cache=shared&mode=rwc" default: return nil, fmt.Errorf("Unknown database type: %s", DbCfg.Type) } diff --git a/models/webhook.go b/models/webhook.go index 5c0e2179..3c07cc81 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -236,6 +236,7 @@ func UpdateHookTask(t *HookTask) error { // DeliverHooks checks and delivers undelivered hooks. func DeliverHooks() { + tasks := make([]*HookTask, 0, 10) timeout := time.Duration(setting.WebhookDeliverTimeout) * time.Second x.Where("is_delivered=?", false).Iterate(new(HookTask), func(idx int, bean interface{}) error { @@ -283,12 +284,18 @@ func DeliverHooks() { } } - if err := UpdateHookTask(t); err != nil { - log.Error(4, "UpdateHookTask: %v", err) - return nil - } + tasks = append(tasks, t) - log.Trace("Hook delivered(%s): %s", t.Uuid, t.PayloadContent) + if t.IsSucceed { + log.Trace("Hook delivered(%s): %s", t.Uuid, t.PayloadContent) + } return nil }) + + // Update hook task status. + for _, t := range tasks { + if err := UpdateHookTask(t); err != nil { + log.Error(4, "UpdateHookTask(%d): %v", t.Id, err) + } + } } -- cgit v1.2.3 From bba401a5dcf8af2fdc4c7c05b11db100019ee4fa Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 12 Sep 2014 19:42:11 -0400 Subject: Prepare 0.5 release --- .gopmfile | 47 ++++++++++++++++++------------------- README.md | 2 +- README_ZH.md | 2 +- models/git_diff.go | 3 +-- public/ng/css/gogs.css | 1 + public/ng/less/gogs/repository.less | 1 + 6 files changed, 28 insertions(+), 28 deletions(-) (limited to 'models') diff --git a/.gopmfile b/.gopmfile index 6aac4953..6edec776 100644 --- a/.gopmfile +++ b/.gopmfile @@ -2,30 +2,29 @@ path = github.com/gogits/gogs [deps] -github.com/beego/memcache = -github.com/beego/redigo = -github.com/Unknwon/cae = -github.com/Unknwon/com = -github.com/Unknwon/goconfig = -github.com/Unknwon/i18n = -github.com/Unknwon/macaron = -github.com/codegangsta/cli = -github.com/go-sql-driver/mysql = -github.com/go-xorm/core = -github.com/go-xorm/xorm = -github.com/gogits/gfm = -github.com/gogits/git = -github.com/gogits/oauth2 = -github.com/lib/pq = -github.com/macaron-contrib/cache = -github.com/macaron-contrib/captcha = -github.com/macaron-contrib/csrf = -github.com/macaron-contrib/i18n = -github.com/macaron-contrib/session = -github.com/macaron-contrib/toolbox = -github.com/mattn/go-sqlite3 = -github.com/nfnt/resize = -github.com/saintfish/chardet = +github.com/beego/memcache = commit:2aea774416 +github.com/beego/redigo = commit:856744a0d5 +github.com/Unknwon/cae = commit:2e70a1351b +github.com/Unknwon/com = commit:2cbcbc6916 +github.com/Unknwon/goconfig = commit:0f8d8dc1c0 +github.com/Unknwon/i18n = commit:47baeff8d0 +github.com/Unknwon/macaron = commit:f22f45d79a +github.com/codegangsta/cli = commit:7381bc4e62 +github.com/go-sql-driver/mysql = commit:8111ee3ec3 +github.com/go-xorm/core = commit:750aae0fa5 +github.com/go-xorm/xorm = commit:2d8b3135b1 +github.com/gogits/gfm = commit:40f747a9c0 +github.com/gogits/oauth2 = commit:99cbec870a +github.com/lib/pq = commit:b021d0ef20 +github.com/macaron-contrib/cache = commit:204d8e5137 +github.com/macaron-contrib/captcha = commit:8f3f1ac0e3 +github.com/macaron-contrib/csrf = commit:cd84c01723 +github.com/macaron-contrib/i18n = commit:489cc194b5 +github.com/macaron-contrib/session = commit:80a88a1bba +github.com/macaron-contrib/toolbox = commit:57127bcc89 +github.com/mattn/go-sqlite3 = commit:a80c27ba33 +github.com/nfnt/resize = commit:581d15cb53 +github.com/saintfish/chardet = commit:3af4cd4741 [res] include = conf|etc|public|scripts|templates diff --git a/README.md b/README.md index 3115d3fc..05771144 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Gogs - Go Git Service [![wercker status](https://app.wercker.com/status/ad0bdb0b Gogs(Go Git Service) is a painless self-hosted Git Service written in Go. -![Demo](http://gowalker.org/public/gogs_demo.gif) +![Demo](https://gowalker.org/public/gogs_demo.gif) ##### Current version: 0.5.0 Beta diff --git a/README_ZH.md b/README_ZH.md index ef154d0e..2fa82e7d 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -3,7 +3,7 @@ Gogs - Go Git Service [![wercker status](https://app.wercker.com/status/ad0bdb0b Gogs(Go Git Service) 是一个基于 Go 语言的自助 Git 服务。 -![Demo](http://gowalker.org/public/gogs_demo.gif) +![Demo](https://gowalker.org/public/gogs_demo.gif) ##### 当前版本:0.5.0 Beta diff --git a/models/git_diff.go b/models/git_diff.go index 21a624de..bf7a9cd5 100644 --- a/models/git_diff.go +++ b/models/git_diff.go @@ -15,8 +15,7 @@ import ( "github.com/Unknwon/com" - "github.com/gogits/git" - + "github.com/gogits/gogs/modules/git" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/process" ) diff --git a/public/ng/css/gogs.css b/public/ng/css/gogs.css index ee364905..5dd35acc 100644 --- a/public/ng/css/gogs.css +++ b/public/ng/css/gogs.css @@ -1316,6 +1316,7 @@ The register and sign-in page style padding: 0; } .code-view .lines-num { + vertical-align: top; text-align: right; color: #999; background: #f5f5f5; diff --git a/public/ng/less/gogs/repository.less b/public/ng/less/gogs/repository.less index 955a617c..48959a62 100644 --- a/public/ng/less/gogs/repository.less +++ b/public/ng/less/gogs/repository.less @@ -399,6 +399,7 @@ border-top-right-radius: .25em; } } .lines-num { + vertical-align: top; text-align: right; color: #999; background: #f5f5f5; -- cgit v1.2.3 From a2cac952a411ab1d1159bdaaf144fbb39a355010 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 12 Sep 2014 21:36:26 -0400 Subject: Prepare 0.5 release --- models/org.go | 32 ++++++++++---------------------- modules/middleware/repo.go | 2 +- routers/org/teams.go | 4 ++-- routers/repo/setting.go | 2 +- 4 files changed, 14 insertions(+), 26 deletions(-) (limited to 'models') diff --git a/models/org.go b/models/org.go index ce506705..31db8e36 100644 --- a/models/org.go +++ b/models/org.go @@ -507,7 +507,7 @@ func (t *Team) AddRepository(repo *Repository) (err error) { mode := AuthorizeToAccessType(t.Authorize) for _, u := range t.Members { - auth, err := GetHighestAuthorize(t.OrgId, u.Id, t.Id, repo.Id) + auth, err := GetHighestAuthorize(t.OrgId, u.Id, repo.Id, t.Id) if err != nil { sess.Rollback() return err @@ -517,13 +517,7 @@ func (t *Team) AddRepository(repo *Repository) (err error) { UserName: u.LowerName, RepoName: path.Join(repo.Owner.LowerName, repo.LowerName), } - if auth == 0 { - access.Mode = mode - if _, err = sess.Insert(access); err != nil { - sess.Rollback() - return fmt.Errorf("fail to insert access: %v", err) - } - } else if auth < t.Authorize { + if auth < t.Authorize { if err = addAccessWithAuthorize(sess, access, mode); err != nil { sess.Rollback() return err @@ -570,7 +564,7 @@ func (t *Team) RemoveRepository(repoId int64) error { // Remove access to team members. for _, u := range t.Members { - auth, err := GetHighestAuthorize(t.OrgId, u.Id, t.Id, repo.Id) + auth, err := GetHighestAuthorize(t.OrgId, u.Id, repo.Id, t.Id) if err != nil { sess.Rollback() return err @@ -668,7 +662,7 @@ func GetTeamById(teamId int64) (*Team, error) { } // GetHighestAuthorize returns highest repository authorize level for given user and team. -func GetHighestAuthorize(orgId, uid, teamId, repoId int64) (AuthorizeType, error) { +func GetHighestAuthorize(orgId, uid, repoId, teamId int64) (AuthorizeType, error) { ts, err := GetUserTeams(orgId, uid) if err != nil { return 0, err @@ -687,6 +681,7 @@ func GetHighestAuthorize(orgId, uid, teamId, repoId int64) (AuthorizeType, error } } } + return auth, nil } @@ -728,7 +723,7 @@ func UpdateTeam(t *Team, authChanged bool) (err error) { // ORG_WRITABLE is the highest authorize level for now. // Skip checking others if current team has this level. if t.Authorize < ORG_WRITABLE { - auth, err := GetHighestAuthorize(org.Id, u.Id, t.Id, repo.Id) + auth, err := GetHighestAuthorize(t.OrgId, u.Id, repo.Id, t.Id) if err != nil { sess.Rollback() return err @@ -782,7 +777,7 @@ func DeleteTeam(t *Team) error { // Delete all accesses. for _, repo := range t.Repos { for _, u := range t.Members { - auth, err := GetHighestAuthorize(org.Id, u.Id, t.Id, repo.Id) + auth, err := GetHighestAuthorize(t.OrgId, u.Id, repo.Id, t.Id) if err != nil { sess.Rollback() return err @@ -943,7 +938,7 @@ func AddTeamMember(orgId, teamId, uid int64) error { // Give access to team repositories. mode := AuthorizeToAccessType(t.Authorize) for _, repo := range t.Repos { - auth, err := GetHighestAuthorize(orgId, uid, teamId, repo.Id) + auth, err := GetHighestAuthorize(t.OrgId, u.Id, repo.Id, teamId) if err != nil { sess.Rollback() return err @@ -953,14 +948,7 @@ func AddTeamMember(orgId, teamId, uid int64) error { UserName: u.LowerName, RepoName: path.Join(org.LowerName, repo.LowerName), } - // Equal 0 means given access doesn't exist. - if auth == 0 { - access.Mode = mode - if _, err = sess.Insert(access); err != nil { - sess.Rollback() - return fmt.Errorf("fail to insert access: %v", err) - } - } else if auth < t.Authorize { + if auth < t.Authorize { if err = addAccessWithAuthorize(sess, access, mode); err != nil { sess.Rollback() return err @@ -1037,7 +1025,7 @@ func removeTeamMemberWithSess(orgId, teamId, uid int64, sess *xorm.Session) erro // Delete access to team repositories. for _, repo := range t.Repos { - auth, err := GetHighestAuthorize(orgId, uid, teamId, repo.Id) + auth, err := GetHighestAuthorize(t.OrgId, u.Id, repo.Id, teamId) if err != nil { sess.Rollback() return err diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index 68a9a2d7..82ef3c79 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -109,7 +109,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { } // Check if current user has admin permission to repository. if u.IsOrganization() { - auth, err := models.GetHighestAuthorize(u.Id, ctx.User.Id, 0, repo.Id) + auth, err := models.GetHighestAuthorize(u.Id, ctx.User.Id, repo.Id, 0) if err != nil { ctx.Handle(500, "GetHighestAuthorize", err) return diff --git a/routers/org/teams.go b/routers/org/teams.go index b0a69da7..9aa8e502 100644 --- a/routers/org/teams.go +++ b/routers/org/teams.go @@ -94,7 +94,7 @@ func TeamsAction(ctx *middleware.Context) { if err == models.ErrLastOrgOwner { ctx.Flash.Error(ctx.Tr("form.last_org_owner")) } else { - log.Error(4, "Action(%s): %v", ctx.Params(":action"), err) + log.Error(3, "Action(%s): %v", ctx.Params(":action"), err) ctx.JSON(200, map[string]interface{}{ "ok": false, "err": err.Error(), @@ -133,7 +133,7 @@ func TeamsRepoAction(ctx *middleware.Context) { } if err != nil { - log.Error(4, "Action(%s): %v", ctx.Params(":action"), err) + log.Error(3, "Action(%s): %v", ctx.Params(":action"), err) ctx.JSON(200, map[string]interface{}{ "ok": false, "err": err.Error(), diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 2354fbc1..b30de91a 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -213,7 +213,7 @@ func SettingsCollaboration(ctx *middleware.Context) { needDelete := true if ctx.User.IsOrganization() { // Check if user belongs to a team that has access to this repository. - auth, err := models.GetHighestAuthorize(ctx.Repo.Owner.Id, ctx.User.Id, 0, ctx.Repo.Repository.Id) + auth, err := models.GetHighestAuthorize(ctx.Repo.Owner.Id, ctx.User.Id, ctx.Repo.Repository.Id, 0) if err != nil { ctx.Handle(500, "GetHighestAuthorize", err) return -- cgit v1.2.3 From c1ceec45da8c600dea2b932127519c04484258d8 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 16 Sep 2014 08:32:13 -0400 Subject: Fix mirror UI style and work on #475 --- gogs.go | 2 +- models/publickey.go | 13 +++++++++---- public/ng/css/gogs.css | 2 +- public/ng/less/gogs/dashboard.less | 4 +--- templates/.VERSION | 2 +- templates/user/dashboard/dashboard.tmpl | 4 ++-- 6 files changed, 15 insertions(+), 12 deletions(-) (limited to 'models') diff --git a/gogs.go b/gogs.go index f492b2f7..f0aebf03 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.1.0915 Beta" +const APP_VER = "0.5.1.0916 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/publickey.go b/models/publickey.go index 1246cffc..dccb8936 100644 --- a/models/publickey.go +++ b/models/publickey.go @@ -14,6 +14,7 @@ import ( "os/exec" "path" "path/filepath" + "runtime" "strings" "sync" "time" @@ -160,10 +161,14 @@ func saveAuthorizedKeyFile(key *PublicKey) error { if err != nil { return err } - if finfo.Mode().Perm() > 0600 { - log.Error(4, "authorized_keys file has unusual permission flags: %s - setting to -rw-------", finfo.Mode().Perm().String()) - if err = f.Chmod(0600); err != nil { - return err + + // FIXME: following command does not support in Windows. + if runtime.GOOS != "windows" { + if finfo.Mode().Perm() > 0600 { + log.Error(4, "authorized_keys file has unusual permission flags: %s - setting to -rw-------", finfo.Mode().Perm().String()) + if err = f.Chmod(0600); err != nil { + return err + } } } diff --git a/public/ng/css/gogs.css b/public/ng/css/gogs.css index 8f82e0af..db4aad22 100644 --- a/public/ng/css/gogs.css +++ b/public/ng/css/gogs.css @@ -686,7 +686,7 @@ ol.linenums { width: auto; } /* -The dashboard page style + The dashboard page style */ #dashboard-header { border-bottom: 1px solid #d6d6d6; diff --git a/public/ng/less/gogs/dashboard.less b/public/ng/less/gogs/dashboard.less index afef60cf..60aa8072 100644 --- a/public/ng/less/gogs/dashboard.less +++ b/public/ng/less/gogs/dashboard.less @@ -1,9 +1,7 @@ @import "../ui/var"; - /* -The dashboard page style + The dashboard page style */ - @dashboardHeaderBorderColor: #D6D6D6; @dashboardHeaderLinkColor: #444; @dashboardHeaderLinkHoverColor: #D9453D; diff --git a/templates/.VERSION b/templates/.VERSION index 6db2a3e6..261667db 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.1.0915 Beta \ No newline at end of file +0.5.1.0916 Beta \ No newline at end of file diff --git a/templates/user/dashboard/dashboard.tmpl b/templates/user/dashboard/dashboard.tmpl index bf0aba09..2f9bbc4e 100644 --- a/templates/user/dashboard/dashboard.tmpl +++ b/templates/user/dashboard/dashboard.tmpl @@ -9,7 +9,7 @@
-
+

{{.GetActUserName}} {{if eq .GetOpType 1}} @@ -30,7 +30,7 @@ {{ $push := ActionContent2Commits .}} {{ $repoLink := .GetRepoLink}} {{range $push.Commits}} -

  • {{ShortSha .Sha1}} {{.Message}}
  • +
  • {{ShortSha .Sha1}} {{.Message}}
  • {{end}}
    -- cgit v1.2.3 From 0d9c41be7d7d4ae1d2a28931be5565c8f6d3f792 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 16 Sep 2014 10:10:33 -0400 Subject: Work on #476 --- README.md | 2 +- README_ZH.md | 2 +- gogs.go | 2 +- models/repo.go | 9 ++++-- modules/git/repo_commit.go | 8 ++++++ modules/git/version.go | 70 ++++++++++++++++++++++++++++++++++++++-------- templates/.VERSION | 2 +- 7 files changed, 78 insertions(+), 17 deletions(-) (limited to 'models') diff --git a/README.md b/README.md index 3c319896..43d75c26 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.0 Beta +##### Current version: 0.5.2 Beta ### NOTICES diff --git a/README_ZH.md b/README_ZH.md index 7faeee2b..bf6c1d03 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.1 Beta +##### 当前版本:0.5.2 Beta ## 开发目的 diff --git a/gogs.go b/gogs.go index f0aebf03..8ae7449e 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.1.0916 Beta" +const APP_VER = "0.5.2.0916 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/repo.go b/models/repo.go index 25876872..a8e53dbc 100644 --- a/models/repo.go +++ b/models/repo.go @@ -95,8 +95,13 @@ func NewRepoContext() { if err != nil { log.Fatal(4, "Fail to get Git version: %v", err) } - if ver.Major < 2 && ver.Minor < 8 { - log.Fatal(4, "Gogs requires Git version greater or equal to 1.8.0") + + reqVer, err := git.ParseVersion("1.7.1") + if err != nil { + log.Fatal(4, "Fail to parse required Git version: %v", err) + } + if ver.Compare(reqVer) == -1 { + log.Fatal(4, "Gogs requires Git version greater or equal to 1.7.1") } // Check if server has basic git setting and set if not. diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go index eebe3dd0..c9258927 100644 --- a/modules/git/repo_commit.go +++ b/modules/git/repo_commit.go @@ -137,6 +137,14 @@ func (repo *Repository) GetCommit(commitId string) (*Commit, error) { } func (repo *Repository) commitsCount(id sha1) (int, error) { + if gitVer.Compare(MustParseVersion("1.8.0")) == -1 { + stdout, stderr, err := com.ExecCmdDirBytes(repo.Path, "git", "log", "--pretty=format:''", id.String()) + if err != nil { + return 0, errors.New(string(stderr)) + } + return len(bytes.Split(stdout, []byte("\n"))), nil + } + stdout, stderr, err := com.ExecCmdDir(repo.Path, "git", "rev-list", "--count", id.String()) if err != nil { return 0, errors.New(stderr) diff --git a/modules/git/version.go b/modules/git/version.go index 683e859b..653503c0 100644 --- a/modules/git/version.go +++ b/modules/git/version.go @@ -11,25 +11,24 @@ import ( "github.com/Unknwon/com" ) +var ( + // Cached Git version. + gitVer *Version +) + // Version represents version of Git. type Version struct { Major, Minor, Patch int } -// GetVersion returns current Git version installed. -func GetVersion() (Version, error) { - stdout, stderr, err := com.ExecCmd("git", "version") - if err != nil { - return Version{}, errors.New(stderr) - } - - infos := strings.Split(stdout, " ") +func ParseVersion(verStr string) (*Version, error) { + infos := strings.Split(verStr, ".") if len(infos) < 3 { - return Version{}, errors.New("not enough output") + return nil, errors.New("incorrect version input") } - v := Version{} - for i, s := range strings.Split(strings.TrimSpace(infos[2]), ".") { + v := &Version{} + for i, s := range infos { switch i { case 0: v.Major, _ = com.StrTo(s).Int() @@ -41,3 +40,52 @@ func GetVersion() (Version, error) { } return v, nil } + +func MustParseVersion(verStr string) *Version { + v, _ := ParseVersion(verStr) + return v +} + +// Compare compares two versions, +// it returns 1 if original is greater, 1 if original is smaller, 0 if equal. +func (v *Version) Compare(that *Version) int { + if v.Major > that.Major { + return 1 + } else if v.Major < that.Major { + return -1 + } + + if v.Minor > that.Minor { + return 1 + } else if v.Minor < that.Minor { + return -1 + } + + if v.Patch > that.Patch { + return 1 + } else if v.Patch < that.Patch { + return -1 + } + + return 0 +} + +// GetVersion returns current Git version installed. +func GetVersion() (*Version, error) { + if gitVer != nil { + return gitVer, nil + } + + stdout, stderr, err := com.ExecCmd("git", "version") + if err != nil { + return nil, errors.New(stderr) + } + + infos := strings.Split(stdout, " ") + if len(infos) < 3 { + return nil, errors.New("not enough output") + } + + gitVer, err = ParseVersion(infos[2]) + return gitVer, err +} diff --git a/templates/.VERSION b/templates/.VERSION index 261667db..aada89d1 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.1.0916 Beta \ No newline at end of file +0.5.2.0916 Beta \ No newline at end of file -- cgit v1.2.3 From 62f21ff3ed1b85a1d3a1eab73da354e4f6e8794a Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 16 Sep 2014 11:29:53 -0400 Subject: Work on #476 --- models/repo.go | 2 +- modules/git/repo_commit.go | 2 +- modules/git/version.go | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'models') diff --git a/models/repo.go b/models/repo.go index a8e53dbc..2e162704 100644 --- a/models/repo.go +++ b/models/repo.go @@ -100,7 +100,7 @@ func NewRepoContext() { if err != nil { log.Fatal(4, "Fail to parse required Git version: %v", err) } - if ver.Compare(reqVer) == -1 { + if ver.LessThan(reqVer) { log.Fatal(4, "Gogs requires Git version greater or equal to 1.7.1") } diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go index c9258927..cd0181c4 100644 --- a/modules/git/repo_commit.go +++ b/modules/git/repo_commit.go @@ -137,7 +137,7 @@ func (repo *Repository) GetCommit(commitId string) (*Commit, error) { } func (repo *Repository) commitsCount(id sha1) (int, error) { - if gitVer.Compare(MustParseVersion("1.8.0")) == -1 { + if gitVer.LessThan(MustParseVersion("1.8.0")) { stdout, stderr, err := com.ExecCmdDirBytes(repo.Path, "git", "log", "--pretty=format:''", id.String()) if err != nil { return 0, errors.New(string(stderr)) diff --git a/modules/git/version.go b/modules/git/version.go index 653503c0..546397aa 100644 --- a/modules/git/version.go +++ b/modules/git/version.go @@ -47,7 +47,7 @@ func MustParseVersion(verStr string) *Version { } // Compare compares two versions, -// it returns 1 if original is greater, 1 if original is smaller, 0 if equal. +// it returns 1 if original is greater, -1 if original is smaller, 0 if equal. func (v *Version) Compare(that *Version) int { if v.Major > that.Major { return 1 @@ -70,6 +70,10 @@ func (v *Version) Compare(that *Version) int { return 0 } +func (v *Version) LessThan(that *Version) bool { + return v.Compare(that) < 0 +} + // GetVersion returns current Git version installed. func GetVersion() (*Version, error) { if gitVer != nil { -- cgit v1.2.3 From ebb4f1b78cdf7ce877eafc346be94b8e8ac3217b Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 16 Sep 2014 13:34:09 -0400 Subject: Work #475 and #458 --- models/publickey.go | 15 +++++++++++---- modules/setting/setting.go | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'models') diff --git a/models/publickey.go b/models/publickey.go index dccb8936..1824e887 100644 --- a/models/publickey.go +++ b/models/publickey.go @@ -14,7 +14,6 @@ import ( "os/exec" "path" "path/filepath" - "runtime" "strings" "sync" "time" @@ -23,6 +22,7 @@ import ( "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/process" + "github.com/gogits/gogs/modules/setting" ) const ( @@ -120,23 +120,30 @@ func CheckPublicKeyString(content string) (bool, error) { tmpFile.WriteString(content) tmpFile.Close() - // … see if ssh-keygen recognizes its contents + // Check if ssh-keygen recognizes its contents. stdout, stderr, err := process.Exec("CheckPublicKeyString", "ssh-keygen", "-l", "-f", tmpPath) if err != nil { return false, errors.New("ssh-keygen -l -f: " + stderr) } else if len(stdout) < 2 { return false, errors.New("ssh-keygen returned not enough output to evaluate the key") } + + // The ssh-keygen in Windows does not print key type, so no need go further. + if setting.IsWindows { + return true, nil + } + sshKeygenOutput := strings.Split(stdout, " ") if len(sshKeygenOutput) < 4 { return false, errors.New("Not enough fields returned by ssh-keygen -l -f") } + + // Check if key type and key size match. keySize, err := com.StrTo(sshKeygenOutput[0]).Int() if err != nil { return false, errors.New("Cannot get key size of the given key") } keyType := strings.TrimSpace(sshKeygenOutput[len(sshKeygenOutput)-1]) - if minimumKeySize := MinimumKeySize[keyType]; minimumKeySize == 0 { return false, errors.New("Sorry, unrecognized public key type") } else if keySize < minimumKeySize { @@ -163,7 +170,7 @@ func saveAuthorizedKeyFile(key *PublicKey) error { } // FIXME: following command does not support in Windows. - if runtime.GOOS != "windows" { + if !setting.IsWindows { if finfo.Mode().Perm() > 0600 { log.Error(4, "authorized_keys file has unusual permission flags: %s - setting to -rw-------", finfo.Mode().Perm().String()) if err = f.Chmod(0600); err != nil { diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 199b4f2c..d2c4d49c 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -10,6 +10,7 @@ import ( "os/exec" "path" "path/filepath" + "runtime" "strings" "time" @@ -98,12 +99,14 @@ var ( CustomPath string // Custom directory path. ProdMode bool RunUser string + IsWindows bool // I18n settings. Langs, Names []string ) func init() { + IsWindows = runtime.GOOS == "windows" log.NewLogger(0, "console", `{"level": 0}`) } -- cgit v1.2.3 From ed84adb679f3de70b2bffaead20a87711c38ee3a Mon Sep 17 00:00:00 2001 From: lunnyxiao Date: Wed, 17 Sep 2014 12:03:03 +0800 Subject: toutf8 improved & add max git diff lines --- conf/app.ini | 3 +++ models/git_diff.go | 34 ++++++++++++++++++++++------------ modules/base/template.go | 27 +++++++++++++++++++++++++++ modules/setting/setting.go | 3 +++ routers/repo/commit.go | 7 +++++-- routers/repo/view.go | 20 +------------------- templates/repo/diff.tmpl | 2 +- 7 files changed, 62 insertions(+), 34 deletions(-) (limited to 'models') diff --git a/conf/app.ini b/conf/app.ini index be49e064..cb907b22 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -255,3 +255,6 @@ CONN = [i18n] LANGS = en-US,zh-CN,de-DE NAMES = English,简体中文,Deutsch + +[git] +MAX_GITDIFF_LINES = 10000 \ No newline at end of file diff --git a/models/git_diff.go b/models/git_diff.go index bf7a9cd5..e093e7ab 100644 --- a/models/git_diff.go +++ b/models/git_diff.go @@ -70,7 +70,7 @@ func (diff *Diff) NumFiles() int { const DIFF_HEAD = "diff --git " -func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) { +func ParsePatch(pid int64, maxlines int, cmd *exec.Cmd, reader io.Reader) (*Diff, error) { scanner := bufio.NewScanner(reader) var ( curFile *DiffFile @@ -79,6 +79,7 @@ func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) { } leftLine, rightLine int + isTooLong bool ) diff := &Diff{Files: make([]*DiffFile, 0)} @@ -90,16 +91,17 @@ func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) { continue } + if line == "" { + continue + } + i = i + 1 - // Diff data too large. - if i == 5000 { + // Diff data too large, we only show the first about maxlines lines + if i == maxlines { + isTooLong = true log.Warn("Diff data too large") - return &Diff{}, nil - } - - if line == "" { - continue + //return &Diff{}, nil } switch { @@ -110,6 +112,10 @@ func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) { curSection.Lines = append(curSection.Lines, diffLine) continue case line[0] == '@': + if isTooLong { + return diff, nil + } + curSection = &DiffSection{} curFile.Sections = append(curFile.Sections, curSection) ss := strings.Split(line, "@@") @@ -143,6 +149,10 @@ func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) { // Get new file. if strings.HasPrefix(line, DIFF_HEAD) { + if isTooLong { + return diff, nil + } + fs := strings.Split(line[len(DIFF_HEAD):], " ") a := fs[0] @@ -174,7 +184,7 @@ func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) { return diff, nil } -func GetDiffRange(repoPath, beforeCommitId string, afterCommitId string) (*Diff, error) { +func GetDiffRange(repoPath, beforeCommitId string, afterCommitId string, maxlines int) (*Diff, error) { repo, err := git.OpenRepository(repoPath) if err != nil { return nil, err @@ -228,9 +238,9 @@ func GetDiffRange(repoPath, beforeCommitId string, afterCommitId string) (*Diff, } }() - return ParsePatch(pid, cmd, rd) + return ParsePatch(pid, maxlines, cmd, rd) } -func GetDiffCommit(repoPath, commitId string) (*Diff, error) { - return GetDiffRange(repoPath, "", commitId) +func GetDiffCommit(repoPath, commitId string, maxlines int) (*Diff, error) { + return GetDiffRange(repoPath, "", commitId, maxlines) } diff --git a/modules/base/template.go b/modules/base/template.go index f2ae00b9..64195729 100644 --- a/modules/base/template.go +++ b/modules/base/template.go @@ -8,13 +8,16 @@ import ( "bytes" "container/list" "encoding/json" + "errors" "fmt" "html/template" "runtime" "strings" "time" + "code.google.com/p/mahonia" "github.com/gogits/gogs/modules/setting" + "github.com/saintfish/chardet" ) func Str2html(raw string) template.HTML { @@ -45,6 +48,29 @@ func ShortSha(sha1 string) string { return sha1 } +func ToUtf8WithErr(content []byte) (error, string) { + detector := chardet.NewTextDetector() + result, err := detector.DetectBest(content) + if err != nil { + return err, "" + } + + if result.Charset == "utf8" { + return nil, string(content) + } + + decoder := mahonia.NewDecoder(result.Charset) + if decoder != nil { + return nil, decoder.ConvertString(string(content)) + } + return errors.New("unknow char decoder"), string(content) +} + +func ToUtf8(content string) string { + _, res := ToUtf8WithErr([]byte(content)) + return res +} + var mailDomains = map[string]string{ "gmail.com": "gmail.com", } @@ -103,6 +129,7 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{ "ActionContent2Commits": ActionContent2Commits, "Oauth2Icon": Oauth2Icon, "Oauth2Name": Oauth2Name, + "ToUtf8": ToUtf8, } type Actioner interface { diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 199b4f2c..011c00c0 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -64,6 +64,7 @@ var ( // Picture settings. PictureService string DisableGravatar bool + MaxGitDiffLines int // Log settings. LogRootPath string @@ -241,6 +242,8 @@ func NewConfigContext() { []string{"server"}) DisableGravatar = Cfg.MustBool("picture", "DISABLE_GRAVATAR") + MaxGitDiffLines = Cfg.MustInt("git", "MAX_GITDIFF_LINES", 5000) + Langs = Cfg.MustValueArray("i18n", "LANGS", ",") Names = Cfg.MustValueArray("i18n", "NAMES", ",") } diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 54acc85b..f7feb4d9 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -12,6 +12,7 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/middleware" + "github.com/gogits/gogs/modules/setting" ) const ( @@ -114,7 +115,8 @@ func Diff(ctx *middleware.Context) { commit := ctx.Repo.Commit - diff, err := models.GetDiffCommit(models.RepoPath(userName, repoName), commitId) + diff, err := models.GetDiffCommit(models.RepoPath(userName, repoName), + commitId, setting.MaxGitDiffLines) if err != nil { ctx.Handle(404, "GetDiffCommit", err) return @@ -176,7 +178,8 @@ func CompareDiff(ctx *middleware.Context) { return } - diff, err := models.GetDiffRange(models.RepoPath(userName, repoName), beforeCommitId, afterCommitId) + diff, err := models.GetDiffRange(models.RepoPath(userName, repoName), beforeCommitId, + afterCommitId, setting.MaxGitDiffLines) if err != nil { ctx.Handle(404, "GetDiffRange", err) return diff --git a/routers/repo/view.go b/routers/repo/view.go index f98eee03..e42894ae 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -11,12 +11,9 @@ import ( "path/filepath" "strings" - "github.com/saintfish/chardet" - "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/git" "github.com/gogits/gogs/modules/log" - "github.com/gogits/gogs/modules/mahonia" "github.com/gogits/gogs/modules/middleware" ) @@ -24,21 +21,6 @@ const ( HOME base.TplName = "repo/home" ) -func toUtf8(content []byte) (error, string) { - detector := chardet.NewTextDetector() - result, err := detector.DetectBest(content) - if err != nil { - return err, "" - } - - if result.Charset == "utf8" { - return nil, string(content) - } - - decoder := mahonia.NewDecoder(result.Charset) - return nil, decoder.ConvertString(string(content)) -} - func Home(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Repo.Repository.Name @@ -117,7 +99,7 @@ func Home(ctx *middleware.Context) { if readmeExist { ctx.Data["FileContent"] = string(base.RenderMarkdown(buf, "")) } else { - if err, content := toUtf8(buf); err != nil { + if err, content := base.ToUtf8WithErr(buf); err != nil { if err != nil { log.Error(4, "Convert content encoding: %s", err) } diff --git a/templates/repo/diff.tmpl b/templates/repo/diff.tmpl index 78733450..a2150f28 100644 --- a/templates/repo/diff.tmpl +++ b/templates/repo/diff.tmpl @@ -105,7 +105,7 @@ {{if .RightIdx}}{{.RightIdx}}{{end}} -
    {{.Content}}
    +
    {{ToUtf8 .Content}}
    {{end}} -- cgit v1.2.3 From f94d7c3f51969d300c3ee1ffdecd642363c207b4 Mon Sep 17 00:00:00 2001 From: Christopher Brickley Date: Wed, 17 Sep 2014 09:11:51 -0400 Subject: clarify name/username/owner/pusher for webhook --- models/action.go | 28 ++++++++++++++++++++++------ models/user.go | 8 ++++++++ models/webhook.go | 7 ++++--- 3 files changed, 34 insertions(+), 9 deletions(-) (limited to 'models') diff --git a/models/action.go b/models/action.go index 295a61cc..a6b22b16 100644 --- a/models/action.go +++ b/models/action.go @@ -243,15 +243,29 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, if !strings.HasPrefix(oldCommitId, "0000000") { compareUrl = fmt.Sprintf("%s/compare/%s...%s", repoLink, oldCommitId, newCommitId) } + + pusher_email, pusher_name := "", "" + pusher, err := GetUserByName(userName) + if err == nil { + pusher_email = pusher.Email + pusher_name = pusher.GetFullNameFallback() + } + commits := make([]*PayloadCommit, len(commit.Commits)) for i, cmt := range commit.Commits { + author_username := "" + author, err := GetUserByEmail(cmt.AuthorEmail) + if err == nil { + author_username = author.Name + } commits[i] = &PayloadCommit{ Id: cmt.Sha1, Message: cmt.Message, Url: fmt.Sprintf("%s/commit/%s", repoLink, cmt.Sha1), Author: &PayloadAuthor{ - Name: cmt.AuthorName, - Email: cmt.AuthorEmail, + Name: cmt.AuthorName, + Email: cmt.AuthorEmail, + UserName: author_username, }, } } @@ -266,14 +280,16 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, Website: repo.Website, Watchers: repo.NumWatches, Owner: &PayloadAuthor{ - Name: repoUserName, - Email: actEmail, + Name: repo.Owner.GetFullNameFallback(), + Email: repo.Owner.Email, + UserName: repo.Owner.Name, }, Private: repo.IsPrivate, }, Pusher: &PayloadAuthor{ - Name: repo.Owner.LowerName, - Email: repo.Owner.Email, + Name: pusher_name, + Email: pusher_email, + UserName: userName, }, Before: oldCommitId, After: newCommitId, diff --git a/models/user.go b/models/user.go index 96881ea3..b3ea8161 100644 --- a/models/user.go +++ b/models/user.go @@ -167,6 +167,14 @@ func (u *User) GetOrganizations() error { return nil } +// GetFullNameFallback returns Full Name if set, otherwise username +func (u *User) GetFullNameFallback() string { + if u.FullName == "" { + return u.Name + } + return u.FullName +} + // IsUserExist checks if given user name exist, // the user name should be noncased unique. func IsUserExist(name string) (bool, error) { diff --git a/models/webhook.go b/models/webhook.go index 3c07cc81..9508c98a 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -154,8 +154,9 @@ const ( ) type PayloadAuthor struct { - Name string `json:"name"` - Email string `json:"email"` + Name string `json:"name"` + Email string `json:"email"` + UserName string `json:"username"` } type PayloadCommit struct { @@ -172,7 +173,7 @@ type PayloadRepo struct { Description string `json:"description"` Website string `json:"website"` Watchers int `json:"watchers"` - Owner *PayloadAuthor `json:"author"` + Owner *PayloadAuthor `json:"owner"` Private bool `json:"private"` } -- cgit v1.2.3 From 8a09256941ab0e2ca81e98ac35081f6dc04bb22a Mon Sep 17 00:00:00 2001 From: Unknwon Date: Wed, 17 Sep 2014 14:22:51 -0400 Subject: Mirror fix and fix #481 --- README.md | 2 +- README_ZH.md | 2 +- conf/app.ini | 8 ++++---- gogs.go | 2 +- models/repo.go | 2 +- modules/base/template.go | 2 +- modules/setting/setting.go | 12 +++++++----- templates/.VERSION | 2 +- 8 files changed, 17 insertions(+), 15 deletions(-) (limited to 'models') diff --git a/README.md b/README.md index 43d75c26..08eed134 100644 --- a/README.md +++ b/README.md @@ -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 etc.) +- Multi-language support(English, Chinese, Germany, French etc.) ## System Requirements diff --git a/README_ZH.md b/README_ZH.md index bf6c1d03..4f59e001 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -35,7 +35,7 @@ Gogs 的目标是打造一个最简单、最快速和最轻松的方式搭建自 - Slack Web 钩子集成 - 支持 MySQL、PostgreSQL 以及 SQLite3 数据库 - 社交帐号登录(GitHub、Google、QQ、微博) -- 多语言支持(英文、简体中文、德语等等) +- 多语言支持(英文、简体中文、德语、法语等等) ## 系统要求 diff --git a/conf/app.ini b/conf/app.ini index 099e8052..ba73a0e8 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -252,9 +252,9 @@ DRIVER = ; Based on xorm, e.g.: root:root@localhost/gogs?charset=utf8 CONN = +[git] +MAX_GITDIFF_LINES = 10000 + [i18n] LANGS = en-US,zh-CN,de-DE,fr-CA -NAMES = English,简体中文,Deutsch,Français - -[git] -MAX_GITDIFF_LINES = 10000 \ No newline at end of file +NAMES = English,简体中文,Deutsch,Français \ No newline at end of file diff --git a/gogs.go b/gogs.go index 8ae7449e..c5249b25 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.2.0916 Beta" +const APP_VER = "0.5.2.0917 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/repo.go b/models/repo.go index 2e162704..ccfaae2c 100644 --- a/models/repo.go +++ b/models/repo.go @@ -656,7 +656,7 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) error { } // Check if new owner has repository with same name. - has, err := IsRepositoryExist(u, repo.Name) + has, err := IsRepositoryExist(newUser, repo.Name) if err != nil { return err } else if has { diff --git a/modules/base/template.go b/modules/base/template.go index 64195729..338fe677 100644 --- a/modules/base/template.go +++ b/modules/base/template.go @@ -14,8 +14,8 @@ import ( "runtime" "strings" "time" - "code.google.com/p/mahonia" + "github.com/gogits/gogs/modules/mahonia" "github.com/gogits/gogs/modules/setting" "github.com/saintfish/chardet" ) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index c56ad242..5fb1d52d 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -65,7 +65,6 @@ var ( // Picture settings. PictureService string DisableGravatar bool - MaxGitDiffLines int // Log settings. LogRootPath string @@ -94,6 +93,12 @@ var ( SessionProvider string SessionConfig *session.Config + // Git settings. + MaxGitDiffLines int + + // I18n settings. + Langs, Names []string + // Global setting objects. Cfg *goconfig.ConfigFile ConfRootPath string @@ -101,9 +106,6 @@ var ( ProdMode bool RunUser string IsWindows bool - - // I18n settings. - Langs, Names []string ) func init() { @@ -245,7 +247,7 @@ func NewConfigContext() { []string{"server"}) DisableGravatar = Cfg.MustBool("picture", "DISABLE_GRAVATAR") - MaxGitDiffLines = Cfg.MustInt("git", "MAX_GITDIFF_LINES", 5000) + MaxGitDiffLines = Cfg.MustInt("git", "MAX_GITDIFF_LINES", 10000) Langs = Cfg.MustValueArray("i18n", "LANGS", ",") Names = Cfg.MustValueArray("i18n", "NAMES", ",") diff --git a/templates/.VERSION b/templates/.VERSION index aada89d1..29de2fdf 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.2.0916 Beta \ No newline at end of file +0.5.2.0917 Beta \ No newline at end of file -- cgit v1.2.3 From 0055cbd3651ebde0f8b6cc70c9c44de56dc38830 Mon Sep 17 00:00:00 2001 From: Martin van Beurden Date: Sun, 14 Sep 2014 19:35:22 +0200 Subject: Allow Gogs to run from a suburl behind a reverse proxy. e.g. http://mydomain.com/gogs/ Conflicts: modules/setting/setting.go Conflicts: templates/repo/release/list.tmpl templates/user/dashboard/dashboard.tmpl Conflicts: routers/repo/setting.go --- conf/locale/locale_de-DE.ini | 8 ++++---- conf/locale/locale_en-US.ini | 8 ++++---- conf/locale/locale_zh-CN.ini | 8 ++++---- models/action.go | 2 +- models/user.go | 6 +++--- modules/base/markdown.go | 3 ++- modules/base/template.go | 31 ++++++++++++++++-------------- modules/middleware/auth.go | 8 ++++---- modules/middleware/context.go | 2 +- modules/middleware/org.go | 7 ++++--- modules/middleware/repo.go | 12 ++++++------ modules/setting/setting.go | 14 +++++++++++--- public/ng/js/gogs.js | 13 +++++++------ routers/admin/admin.go | 2 +- routers/admin/auths.go | 9 +++++---- routers/admin/users.go | 9 +++++---- routers/home.go | 2 +- routers/install.go | 2 +- routers/org/members.go | 3 ++- routers/org/org.go | 3 ++- routers/org/setting.go | 9 +++++---- routers/repo/commit.go | 4 ++-- routers/repo/issue.go | 6 +++--- routers/repo/repo.go | 5 +++-- routers/repo/setting.go | 16 +++++++-------- routers/user/auth.go | 12 ++++++------ routers/user/home.go | 7 ++++--- routers/user/setting.go | 19 +++++++++--------- routers/user/social.go | 4 ++-- templates/admin/auth/edit.tmpl | 2 +- templates/admin/auth/list.tmpl | 10 +++++----- templates/admin/auth/new.tmpl | 2 +- templates/admin/dashboard.tmpl | 4 ++-- templates/admin/nav.tmpl | 14 +++++++------- templates/admin/org/list.tmpl | 6 +++--- templates/admin/repo/list.tmpl | 8 ++++---- templates/admin/user/edit.tmpl | 2 +- templates/admin/user/list.tmpl | 10 +++++----- templates/admin/user/new.tmpl | 2 +- templates/base/head.tmpl | 26 ++++++++++++------------- templates/base/navbar.tmpl | 18 ++++++++--------- templates/explore/nav.tmpl | 2 +- templates/explore/repos.tmpl | 2 +- templates/home.tmpl | 4 ++-- templates/install.tmpl | 2 +- templates/ng/base/head.tmpl | 22 ++++++++++----------- templates/ng/base/header.tmpl | 26 ++++++++++++------------- templates/ng/base/social.tmpl | 8 ++++---- templates/org/base/header.tmpl | 2 +- templates/org/create.tmpl | 4 ++-- templates/org/home.tmpl | 16 +++++++-------- templates/org/member/members.tmpl | 2 +- templates/org/new.tmpl | 4 ++-- templates/org/settings/delete.tmpl | 2 +- templates/org/settings/nav.tmpl | 6 +++--- templates/org/settings/options.tmpl | 2 +- templates/org/team/members.tmpl | 2 +- templates/org/team/repositories.tmpl | 2 +- templates/org/team/teams.tmpl | 2 +- templates/repo/bare.tmpl | 2 +- templates/repo/commits_table.tmpl | 4 ++-- templates/repo/create.tmpl | 4 ++-- templates/repo/diff.tmpl | 2 +- templates/repo/header.tmpl | 2 +- templates/repo/issue/list.tmpl | 2 +- templates/repo/issue/view.tmpl | 26 ++++++++++++------------- templates/repo/migrate.tmpl | 4 ++-- templates/repo/nav.tmpl | 6 +++--- templates/repo/release/list.tmpl | 4 ++-- templates/repo/setting_nav.tmpl | 6 +++--- templates/repo/settings/collaboration.tmpl | 2 +- templates/repo/single.tmpl | 2 +- templates/repo/single_list.tmpl | 6 +++--- templates/repo/view_list.tmpl | 4 ++-- templates/status/404.tmpl | 2 +- templates/status/500.tmpl | 2 +- templates/user/auth/activate.tmpl | 2 +- templates/user/auth/forgot_passwd.tmpl | 2 +- templates/user/auth/reset_passwd.tmpl | 2 +- templates/user/auth/signin.tmpl | 6 +++--- templates/user/auth/signup.tmpl | 4 ++-- templates/user/dashboard/dashboard.tmpl | 24 +++++++++++------------ templates/user/dashboard/nav.tmpl | 6 +++--- templates/user/issues.tmpl | 24 +++++++++++------------ templates/user/profile.tmpl | 2 +- templates/user/settings/delete.tmpl | 2 +- templates/user/settings/nav.tmpl | 10 +++++----- templates/user/settings/password.tmpl | 2 +- templates/user/settings/profile.tmpl | 2 +- templates/user/settings/social.tmpl | 2 +- templates/user/settings/sshkeys.tmpl | 4 ++-- 91 files changed, 322 insertions(+), 300 deletions(-) (limited to 'models') diff --git a/conf/locale/locale_de-DE.ini b/conf/locale/locale_de-DE.ini index d8060f0b..20f27e18 100644 --- a/conf/locale/locale_de-DE.ini +++ b/conf/locale/locale_de-DE.ini @@ -490,10 +490,10 @@ monitor.start = Startzeit monitor.execute_time = Ausführungszeit [action] -create_repo = Repository erstellen %s -commit_repo = pushed to %s at %s -create_issue = opened issue %s#%s -comment_issue = commented on issue %s#%s +create_repo = Repository erstellen %s +commit_repo = pushed to %s at %s +create_issue = opened issue %s#%s +comment_issue = commented on issue %s#%s [tool] ago = vor diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index 75ea7fcc..50422bd2 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -541,10 +541,10 @@ monitor.start = Start Time monitor.execute_time = Execution Time [action] -create_repo = created repository %s -commit_repo = pushed to %s at %s -create_issue = opened issue %s#%s -comment_issue = commented on issue %s#%s +create_repo = created repository %s +commit_repo = pushed to %s at %s +create_issue = opened issue %s#%s +comment_issue = commented on issue %s#%s [tool] ago = ago diff --git a/conf/locale/locale_zh-CN.ini b/conf/locale/locale_zh-CN.ini index 606e4c98..f26d46fc 100644 --- a/conf/locale/locale_zh-CN.ini +++ b/conf/locale/locale_zh-CN.ini @@ -539,10 +539,10 @@ monitor.start = 开始时间 monitor.execute_time = 已执行时间 [action] -create_repo = 创建了仓库 %s -commit_repo = 推送了 %s 分支的代码到 %s -create_issue = 创建了工单 %s#%s -comment_issue = 评论了工单 %s#%s +create_repo = 创建了仓库 %s +commit_repo = 推送了 %s 分支的代码到 %s +create_issue = 创建了工单 %s#%s +comment_issue = 评论了工单 %s#%s [tool] ago = 之前 diff --git a/models/action.go b/models/action.go index a6b22b16..596f51af 100644 --- a/models/action.go +++ b/models/action.go @@ -137,7 +137,7 @@ func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, com return err } - url := fmt.Sprintf("/%s/%s/commit/%s", repoUserName, repoName, c.Sha1) + url := fmt.Sprintf("%s/%s/%s/commit/%s", setting.AppRootSubUrl, repoUserName, repoName, c.Sha1) message := fmt.Sprintf(`%s`, url, c.Message) if _, err = CreateComment(userId, issue.RepoId, issue.Id, 0, 0, COMMIT, message, nil); err != nil { diff --git a/models/user.go b/models/user.go index b3ea8161..1bed8109 100644 --- a/models/user.go +++ b/models/user.go @@ -82,14 +82,14 @@ type User struct { // DashboardLink returns the user dashboard page link. func (u *User) DashboardLink() string { if u.IsOrganization() { - return "/org/" + u.Name + "/dashboard/" + return setting.AppRootSubUrl + "/org/" + u.Name + "/dashboard/" } - return "/" + return setting.AppRootSubUrl + "/" } // HomeLink returns the user home page link. func (u *User) HomeLink() string { - return "/user/" + u.Name + return setting.AppRootSubUrl + "/user/" + u.Name } // AvatarLink returns user gravatar link. diff --git a/modules/base/markdown.go b/modules/base/markdown.go index b8bd33e1..2aa81005 100644 --- a/modules/base/markdown.go +++ b/modules/base/markdown.go @@ -14,6 +14,7 @@ import ( "strings" "github.com/gogits/gfm" + "github.com/gogits/gogs/modules/setting" ) func isletter(c byte) bool { @@ -112,7 +113,7 @@ func RenderSpecialLink(rawBytes []byte, urlPrefix string) []byte { ms := MentionPattern.FindAll(line, -1) for _, m := range ms { line = bytes.Replace(line, m, - []byte(fmt.Sprintf(`%s`, m[1:], m)), -1) + []byte(fmt.Sprintf(`%s`, setting.AppRootSubUrl, m[1:], m)), -1) } } diff --git a/modules/base/template.go b/modules/base/template.go index 338fe677..dd883ea3 100644 --- a/modules/base/template.go +++ b/modules/base/template.go @@ -82,6 +82,9 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{ "AppName": func() string { return setting.AppName }, + "AppRootSubUrl": func() string { + return setting.AppRootSubUrl + }, "AppVer": func() string { return setting.AppVer }, @@ -163,14 +166,14 @@ func ActionIcon(opType int) string { // TODO: Legacy const ( - TPL_CREATE_REPO = `%s created repository %s` - TPL_COMMIT_REPO = `%s pushed to %s at %s%s` - TPL_COMMIT_REPO_LI = `
    user-avatar %s %s
    ` - TPL_CREATE_ISSUE = `%s opened issue %s#%s + TPL_CREATE_REPO = `%s created repository %s` + TPL_COMMIT_REPO = `%s pushed to %s at %s%s` + TPL_COMMIT_REPO_LI = `
    user-avatar %s %s
    ` + TPL_CREATE_ISSUE = `%s opened issue %s#%s
    user-avatar %s
    ` - TPL_TRANSFER_REPO = `%s transfered repository %s to %s` - TPL_PUSH_TAG = `%s pushed tag %s at %s` - TPL_COMMENT_ISSUE = `%s commented on issue %s#%s + TPL_TRANSFER_REPO = `%s transfered repository %s to %s` + TPL_PUSH_TAG = `%s pushed tag %s at %s` + TPL_COMMENT_ISSUE = `%s commented on issue %s#%s
    user-avatar %s
    ` ) @@ -207,7 +210,7 @@ func ActionDesc(act Actioner) string { content := act.GetContent() switch act.GetOpType() { case 1: // Create repository. - return fmt.Sprintf(TPL_CREATE_REPO, actUserName, actUserName, repoLink, repoName) + return fmt.Sprintf(TPL_CREATE_REPO, setting.AppRootSubUrl, actUserName, actUserName, repoLink, repoName) case 5: // Commit repository. var push *PushCommits if err := json.Unmarshal([]byte(content), &push); err != nil { @@ -218,22 +221,22 @@ func ActionDesc(act Actioner) string { buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, AvatarLink(commit.AuthorEmail), repoLink, commit.Sha1, commit.Sha1[:7], commit.Message) + "\n") } if push.Len > 3 { - buf.WriteString(fmt.Sprintf(``, actUserName, repoName, branch, push.Len)) + buf.WriteString(fmt.Sprintf(``, actUserName, repoName, branch, push.Len)) } - return fmt.Sprintf(TPL_COMMIT_REPO, actUserName, actUserName, repoLink, branch, branch, repoLink, repoLink, + return fmt.Sprintf(TPL_COMMIT_REPO, setting.AppRootSubUrl, actUserName, actUserName, repoLink, branch, branch, repoLink, repoLink, buf.String()) case 6: // Create issue. infos := strings.SplitN(content, "|", 2) - return fmt.Sprintf(TPL_CREATE_ISSUE, actUserName, actUserName, repoLink, infos[0], repoLink, infos[0], + return fmt.Sprintf(TPL_CREATE_ISSUE, setting.AppRootSubUrl, actUserName, actUserName, repoLink, infos[0], repoLink, infos[0], AvatarLink(email), infos[1]) case 8: // Transfer repository. newRepoLink := content + "/" + repoName - return fmt.Sprintf(TPL_TRANSFER_REPO, actUserName, actUserName, repoLink, newRepoLink, newRepoLink) + return fmt.Sprintf(TPL_TRANSFER_REPO, setting.AppRootSubUrl, actUserName, actUserName, repoLink, newRepoLink, newRepoLink) case 9: // Push tag. - return fmt.Sprintf(TPL_PUSH_TAG, actUserName, actUserName, repoLink, branch, branch, repoLink, repoLink) + return fmt.Sprintf(TPL_PUSH_TAG, setting.AppRootSubUrl, actUserName, actUserName, repoLink, branch, branch, repoLink, repoLink) case 10: // Comment issue. infos := strings.SplitN(content, "|", 2) - return fmt.Sprintf(TPL_COMMENT_ISSUE, actUserName, actUserName, repoLink, infos[0], repoLink, infos[0], + return fmt.Sprintf(TPL_COMMENT_ISSUE, setting.AppRootSubUrl, actUserName, actUserName, repoLink, infos[0], repoLink, infos[0], AvatarLink(email), infos[1]) default: return "invalid type" diff --git a/modules/middleware/auth.go b/modules/middleware/auth.go index 51ce48c6..ccd8d031 100644 --- a/modules/middleware/auth.go +++ b/modules/middleware/auth.go @@ -25,13 +25,13 @@ func Toggle(options *ToggleOptions) macaron.Handler { return func(ctx *Context) { // Cannot view any page before installation. if !setting.InstallLock { - ctx.Redirect("/install") + ctx.Redirect(setting.AppRootSubUrl + "/install") return } // Redirect to dashboard if user tries to visit any non-login page. if options.SignOutRequire && ctx.IsSigned && ctx.Req.RequestURI != "/" { - ctx.Redirect("/") + ctx.Redirect(setting.AppRootSubUrl + "/") return } @@ -48,8 +48,8 @@ func Toggle(options *ToggleOptions) macaron.Handler { if strings.HasSuffix(ctx.Req.RequestURI, "watch") { return } - ctx.SetCookie("redirect_to", "/"+url.QueryEscape(ctx.Req.RequestURI)) - ctx.Redirect("/user/login") + ctx.SetCookie("redirect_to", "/"+url.QueryEscape(setting.AppRootSubUrl + ctx.Req.RequestURI)) + ctx.Redirect(setting.AppRootSubUrl + "/user/login") return } else if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm { ctx.Data["Title"] = ctx.Tr("auth.active_your_account") diff --git a/modules/middleware/context.go b/modules/middleware/context.go index 3ef1b1d6..5c26f91f 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -187,7 +187,7 @@ func Contexter() macaron.Handler { Session: sess, } // Compute current URL for real-time change language. - link := ctx.Req.RequestURI + link := setting.AppRootSubUrl + ctx.Req.RequestURI i := strings.Index(link, "?") if i > -1 { link = link[:i] diff --git a/modules/middleware/org.go b/modules/middleware/org.go index 7bb24ab7..3a2cf7bc 100644 --- a/modules/middleware/org.go +++ b/modules/middleware/org.go @@ -9,6 +9,7 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/log" + "github.com/gogits/gogs/modules/setting" ) func OrgAssignment(redirect bool, args ...bool) macaron.Handler { @@ -37,7 +38,7 @@ func OrgAssignment(redirect bool, args ...bool) macaron.Handler { ctx.Handle(404, "GetUserByName", err) } else if redirect { log.Error(4, "GetUserByName", err) - ctx.Redirect("/") + ctx.Redirect(setting.AppRootSubUrl + "/") } else { ctx.Handle(500, "GetUserByName", err) } @@ -67,7 +68,7 @@ func OrgAssignment(redirect bool, args ...bool) macaron.Handler { } ctx.Data["IsOrganizationOwner"] = ctx.Org.IsOwner - ctx.Org.OrgLink = "/org/" + org.Name + ctx.Org.OrgLink = setting.AppRootSubUrl + "/org/" + org.Name ctx.Data["OrgLink"] = ctx.Org.OrgLink // Team. @@ -79,7 +80,7 @@ func OrgAssignment(redirect bool, args ...bool) macaron.Handler { ctx.Handle(404, "GetTeam", err) } else if redirect { log.Error(4, "GetTeam", err) - ctx.Redirect("/") + ctx.Redirect(setting.AppRootSubUrl + "/") } else { ctx.Handle(500, "GetTeam", err) } diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index 82ef3c79..e7d7fb56 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -60,7 +60,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { ctx.Handle(404, "GetUserByName", err) } else if redirect { log.Error(4, "GetUserByName", err) - ctx.Redirect("/") + ctx.Redirect(setting.AppRootSubUrl + "/") } else { ctx.Handle(500, "GetUserByName", err) } @@ -72,7 +72,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { if u == nil { if redirect { - ctx.Redirect("/") + ctx.Redirect(setting.AppRootSubUrl + "/") return } ctx.Handle(404, "RepoAssignment", errors.New("invliad user account for single repository")) @@ -92,7 +92,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { ctx.Handle(404, "GetRepositoryByName", err) return } else if redirect { - ctx.Redirect("/") + ctx.Redirect(setting.AppRootSubUrl + "/") return } ctx.Handle(500, "GetRepositoryByName", err) @@ -160,7 +160,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { return } ctx.Repo.GitRepo = gitRepo - ctx.Repo.RepoLink = "/" + u.Name + "/" + repo.Name + ctx.Repo.RepoLink = setting.AppRootSubUrl + "/" + u.Name + "/" + repo.Name ctx.Data["RepoLink"] = ctx.Repo.RepoLink tags, err := ctx.Repo.GitRepo.GetTags() @@ -298,8 +298,8 @@ func RequireTrueOwner() macaron.Handler { return func(ctx *Context) { if !ctx.Repo.IsTrueOwner && !ctx.Repo.IsAdmin { if !ctx.IsSigned { - ctx.SetCookie("redirect_to", "/"+url.QueryEscape(ctx.Req.RequestURI)) - ctx.Redirect("/user/login") + ctx.SetCookie("redirect_to", "/"+url.QueryEscape(setting.AppRootSubUrl + ctx.Req.RequestURI)) + ctx.Redirect(setting.AppRootSubUrl + "/user/login") return } ctx.Handle(404, ctx.Req.RequestURI, nil) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 5fb1d52d..74427744 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -6,6 +6,7 @@ package setting import ( "fmt" + "net/url" "os" "os/exec" "path" @@ -31,9 +32,10 @@ const ( var ( // App settings. - AppVer string - AppName string - AppUrl string + AppVer string + AppName string + AppUrl string + AppRootSubUrl string // Server settings. Protocol Scheme @@ -165,6 +167,12 @@ func NewConfigContext() { AppUrl += "/" } + url, err := url.Parse(AppUrl) + if err != nil { + log.Fatal(4, "Invalid ROOT_URL %s: %s", AppUrl, err) + } + AppRootSubUrl = strings.TrimSuffix(url.Path, "/") + Protocol = HTTP if Cfg.MustValue("server", "PROTOCOL") == "https" { Protocol = HTTPS diff --git a/public/ng/js/gogs.js b/public/ng/js/gogs.js index 74bb6cc2..fcc470e9 100644 --- a/public/ng/js/gogs.js +++ b/public/ng/js/gogs.js @@ -202,7 +202,7 @@ var Gogs = {}; // Search users by keyword. Gogs.searchUsers = function (val, $target) { $.ajax({ - url: '/api/v1/users/search?q=' + val, + url: Gogs.AppRootSubUrl + '/api/v1/users/search?q=' + val, dataType: "json", success: function (json) { if (json.ok && json.data.length) { @@ -222,7 +222,7 @@ var Gogs = {}; // Search repositories by keyword. Gogs.searchRepos = function (val, $target, $param) { $.ajax({ - url: '/api/v1/repos/search?q=' + val + '&' + $param, + url: Gogs.AppRootSubUrl + '/api/v1/repos/search?q=' + val + '&' + $param, dataType: "json", success: function (json) { if (json.ok && json.data.length) { @@ -245,7 +245,7 @@ var Gogs = {}; return; } $(selector).zclip({ - path: "/js/ZeroClipboard.swf", + path: Gogs.AppRootSubUrl + "/js/ZeroClipboard.swf", copy: function () { var t = $(this).data("copy-val"); var to = $($(this).data("copy-from")); @@ -592,6 +592,7 @@ function initInstall() { } $(document).ready(function () { + Gogs.AppRootSubUrl = $('head').data('suburl'); initCore(); if ($('#user-profile-setting').length) { initUserSetting(); @@ -644,7 +645,7 @@ function homepage() { $('#promo-form').submit(function (e) { if ($('#username').val() === "") { e.preventDefault(); - window.location.href = '/user/login'; + window.location.href = Gogs.AppRootSubUrl + '/user/login'; return true } }); @@ -652,9 +653,9 @@ function homepage() { $('#register-button').click(function (e) { if ($('#username').val() === "") { e.preventDefault(); - window.location.href = '/user/sign_up'; + window.location.href = Gogs.AppRootSubUrl + '/user/sign_up'; return true } - $('#promo-form').attr('action', '/user/sign_up'); + $('#promo-form').attr('action', Gogs.AppRootSubUrl + '/user/sign_up'); }); } diff --git a/routers/admin/admin.go b/routers/admin/admin.go index 756d76c0..1fee7adb 100644 --- a/routers/admin/admin.go +++ b/routers/admin/admin.go @@ -143,7 +143,7 @@ func Dashboard(ctx *middleware.Context) { } else { ctx.Flash.Success(success) } - ctx.Redirect("/admin") + ctx.Redirect(setting.AppRootSubUrl + "/admin") return } diff --git a/routers/admin/auths.go b/routers/admin/auths.go index 6fbeab35..9eaae489 100644 --- a/routers/admin/auths.go +++ b/routers/admin/auths.go @@ -14,6 +14,7 @@ import ( "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware" + "github.com/gogits/gogs/modules/setting" ) const ( @@ -99,7 +100,7 @@ func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) { } log.Trace("Authentication created by admin(%s): %s", ctx.User.Name, form.AuthName) - ctx.Redirect("/admin/auths") + ctx.Redirect(setting.AppRootSubUrl + "/admin/auths") } func EditAuthSource(ctx *middleware.Context) { @@ -180,7 +181,7 @@ func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) { log.Trace("Authentication changed by admin(%s): %s", ctx.User.Name, form.AuthName) ctx.Flash.Success(ctx.Tr("admin.auths.update_success")) - ctx.Redirect("/admin/auths/" + ctx.Params(":authid")) + ctx.Redirect(setting.AppRootSubUrl + "/admin/auths/" + ctx.Params(":authid")) } func DeleteAuthSource(ctx *middleware.Context) { @@ -200,12 +201,12 @@ func DeleteAuthSource(ctx *middleware.Context) { switch err { case models.ErrAuthenticationUserUsed: ctx.Flash.Error("form.still_own_user") - ctx.Redirect("/admin/auths/" + ctx.Params(":authid")) + ctx.Redirect(setting.AppRootSubUrl + "/admin/auths/" + ctx.Params(":authid")) default: ctx.Handle(500, "DelLoginSource", err) } return } log.Trace("Authentication deleted by admin(%s): %s", ctx.User.Name, a.Name) - ctx.Redirect("/admin/auths") + ctx.Redirect(setting.AppRootSubUrl + "/admin/auths") } diff --git a/routers/admin/users.go b/routers/admin/users.go index 3f14e48f..5cdb0f5c 100644 --- a/routers/admin/users.go +++ b/routers/admin/users.go @@ -14,6 +14,7 @@ import ( "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware" + "github.com/gogits/gogs/modules/setting" ) const ( @@ -120,7 +121,7 @@ func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) { return } log.Trace("Account created by admin(%s): %s", ctx.User.Name, u.Name) - ctx.Redirect("/admin/users") + ctx.Redirect(setting.AppRootSubUrl + "/admin/users") } func EditUser(ctx *middleware.Context) { @@ -197,7 +198,7 @@ func EditUserPost(ctx *middleware.Context, form auth.AdminEditUserForm) { ctx.Data["User"] = u ctx.Flash.Success(ctx.Tr("admin.users.update_profile_success")) - ctx.Redirect("/admin/users/" + ctx.Params(":userid")) + ctx.Redirect(setting.AppRootSubUrl + "/admin/users/" + ctx.Params(":userid")) } func DeleteUser(ctx *middleware.Context) { @@ -217,12 +218,12 @@ func DeleteUser(ctx *middleware.Context) { switch err { case models.ErrUserOwnRepos: ctx.Flash.Error(ctx.Tr("admin.users.still_own_repo")) - ctx.Redirect("/admin/users/" + ctx.Params(":userid")) + ctx.Redirect(setting.AppRootSubUrl + "/admin/users/" + ctx.Params(":userid")) default: ctx.Handle(500, "DeleteUser", err) } return } log.Trace("Account deleted by admin(%s): %s", ctx.User.Name, u.Name) - ctx.Redirect("/admin/users") + ctx.Redirect(setting.AppRootSubUrl + "/admin/users") } diff --git a/routers/home.go b/routers/home.go index 36a4f50f..8e973d16 100644 --- a/routers/home.go +++ b/routers/home.go @@ -33,7 +33,7 @@ func Home(ctx *middleware.Context) { // Check auto-login. uname := ctx.GetCookie(setting.CookieUserName) if len(uname) != 0 { - ctx.Redirect("/user/login") + ctx.Redirect(setting.AppRootSubUrl + "/user/login") return } diff --git a/routers/install.go b/routers/install.go index 26409814..54da4d4f 100644 --- a/routers/install.go +++ b/routers/install.go @@ -253,5 +253,5 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) { log.Info("First-time run install finished!") ctx.Flash.Success(ctx.Tr("install.install_success")) - ctx.Redirect("/user/login") + ctx.Redirect(setting.AppRootSubUrl + "/user/login") } diff --git a/routers/org/members.go b/routers/org/members.go index 823daec9..d3bd51ea 100644 --- a/routers/org/members.go +++ b/routers/org/members.go @@ -11,6 +11,7 @@ import ( "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware" + "github.com/gogits/gogs/modules/setting" ) const ( @@ -86,7 +87,7 @@ func MembersAction(ctx *middleware.Context) { if ctx.Params(":action") != "leave" { ctx.Redirect(ctx.Org.OrgLink + "/members") } else { - ctx.Redirect("/") + ctx.Redirect(setting.AppRootSubUrl + "/") } } diff --git a/routers/org/org.go b/routers/org/org.go index 27ccf02d..cea70823 100644 --- a/routers/org/org.go +++ b/routers/org/org.go @@ -10,6 +10,7 @@ import ( "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware" + "github.com/gogits/gogs/modules/setting" ) const ( @@ -82,5 +83,5 @@ func CreatePost(ctx *middleware.Context, form auth.CreateOrgForm) { } log.Trace("Organization created: %s", org.Name) - ctx.Redirect("/org/" + form.OrgName + "/dashboard") + ctx.Redirect(setting.AppRootSubUrl + "/org/" + form.OrgName + "/dashboard") } diff --git a/routers/org/setting.go b/routers/org/setting.go index f853ef0e..3d397c0c 100644 --- a/routers/org/setting.go +++ b/routers/org/setting.go @@ -11,6 +11,7 @@ import ( "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware" + "github.com/gogits/gogs/modules/setting" ) const ( @@ -48,7 +49,7 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateOrgSettingForm) { } else if err = models.ChangeUserName(org, form.OrgUserName); err != nil { if err == models.ErrUserNameIllegal { ctx.Flash.Error(ctx.Tr("form.illegal_username")) - ctx.Redirect("/org/" + org.LowerName + "/settings") + ctx.Redirect(setting.AppRootSubUrl + "/org/" + org.LowerName + "/settings") return } else { ctx.Handle(500, "ChangeUserName", err) @@ -72,7 +73,7 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateOrgSettingForm) { } log.Trace("Organization setting updated: %s", org.Name) ctx.Flash.Success(ctx.Tr("org.settings.update_setting_success")) - ctx.Redirect("/org/" + org.Name + "/settings") + ctx.Redirect(setting.AppRootSubUrl + "/org/" + org.Name + "/settings") } func SettingsDelete(ctx *middleware.Context) { @@ -86,13 +87,13 @@ func SettingsDelete(ctx *middleware.Context) { switch err { case models.ErrUserOwnRepos: ctx.Flash.Error(ctx.Tr("form.org_still_own_repo")) - ctx.Redirect("/org/" + org.LowerName + "/settings/delete") + ctx.Redirect(setting.AppRootSubUrl + "/org/" + org.LowerName + "/settings/delete") default: ctx.Handle(500, "DeleteOrganization", err) } } else { log.Trace("Organization deleted: %s", ctx.User.Name) - ctx.Redirect("/") + ctx.Redirect(setting.AppRootSubUrl + "/") } return } diff --git a/routers/repo/commit.go b/routers/repo/commit.go index f7feb4d9..e58b9e78 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -159,8 +159,8 @@ func Diff(ctx *middleware.Context) { ctx.Data["Diff"] = diff ctx.Data["Parents"] = parents ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0 - ctx.Data["SourcePath"] = "/" + path.Join(userName, repoName, "src", commitId) - ctx.Data["RawPath"] = "/" + path.Join(userName, repoName, "raw", commitId) + ctx.Data["SourcePath"] = setting.AppRootSubUrl + "/" + path.Join(userName, repoName, "src", commitId) + ctx.Data["RawPath"] = setting.AppRootSubUrl + "/" + path.Join(userName, repoName, "raw", commitId) ctx.HTML(200, DIFF) } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 934cf3c9..8aba82ff 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -54,8 +54,8 @@ func Issues(ctx *middleware.Context) { isShowClosed := ctx.Query("state") == "closed" if viewType != "all" && !ctx.IsSigned { - ctx.SetCookie("redirect_to", "/"+url.QueryEscape(ctx.Req.RequestURI)) - ctx.Redirect("/user/login") + ctx.SetCookie("redirect_to", "/"+url.QueryEscape(setting.AppRootSubUrl + ctx.Req.RequestURI)) + ctx.Redirect(setting.AppRootSubUrl + "/user/login") return } @@ -312,7 +312,7 @@ func CreateIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) { } log.Trace("%d Issue created: %d", ctx.Repo.Repository.Id, issue.Id) - send(200, fmt.Sprintf("/%s/%s/issues/%d", ctx.Params(":username"), ctx.Params(":reponame"), issue.Index), nil) + send(200, fmt.Sprintf("%s/%s/%s/issues/%d", setting.AppRootSubUrl, ctx.Params(":username"), ctx.Params(":reponame"), issue.Index), nil) } func checkLabels(labels, allLabels []*models.Label) { diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 17f20a0a..3bd9aa7c 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -18,6 +18,7 @@ import ( "github.com/gogits/gogs/modules/git" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware" + "github.com/gogits/gogs/modules/setting" ) const ( @@ -95,7 +96,7 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { form.Gitignore, form.License, form.Private, false, form.InitReadme) if err == nil { log.Trace("Repository created: %s/%s", ctxUser.Name, form.RepoName) - ctx.Redirect("/" + ctxUser.Name + "/" + form.RepoName) + ctx.Redirect(setting.AppRootSubUrl + "/" + ctxUser.Name + "/" + form.RepoName) return } else if err == models.ErrRepoAlreadyExist { ctx.Data["Err_RepoName"] = true @@ -179,7 +180,7 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { form.Mirror, url) if err == nil { log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName) - ctx.Redirect("/" + ctxUser.Name + "/" + form.RepoName) + ctx.Redirect(setting.AppRootSubUrl + "/" + ctxUser.Name + "/" + form.RepoName) return } else if err == models.ErrRepoAlreadyExist { ctx.Data["Err_RepoName"] = true diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 62f2dbf5..926b5432 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -97,7 +97,7 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) { } ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success")) - ctx.Redirect(fmt.Sprintf("/%s/%s/settings", ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)) + ctx.Redirect(fmt.Sprintf("%s/%s/%s/settings", setting.AppRootSubUrl, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)) case "transfer": if ctx.Repo.Repository.Name != form.RepoName { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), SETTINGS_OPTIONS, nil) @@ -122,7 +122,7 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) { } log.Trace("Repository transfered: %s/%s -> %s", ctx.Repo.Owner.Name, ctx.Repo.Repository.Name, newOwner) ctx.Flash.Success(ctx.Tr("repo.settings.transfer_succeed")) - ctx.Redirect("/") + ctx.Redirect(setting.AppRootSubUrl + "/") case "delete": if ctx.Repo.Repository.Name != form.RepoName { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), SETTINGS_OPTIONS, nil) @@ -151,9 +151,9 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) { } log.Trace("Repository deleted: %s/%s", ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) if ctx.Repo.Owner.IsOrganization() { - ctx.Redirect("/org/" + ctx.Repo.Owner.Name + "/dashboard") + ctx.Redirect(setting.AppRootSubUrl + "/org/" + ctx.Repo.Owner.Name + "/dashboard") } else { - ctx.Redirect("/") + ctx.Redirect(setting.AppRootSubUrl + "/") } } } @@ -167,7 +167,7 @@ func SettingsCollaboration(ctx *middleware.Context) { if ctx.Req.Method == "POST" { name := strings.ToLower(ctx.Query("collaborator")) if len(name) == 0 || ctx.Repo.Owner.LowerName == name { - ctx.Redirect(ctx.Req.URL.Path) + ctx.Redirect(setting.AppRootSubUrl + ctx.Req.URL.Path) return } has, err := models.HasAccess(name, repoLink, models.WRITABLE) @@ -175,7 +175,7 @@ func SettingsCollaboration(ctx *middleware.Context) { ctx.Handle(500, "HasAccess", err) return } else if has { - ctx.Redirect(ctx.Req.URL.Path) + ctx.Redirect(setting.AppRootSubUrl + ctx.Req.URL.Path) return } @@ -183,7 +183,7 @@ func SettingsCollaboration(ctx *middleware.Context) { if err != nil { if err == models.ErrUserNotExist { ctx.Flash.Error(ctx.Tr("form.user_not_exist")) - ctx.Redirect(ctx.Req.URL.Path) + ctx.Redirect(setting.AppRootSubUrl + ctx.Req.URL.Path) } else { ctx.Handle(500, "GetUserByName", err) } @@ -204,7 +204,7 @@ func SettingsCollaboration(ctx *middleware.Context) { } ctx.Flash.Success(ctx.Tr("repo.settings.add_collaborator_success")) - ctx.Redirect(ctx.Req.URL.Path) + ctx.Redirect(setting.AppRootSubUrl + ctx.Req.URL.Path) return } diff --git a/routers/user/auth.go b/routers/user/auth.go index e3d13216..1dbc3300 100644 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -82,7 +82,7 @@ func SignIn(ctx *middleware.Context) { return } - ctx.Redirect("/") + ctx.Redirect(setting.AppRootSubUrl + "/") } func SignInPost(ctx *middleware.Context, form auth.SignInForm) { @@ -140,7 +140,7 @@ func SignInPost(ctx *middleware.Context, form auth.SignInForm) { return } - ctx.Redirect("/") + ctx.Redirect(setting.AppRootSubUrl + "/") } func SignOut(ctx *middleware.Context) { @@ -151,7 +151,7 @@ func SignOut(ctx *middleware.Context) { ctx.Session.Delete("socialEmail") ctx.SetCookie(setting.CookieUserName, "", -1) ctx.SetCookie(setting.CookieRememberName, "", -1) - ctx.Redirect("/") + ctx.Redirect(setting.AppRootSubUrl + "/") } func oauthSignUp(ctx *middleware.Context, sid int64) { @@ -288,7 +288,7 @@ func SignUpPost(ctx *middleware.Context, cpt *captcha.Captcha, form auth.Registe return } - ctx.Redirect("/user/login") + ctx.Redirect(setting.AppRootSubUrl + "/user/login") } func Activate(ctx *middleware.Context) { @@ -335,7 +335,7 @@ func Activate(ctx *middleware.Context) { ctx.Session.Set("uid", user.Id) ctx.Session.Set("uname", user.Name) - ctx.Redirect("/") + ctx.Redirect(setting.AppRootSubUrl + "/") return } @@ -437,7 +437,7 @@ func ResetPasswdPost(ctx *middleware.Context) { } log.Trace("User password reset: %s", u.Name) - ctx.Redirect("/user/login") + ctx.Redirect(setting.AppRootSubUrl + "/user/login") return } diff --git a/routers/user/home.go b/routers/user/home.go index 372f111a..b411b8fc 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -13,6 +13,7 @@ import ( "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware" + "github.com/gogits/gogs/modules/setting" ) const ( @@ -126,7 +127,7 @@ func Profile(ctx *middleware.Context) { uname := ctx.Params(":username") // Special handle for FireFox requests favicon.ico. if uname == "favicon.ico" { - ctx.Redirect("/img/favicon.png") + ctx.Redirect(setting.AppRootSubUrl + "/img/favicon.png") return } @@ -141,7 +142,7 @@ func Profile(ctx *middleware.Context) { } if u.IsOrganization() { - ctx.Redirect("/org/" + u.Name) + ctx.Redirect(setting.AppRootSubUrl + "/org/" + u.Name) return } @@ -181,7 +182,7 @@ func Email2User(ctx *middleware.Context) { } return } - ctx.Redirect("/user/" + u.Name) + ctx.Redirect(setting.AppRootSubUrl + "/user/" + u.Name) } const ( diff --git a/routers/user/setting.go b/routers/user/setting.go index 4e0e468f..a540f054 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -14,6 +14,7 @@ import ( "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware" + "github.com/gogits/gogs/modules/setting" ) const ( @@ -55,7 +56,7 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) { } else if err = models.ChangeUserName(ctx.User, form.UserName); err != nil { if err == models.ErrUserNameIllegal { ctx.Flash.Error(ctx.Tr("form.illegal_username")) - ctx.Redirect("/user/settings") + ctx.Redirect(setting.AppRootSubUrl + "/user/settings") return } else { ctx.Handle(500, "ChangeUserName", err) @@ -78,7 +79,7 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) { } log.Trace("User setting updated: %s", ctx.User.Name) ctx.Flash.Success(ctx.Tr("settings.update_profile_success")) - ctx.Redirect("/user/settings") + ctx.Redirect(setting.AppRootSubUrl + "/user/settings") } func SettingsPassword(ctx *middleware.Context) { @@ -119,7 +120,7 @@ func SettingsPasswordPost(ctx *middleware.Context, form auth.ChangePasswordForm) ctx.Flash.Success(ctx.Tr("settings.change_password_success")) } - ctx.Redirect("/user/settings/password") + ctx.Redirect(setting.AppRootSubUrl + "/user/settings/password") } func SettingsSSHKeys(ctx *middleware.Context) { @@ -160,7 +161,7 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { ctx.Handle(500, "DeletePublicKey", err) } else { log.Trace("SSH key deleted: %s", ctx.User.Name) - ctx.Redirect("/user/settings/ssh") + ctx.Redirect(setting.AppRootSubUrl + "/user/settings/ssh") } return } @@ -177,7 +178,7 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { if ok, err := models.CheckPublicKeyString(cleanContent); !ok { ctx.Flash.Error(ctx.Tr("form.invalid_ssh_key", err.Error())) - ctx.Redirect("/user/settings/ssh") + ctx.Redirect(setting.AppRootSubUrl + "/user/settings/ssh") return } @@ -196,7 +197,7 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { } else { log.Trace("SSH key added: %s", ctx.User.Name) ctx.Flash.Success(ctx.Tr("settings.add_key_success")) - ctx.Redirect("/user/settings/ssh") + ctx.Redirect(setting.AppRootSubUrl + "/user/settings/ssh") return } } @@ -217,7 +218,7 @@ func SettingsSocial(ctx *middleware.Context) { return } ctx.Flash.Success(ctx.Tr("settings.unbind_success")) - ctx.Redirect("/user/settings/social") + ctx.Redirect(setting.AppRootSubUrl + "/user/settings/social") return } @@ -248,13 +249,13 @@ func SettingsDelete(ctx *middleware.Context) { switch err { case models.ErrUserOwnRepos: ctx.Flash.Error(ctx.Tr("form.still_own_repo")) - ctx.Redirect("/user/settings/delete") + ctx.Redirect(setting.AppRootSubUrl + "/user/settings/delete") default: ctx.Handle(500, "DeleteUser", err) } } else { log.Trace("Account deleted: %s", ctx.User.Name) - ctx.Redirect("/") + ctx.Redirect(setting.AppRootSubUrl + "/") } return } diff --git a/routers/user/social.go b/routers/user/social.go index 07c6deed..fc2ea5fb 100644 --- a/routers/user/social.go +++ b/routers/user/social.go @@ -22,7 +22,7 @@ import ( func extractPath(next string) string { n, err := url.Parse(next) if err != nil { - return "/" + return setting.AppRootSubUrl + "/" } return n.Path } @@ -88,7 +88,7 @@ func SocialSignIn(ctx *middleware.Context) { return } case models.ErrOauth2NotAssociated: - next = "/user/sign_up" + next = setting.AppRootSubUrl + "/user/sign_up" default: ctx.Handle(500, "social.SocialSignIn(GetOauth2)", err) return diff --git a/templates/admin/auth/edit.tmpl b/templates/admin/auth/edit.tmpl index 400a4ceb..4dead7f0 100644 --- a/templates/admin/auth/edit.tmpl +++ b/templates/admin/auth/edit.tmpl @@ -12,7 +12,7 @@
    {{.i18n.Tr "admin.auths.edit"}}
    -
    + {{.CsrfTokenHtml}} {{$type := .Source.Type}} diff --git a/templates/admin/auth/list.tmpl b/templates/admin/auth/list.tmpl index 591d2ed4..ba10e1d2 100644 --- a/templates/admin/auth/list.tmpl +++ b/templates/admin/auth/list.tmpl @@ -13,7 +13,7 @@ {{.i18n.Tr "admin.auths.auth_manage_panel"}}
    - {{.i18n.Tr "admin.auths.new"}} + {{.i18n.Tr "admin.auths.new"}}
    @@ -31,20 +31,20 @@ {{range .Sources}} - + - + {{end}}
    {{.Id}}{{.Name}}{{.Name}} {{.TypeString}} {{DateFormat .Updated "M d, Y"}} {{DateFormat .Created "M d, Y"}}
    {{if or .LastPageNum .NextPageNum}} {{end}}
    diff --git a/templates/admin/auth/new.tmpl b/templates/admin/auth/new.tmpl index 8f9f5ccc..869eff32 100644 --- a/templates/admin/auth/new.tmpl +++ b/templates/admin/auth/new.tmpl @@ -12,7 +12,7 @@
    {{.i18n.Tr "admin.auths.new"}}
    - + {{.CsrfTokenHtml}}
    diff --git a/templates/admin/dashboard.tmpl b/templates/admin/dashboard.tmpl index 09e10582..00696611 100644 --- a/templates/admin/dashboard.tmpl +++ b/templates/admin/dashboard.tmpl @@ -34,11 +34,11 @@ {{.i18n.Tr "admin.dashboard.clean_unbind_oauth"}} - {{.i18n.Tr "admin.dashboard.operation_run"}} + {{.i18n.Tr "admin.dashboard.operation_run"}} {{.i18n.Tr "admin.dashboard.delete_inactivate_accounts"}} - {{.i18n.Tr "admin.dashboard.operation_run"}} + {{.i18n.Tr "admin.dashboard.operation_run"}} diff --git a/templates/admin/nav.tmpl b/templates/admin/nav.tmpl index ccb250c2..ae44f4a8 100644 --- a/templates/admin/nav.tmpl +++ b/templates/admin/nav.tmpl @@ -2,13 +2,13 @@

    {{.i18n.Tr "admin_panel"}}

    \ No newline at end of file diff --git a/templates/admin/org/list.tmpl b/templates/admin/org/list.tmpl index ea9167c0..f42c2c53 100644 --- a/templates/admin/org/list.tmpl +++ b/templates/admin/org/list.tmpl @@ -30,7 +30,7 @@ {{range .Orgs}} {{.Id}} - {{.Name}} + {{.Name}} {{.Email}} {{.NumTeams}} {{.NumMembers}} @@ -42,8 +42,8 @@ {{if or .LastPageNum .NextPageNum}} {{end}}
    diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl index 3f357158..3e7442a6 100644 --- a/templates/admin/repo/list.tmpl +++ b/templates/admin/repo/list.tmpl @@ -31,8 +31,8 @@ {{range .Repos}} {{.Id}} - {{.Owner.Name}} - {{.Name}} + {{.Owner.Name}} + {{.Name}} {{.NumWatches}} {{.NumIssues}} @@ -44,8 +44,8 @@ {{if or .LastPageNum .NextPageNum}} {{end}}
    diff --git a/templates/admin/user/edit.tmpl b/templates/admin/user/edit.tmpl index e8812670..e9ed7836 100644 --- a/templates/admin/user/edit.tmpl +++ b/templates/admin/user/edit.tmpl @@ -12,7 +12,7 @@
    {{.i18n.Tr "admin.users.edit_account"}}
    - + {{.CsrfTokenHtml}}
    diff --git a/templates/admin/user/list.tmpl b/templates/admin/user/list.tmpl index 51e6604f..f85bb6c0 100644 --- a/templates/admin/user/list.tmpl +++ b/templates/admin/user/list.tmpl @@ -13,7 +13,7 @@ {{.i18n.Tr "admin.users.user_manage_panel"}}
    - {{.i18n.Tr "admin.users.new_account"}} + {{.i18n.Tr "admin.users.new_account"}}
    @@ -32,21 +32,21 @@ {{range .Users}} - + - + {{end}}
    {{.Id}}{{.Name}}{{.Name}} {{.Email}} {{.NumRepos}} {{DateFormat .Created "M d, Y"}}
    {{if or .LastPageNum .NextPageNum}} {{end}}
    diff --git a/templates/admin/user/new.tmpl b/templates/admin/user/new.tmpl index 0c4ad603..db842c68 100644 --- a/templates/admin/user/new.tmpl +++ b/templates/admin/user/new.tmpl @@ -12,7 +12,7 @@
    {{.i18n.Tr "admin.users.new_account"}}
    - + {{.CsrfTokenHtml}}
    diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index a58299f8..55dd4690 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -1,8 +1,8 @@ - + - + @@ -19,21 +19,21 @@ {{else}} - - + + - - + + {{end}} - - - - - + + + + + - - + + {{if .Title}}{{.Title}} - {{end}}{{AppName}} diff --git a/templates/base/navbar.tmpl b/templates/base/navbar.tmpl index 75096a4e..991e773d 100644 --- a/templates/base/navbar.tmpl +++ b/templates/base/navbar.tmpl @@ -1,8 +1,8 @@ diff --git a/templates/explore/nav.tmpl b/templates/explore/nav.tmpl index 1310bccf..a6c0acad 100644 --- a/templates/explore/nav.tmpl +++ b/templates/explore/nav.tmpl @@ -2,7 +2,7 @@

    {{.i18n.Tr "explore"}}

    \ No newline at end of file diff --git a/templates/explore/repos.tmpl b/templates/explore/repos.tmpl index a1e3d408..b8ae1791 100644 --- a/templates/explore/repos.tmpl +++ b/templates/explore/repos.tmpl @@ -12,7 +12,7 @@
  • {{.NumStars}}
  • {{.NumForks}}
  • -

    {{.Name}}

    +

    {{.Name}}

    {{.Description}}

    {{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Updated $.i18n.Lang}}

    diff --git a/templates/home.tmpl b/templates/home.tmpl index ba9cbe40..0fa70869 100644 --- a/templates/home.tmpl +++ b/templates/home.tmpl @@ -3,12 +3,12 @@

    Gogs

    {{.i18n.Tr "app_desc"}}

    -
    + {{.CsrfTokenHtml}} diff --git a/templates/install.tmpl b/templates/install.tmpl index 7840f7ad..eb294082 100644 --- a/templates/install.tmpl +++ b/templates/install.tmpl @@ -8,7 +8,7 @@
    {{.i18n.Tr "install.title"}}
    - + {{.CsrfTokenHtml}}
    {{.i18n.Tr "install.requite_db_desc"}}
    diff --git a/templates/ng/base/head.tmpl b/templates/ng/base/head.tmpl index 40c3899e..222edb69 100644 --- a/templates/ng/base/head.tmpl +++ b/templates/ng/base/head.tmpl @@ -1,6 +1,6 @@ - + @@ -9,27 +9,27 @@ {{if .Repository.IsGoget}}{{end}} - + {{if CdnMode}} {{else}} - + - + {{end}} - - - - + + + + - - - + + + {{if .Title}}{{.Title}} - {{end}}{{AppName}} diff --git a/templates/ng/base/header.tmpl b/templates/ng/base/header.tmpl index 31533d27..af3bc02f 100644 --- a/templates/ng/base/header.tmpl +++ b/templates/ng/base/header.tmpl @@ -2,37 +2,37 @@ -

    {{.Name}}

    +

    {{.Name}}

    {{.Description}}

    {{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Updated $.i18n.Lang}}

    @@ -46,20 +46,20 @@
    {{if $isMember}} - {{.Org.NumMembers}} + {{.Org.NumMembers}} {{end}} {{.i18n.Tr "org.people"}}
    {{range .Members}} {{if or $isMember (.IsPublicMember $.Org.Id)}} - + {{end}} {{end}}
    {{if .IsOrganizationOwner}} {{end}}
    @@ -67,14 +67,14 @@
    - {{.Org.NumTeams}} + {{.Org.NumTeams}} {{.i18n.Tr "org.teams"}}
      {{range .Teams}}
    • - {{.Name}} + {{.Name}}

      {{.NumMembers}} {{$.i18n.Tr "org.lower_members"}} · {{.NumRepos}} {{$.i18n.Tr "org.lower_repositories"}}

    • {{end}} @@ -82,7 +82,7 @@
    {{if .IsOrganizationOwner}} {{end}}
    diff --git a/templates/org/member/members.tmpl b/templates/org/member/members.tmpl index 1c530982..eb4b9b7f 100644 --- a/templates/org/member/members.tmpl +++ b/templates/org/member/members.tmpl @@ -14,7 +14,7 @@ {{range .Members}}
    - {{.FullName}}({{.Name}}) + {{.FullName}}({{.Name}})
    • {{ $isPublic := .IsPublicMember $.Org.Id}} diff --git a/templates/org/new.tmpl b/templates/org/new.tmpl index 870f3982..eb5fd9a3 100644 --- a/templates/org/new.tmpl +++ b/templates/org/new.tmpl @@ -1,7 +1,7 @@ {{template "base/head" .}} {{template "base/navbar" .}}
      -
      + {{.CsrfTokenHtml}}

      Create New Organization

      {{template "base/alert" .}} @@ -24,7 +24,7 @@
      - Cancel + Cancel
      diff --git a/templates/org/settings/delete.tmpl b/templates/org/settings/delete.tmpl index ea9853d9..938fdd64 100644 --- a/templates/org/settings/delete.tmpl +++ b/templates/org/settings/delete.tmpl @@ -12,7 +12,7 @@

      {{.i18n.Tr "org.settings.delete_account"}}

      {{.i18n.Tr "org.settings.delete_prompt" | Str2html}} -
      + {{.CsrfTokenHtml}}

      diff --git a/templates/org/settings/nav.tmpl b/templates/org/settings/nav.tmpl index 954893c6..63cb6f08 100644 --- a/templates/org/settings/nav.tmpl +++ b/templates/org/settings/nav.tmpl @@ -4,9 +4,9 @@

      diff --git a/templates/org/settings/options.tmpl b/templates/org/settings/options.tmpl index 14ea1b34..09492193 100644 --- a/templates/org/settings/options.tmpl +++ b/templates/org/settings/options.tmpl @@ -12,7 +12,7 @@
      {{.i18n.Tr "org.settings.options"}}
      - + {{.CsrfTokenHtml}}
      diff --git a/templates/org/team/members.tmpl b/templates/org/team/members.tmpl index d3176be1..ad9b30ed 100644 --- a/templates/org/team/members.tmpl +++ b/templates/org/team/members.tmpl @@ -30,7 +30,7 @@ {{if $.IsOrganizationOwner}} {{$.i18n.Tr "org.members.remove"}} {{end}} - + {{.Name}} {{.FullName}} ({{.Name}}) diff --git a/templates/org/team/repositories.tmpl b/templates/org/team/repositories.tmpl index 0a3f7710..f7ff97d8 100644 --- a/templates/org/team/repositories.tmpl +++ b/templates/org/team/repositories.tmpl @@ -30,7 +30,7 @@ {{if $canAddRemove}} {{$.i18n.Tr "org.teams.remove_repo"}} {{end}} - + {{$.Org.Name}}/{{.Name}} diff --git a/templates/org/team/teams.tmpl b/templates/org/team/teams.tmpl index 9c47cb5a..6440807f 100644 --- a/templates/org/team/teams.tmpl +++ b/templates/org/team/teams.tmpl @@ -25,7 +25,7 @@ {{if .NumMembers}}
      {{range .Members}} - + {{end}} diff --git a/templates/repo/bare.tmpl b/templates/repo/bare.tmpl index d53cd823..712e7013 100644 --- a/templates/repo/bare.tmpl +++ b/templates/repo/bare.tmpl @@ -5,7 +5,7 @@

      - {{.Repository.Owner.Name}} + {{.Repository.Owner.Name}} / {{.Repository.Name}}

      diff --git a/templates/repo/commits_table.tmpl b/templates/repo/commits_table.tmpl index 4612398a..aa97925c 100644 --- a/templates/repo/commits_table.tmpl +++ b/templates/repo/commits_table.tmpl @@ -26,8 +26,8 @@ {{$r := List .Commits}} {{range $r}} - {{.Author.Name}} - {{SubStr .Id.String 0 10}} + {{.Author.Name}} + {{SubStr .Id.String 0 10}} {{.Summary}} {{TimeSince .Author.When $.Lang}} diff --git a/templates/repo/create.tmpl b/templates/repo/create.tmpl index 6baa6d31..7b3c85ae 100644 --- a/templates/repo/create.tmpl +++ b/templates/repo/create.tmpl @@ -1,7 +1,7 @@ {{template "ng/base/head" .}} {{template "ng/base/header" .}}
      - + {{.CsrfTokenHtml}}

      {{.i18n.Tr "new_repo"}}

      @@ -75,7 +75,7 @@
      - {{.i18n.Tr "cancel"}} + {{.i18n.Tr "cancel"}}
      diff --git a/templates/repo/diff.tmpl b/templates/repo/diff.tmpl index a2150f28..548c7a35 100644 --- a/templates/repo/diff.tmpl +++ b/templates/repo/diff.tmpl @@ -30,7 +30,7 @@

      - {{.Commit.Author.Name}} + {{.Commit.Author.Name}} {{TimeSince .Commit.Author.When $.Lang}}

      diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index 42ae775a..dc271a75 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -2,7 +2,7 @@

      - {{.Owner.Name}} + {{.Owner.Name}} / {{.Repository.Name}} {{if .Repository.IsMirror}}{{.i18n.Tr "mirror"}}{{end}} diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index 099e41b2..1849602b 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -85,7 +85,7 @@

      - {{.Poster.Name}} + {{.Poster.Name}} {{TimeSince .Created $.Lang}} {{.NumComments}}

      diff --git a/templates/repo/issue/view.tmpl b/templates/repo/issue/view.tmpl index ff68ce0c..dbbd1d92 100644 --- a/templates/repo/issue/view.tmpl +++ b/templates/repo/issue/view.tmpl @@ -8,7 +8,7 @@
      #{{.Issue.Index}}
      - +

      {{.Issue.Name}}

      @@ -17,7 +17,7 @@ {{end}} {{if .Issue.IsClosed}}Closed{{else}}Open{{end}} - {{.Issue.Poster.Name}} opened this issue + {{.Issue.Poster.Name}} opened this issue {{TimeSince .Issue.Created $.Lang}} · {{.Issue.NumComments}} comments

      @@ -63,10 +63,10 @@ {{/* 0 = COMMENT, 1 = REOPEN, 2 = CLOSE, 3 = ISSUE, 4 = COMMIT, 5 = PULL */}} {{if eq .Type 0}}
      - +
      - {{.Poster.Name}} commented {{TimeSince .Created $.Lang}} + {{.Poster.Name}} commented {{TimeSince .Created $.Lang}} Owner @@ -93,25 +93,25 @@
      {{else if eq .Type 1}}
      - +
      - {{.Poster.Name}} Reopened this issue {{TimeSince .Created $.Lang}} + {{.Poster.Name}} Reopened this issue {{TimeSince .Created $.Lang}}
      {{else if eq .Type 2}}
      - +
      - {{.Poster.Name}} Closed this issue {{TimeSince .Created $.Lang}} + {{.Poster.Name}} Closed this issue {{TimeSince .Created $.Lang}}
      {{else if eq .Type 4}}
      - +
      - {{.Poster.Name}} Referenced this issue {{TimeSince .Created $.Lang}} + {{.Poster.Name}} Referenced this issue {{TimeSince .Created $.Lang}}

      - + {{.ContentHtml}}

      @@ -120,7 +120,7 @@ {{end}}
      {{if .SignedUser}}
      - +
      {{.CsrfTokenHtml}}
      @@ -163,7 +163,7 @@
      -
      {{else}}
      Sign up for free to join this conversation. Already have an account? Sign in to comment
      {{end}} +
      {{else}}
      Sign up for free to join this conversation. Already have an account? Sign in to comment
      {{end}}
      diff --git a/templates/repo/migrate.tmpl b/templates/repo/migrate.tmpl index 7c983d76..f40124bf 100644 --- a/templates/repo/migrate.tmpl +++ b/templates/repo/migrate.tmpl @@ -1,7 +1,7 @@ {{template "ng/base/head" .}} {{template "ng/base/header" .}}
      -
      + {{.CsrfTokenHtml}}

      {{.i18n.Tr "new_migrate"}}

      @@ -74,7 +74,7 @@
      - {{.i18n.Tr "cancel"}} + {{.i18n.Tr "cancel"}}
      diff --git a/templates/repo/nav.tmpl b/templates/repo/nav.tmpl index 69f60ba4..566e11a0 100644 --- a/templates/repo/nav.tmpl +++ b/templates/repo/nav.tmpl @@ -2,7 +2,7 @@
      -

      {{.Owner.Name}} / {{.Repository.Name}} {{if .Repository.IsPrivate}}Private{{else if .Repository.IsMirror}}Mirror{{end}}

      +

      {{.Owner.Name}} / {{.Repository.Name}} {{if .Repository.IsPrivate}}Private{{else if .Repository.IsMirror}}Mirror{{end}}

      {{.Repository.DescriptionHtml}}{{if .Repository.Website}} {{.Repository.Website}}{{end}}

      @@ -32,7 +32,7 @@
      {{if .IsSigned}} -
      +
      {{if .IsRepositoryWatching}} {{else}} @@ -59,7 +59,7 @@
      --> {{end}}
      diff --git a/templates/repo/release/list.tmpl b/templates/repo/release/list.tmpl index b9f46258..2bb5faa4 100644 --- a/templates/repo/release/list.tmpl +++ b/templates/repo/release/list.tmpl @@ -6,7 +6,7 @@

      Releases + Tags -->

        @@ -28,7 +28,7 @@

        {{.Title}} (edit)

           - {{.Publisher.Name}} + {{.Publisher.Name}} {{if .Created}}{{TimeSince .Created $.Lang}}{{end}} {{.NumCommitsBehind}} commits to {{.Target}} since this release

        diff --git a/templates/repo/setting_nav.tmpl b/templates/repo/setting_nav.tmpl index 489602b4..8cd1f2a2 100644 --- a/templates/repo/setting_nav.tmpl +++ b/templates/repo/setting_nav.tmpl @@ -1,7 +1,7 @@ \ No newline at end of file diff --git a/templates/repo/settings/collaboration.tmpl b/templates/repo/settings/collaboration.tmpl index fe4ec498..99561e27 100644 --- a/templates/repo/settings/collaboration.tmpl +++ b/templates/repo/settings/collaboration.tmpl @@ -18,7 +18,7 @@ {{range .Collaborators}}
      • {{if not (eq .Id $.Owner.Id)}}{{end}} - + {{.Name}} {{.FullName}} ({{.Name}}) diff --git a/templates/repo/single.tmpl b/templates/repo/single.tmpl index 7ee6b0ca..9fbf2f55 100644 --- a/templates/repo/single.tmpl +++ b/templates/repo/single.tmpl @@ -12,7 +12,7 @@
      diff --git a/templates/repo/single_list.tmpl b/templates/repo/single_list.tmpl index 640f7f09..6728dd70 100644 --- a/templates/repo/single_list.tmpl +++ b/templates/repo/single_list.tmpl @@ -1,9 +1,9 @@
      - {{.LastCommit.Author.Name}} {{TimeSince .LastCommit.Author.When}} + {{.LastCommit.Author.Name}} {{TimeSince .LastCommit.Author.When}}
      @@ -36,7 +36,7 @@ diff --git a/templates/status/404.tmpl b/templates/status/404.tmpl index e024715e..5a57e954 100644 --- a/templates/status/404.tmpl +++ b/templates/status/404.tmpl @@ -1,7 +1,7 @@ {{template "ng/base/head" .}} {{template "ng/base/header" .}}
      -

      404

      +

      404



      Application Version: {{AppVer}}

      diff --git a/templates/status/500.tmpl b/templates/status/500.tmpl index b887532d..5bfdccc6 100644 --- a/templates/status/500.tmpl +++ b/templates/status/500.tmpl @@ -1,7 +1,7 @@ {{template "ng/base/head" .}} {{template "ng/base/header" .}}
      -

      500

      +

      500



      {{if .ErrorMsg}}

      An error has occurred : {{.ErrorMsg}}

      {{end}} diff --git a/templates/user/auth/activate.tmpl b/templates/user/auth/activate.tmpl index 6a9e0b0d..554e2b78 100644 --- a/templates/user/auth/activate.tmpl +++ b/templates/user/auth/activate.tmpl @@ -1,7 +1,7 @@ {{template "ng/base/head" .}} {{template "ng/base/header" .}}
      -
      + {{.CsrfTokenHtml}}

      {{.i18n.Tr "auth.active_your_account"}}

      diff --git a/templates/user/auth/forgot_passwd.tmpl b/templates/user/auth/forgot_passwd.tmpl index 3e9f76e9..a1a10093 100644 --- a/templates/user/auth/forgot_passwd.tmpl +++ b/templates/user/auth/forgot_passwd.tmpl @@ -1,7 +1,7 @@ {{template "ng/base/head" .}} {{template "ng/base/header" .}}
      - + {{.CsrfTokenHtml}}

      {{.i18n.Tr "auth.forgot_password"}}

      diff --git a/templates/user/auth/reset_passwd.tmpl b/templates/user/auth/reset_passwd.tmpl index 3c9da96b..de2976d6 100644 --- a/templates/user/auth/reset_passwd.tmpl +++ b/templates/user/auth/reset_passwd.tmpl @@ -1,7 +1,7 @@ {{template "ng/base/head" .}} {{template "ng/base/header" .}}
      - + {{.CsrfTokenHtml}}

      {{.i18n.Tr "auth.reset_password"}}

      diff --git a/templates/user/auth/signin.tmpl b/templates/user/auth/signin.tmpl index c2f6ef87..e9ec87cc 100644 --- a/templates/user/auth/signin.tmpl +++ b/templates/user/auth/signin.tmpl @@ -1,7 +1,7 @@ {{template "ng/base/head" .}} {{template "ng/base/header" .}}
      - +

      {{if .IsSocialLogin}}{{.i18n.Tr "social_sign_in" | Str2html}}{{else}}{{.i18n.Tr "sign_in"}}{{end}}

      @@ -24,12 +24,12 @@
           - {{if not .IsSocialLogin}}{{.i18n.Tr "auth.forget_password"}}{{end}} + {{if not .IsSocialLogin}}{{.i18n.Tr "auth.forget_password"}}{{end}}
      {{if not .IsSocialLogin}} {{if .OauthEnabled}}
      diff --git a/templates/user/auth/signup.tmpl b/templates/user/auth/signup.tmpl index d116ad62..af4c250f 100644 --- a/templates/user/auth/signup.tmpl +++ b/templates/user/auth/signup.tmpl @@ -1,7 +1,7 @@ {{template "ng/base/head" .}} {{template "ng/base/header" .}}
      - +

      {{if .IsSocialLogin}}{{.i18n.Tr "social_sign_in" | Str2html}}{{else}}{{.i18n.Tr "sign_up"}}{{end}}

      @@ -40,7 +40,7 @@
      {{end}}
      diff --git a/templates/user/dashboard/dashboard.tmpl b/templates/user/dashboard/dashboard.tmpl index a9326fa6..db838452 100644 --- a/templates/user/dashboard/dashboard.tmpl +++ b/templates/user/dashboard/dashboard.tmpl @@ -12,17 +12,17 @@

      - {{.GetActUserName}} + {{.GetActUserName}} {{if eq .GetOpType 1}} - {{$.i18n.Tr "action.create_repo" .GetRepoLink .GetRepoLink | Str2html}} + {{$.i18n.Tr "action.create_repo" AppRootSubUrl .GetRepoLink .GetRepoLink | Str2html}} {{else if eq .GetOpType 5}} - {{$.i18n.Tr "action.commit_repo" .GetRepoLink .GetBranch .GetBranch .GetRepoLink .GetRepoLink | Str2html}} + {{$.i18n.Tr "action.commit_repo" AppRootSubUrl .GetRepoLink .GetBranch .GetBranch AppRootSubUrl .GetRepoLink .GetRepoLink | Str2html}} {{else if eq .GetOpType 6}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.create_issue" .GetRepoLink $index .GetRepoLink $index | Str2html}} + {{$.i18n.Tr "action.create_issue" AppRootSubUrl .GetRepoLink $index .GetRepoLink $index | Str2html}} {{else if eq .GetOpType 10}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.comment_issue" .GetRepoLink $index .GetRepoLink $index | Str2html}} + {{$.i18n.Tr "action.comment_issue" AppRootSubUrl .GetRepoLink $index .GetRepoLink $index | Str2html}} {{end}}

      {{if eq .GetOpType 5}} @@ -31,7 +31,7 @@ {{ $push := ActionContent2Commits .}} {{ $repoLink := .GetRepoLink}} {{range $push.Commits}} -
    • {{ShortSha .Sha1}} {{.Message}}
    • +
    • {{ShortSha .Sha1}} {{.Message}}
    • {{end}}
      @@ -58,9 +58,9 @@ @@ -75,7 +75,7 @@
      diff --git a/templates/user/issues.tmpl b/templates/user/issues.tmpl index 93e798aa..19b0526c 100644 --- a/templates/user/issues.tmpl +++ b/templates/user/issues.tmpl @@ -3,10 +3,10 @@

      Your Issues

      @@ -17,30 +17,30 @@
      {{range .Issues}}{{if .}}
      #{{.Index}} -
      {{.Name}}
      +
      {{.Name}}

      - {{.Poster.Name}} + {{.Poster.Name}} {{TimeSince .Created $.Lang}} {{.NumComments}}

      diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index fe4e32f7..1b51a871 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -66,7 +66,7 @@
    • {{.NumForks}}

      - {{.Name}}{{if .IsPrivate}} Private{{end}} + {{.Name}}{{if .IsPrivate}} Private{{end}}

      {{.Description}}

      Last updated {{TimeSince .Updated $.Lang}}
      diff --git a/templates/user/settings/delete.tmpl b/templates/user/settings/delete.tmpl index 9bfc287d..78574ba1 100644 --- a/templates/user/settings/delete.tmpl +++ b/templates/user/settings/delete.tmpl @@ -11,7 +11,7 @@

      {{.i18n.Tr "settings.delete_account"}}

      {{.i18n.Tr "settings.delete_prompt" | Str2html}} - + {{.CsrfTokenHtml}}

      diff --git a/templates/user/settings/nav.tmpl b/templates/user/settings/nav.tmpl index d6d20dee..52fc83e1 100644 --- a/templates/user/settings/nav.tmpl +++ b/templates/user/settings/nav.tmpl @@ -2,11 +2,11 @@

      {{.i18n.Tr "settings"}}

      \ No newline at end of file diff --git a/templates/user/settings/password.tmpl b/templates/user/settings/password.tmpl index 44e087af..ccafd3ed 100644 --- a/templates/user/settings/password.tmpl +++ b/templates/user/settings/password.tmpl @@ -9,7 +9,7 @@

      {{.i18n.Tr "settings.change_password"}}

      - + {{.CsrfTokenHtml}}

      diff --git a/templates/user/settings/profile.tmpl b/templates/user/settings/profile.tmpl index 663d8bdb..e344fb9a 100644 --- a/templates/user/settings/profile.tmpl +++ b/templates/user/settings/profile.tmpl @@ -11,7 +11,7 @@

      {{.i18n.Tr "settings.public_profile"}}
      - + {{.CsrfTokenHtml}}
      {{.i18n.Tr "settings.profile_desc"}}
      diff --git a/templates/user/settings/social.tmpl b/templates/user/settings/social.tmpl index bcbc1fc5..a2585922 100644 --- a/templates/user/settings/social.tmpl +++ b/templates/user/settings/social.tmpl @@ -20,7 +20,7 @@

      {{.Identity}}

      {{$.i18n.Tr "settings.add_on"}} {{DateFormat .Created "M d, Y"}} — {{$.i18n.Tr "settings.last_used"}} {{DateFormat .Updated "M d, Y"}}

      - {{$.i18n.Tr "settings.unbind"}} + {{$.i18n.Tr "settings.unbind"}}
    • {{end}} diff --git a/templates/user/settings/sshkeys.tmpl b/templates/user/settings/sshkeys.tmpl index 3db0f54b..2d186121 100644 --- a/templates/user/settings/sshkeys.tmpl +++ b/templates/user/settings/sshkeys.tmpl @@ -23,7 +23,7 @@

      {{.Fingerprint}}

      {{$.i18n.Tr "settings.add_on"}} {{DateFormat .Created "M d, Y"}} — {{if .HasUsed}}{{$.i18n.Tr "settings.last_used"}} {{DateFormat .Updated "M d, Y"}}{{else}}{{$.i18n.Tr "settings.no_activity"}}{{end}}

      - + {{$.CsrfTokenHtml}} @@ -35,7 +35,7 @@

      {{.i18n.Tr "settings.ssh_helper" | Str2html}}


      - + {{.CsrfTokenHtml}}

      {{.i18n.Tr "settings.add_new_key"}}

      -- cgit v1.2.3 From 7ba9257a7ff659417501baf7358216555cebcd86 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 19 Sep 2014 20:11:34 -0400 Subject: Add suburl support --- cmd/web.go | 7 +++++-- gogs.go | 2 +- models/action.go | 2 +- models/user.go | 6 +++--- modules/base/markdown.go | 2 +- modules/base/template.go | 16 ++++++++-------- modules/middleware/auth.go | 8 ++++---- modules/middleware/context.go | 2 +- modules/middleware/org.go | 6 +++--- modules/middleware/repo.go | 12 ++++++------ modules/setting/setting.go | 13 +++++++------ routers/admin/admin.go | 2 +- routers/admin/auths.go | 8 ++++---- routers/admin/users.go | 8 ++++---- routers/home.go | 2 +- routers/install.go | 2 +- routers/org/members.go | 2 +- routers/org/org.go | 2 +- routers/org/setting.go | 8 ++++---- routers/repo/commit.go | 4 ++-- routers/repo/issue.go | 6 +++--- routers/repo/repo.go | 4 ++-- routers/repo/setting.go | 16 ++++++++-------- routers/user/auth.go | 12 ++++++------ routers/user/home.go | 6 +++--- routers/user/setting.go | 18 +++++++++--------- routers/user/social.go | 4 ++-- templates/.VERSION | 2 +- templates/admin/auth/edit.tmpl | 2 +- templates/admin/auth/list.tmpl | 10 +++++----- templates/admin/auth/new.tmpl | 2 +- templates/admin/dashboard.tmpl | 4 ++-- templates/admin/nav.tmpl | 14 +++++++------- templates/admin/org/list.tmpl | 6 +++--- templates/admin/repo/list.tmpl | 8 ++++---- templates/admin/user/edit.tmpl | 2 +- templates/admin/user/list.tmpl | 10 +++++----- templates/admin/user/new.tmpl | 2 +- templates/base/head.tmpl | 26 +++++++++++++------------- templates/base/navbar.tmpl | 18 +++++++++--------- templates/explore/nav.tmpl | 2 +- templates/explore/repos.tmpl | 2 +- templates/home.tmpl | 4 ++-- templates/install.tmpl | 2 +- templates/ng/base/head.tmpl | 22 +++++++++++----------- templates/ng/base/header.tmpl | 26 +++++++++++++------------- templates/ng/base/social.tmpl | 8 ++++---- templates/org/base/header.tmpl | 2 +- templates/org/create.tmpl | 4 ++-- templates/org/home.tmpl | 16 ++++++++-------- templates/org/member/members.tmpl | 2 +- templates/org/new.tmpl | 4 ++-- templates/org/settings/delete.tmpl | 2 +- templates/org/settings/nav.tmpl | 6 +++--- templates/org/settings/options.tmpl | 2 +- templates/org/team/members.tmpl | 2 +- templates/org/team/repositories.tmpl | 2 +- templates/org/team/teams.tmpl | 2 +- templates/repo/bare.tmpl | 2 +- templates/repo/commits_table.tmpl | 4 ++-- templates/repo/create.tmpl | 4 ++-- templates/repo/diff.tmpl | 2 +- templates/repo/header.tmpl | 2 +- templates/repo/issue/list.tmpl | 2 +- templates/repo/issue/view.tmpl | 26 +++++++++++++------------- templates/repo/migrate.tmpl | 4 ++-- templates/repo/nav.tmpl | 6 +++--- templates/repo/release/list.tmpl | 4 ++-- templates/repo/setting_nav.tmpl | 6 +++--- templates/repo/settings/collaboration.tmpl | 2 +- templates/repo/single.tmpl | 2 +- templates/repo/single_list.tmpl | 6 +++--- templates/repo/view_list.tmpl | 4 ++-- templates/status/404.tmpl | 2 +- templates/status/500.tmpl | 2 +- templates/user/auth/activate.tmpl | 2 +- templates/user/auth/forgot_passwd.tmpl | 2 +- templates/user/auth/reset_passwd.tmpl | 2 +- templates/user/auth/signin.tmpl | 6 +++--- templates/user/auth/signup.tmpl | 4 ++-- templates/user/dashboard/dashboard.tmpl | 24 ++++++++++++------------ templates/user/dashboard/nav.tmpl | 6 +++--- templates/user/issues.tmpl | 24 ++++++++++++------------ templates/user/profile.tmpl | 2 +- templates/user/settings/delete.tmpl | 2 +- templates/user/settings/nav.tmpl | 10 +++++----- templates/user/settings/password.tmpl | 2 +- templates/user/settings/profile.tmpl | 2 +- templates/user/settings/social.tmpl | 2 +- templates/user/settings/sshkeys.tmpl | 4 ++-- 90 files changed, 287 insertions(+), 283 deletions(-) (limited to 'models') diff --git a/cmd/web.go b/cmd/web.go index f56ae826..45f35a35 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -79,6 +79,7 @@ func newMacaron() *macaron.Macaron { IndentJSON: macaron.Env != macaron.PROD, })) m.Use(i18n.I18n(i18n.Options{ + SubURL: setting.AppSubUrl, Langs: setting.Langs, Names: setting.Names, Redirect: true, @@ -88,7 +89,9 @@ func newMacaron() *macaron.Macaron { Interval: setting.CacheInternal, Conn: setting.CacheConn, })) - m.Use(captcha.Captchaer()) + m.Use(captcha.Captchaer(captcha.Options{ + SubURL: setting.AppSubUrl, + })) m.Use(session.Sessioner(session.Options{ Provider: setting.SessionProvider, Config: *setting.SessionConfig, @@ -365,7 +368,7 @@ func runWeb(*cli.Context) { var err error listenAddr := fmt.Sprintf("%s:%s", setting.HttpAddr, setting.HttpPort) - log.Info("Listen: %v://%s", setting.Protocol, listenAddr) + log.Info("Listen: %v://%s%s", setting.Protocol, listenAddr, setting.AppSubUrl) switch setting.Protocol { case setting.HTTP: err = http.ListenAndServe(listenAddr, m) diff --git a/gogs.go b/gogs.go index c5249b25..8f9bc767 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.2.0917 Beta" +const APP_VER = "0.5.3.0919 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/action.go b/models/action.go index 596f51af..b4457656 100644 --- a/models/action.go +++ b/models/action.go @@ -137,7 +137,7 @@ func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, com return err } - url := fmt.Sprintf("%s/%s/%s/commit/%s", setting.AppRootSubUrl, repoUserName, repoName, c.Sha1) + url := fmt.Sprintf("%s/%s/%s/commit/%s", setting.AppSubUrl, repoUserName, repoName, c.Sha1) message := fmt.Sprintf(`%s`, url, c.Message) if _, err = CreateComment(userId, issue.RepoId, issue.Id, 0, 0, COMMIT, message, nil); err != nil { diff --git a/models/user.go b/models/user.go index 1bed8109..46e1b155 100644 --- a/models/user.go +++ b/models/user.go @@ -82,14 +82,14 @@ type User struct { // DashboardLink returns the user dashboard page link. func (u *User) DashboardLink() string { if u.IsOrganization() { - return setting.AppRootSubUrl + "/org/" + u.Name + "/dashboard/" + return setting.AppSubUrl + "/org/" + u.Name + "/dashboard/" } - return setting.AppRootSubUrl + "/" + return setting.AppSubUrl + "/" } // HomeLink returns the user home page link. func (u *User) HomeLink() string { - return setting.AppRootSubUrl + "/user/" + u.Name + return setting.AppSubUrl + "/user/" + u.Name } // AvatarLink returns user gravatar link. diff --git a/modules/base/markdown.go b/modules/base/markdown.go index 2aa81005..a3db15df 100644 --- a/modules/base/markdown.go +++ b/modules/base/markdown.go @@ -113,7 +113,7 @@ func RenderSpecialLink(rawBytes []byte, urlPrefix string) []byte { ms := MentionPattern.FindAll(line, -1) for _, m := range ms { line = bytes.Replace(line, m, - []byte(fmt.Sprintf(`%s`, setting.AppRootSubUrl, m[1:], m)), -1) + []byte(fmt.Sprintf(`%s`, setting.AppSubUrl, m[1:], m)), -1) } } diff --git a/modules/base/template.go b/modules/base/template.go index dd883ea3..ec419149 100644 --- a/modules/base/template.go +++ b/modules/base/template.go @@ -82,8 +82,8 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{ "AppName": func() string { return setting.AppName }, - "AppRootSubUrl": func() string { - return setting.AppRootSubUrl + "AppSubUrl": func() string { + return setting.AppSubUrl }, "AppVer": func() string { return setting.AppVer @@ -210,7 +210,7 @@ func ActionDesc(act Actioner) string { content := act.GetContent() switch act.GetOpType() { case 1: // Create repository. - return fmt.Sprintf(TPL_CREATE_REPO, setting.AppRootSubUrl, actUserName, actUserName, repoLink, repoName) + return fmt.Sprintf(TPL_CREATE_REPO, setting.AppSubUrl, actUserName, actUserName, repoLink, repoName) case 5: // Commit repository. var push *PushCommits if err := json.Unmarshal([]byte(content), &push); err != nil { @@ -223,20 +223,20 @@ func ActionDesc(act Actioner) string { if push.Len > 3 { buf.WriteString(fmt.Sprintf(``, actUserName, repoName, branch, push.Len)) } - return fmt.Sprintf(TPL_COMMIT_REPO, setting.AppRootSubUrl, actUserName, actUserName, repoLink, branch, branch, repoLink, repoLink, + return fmt.Sprintf(TPL_COMMIT_REPO, setting.AppSubUrl, actUserName, actUserName, repoLink, branch, branch, repoLink, repoLink, buf.String()) case 6: // Create issue. infos := strings.SplitN(content, "|", 2) - return fmt.Sprintf(TPL_CREATE_ISSUE, setting.AppRootSubUrl, actUserName, actUserName, repoLink, infos[0], repoLink, infos[0], + return fmt.Sprintf(TPL_CREATE_ISSUE, setting.AppSubUrl, actUserName, actUserName, repoLink, infos[0], repoLink, infos[0], AvatarLink(email), infos[1]) case 8: // Transfer repository. newRepoLink := content + "/" + repoName - return fmt.Sprintf(TPL_TRANSFER_REPO, setting.AppRootSubUrl, actUserName, actUserName, repoLink, newRepoLink, newRepoLink) + return fmt.Sprintf(TPL_TRANSFER_REPO, setting.AppSubUrl, actUserName, actUserName, repoLink, newRepoLink, newRepoLink) case 9: // Push tag. - return fmt.Sprintf(TPL_PUSH_TAG, setting.AppRootSubUrl, actUserName, actUserName, repoLink, branch, branch, repoLink, repoLink) + return fmt.Sprintf(TPL_PUSH_TAG, setting.AppSubUrl, actUserName, actUserName, repoLink, branch, branch, repoLink, repoLink) case 10: // Comment issue. infos := strings.SplitN(content, "|", 2) - return fmt.Sprintf(TPL_COMMENT_ISSUE, setting.AppRootSubUrl, actUserName, actUserName, repoLink, infos[0], repoLink, infos[0], + return fmt.Sprintf(TPL_COMMENT_ISSUE, setting.AppSubUrl, actUserName, actUserName, repoLink, infos[0], repoLink, infos[0], AvatarLink(email), infos[1]) default: return "invalid type" diff --git a/modules/middleware/auth.go b/modules/middleware/auth.go index ccd8d031..8fae5d1e 100644 --- a/modules/middleware/auth.go +++ b/modules/middleware/auth.go @@ -25,13 +25,13 @@ func Toggle(options *ToggleOptions) macaron.Handler { return func(ctx *Context) { // Cannot view any page before installation. if !setting.InstallLock { - ctx.Redirect(setting.AppRootSubUrl + "/install") + ctx.Redirect(setting.AppSubUrl + "/install") return } // Redirect to dashboard if user tries to visit any non-login page. if options.SignOutRequire && ctx.IsSigned && ctx.Req.RequestURI != "/" { - ctx.Redirect(setting.AppRootSubUrl + "/") + ctx.Redirect(setting.AppSubUrl + "/") return } @@ -48,8 +48,8 @@ func Toggle(options *ToggleOptions) macaron.Handler { if strings.HasSuffix(ctx.Req.RequestURI, "watch") { return } - ctx.SetCookie("redirect_to", "/"+url.QueryEscape(setting.AppRootSubUrl + ctx.Req.RequestURI)) - ctx.Redirect(setting.AppRootSubUrl + "/user/login") + ctx.SetCookie("redirect_to", "/"+url.QueryEscape(setting.AppSubUrl+ctx.Req.RequestURI)) + ctx.Redirect(setting.AppSubUrl + "/user/login") return } else if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm { ctx.Data["Title"] = ctx.Tr("auth.active_your_account") diff --git a/modules/middleware/context.go b/modules/middleware/context.go index 5c26f91f..9145038f 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -187,7 +187,7 @@ func Contexter() macaron.Handler { Session: sess, } // Compute current URL for real-time change language. - link := setting.AppRootSubUrl + ctx.Req.RequestURI + link := setting.AppSubUrl + ctx.Req.RequestURI i := strings.Index(link, "?") if i > -1 { link = link[:i] diff --git a/modules/middleware/org.go b/modules/middleware/org.go index 3a2cf7bc..be102989 100644 --- a/modules/middleware/org.go +++ b/modules/middleware/org.go @@ -38,7 +38,7 @@ func OrgAssignment(redirect bool, args ...bool) macaron.Handler { ctx.Handle(404, "GetUserByName", err) } else if redirect { log.Error(4, "GetUserByName", err) - ctx.Redirect(setting.AppRootSubUrl + "/") + ctx.Redirect(setting.AppSubUrl + "/") } else { ctx.Handle(500, "GetUserByName", err) } @@ -68,7 +68,7 @@ func OrgAssignment(redirect bool, args ...bool) macaron.Handler { } ctx.Data["IsOrganizationOwner"] = ctx.Org.IsOwner - ctx.Org.OrgLink = setting.AppRootSubUrl + "/org/" + org.Name + ctx.Org.OrgLink = setting.AppSubUrl + "/org/" + org.Name ctx.Data["OrgLink"] = ctx.Org.OrgLink // Team. @@ -80,7 +80,7 @@ func OrgAssignment(redirect bool, args ...bool) macaron.Handler { ctx.Handle(404, "GetTeam", err) } else if redirect { log.Error(4, "GetTeam", err) - ctx.Redirect(setting.AppRootSubUrl + "/") + ctx.Redirect(setting.AppSubUrl + "/") } else { ctx.Handle(500, "GetTeam", err) } diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index e7d7fb56..79b01133 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -60,7 +60,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { ctx.Handle(404, "GetUserByName", err) } else if redirect { log.Error(4, "GetUserByName", err) - ctx.Redirect(setting.AppRootSubUrl + "/") + ctx.Redirect(setting.AppSubUrl + "/") } else { ctx.Handle(500, "GetUserByName", err) } @@ -72,7 +72,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { if u == nil { if redirect { - ctx.Redirect(setting.AppRootSubUrl + "/") + ctx.Redirect(setting.AppSubUrl + "/") return } ctx.Handle(404, "RepoAssignment", errors.New("invliad user account for single repository")) @@ -92,7 +92,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { ctx.Handle(404, "GetRepositoryByName", err) return } else if redirect { - ctx.Redirect(setting.AppRootSubUrl + "/") + ctx.Redirect(setting.AppSubUrl + "/") return } ctx.Handle(500, "GetRepositoryByName", err) @@ -160,7 +160,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { return } ctx.Repo.GitRepo = gitRepo - ctx.Repo.RepoLink = setting.AppRootSubUrl + "/" + u.Name + "/" + repo.Name + ctx.Repo.RepoLink = setting.AppSubUrl + "/" + u.Name + "/" + repo.Name ctx.Data["RepoLink"] = ctx.Repo.RepoLink tags, err := ctx.Repo.GitRepo.GetTags() @@ -298,8 +298,8 @@ func RequireTrueOwner() macaron.Handler { return func(ctx *Context) { if !ctx.Repo.IsTrueOwner && !ctx.Repo.IsAdmin { if !ctx.IsSigned { - ctx.SetCookie("redirect_to", "/"+url.QueryEscape(setting.AppRootSubUrl + ctx.Req.RequestURI)) - ctx.Redirect(setting.AppRootSubUrl + "/user/login") + ctx.SetCookie("redirect_to", "/"+url.QueryEscape(setting.AppSubUrl+ctx.Req.RequestURI)) + ctx.Redirect(setting.AppSubUrl + "/user/login") return } ctx.Handle(404, ctx.Req.RequestURI, nil) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 74427744..321282df 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -32,10 +32,10 @@ const ( var ( // App settings. - AppVer string - AppName string - AppUrl string - AppRootSubUrl string + AppVer string + AppName string + AppUrl string + AppSubUrl string // Server settings. Protocol Scheme @@ -167,11 +167,12 @@ func NewConfigContext() { AppUrl += "/" } + // Check if has app suburl. url, err := url.Parse(AppUrl) if err != nil { - log.Fatal(4, "Invalid ROOT_URL %s: %s", AppUrl, err) + log.Fatal(4, "Invalid ROOT_URL(%s): %s", AppUrl, err) } - AppRootSubUrl = strings.TrimSuffix(url.Path, "/") + AppSubUrl = strings.TrimSuffix(url.Path, "/") Protocol = HTTP if Cfg.MustValue("server", "PROTOCOL") == "https" { diff --git a/routers/admin/admin.go b/routers/admin/admin.go index 1fee7adb..6f2966bc 100644 --- a/routers/admin/admin.go +++ b/routers/admin/admin.go @@ -143,7 +143,7 @@ func Dashboard(ctx *middleware.Context) { } else { ctx.Flash.Success(success) } - ctx.Redirect(setting.AppRootSubUrl + "/admin") + ctx.Redirect(setting.AppSubUrl + "/admin") return } diff --git a/routers/admin/auths.go b/routers/admin/auths.go index 9eaae489..e537572b 100644 --- a/routers/admin/auths.go +++ b/routers/admin/auths.go @@ -100,7 +100,7 @@ func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) { } log.Trace("Authentication created by admin(%s): %s", ctx.User.Name, form.AuthName) - ctx.Redirect(setting.AppRootSubUrl + "/admin/auths") + ctx.Redirect(setting.AppSubUrl + "/admin/auths") } func EditAuthSource(ctx *middleware.Context) { @@ -181,7 +181,7 @@ func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) { log.Trace("Authentication changed by admin(%s): %s", ctx.User.Name, form.AuthName) ctx.Flash.Success(ctx.Tr("admin.auths.update_success")) - ctx.Redirect(setting.AppRootSubUrl + "/admin/auths/" + ctx.Params(":authid")) + ctx.Redirect(setting.AppSubUrl + "/admin/auths/" + ctx.Params(":authid")) } func DeleteAuthSource(ctx *middleware.Context) { @@ -201,12 +201,12 @@ func DeleteAuthSource(ctx *middleware.Context) { switch err { case models.ErrAuthenticationUserUsed: ctx.Flash.Error("form.still_own_user") - ctx.Redirect(setting.AppRootSubUrl + "/admin/auths/" + ctx.Params(":authid")) + ctx.Redirect(setting.AppSubUrl + "/admin/auths/" + ctx.Params(":authid")) default: ctx.Handle(500, "DelLoginSource", err) } return } log.Trace("Authentication deleted by admin(%s): %s", ctx.User.Name, a.Name) - ctx.Redirect(setting.AppRootSubUrl + "/admin/auths") + ctx.Redirect(setting.AppSubUrl + "/admin/auths") } diff --git a/routers/admin/users.go b/routers/admin/users.go index 5cdb0f5c..fc3b0cbc 100644 --- a/routers/admin/users.go +++ b/routers/admin/users.go @@ -121,7 +121,7 @@ func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) { return } log.Trace("Account created by admin(%s): %s", ctx.User.Name, u.Name) - ctx.Redirect(setting.AppRootSubUrl + "/admin/users") + ctx.Redirect(setting.AppSubUrl + "/admin/users") } func EditUser(ctx *middleware.Context) { @@ -198,7 +198,7 @@ func EditUserPost(ctx *middleware.Context, form auth.AdminEditUserForm) { ctx.Data["User"] = u ctx.Flash.Success(ctx.Tr("admin.users.update_profile_success")) - ctx.Redirect(setting.AppRootSubUrl + "/admin/users/" + ctx.Params(":userid")) + ctx.Redirect(setting.AppSubUrl + "/admin/users/" + ctx.Params(":userid")) } func DeleteUser(ctx *middleware.Context) { @@ -218,12 +218,12 @@ func DeleteUser(ctx *middleware.Context) { switch err { case models.ErrUserOwnRepos: ctx.Flash.Error(ctx.Tr("admin.users.still_own_repo")) - ctx.Redirect(setting.AppRootSubUrl + "/admin/users/" + ctx.Params(":userid")) + ctx.Redirect(setting.AppSubUrl + "/admin/users/" + ctx.Params(":userid")) default: ctx.Handle(500, "DeleteUser", err) } return } log.Trace("Account deleted by admin(%s): %s", ctx.User.Name, u.Name) - ctx.Redirect(setting.AppRootSubUrl + "/admin/users") + ctx.Redirect(setting.AppSubUrl + "/admin/users") } diff --git a/routers/home.go b/routers/home.go index 8e973d16..dd604ec7 100644 --- a/routers/home.go +++ b/routers/home.go @@ -33,7 +33,7 @@ func Home(ctx *middleware.Context) { // Check auto-login. uname := ctx.GetCookie(setting.CookieUserName) if len(uname) != 0 { - ctx.Redirect(setting.AppRootSubUrl + "/user/login") + ctx.Redirect(setting.AppSubUrl + "/user/login") return } diff --git a/routers/install.go b/routers/install.go index 54da4d4f..07af613c 100644 --- a/routers/install.go +++ b/routers/install.go @@ -253,5 +253,5 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) { log.Info("First-time run install finished!") ctx.Flash.Success(ctx.Tr("install.install_success")) - ctx.Redirect(setting.AppRootSubUrl + "/user/login") + ctx.Redirect(setting.AppSubUrl + "/user/login") } diff --git a/routers/org/members.go b/routers/org/members.go index d3bd51ea..f571e334 100644 --- a/routers/org/members.go +++ b/routers/org/members.go @@ -87,7 +87,7 @@ func MembersAction(ctx *middleware.Context) { if ctx.Params(":action") != "leave" { ctx.Redirect(ctx.Org.OrgLink + "/members") } else { - ctx.Redirect(setting.AppRootSubUrl + "/") + ctx.Redirect(setting.AppSubUrl + "/") } } diff --git a/routers/org/org.go b/routers/org/org.go index cea70823..ab589832 100644 --- a/routers/org/org.go +++ b/routers/org/org.go @@ -83,5 +83,5 @@ func CreatePost(ctx *middleware.Context, form auth.CreateOrgForm) { } log.Trace("Organization created: %s", org.Name) - ctx.Redirect(setting.AppRootSubUrl + "/org/" + form.OrgName + "/dashboard") + ctx.Redirect(setting.AppSubUrl + "/org/" + form.OrgName + "/dashboard") } diff --git a/routers/org/setting.go b/routers/org/setting.go index 3d397c0c..0522f998 100644 --- a/routers/org/setting.go +++ b/routers/org/setting.go @@ -49,7 +49,7 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateOrgSettingForm) { } else if err = models.ChangeUserName(org, form.OrgUserName); err != nil { if err == models.ErrUserNameIllegal { ctx.Flash.Error(ctx.Tr("form.illegal_username")) - ctx.Redirect(setting.AppRootSubUrl + "/org/" + org.LowerName + "/settings") + ctx.Redirect(setting.AppSubUrl + "/org/" + org.LowerName + "/settings") return } else { ctx.Handle(500, "ChangeUserName", err) @@ -73,7 +73,7 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateOrgSettingForm) { } log.Trace("Organization setting updated: %s", org.Name) ctx.Flash.Success(ctx.Tr("org.settings.update_setting_success")) - ctx.Redirect(setting.AppRootSubUrl + "/org/" + org.Name + "/settings") + ctx.Redirect(setting.AppSubUrl + "/org/" + org.Name + "/settings") } func SettingsDelete(ctx *middleware.Context) { @@ -87,13 +87,13 @@ func SettingsDelete(ctx *middleware.Context) { switch err { case models.ErrUserOwnRepos: ctx.Flash.Error(ctx.Tr("form.org_still_own_repo")) - ctx.Redirect(setting.AppRootSubUrl + "/org/" + org.LowerName + "/settings/delete") + ctx.Redirect(setting.AppSubUrl + "/org/" + org.LowerName + "/settings/delete") default: ctx.Handle(500, "DeleteOrganization", err) } } else { log.Trace("Organization deleted: %s", ctx.User.Name) - ctx.Redirect(setting.AppRootSubUrl + "/") + ctx.Redirect(setting.AppSubUrl + "/") } return } diff --git a/routers/repo/commit.go b/routers/repo/commit.go index e58b9e78..218cae7b 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -159,8 +159,8 @@ func Diff(ctx *middleware.Context) { ctx.Data["Diff"] = diff ctx.Data["Parents"] = parents ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0 - ctx.Data["SourcePath"] = setting.AppRootSubUrl + "/" + path.Join(userName, repoName, "src", commitId) - ctx.Data["RawPath"] = setting.AppRootSubUrl + "/" + path.Join(userName, repoName, "raw", commitId) + ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", commitId) + ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "raw", commitId) ctx.HTML(200, DIFF) } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 8aba82ff..3a028e58 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -54,8 +54,8 @@ func Issues(ctx *middleware.Context) { isShowClosed := ctx.Query("state") == "closed" if viewType != "all" && !ctx.IsSigned { - ctx.SetCookie("redirect_to", "/"+url.QueryEscape(setting.AppRootSubUrl + ctx.Req.RequestURI)) - ctx.Redirect(setting.AppRootSubUrl + "/user/login") + ctx.SetCookie("redirect_to", "/"+url.QueryEscape(setting.AppSubUrl+ctx.Req.RequestURI)) + ctx.Redirect(setting.AppSubUrl + "/user/login") return } @@ -312,7 +312,7 @@ func CreateIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) { } log.Trace("%d Issue created: %d", ctx.Repo.Repository.Id, issue.Id) - send(200, fmt.Sprintf("%s/%s/%s/issues/%d", setting.AppRootSubUrl, ctx.Params(":username"), ctx.Params(":reponame"), issue.Index), nil) + send(200, fmt.Sprintf("%s/%s/%s/issues/%d", setting.AppSubUrl, ctx.Params(":username"), ctx.Params(":reponame"), issue.Index), nil) } func checkLabels(labels, allLabels []*models.Label) { diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 3bd9aa7c..ae599f9f 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -96,7 +96,7 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { form.Gitignore, form.License, form.Private, false, form.InitReadme) if err == nil { log.Trace("Repository created: %s/%s", ctxUser.Name, form.RepoName) - ctx.Redirect(setting.AppRootSubUrl + "/" + ctxUser.Name + "/" + form.RepoName) + ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + form.RepoName) return } else if err == models.ErrRepoAlreadyExist { ctx.Data["Err_RepoName"] = true @@ -180,7 +180,7 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { form.Mirror, url) if err == nil { log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName) - ctx.Redirect(setting.AppRootSubUrl + "/" + ctxUser.Name + "/" + form.RepoName) + ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + form.RepoName) return } else if err == models.ErrRepoAlreadyExist { ctx.Data["Err_RepoName"] = true diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 926b5432..137d104f 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -97,7 +97,7 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) { } ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success")) - ctx.Redirect(fmt.Sprintf("%s/%s/%s/settings", setting.AppRootSubUrl, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)) + ctx.Redirect(fmt.Sprintf("%s/%s/%s/settings", setting.AppSubUrl, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)) case "transfer": if ctx.Repo.Repository.Name != form.RepoName { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), SETTINGS_OPTIONS, nil) @@ -122,7 +122,7 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) { } log.Trace("Repository transfered: %s/%s -> %s", ctx.Repo.Owner.Name, ctx.Repo.Repository.Name, newOwner) ctx.Flash.Success(ctx.Tr("repo.settings.transfer_succeed")) - ctx.Redirect(setting.AppRootSubUrl + "/") + ctx.Redirect(setting.AppSubUrl + "/") case "delete": if ctx.Repo.Repository.Name != form.RepoName { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), SETTINGS_OPTIONS, nil) @@ -151,9 +151,9 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) { } log.Trace("Repository deleted: %s/%s", ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) if ctx.Repo.Owner.IsOrganization() { - ctx.Redirect(setting.AppRootSubUrl + "/org/" + ctx.Repo.Owner.Name + "/dashboard") + ctx.Redirect(setting.AppSubUrl + "/org/" + ctx.Repo.Owner.Name + "/dashboard") } else { - ctx.Redirect(setting.AppRootSubUrl + "/") + ctx.Redirect(setting.AppSubUrl + "/") } } } @@ -167,7 +167,7 @@ func SettingsCollaboration(ctx *middleware.Context) { if ctx.Req.Method == "POST" { name := strings.ToLower(ctx.Query("collaborator")) if len(name) == 0 || ctx.Repo.Owner.LowerName == name { - ctx.Redirect(setting.AppRootSubUrl + ctx.Req.URL.Path) + ctx.Redirect(setting.AppSubUrl + ctx.Req.URL.Path) return } has, err := models.HasAccess(name, repoLink, models.WRITABLE) @@ -175,7 +175,7 @@ func SettingsCollaboration(ctx *middleware.Context) { ctx.Handle(500, "HasAccess", err) return } else if has { - ctx.Redirect(setting.AppRootSubUrl + ctx.Req.URL.Path) + ctx.Redirect(setting.AppSubUrl + ctx.Req.URL.Path) return } @@ -183,7 +183,7 @@ func SettingsCollaboration(ctx *middleware.Context) { if err != nil { if err == models.ErrUserNotExist { ctx.Flash.Error(ctx.Tr("form.user_not_exist")) - ctx.Redirect(setting.AppRootSubUrl + ctx.Req.URL.Path) + ctx.Redirect(setting.AppSubUrl + ctx.Req.URL.Path) } else { ctx.Handle(500, "GetUserByName", err) } @@ -204,7 +204,7 @@ func SettingsCollaboration(ctx *middleware.Context) { } ctx.Flash.Success(ctx.Tr("repo.settings.add_collaborator_success")) - ctx.Redirect(setting.AppRootSubUrl + ctx.Req.URL.Path) + ctx.Redirect(setting.AppSubUrl + ctx.Req.URL.Path) return } diff --git a/routers/user/auth.go b/routers/user/auth.go index 1dbc3300..71622e55 100644 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -82,7 +82,7 @@ func SignIn(ctx *middleware.Context) { return } - ctx.Redirect(setting.AppRootSubUrl + "/") + ctx.Redirect(setting.AppSubUrl + "/") } func SignInPost(ctx *middleware.Context, form auth.SignInForm) { @@ -140,7 +140,7 @@ func SignInPost(ctx *middleware.Context, form auth.SignInForm) { return } - ctx.Redirect(setting.AppRootSubUrl + "/") + ctx.Redirect(setting.AppSubUrl + "/") } func SignOut(ctx *middleware.Context) { @@ -151,7 +151,7 @@ func SignOut(ctx *middleware.Context) { ctx.Session.Delete("socialEmail") ctx.SetCookie(setting.CookieUserName, "", -1) ctx.SetCookie(setting.CookieRememberName, "", -1) - ctx.Redirect(setting.AppRootSubUrl + "/") + ctx.Redirect(setting.AppSubUrl + "/") } func oauthSignUp(ctx *middleware.Context, sid int64) { @@ -288,7 +288,7 @@ func SignUpPost(ctx *middleware.Context, cpt *captcha.Captcha, form auth.Registe return } - ctx.Redirect(setting.AppRootSubUrl + "/user/login") + ctx.Redirect(setting.AppSubUrl + "/user/login") } func Activate(ctx *middleware.Context) { @@ -335,7 +335,7 @@ func Activate(ctx *middleware.Context) { ctx.Session.Set("uid", user.Id) ctx.Session.Set("uname", user.Name) - ctx.Redirect(setting.AppRootSubUrl + "/") + ctx.Redirect(setting.AppSubUrl + "/") return } @@ -437,7 +437,7 @@ func ResetPasswdPost(ctx *middleware.Context) { } log.Trace("User password reset: %s", u.Name) - ctx.Redirect(setting.AppRootSubUrl + "/user/login") + ctx.Redirect(setting.AppSubUrl + "/user/login") return } diff --git a/routers/user/home.go b/routers/user/home.go index b411b8fc..031872fc 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -127,7 +127,7 @@ func Profile(ctx *middleware.Context) { uname := ctx.Params(":username") // Special handle for FireFox requests favicon.ico. if uname == "favicon.ico" { - ctx.Redirect(setting.AppRootSubUrl + "/img/favicon.png") + ctx.Redirect(setting.AppSubUrl + "/img/favicon.png") return } @@ -142,7 +142,7 @@ func Profile(ctx *middleware.Context) { } if u.IsOrganization() { - ctx.Redirect(setting.AppRootSubUrl + "/org/" + u.Name) + ctx.Redirect(setting.AppSubUrl + "/org/" + u.Name) return } @@ -182,7 +182,7 @@ func Email2User(ctx *middleware.Context) { } return } - ctx.Redirect(setting.AppRootSubUrl + "/user/" + u.Name) + ctx.Redirect(setting.AppSubUrl + "/user/" + u.Name) } const ( diff --git a/routers/user/setting.go b/routers/user/setting.go index a540f054..8f778acd 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -56,7 +56,7 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) { } else if err = models.ChangeUserName(ctx.User, form.UserName); err != nil { if err == models.ErrUserNameIllegal { ctx.Flash.Error(ctx.Tr("form.illegal_username")) - ctx.Redirect(setting.AppRootSubUrl + "/user/settings") + ctx.Redirect(setting.AppSubUrl + "/user/settings") return } else { ctx.Handle(500, "ChangeUserName", err) @@ -79,7 +79,7 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) { } log.Trace("User setting updated: %s", ctx.User.Name) ctx.Flash.Success(ctx.Tr("settings.update_profile_success")) - ctx.Redirect(setting.AppRootSubUrl + "/user/settings") + ctx.Redirect(setting.AppSubUrl + "/user/settings") } func SettingsPassword(ctx *middleware.Context) { @@ -120,7 +120,7 @@ func SettingsPasswordPost(ctx *middleware.Context, form auth.ChangePasswordForm) ctx.Flash.Success(ctx.Tr("settings.change_password_success")) } - ctx.Redirect(setting.AppRootSubUrl + "/user/settings/password") + ctx.Redirect(setting.AppSubUrl + "/user/settings/password") } func SettingsSSHKeys(ctx *middleware.Context) { @@ -161,7 +161,7 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { ctx.Handle(500, "DeletePublicKey", err) } else { log.Trace("SSH key deleted: %s", ctx.User.Name) - ctx.Redirect(setting.AppRootSubUrl + "/user/settings/ssh") + ctx.Redirect(setting.AppSubUrl + "/user/settings/ssh") } return } @@ -178,7 +178,7 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { if ok, err := models.CheckPublicKeyString(cleanContent); !ok { ctx.Flash.Error(ctx.Tr("form.invalid_ssh_key", err.Error())) - ctx.Redirect(setting.AppRootSubUrl + "/user/settings/ssh") + ctx.Redirect(setting.AppSubUrl + "/user/settings/ssh") return } @@ -197,7 +197,7 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { } else { log.Trace("SSH key added: %s", ctx.User.Name) ctx.Flash.Success(ctx.Tr("settings.add_key_success")) - ctx.Redirect(setting.AppRootSubUrl + "/user/settings/ssh") + ctx.Redirect(setting.AppSubUrl + "/user/settings/ssh") return } } @@ -218,7 +218,7 @@ func SettingsSocial(ctx *middleware.Context) { return } ctx.Flash.Success(ctx.Tr("settings.unbind_success")) - ctx.Redirect(setting.AppRootSubUrl + "/user/settings/social") + ctx.Redirect(setting.AppSubUrl + "/user/settings/social") return } @@ -249,13 +249,13 @@ func SettingsDelete(ctx *middleware.Context) { switch err { case models.ErrUserOwnRepos: ctx.Flash.Error(ctx.Tr("form.still_own_repo")) - ctx.Redirect(setting.AppRootSubUrl + "/user/settings/delete") + ctx.Redirect(setting.AppSubUrl + "/user/settings/delete") default: ctx.Handle(500, "DeleteUser", err) } } else { log.Trace("Account deleted: %s", ctx.User.Name) - ctx.Redirect(setting.AppRootSubUrl + "/") + ctx.Redirect(setting.AppSubUrl + "/") } return } diff --git a/routers/user/social.go b/routers/user/social.go index fc2ea5fb..0bc1fa59 100644 --- a/routers/user/social.go +++ b/routers/user/social.go @@ -22,7 +22,7 @@ import ( func extractPath(next string) string { n, err := url.Parse(next) if err != nil { - return setting.AppRootSubUrl + "/" + return setting.AppSubUrl + "/" } return n.Path } @@ -88,7 +88,7 @@ func SocialSignIn(ctx *middleware.Context) { return } case models.ErrOauth2NotAssociated: - next = setting.AppRootSubUrl + "/user/sign_up" + next = setting.AppSubUrl + "/user/sign_up" default: ctx.Handle(500, "social.SocialSignIn(GetOauth2)", err) return diff --git a/templates/.VERSION b/templates/.VERSION index 29de2fdf..9df945b7 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.2.0917 Beta \ No newline at end of file +0.5.3.0919 Beta \ No newline at end of file diff --git a/templates/admin/auth/edit.tmpl b/templates/admin/auth/edit.tmpl index 4dead7f0..9697b773 100644 --- a/templates/admin/auth/edit.tmpl +++ b/templates/admin/auth/edit.tmpl @@ -12,7 +12,7 @@
      {{.i18n.Tr "admin.auths.edit"}}
      - + {{.CsrfTokenHtml}} {{$type := .Source.Type}} diff --git a/templates/admin/auth/list.tmpl b/templates/admin/auth/list.tmpl index ba10e1d2..01b586fb 100644 --- a/templates/admin/auth/list.tmpl +++ b/templates/admin/auth/list.tmpl @@ -13,7 +13,7 @@ {{.i18n.Tr "admin.auths.auth_manage_panel"}}
      @@ -31,20 +31,20 @@ {{range .Sources}} - + - + {{end}}
      {{.Id}}{{.Name}}{{.Name}} {{.TypeString}} {{DateFormat .Updated "M d, Y"}} {{DateFormat .Created "M d, Y"}}
      {{if or .LastPageNum .NextPageNum}} {{end}}
      diff --git a/templates/admin/auth/new.tmpl b/templates/admin/auth/new.tmpl index 869eff32..daae60e0 100644 --- a/templates/admin/auth/new.tmpl +++ b/templates/admin/auth/new.tmpl @@ -12,7 +12,7 @@
      {{.i18n.Tr "admin.auths.new"}}
      - + {{.CsrfTokenHtml}}
      diff --git a/templates/admin/dashboard.tmpl b/templates/admin/dashboard.tmpl index 00696611..80c02828 100644 --- a/templates/admin/dashboard.tmpl +++ b/templates/admin/dashboard.tmpl @@ -34,11 +34,11 @@ {{.i18n.Tr "admin.dashboard.clean_unbind_oauth"}} - {{.i18n.Tr "admin.dashboard.operation_run"}} + {{.i18n.Tr "admin.dashboard.operation_run"}} {{.i18n.Tr "admin.dashboard.delete_inactivate_accounts"}} - {{.i18n.Tr "admin.dashboard.operation_run"}} + {{.i18n.Tr "admin.dashboard.operation_run"}} diff --git a/templates/admin/nav.tmpl b/templates/admin/nav.tmpl index ae44f4a8..e294cd92 100644 --- a/templates/admin/nav.tmpl +++ b/templates/admin/nav.tmpl @@ -2,13 +2,13 @@

      {{.i18n.Tr "admin_panel"}}

      \ No newline at end of file diff --git a/templates/admin/org/list.tmpl b/templates/admin/org/list.tmpl index f42c2c53..f901c696 100644 --- a/templates/admin/org/list.tmpl +++ b/templates/admin/org/list.tmpl @@ -30,7 +30,7 @@ {{range .Orgs}} {{.Id}} - {{.Name}} + {{.Name}} {{.Email}} {{.NumTeams}} {{.NumMembers}} @@ -42,8 +42,8 @@ {{if or .LastPageNum .NextPageNum}} {{end}}
      diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl index 3e7442a6..cb333aeb 100644 --- a/templates/admin/repo/list.tmpl +++ b/templates/admin/repo/list.tmpl @@ -31,8 +31,8 @@ {{range .Repos}} {{.Id}} - {{.Owner.Name}} - {{.Name}} + {{.Owner.Name}} + {{.Name}} {{.NumWatches}} {{.NumIssues}} @@ -44,8 +44,8 @@ {{if or .LastPageNum .NextPageNum}} {{end}}
      diff --git a/templates/admin/user/edit.tmpl b/templates/admin/user/edit.tmpl index e9ed7836..3924afec 100644 --- a/templates/admin/user/edit.tmpl +++ b/templates/admin/user/edit.tmpl @@ -12,7 +12,7 @@
      {{.i18n.Tr "admin.users.edit_account"}}
      - + {{.CsrfTokenHtml}}
      diff --git a/templates/admin/user/list.tmpl b/templates/admin/user/list.tmpl index f85bb6c0..1092539e 100644 --- a/templates/admin/user/list.tmpl +++ b/templates/admin/user/list.tmpl @@ -13,7 +13,7 @@ {{.i18n.Tr "admin.users.user_manage_panel"}}
      - {{.i18n.Tr "admin.users.new_account"}} + {{.i18n.Tr "admin.users.new_account"}}
      @@ -32,21 +32,21 @@ {{range .Users}} - + - + {{end}}
      {{.Id}}{{.Name}}{{.Name}} {{.Email}} {{.NumRepos}} {{DateFormat .Created "M d, Y"}}
      {{if or .LastPageNum .NextPageNum}} {{end}}
      diff --git a/templates/admin/user/new.tmpl b/templates/admin/user/new.tmpl index db842c68..38acbf8f 100644 --- a/templates/admin/user/new.tmpl +++ b/templates/admin/user/new.tmpl @@ -12,7 +12,7 @@
      {{.i18n.Tr "admin.users.new_account"}}
      - + {{.CsrfTokenHtml}}
      diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index 55dd4690..7775933c 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -1,8 +1,8 @@ - + - + @@ -19,21 +19,21 @@ {{else}} - - + + - - + + {{end}} - - - - - + + + + + - - + + {{if .Title}}{{.Title}} - {{end}}{{AppName}} diff --git a/templates/base/navbar.tmpl b/templates/base/navbar.tmpl index 991e773d..b69e9dc4 100644 --- a/templates/base/navbar.tmpl +++ b/templates/base/navbar.tmpl @@ -1,8 +1,8 @@ diff --git a/templates/explore/nav.tmpl b/templates/explore/nav.tmpl index a6c0acad..556627b0 100644 --- a/templates/explore/nav.tmpl +++ b/templates/explore/nav.tmpl @@ -2,7 +2,7 @@

      {{.i18n.Tr "explore"}}

      \ No newline at end of file diff --git a/templates/explore/repos.tmpl b/templates/explore/repos.tmpl index b8ae1791..954d0b06 100644 --- a/templates/explore/repos.tmpl +++ b/templates/explore/repos.tmpl @@ -12,7 +12,7 @@
    • {{.NumStars}}
    • {{.NumForks}}
    -

    {{.Name}}

    +

    {{.Name}}

    {{.Description}}

    {{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Updated $.i18n.Lang}}

    diff --git a/templates/home.tmpl b/templates/home.tmpl index 0fa70869..da73025d 100644 --- a/templates/home.tmpl +++ b/templates/home.tmpl @@ -3,12 +3,12 @@

    Gogs

    {{.i18n.Tr "app_desc"}}

    -
    + {{.CsrfTokenHtml}} diff --git a/templates/install.tmpl b/templates/install.tmpl index eb294082..f1c28031 100644 --- a/templates/install.tmpl +++ b/templates/install.tmpl @@ -8,7 +8,7 @@
    {{.i18n.Tr "install.title"}}
    - + {{.CsrfTokenHtml}}
    {{.i18n.Tr "install.requite_db_desc"}}
    diff --git a/templates/ng/base/head.tmpl b/templates/ng/base/head.tmpl index 222edb69..efdc9653 100644 --- a/templates/ng/base/head.tmpl +++ b/templates/ng/base/head.tmpl @@ -1,6 +1,6 @@ - + @@ -9,27 +9,27 @@ {{if .Repository.IsGoget}}{{end}} - + {{if CdnMode}} {{else}} - + - + {{end}} - - - - + + + + - - - + + + {{if .Title}}{{.Title}} - {{end}}{{AppName}} diff --git a/templates/ng/base/header.tmpl b/templates/ng/base/header.tmpl index af3bc02f..aec4e2ef 100644 --- a/templates/ng/base/header.tmpl +++ b/templates/ng/base/header.tmpl @@ -2,37 +2,37 @@ -

    {{.Name}}

    +

    {{.Name}}

    {{.Description}}

    {{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Updated $.i18n.Lang}}

    @@ -46,20 +46,20 @@
    {{if $isMember}} - {{.Org.NumMembers}} + {{.Org.NumMembers}} {{end}} {{.i18n.Tr "org.people"}}
    {{range .Members}} {{if or $isMember (.IsPublicMember $.Org.Id)}} - + {{end}} {{end}}
    {{if .IsOrganizationOwner}} {{end}}
    @@ -67,14 +67,14 @@
    - {{.Org.NumTeams}} + {{.Org.NumTeams}} {{.i18n.Tr "org.teams"}}
      {{range .Teams}}
    • - {{.Name}} + {{.Name}}

      {{.NumMembers}} {{$.i18n.Tr "org.lower_members"}} · {{.NumRepos}} {{$.i18n.Tr "org.lower_repositories"}}

    • {{end}} @@ -82,7 +82,7 @@
    {{if .IsOrganizationOwner}} {{end}}
    diff --git a/templates/org/member/members.tmpl b/templates/org/member/members.tmpl index eb4b9b7f..0e7453ac 100644 --- a/templates/org/member/members.tmpl +++ b/templates/org/member/members.tmpl @@ -14,7 +14,7 @@ {{range .Members}}
    - {{.FullName}}({{.Name}}) + {{.FullName}}({{.Name}})
    • {{ $isPublic := .IsPublicMember $.Org.Id}} diff --git a/templates/org/new.tmpl b/templates/org/new.tmpl index eb5fd9a3..4e42775a 100644 --- a/templates/org/new.tmpl +++ b/templates/org/new.tmpl @@ -1,7 +1,7 @@ {{template "base/head" .}} {{template "base/navbar" .}}
      -
      + {{.CsrfTokenHtml}}

      Create New Organization

      {{template "base/alert" .}} @@ -24,7 +24,7 @@
      - Cancel + Cancel
      diff --git a/templates/org/settings/delete.tmpl b/templates/org/settings/delete.tmpl index 938fdd64..8b698e0d 100644 --- a/templates/org/settings/delete.tmpl +++ b/templates/org/settings/delete.tmpl @@ -12,7 +12,7 @@

      {{.i18n.Tr "org.settings.delete_account"}}

      {{.i18n.Tr "org.settings.delete_prompt" | Str2html}} -
      + {{.CsrfTokenHtml}}

      diff --git a/templates/org/settings/nav.tmpl b/templates/org/settings/nav.tmpl index 63cb6f08..11d32d7f 100644 --- a/templates/org/settings/nav.tmpl +++ b/templates/org/settings/nav.tmpl @@ -4,9 +4,9 @@

      diff --git a/templates/org/settings/options.tmpl b/templates/org/settings/options.tmpl index 09492193..793b9c29 100644 --- a/templates/org/settings/options.tmpl +++ b/templates/org/settings/options.tmpl @@ -12,7 +12,7 @@
      {{.i18n.Tr "org.settings.options"}}
      - + {{.CsrfTokenHtml}}
      diff --git a/templates/org/team/members.tmpl b/templates/org/team/members.tmpl index ad9b30ed..66f496eb 100644 --- a/templates/org/team/members.tmpl +++ b/templates/org/team/members.tmpl @@ -30,7 +30,7 @@ {{if $.IsOrganizationOwner}} {{$.i18n.Tr "org.members.remove"}} {{end}} - + {{.Name}} {{.FullName}} ({{.Name}}) diff --git a/templates/org/team/repositories.tmpl b/templates/org/team/repositories.tmpl index f7ff97d8..31b6477c 100644 --- a/templates/org/team/repositories.tmpl +++ b/templates/org/team/repositories.tmpl @@ -30,7 +30,7 @@ {{if $canAddRemove}} {{$.i18n.Tr "org.teams.remove_repo"}} {{end}} - + {{$.Org.Name}}/{{.Name}} diff --git a/templates/org/team/teams.tmpl b/templates/org/team/teams.tmpl index 6440807f..30df3e40 100644 --- a/templates/org/team/teams.tmpl +++ b/templates/org/team/teams.tmpl @@ -25,7 +25,7 @@ {{if .NumMembers}}
      {{range .Members}} - + {{end}} diff --git a/templates/repo/bare.tmpl b/templates/repo/bare.tmpl index 712e7013..2a1409a6 100644 --- a/templates/repo/bare.tmpl +++ b/templates/repo/bare.tmpl @@ -5,7 +5,7 @@

      - {{.Repository.Owner.Name}} + {{.Repository.Owner.Name}} / {{.Repository.Name}}

      diff --git a/templates/repo/commits_table.tmpl b/templates/repo/commits_table.tmpl index aa97925c..cb2ed5d0 100644 --- a/templates/repo/commits_table.tmpl +++ b/templates/repo/commits_table.tmpl @@ -26,8 +26,8 @@ {{$r := List .Commits}} {{range $r}} - {{.Author.Name}} - {{SubStr .Id.String 0 10}} + {{.Author.Name}} + {{SubStr .Id.String 0 10}} {{.Summary}} {{TimeSince .Author.When $.Lang}} diff --git a/templates/repo/create.tmpl b/templates/repo/create.tmpl index 7b3c85ae..5d0c9b0f 100644 --- a/templates/repo/create.tmpl +++ b/templates/repo/create.tmpl @@ -1,7 +1,7 @@ {{template "ng/base/head" .}} {{template "ng/base/header" .}}
      - + {{.CsrfTokenHtml}}

      {{.i18n.Tr "new_repo"}}

      @@ -75,7 +75,7 @@
      - {{.i18n.Tr "cancel"}} + {{.i18n.Tr "cancel"}}
      diff --git a/templates/repo/diff.tmpl b/templates/repo/diff.tmpl index 548c7a35..8e5efd14 100644 --- a/templates/repo/diff.tmpl +++ b/templates/repo/diff.tmpl @@ -30,7 +30,7 @@

      - {{.Commit.Author.Name}} + {{.Commit.Author.Name}} {{TimeSince .Commit.Author.When $.Lang}}

      diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index dc271a75..524bfd11 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -2,7 +2,7 @@

      - {{.Owner.Name}} + {{.Owner.Name}} / {{.Repository.Name}} {{if .Repository.IsMirror}}{{.i18n.Tr "mirror"}}{{end}} diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index 1849602b..0f9daae9 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -85,7 +85,7 @@

      - {{.Poster.Name}} + {{.Poster.Name}} {{TimeSince .Created $.Lang}} {{.NumComments}}

      diff --git a/templates/repo/issue/view.tmpl b/templates/repo/issue/view.tmpl index dbbd1d92..49aa982a 100644 --- a/templates/repo/issue/view.tmpl +++ b/templates/repo/issue/view.tmpl @@ -8,7 +8,7 @@
      #{{.Issue.Index}}
      - +

      {{.Issue.Name}}

      @@ -17,7 +17,7 @@ {{end}} {{if .Issue.IsClosed}}Closed{{else}}Open{{end}} - {{.Issue.Poster.Name}} opened this issue + {{.Issue.Poster.Name}} opened this issue {{TimeSince .Issue.Created $.Lang}} · {{.Issue.NumComments}} comments

      @@ -63,10 +63,10 @@ {{/* 0 = COMMENT, 1 = REOPEN, 2 = CLOSE, 3 = ISSUE, 4 = COMMIT, 5 = PULL */}} {{if eq .Type 0}}
      - +
      - {{.Poster.Name}} commented {{TimeSince .Created $.Lang}} + {{.Poster.Name}} commented {{TimeSince .Created $.Lang}} Owner @@ -93,25 +93,25 @@
      {{else if eq .Type 1}}
      - +
      - {{.Poster.Name}} Reopened this issue {{TimeSince .Created $.Lang}} + {{.Poster.Name}} Reopened this issue {{TimeSince .Created $.Lang}}
      {{else if eq .Type 2}}
      - +
      - {{.Poster.Name}} Closed this issue {{TimeSince .Created $.Lang}} + {{.Poster.Name}} Closed this issue {{TimeSince .Created $.Lang}}
      {{else if eq .Type 4}}
      - +
      - {{.Poster.Name}} Referenced this issue {{TimeSince .Created $.Lang}} + {{.Poster.Name}} Referenced this issue {{TimeSince .Created $.Lang}}

      - + {{.ContentHtml}}

      @@ -120,7 +120,7 @@ {{end}}
      {{if .SignedUser}}
      - +
      {{.CsrfTokenHtml}}
      @@ -163,7 +163,7 @@
      -
      {{else}}
      Sign up for free to join this conversation. Already have an account? Sign in to comment
      {{end}} +
      {{else}}
      Sign up for free to join this conversation. Already have an account? Sign in to comment
      {{end}}
      diff --git a/templates/repo/migrate.tmpl b/templates/repo/migrate.tmpl index f40124bf..b28d0647 100644 --- a/templates/repo/migrate.tmpl +++ b/templates/repo/migrate.tmpl @@ -1,7 +1,7 @@ {{template "ng/base/head" .}} {{template "ng/base/header" .}}
      -
      + {{.CsrfTokenHtml}}

      {{.i18n.Tr "new_migrate"}}

      @@ -74,7 +74,7 @@
      - {{.i18n.Tr "cancel"}} + {{.i18n.Tr "cancel"}}
      diff --git a/templates/repo/nav.tmpl b/templates/repo/nav.tmpl index 566e11a0..dfcfd745 100644 --- a/templates/repo/nav.tmpl +++ b/templates/repo/nav.tmpl @@ -2,7 +2,7 @@
      -

      {{.Owner.Name}} / {{.Repository.Name}} {{if .Repository.IsPrivate}}Private{{else if .Repository.IsMirror}}Mirror{{end}}

      +

      {{.Owner.Name}} / {{.Repository.Name}} {{if .Repository.IsPrivate}}Private{{else if .Repository.IsMirror}}Mirror{{end}}

      {{.Repository.DescriptionHtml}}{{if .Repository.Website}} {{.Repository.Website}}{{end}}

      @@ -32,7 +32,7 @@
      {{if .IsSigned}} -
      +
      {{if .IsRepositoryWatching}} {{else}} @@ -59,7 +59,7 @@
      --> {{end}}
      diff --git a/templates/repo/release/list.tmpl b/templates/repo/release/list.tmpl index 2bb5faa4..58a050ab 100644 --- a/templates/repo/release/list.tmpl +++ b/templates/repo/release/list.tmpl @@ -6,7 +6,7 @@

      Releases + Tags -->

        @@ -28,7 +28,7 @@

        {{.Title}} (edit)

           - {{.Publisher.Name}} + {{.Publisher.Name}} {{if .Created}}{{TimeSince .Created $.Lang}}{{end}} {{.NumCommitsBehind}} commits to {{.Target}} since this release

        diff --git a/templates/repo/setting_nav.tmpl b/templates/repo/setting_nav.tmpl index 8cd1f2a2..5aa77f0b 100644 --- a/templates/repo/setting_nav.tmpl +++ b/templates/repo/setting_nav.tmpl @@ -1,7 +1,7 @@ \ No newline at end of file diff --git a/templates/repo/settings/collaboration.tmpl b/templates/repo/settings/collaboration.tmpl index 99561e27..98091c35 100644 --- a/templates/repo/settings/collaboration.tmpl +++ b/templates/repo/settings/collaboration.tmpl @@ -18,7 +18,7 @@ {{range .Collaborators}}
      • {{if not (eq .Id $.Owner.Id)}}{{end}} - + {{.Name}} {{.FullName}} ({{.Name}}) diff --git a/templates/repo/single.tmpl b/templates/repo/single.tmpl index 9fbf2f55..d640fb00 100644 --- a/templates/repo/single.tmpl +++ b/templates/repo/single.tmpl @@ -12,7 +12,7 @@
      diff --git a/templates/repo/single_list.tmpl b/templates/repo/single_list.tmpl index 6728dd70..03511a80 100644 --- a/templates/repo/single_list.tmpl +++ b/templates/repo/single_list.tmpl @@ -1,9 +1,9 @@
      - {{.LastCommit.Author.Name}} {{TimeSince .LastCommit.Author.When}} + {{.LastCommit.Author.Name}} {{TimeSince .LastCommit.Author.When}}
      @@ -36,7 +36,7 @@ diff --git a/templates/status/404.tmpl b/templates/status/404.tmpl index 5a57e954..fe6739b9 100644 --- a/templates/status/404.tmpl +++ b/templates/status/404.tmpl @@ -1,7 +1,7 @@ {{template "ng/base/head" .}} {{template "ng/base/header" .}}
      -

      404

      +

      404



      Application Version: {{AppVer}}

      diff --git a/templates/status/500.tmpl b/templates/status/500.tmpl index 5bfdccc6..21116fa3 100644 --- a/templates/status/500.tmpl +++ b/templates/status/500.tmpl @@ -1,7 +1,7 @@ {{template "ng/base/head" .}} {{template "ng/base/header" .}}
      -

      500

      +

      500



      {{if .ErrorMsg}}

      An error has occurred : {{.ErrorMsg}}

      {{end}} diff --git a/templates/user/auth/activate.tmpl b/templates/user/auth/activate.tmpl index 554e2b78..b4dbb2e2 100644 --- a/templates/user/auth/activate.tmpl +++ b/templates/user/auth/activate.tmpl @@ -1,7 +1,7 @@ {{template "ng/base/head" .}} {{template "ng/base/header" .}}
      -
      + {{.CsrfTokenHtml}}

      {{.i18n.Tr "auth.active_your_account"}}

      diff --git a/templates/user/auth/forgot_passwd.tmpl b/templates/user/auth/forgot_passwd.tmpl index a1a10093..6122dfce 100644 --- a/templates/user/auth/forgot_passwd.tmpl +++ b/templates/user/auth/forgot_passwd.tmpl @@ -1,7 +1,7 @@ {{template "ng/base/head" .}} {{template "ng/base/header" .}}
      - + {{.CsrfTokenHtml}}

      {{.i18n.Tr "auth.forgot_password"}}

      diff --git a/templates/user/auth/reset_passwd.tmpl b/templates/user/auth/reset_passwd.tmpl index de2976d6..d63d7a0f 100644 --- a/templates/user/auth/reset_passwd.tmpl +++ b/templates/user/auth/reset_passwd.tmpl @@ -1,7 +1,7 @@ {{template "ng/base/head" .}} {{template "ng/base/header" .}}
      - + {{.CsrfTokenHtml}}

      {{.i18n.Tr "auth.reset_password"}}

      diff --git a/templates/user/auth/signin.tmpl b/templates/user/auth/signin.tmpl index e9ec87cc..54748077 100644 --- a/templates/user/auth/signin.tmpl +++ b/templates/user/auth/signin.tmpl @@ -1,7 +1,7 @@ {{template "ng/base/head" .}} {{template "ng/base/header" .}}
      - +

      {{if .IsSocialLogin}}{{.i18n.Tr "social_sign_in" | Str2html}}{{else}}{{.i18n.Tr "sign_in"}}{{end}}

      @@ -24,12 +24,12 @@
           - {{if not .IsSocialLogin}}{{.i18n.Tr "auth.forget_password"}}{{end}} + {{if not .IsSocialLogin}}{{.i18n.Tr "auth.forget_password"}}{{end}}
      {{if not .IsSocialLogin}} {{if .OauthEnabled}}
      diff --git a/templates/user/auth/signup.tmpl b/templates/user/auth/signup.tmpl index af4c250f..b68c7963 100644 --- a/templates/user/auth/signup.tmpl +++ b/templates/user/auth/signup.tmpl @@ -1,7 +1,7 @@ {{template "ng/base/head" .}} {{template "ng/base/header" .}}
      - +

      {{if .IsSocialLogin}}{{.i18n.Tr "social_sign_in" | Str2html}}{{else}}{{.i18n.Tr "sign_up"}}{{end}}

      @@ -40,7 +40,7 @@
      {{end}}
      diff --git a/templates/user/dashboard/dashboard.tmpl b/templates/user/dashboard/dashboard.tmpl index db838452..0d728ef4 100644 --- a/templates/user/dashboard/dashboard.tmpl +++ b/templates/user/dashboard/dashboard.tmpl @@ -12,17 +12,17 @@

      - {{.GetActUserName}} + {{.GetActUserName}} {{if eq .GetOpType 1}} - {{$.i18n.Tr "action.create_repo" AppRootSubUrl .GetRepoLink .GetRepoLink | Str2html}} + {{$.i18n.Tr "action.create_repo" AppSubUrl .GetRepoLink .GetRepoLink | Str2html}} {{else if eq .GetOpType 5}} - {{$.i18n.Tr "action.commit_repo" AppRootSubUrl .GetRepoLink .GetBranch .GetBranch AppRootSubUrl .GetRepoLink .GetRepoLink | Str2html}} + {{$.i18n.Tr "action.commit_repo" AppSubUrl .GetRepoLink .GetBranch .GetBranch AppSubUrl .GetRepoLink .GetRepoLink | Str2html}} {{else if eq .GetOpType 6}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.create_issue" AppRootSubUrl .GetRepoLink $index .GetRepoLink $index | Str2html}} + {{$.i18n.Tr "action.create_issue" AppSubUrl .GetRepoLink $index .GetRepoLink $index | Str2html}} {{else if eq .GetOpType 10}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.comment_issue" AppRootSubUrl .GetRepoLink $index .GetRepoLink $index | Str2html}} + {{$.i18n.Tr "action.comment_issue" AppSubUrl .GetRepoLink $index .GetRepoLink $index | Str2html}} {{end}}

      {{if eq .GetOpType 5}} @@ -31,7 +31,7 @@ {{ $push := ActionContent2Commits .}} {{ $repoLink := .GetRepoLink}} {{range $push.Commits}} -
    • {{ShortSha .Sha1}} {{.Message}}
    • +
    • {{ShortSha .Sha1}} {{.Message}}
    • {{end}}
      @@ -58,9 +58,9 @@ @@ -75,7 +75,7 @@
      diff --git a/templates/user/issues.tmpl b/templates/user/issues.tmpl index 19b0526c..45492039 100644 --- a/templates/user/issues.tmpl +++ b/templates/user/issues.tmpl @@ -3,10 +3,10 @@

      Your Issues

      @@ -17,30 +17,30 @@
      {{range .Issues}}{{if .}}
      #{{.Index}} -
      {{.Name}}
      +
      {{.Name}}

      - {{.Poster.Name}} + {{.Poster.Name}} {{TimeSince .Created $.Lang}} {{.NumComments}}

      diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 1b51a871..4e3b32b5 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -66,7 +66,7 @@
    • {{.NumForks}}

      - {{.Name}}{{if .IsPrivate}} Private{{end}} + {{.Name}}{{if .IsPrivate}} Private{{end}}

      {{.Description}}

      Last updated {{TimeSince .Updated $.Lang}}
      diff --git a/templates/user/settings/delete.tmpl b/templates/user/settings/delete.tmpl index 78574ba1..cc6bf273 100644 --- a/templates/user/settings/delete.tmpl +++ b/templates/user/settings/delete.tmpl @@ -11,7 +11,7 @@

      {{.i18n.Tr "settings.delete_account"}}

      {{.i18n.Tr "settings.delete_prompt" | Str2html}} - + {{.CsrfTokenHtml}}

      diff --git a/templates/user/settings/nav.tmpl b/templates/user/settings/nav.tmpl index 52fc83e1..fd60cb53 100644 --- a/templates/user/settings/nav.tmpl +++ b/templates/user/settings/nav.tmpl @@ -2,11 +2,11 @@

      {{.i18n.Tr "settings"}}

      \ No newline at end of file diff --git a/templates/user/settings/password.tmpl b/templates/user/settings/password.tmpl index ccafd3ed..4f2f63e4 100644 --- a/templates/user/settings/password.tmpl +++ b/templates/user/settings/password.tmpl @@ -9,7 +9,7 @@

      {{.i18n.Tr "settings.change_password"}}

      - + {{.CsrfTokenHtml}}

      diff --git a/templates/user/settings/profile.tmpl b/templates/user/settings/profile.tmpl index e344fb9a..577b6ee2 100644 --- a/templates/user/settings/profile.tmpl +++ b/templates/user/settings/profile.tmpl @@ -11,7 +11,7 @@

      {{.i18n.Tr "settings.public_profile"}}
      - + {{.CsrfTokenHtml}}
      {{.i18n.Tr "settings.profile_desc"}}
      diff --git a/templates/user/settings/social.tmpl b/templates/user/settings/social.tmpl index a2585922..7514b232 100644 --- a/templates/user/settings/social.tmpl +++ b/templates/user/settings/social.tmpl @@ -20,7 +20,7 @@

      {{.Identity}}

      {{$.i18n.Tr "settings.add_on"}} {{DateFormat .Created "M d, Y"}} — {{$.i18n.Tr "settings.last_used"}} {{DateFormat .Updated "M d, Y"}}

      - {{$.i18n.Tr "settings.unbind"}} + {{$.i18n.Tr "settings.unbind"}}
    • {{end}} diff --git a/templates/user/settings/sshkeys.tmpl b/templates/user/settings/sshkeys.tmpl index 2d186121..188f078a 100644 --- a/templates/user/settings/sshkeys.tmpl +++ b/templates/user/settings/sshkeys.tmpl @@ -23,7 +23,7 @@

      {{.Fingerprint}}

      {{$.i18n.Tr "settings.add_on"}} {{DateFormat .Created "M d, Y"}} — {{if .HasUsed}}{{$.i18n.Tr "settings.last_used"}} {{DateFormat .Updated "M d, Y"}}{{else}}{{$.i18n.Tr "settings.no_activity"}}{{end}}

      - + {{$.CsrfTokenHtml}} @@ -35,7 +35,7 @@

      {{.i18n.Tr "settings.ssh_helper" | Str2html}}


      - + {{.CsrfTokenHtml}}

      {{.i18n.Tr "settings.add_new_key"}}

      -- cgit v1.2.3 From 25c8d01676217ab37e117a2aefb77ff4aeed4448 Mon Sep 17 00:00:00 2001 From: Christopher Brickley Date: Mon, 22 Sep 2014 08:25:39 -0400 Subject: increase max commits in payload to 5 --- models/update.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'models') diff --git a/models/update.go b/models/update.go index ec6a9790..d939a908 100644 --- a/models/update.go +++ b/models/update.go @@ -23,6 +23,10 @@ type UpdateTask struct { NewCommitId string } +const ( + MAX_COMMITS int = 5 +) + func AddUpdateTask(task *UpdateTask) error { _, err := x.Insert(task) return err @@ -132,7 +136,6 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName // if commits push commits := make([]*base.PushCommit, 0) - var maxCommits = 2 var actEmail string for e := l.Front(); e != nil; e = e.Next() { commit := e.Value.(*git.Commit) @@ -145,7 +148,7 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName commit.Message(), commit.Author.Email, commit.Author.Name}) - if len(commits) >= maxCommits { + if len(commits) >= MAX_COMMITS { break } } -- cgit v1.2.3 From 5bbeeb0f1b5cecb67e1527410a45fb65df0096d1 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 23 Sep 2014 15:30:04 -0400 Subject: Page: Commits and fix #249 --- conf/locale/locale_en-US.ini | 9 +++++++++ conf/locale/locale_zh-CN.ini | 9 +++++++++ models/repo.go | 14 +++++++++++++ models/user.go | 29 +++++++++++++++++++++++++++ public/ng/css/gogs.css | 26 ++++++++++++++++++++++++ public/ng/css/ui.css | 4 ++++ public/ng/less/gogs/base.less | 5 +++++ public/ng/less/gogs/repository.less | 33 ++++++++++++++++++++++++------ public/ng/less/ui/label.less | 8 +++++--- routers/repo/commit.go | 4 +++- templates/admin/user/list.tmpl | 4 ++-- templates/repo/commits.tmpl | 15 +++++++------- templates/repo/commits_table.tmpl | 40 ++++++++++++++++++------------------- 13 files changed, 160 insertions(+), 40 deletions(-) (limited to 'models') diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index b241e45d..15d8028c 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -258,6 +258,15 @@ issues = Issues commits = Commits releases = Releases +commits.commits = Commits +commits.search = Search commits +commits.find = Find +commits.author = Author +commits.message = Message +commits.date = Date +commits.older = Older +commits.newer = Newer + settings = Settings settings.options = Options settings.collaboration = Collaboration diff --git a/conf/locale/locale_zh-CN.ini b/conf/locale/locale_zh-CN.ini index 2957cf90..e479f5cd 100644 --- a/conf/locale/locale_zh-CN.ini +++ b/conf/locale/locale_zh-CN.ini @@ -258,6 +258,15 @@ issues = 工单管理 commits = 提交历史 releases = 版本发布 +commits.commits = 次代码提交 +commits.search = 搜索提交历史 +commits.find = 查找 +commits.author = 作者 +commits.message = 备注 +commits.date = 提交日期 +commits.older = 更旧的提交 +commits.newer = 更新的提交 + settings = 仓库设置 settings.options = 基本设置 settings.collaboration = 管理协作者 diff --git a/models/repo.go b/models/repo.go index ccfaae2c..c0a581b9 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1081,6 +1081,13 @@ func SearchRepositoryByName(opt SearchOption) (repos []*Repository, err error) { return repos, err } +// __ __ __ .__ +// / \ / \_____ _/ |_ ____ | |__ +// \ \/\/ /\__ \\ __\/ ___\| | \ +// \ / / __ \| | \ \___| Y \ +// \__/\ / (____ /__| \___ >___| / +// \/ \/ \/ \/ + // Watch is connection request for receiving repository notifycation. type Watch struct { Id int64 @@ -1151,6 +1158,13 @@ func NotifyWatchers(act *Action) error { return nil } +// _________ __ +// / _____// |______ _______ +// \_____ \\ __\__ \\_ __ \ +// / \| | / __ \| | \/ +// /_______ /|__| (____ /__| +// \/ \/ + type Star struct { Id int64 Uid int64 `xorm:"UNIQUE(s)"` diff --git a/models/user.go b/models/user.go index 46e1b155..c09a7726 100644 --- a/models/user.go +++ b/models/user.go @@ -5,6 +5,7 @@ package models import ( + "container/list" "crypto/sha256" "encoding/hex" "errors" @@ -513,6 +514,34 @@ func GetUserIdsByNames(names []string) []int64 { return ids } +// UserCommit represtns a commit with validation of user. +type UserCommit struct { + UserName string + *git.Commit +} + +// ValidCommitsWithEmails checks if authors' e-mails of commits are correcponding to users. +func ValidCommitsWithEmails(oldCommits *list.List) *list.List { + newCommits := list.New() + e := oldCommits.Front() + for e != nil { + c := e.Value.(*git.Commit) + + uname := "" + u, err := GetUserByEmail(c.Author.Email) + if err == nil { + uname = u.Name + } + + newCommits.PushBack(UserCommit{ + UserName: uname, + Commit: c, + }) + e = e.Next() + } + return newCommits +} + // GetUserByEmail returns the user object by given e-mail if exists. func GetUserByEmail(email string) (*User, error) { if len(email) == 0 { diff --git a/public/ng/css/gogs.css b/public/ng/css/gogs.css index d11ae959..662a737f 100644 --- a/public/ng/css/gogs.css +++ b/public/ng/css/gogs.css @@ -20,6 +20,11 @@ img.avatar-16 { height: 16px; vertical-align: middle; } +img.avatar-20 { + width: 20px; + height: 20px; + vertical-align: middle; +} img.avatar-24 { width: 24px; height: 24px; @@ -1446,6 +1451,27 @@ The register and sign-in page style width: 100%; list-style: none; } +#commits-list { + padding-top: 20px; +} +.commit-list th { + background-color: #FFF; + line-height: 28px !important; +} +.commit-list .date { + width: 120px; +} +.commit-list .author { + padding-left: 20px; + min-width: 180px; +} +.commit-list .author img { + margin-top: -4px; +} +.commit-list .sha a { + font-family: Consolas, Menlo, Monaco, "Lucida Console", monospace; + font-size: 14px; +} #admin-wrapper, #setting-wrapper { padding-bottom: 100px; diff --git a/public/ng/css/ui.css b/public/ng/css/ui.css index 5dc3cc04..bd2eb4c9 100644 --- a/public/ng/css/ui.css +++ b/public/ng/css/ui.css @@ -732,6 +732,10 @@ ul.menu-radius > li:last-child > a { .label-green { background-color: #65ad4e; } +.label-green:hover { + background-color: #71bf57; + color: #FFF; +} .label-orange { background-color: #df7514; } diff --git a/public/ng/less/gogs/base.less b/public/ng/less/gogs/base.less index 47d8b1b6..4319a56e 100644 --- a/public/ng/less/gogs/base.less +++ b/public/ng/less/gogs/base.less @@ -30,6 +30,11 @@ img.avatar-16 { height: 16px; vertical-align: middle; } +img.avatar-20 { + width: 20px; + height: 20px; + vertical-align: middle; +} img.avatar-24 { width: 24px; height: 24px; diff --git a/public/ng/less/gogs/repository.less b/public/ng/less/gogs/repository.less index d9824913..7d6cdd0a 100644 --- a/public/ng/less/gogs/repository.less +++ b/public/ng/less/gogs/repository.less @@ -6,14 +6,12 @@ /* repository main */ #repo-wrapper { - padding-bottom: 100px; + padding-bottom: 100px; } #repo-header { - height: 69px; - border-bottom: 1px solid@repoHeaderBorderColor; - - background-color: @repoHeaderBgColor; - + height: 69px; + border-bottom: 1px solid@repoHeaderBorderColor; + background-color: @repoHeaderBgColor; } #repo-header-name { line-height: 66px; @@ -494,4 +492,27 @@ .setting-list { width: 100%; list-style: none; +} +#commits-list { + padding-top: 20px; +} +.commit-list { + th { + background-color: #FFF; + line-height: 28px !important; + } + .date { + width: 120px; + } + .author { + padding-left: 20px; + min-width: 180px; + img { + margin-top: -4px; + } + } + .sha a { + font-family: Consolas, Menlo, Monaco, "Lucida Console", monospace; + font-size: 14px; + } } \ No newline at end of file diff --git a/public/ng/less/ui/label.less b/public/ng/less/ui/label.less index a2a8a679..21a4c82d 100644 --- a/public/ng/less/ui/label.less +++ b/public/ng/less/ui/label.less @@ -16,11 +16,13 @@ .label-gray { background-color: @labelGrayColor; } - .label-green { - background-color: @labelGreenColor; + background-color: @labelGreenColor; + &:hover { + background-color: @btnHoverGreenColor; + color: #FFF; + } } - .label-orange { background-color: @labelOrangeColor; } diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 218cae7b..c23fdfe7 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -56,12 +56,14 @@ func Commits(ctx *middleware.Context) { } // Both `git log branchName` and `git log commitId` work. - ctx.Data["Commits"], err = ctx.Repo.Commit.CommitsByRange(page) + commits, err := ctx.Repo.Commit.CommitsByRange(page) if err != nil { ctx.Handle(500, "CommitsByRange", err) return } + commits = models.ValidCommitsWithEmails(commits) + ctx.Data["Commits"] = commits ctx.Data["Username"] = userName ctx.Data["Reponame"] = repoName ctx.Data["CommitCount"] = commitsCount diff --git a/templates/admin/user/list.tmpl b/templates/admin/user/list.tmpl index 1092539e..a09863ae 100644 --- a/templates/admin/user/list.tmpl +++ b/templates/admin/user/list.tmpl @@ -45,8 +45,8 @@
      {{if or .LastPageNum .NextPageNum}} {{end}}
      diff --git a/templates/repo/commits.tmpl b/templates/repo/commits.tmpl index e7518e98..2f68f1e0 100644 --- a/templates/repo/commits.tmpl +++ b/templates/repo/commits.tmpl @@ -1,8 +1,9 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -{{template "repo/nav" .}} -{{template "repo/toolbar" .}} -
      - {{template "repo/commits_table" .}} +{{template "ng/base/head" .}} +{{template "ng/base/header" .}} +
      + {{template "repo/header" .}} +
      + {{template "repo/commits_table" .}} +
      -{{template "base/footer" .}} +{{template "ng/base/footer" .}} diff --git a/templates/repo/commits_table.tmpl b/templates/repo/commits_table.tmpl index cb2ed5d0..032299b1 100644 --- a/templates/repo/commits_table.tmpl +++ b/templates/repo/commits_table.tmpl @@ -1,23 +1,19 @@ -
      -
      -
      - -
      - -
      - -
      -
      +
      +
      +
      + + + -

      {{.CommitCount}} Commits

      +

      {{.CommitCount}} {{.i18n.Tr "repo.commits.commits"}}

      - + - + - - + + @@ -26,8 +22,8 @@ {{$r := List .Commits}} {{range $r}} - - + + @@ -35,8 +31,10 @@
      Author{{.i18n.Tr "repo.commits.author"}} SHA1MessageDate{{.i18n.Tr "repo.commits.message"}}{{.i18n.Tr "repo.commits.date"}}
      {{.Author.Name}}{{SubStr .Id.String 0 10}}    {{if .UserName}}{{.Author.Name}}{{else}}{{.Author.Name}}{{end}}{{SubStr .Id.String 0 10}} {{.Summary}} {{TimeSince .Author.When $.Lang}}
      - {{if not .IsSearchPage}}{{end}} + {{if not .IsSearchPage}} + + {{end}}
      -- cgit v1.2.3 From bd55b78775f8dd04448d30e32f175918ee2b702e Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 23 Sep 2014 23:18:14 -0400 Subject: Page: Commits and fix #249 --- models/user.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'models') diff --git a/models/user.go b/models/user.go index c09a7726..49f8387d 100644 --- a/models/user.go +++ b/models/user.go @@ -522,15 +522,21 @@ type UserCommit struct { // ValidCommitsWithEmails checks if authors' e-mails of commits are correcponding to users. func ValidCommitsWithEmails(oldCommits *list.List) *list.List { + emails := map[string]string{} newCommits := list.New() e := oldCommits.Front() for e != nil { c := e.Value.(*git.Commit) uname := "" - u, err := GetUserByEmail(c.Author.Email) - if err == nil { - uname = u.Name + if v, ok := emails[c.Author.Email]; !ok { + u, err := GetUserByEmail(c.Author.Email) + if err == nil { + uname = u.Name + } + emails[c.Author.Email] = uname + } else { + uname = v } newCommits.PushBack(UserCommit{ -- cgit v1.2.3 From 089d934547c88a8c3c7ce5587fcc2481cc98f3a3 Mon Sep 17 00:00:00 2001 From: lunnyxiao Date: Thu, 25 Sep 2014 16:43:14 +0800 Subject: add action repousername for transfer --- models/action.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'models') diff --git a/models/action.go b/models/action.go index b4457656..18c956bd 100644 --- a/models/action.go +++ b/models/action.go @@ -351,7 +351,8 @@ func NewRepoAction(u *User, repo *Repository) (err error) { // TransferRepoAction adds new action for transfering repository. func TransferRepoAction(u, newUser *User, repo *Repository) (err error) { if err = NotifyWatchers(&Action{ActUserId: u.Id, ActUserName: u.Name, ActEmail: u.Email, - OpType: TRANSFER_REPO, RepoId: repo.Id, RepoName: repo.Name, Content: newUser.Name, + OpType: TRANSFER_REPO, RepoId: repo.Id, RepoUserName: repo.Owner.Name, + RepoName: repo.Name, Content: newUser.Name, IsPrivate: repo.IsPrivate}); err != nil { log.Error(4, "NotifyWatchers: %d/%s", u.Id, repo.Name) return err -- cgit v1.2.3 From f69761563b7a4fe9ace2a1643391cbcf9b92b372 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 25 Sep 2014 16:36:19 -0400 Subject: Fix bug on transfer repo --- .gitignore | 3 +++ cmd/web.go | 3 ++- conf/locale/locale_en-US.ini | 1 + conf/locale/locale_zh-CN.ini | 1 + gogs.go | 2 +- models/action.go | 4 ++-- models/repo.go | 40 ++++++++++++++++++++++++--------- modules/base/template.go | 8 +++---- templates/.VERSION | 2 +- templates/user/dashboard/dashboard.tmpl | 2 ++ 10 files changed, 45 insertions(+), 21 deletions(-) (limited to 'models') diff --git a/.gitignore b/.gitignore index 57d1493b..3f7608d7 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,6 @@ __pycache__ output* config.codekit .brackets.json +docker/fig.yml +docker/docker/Dockerfile +docker/docker/init_gogs.sh diff --git a/cmd/web.go b/cmd/web.go index 2376fd21..8a87f86b 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -190,7 +190,8 @@ func runWeb(*cli.Context) { r.Get("/logout", user.SignOut) }) - m.Get("/user/:username", ignSignIn, user.Profile) // TODO: Legacy + // FIXME: Legacy + m.Get("/user/:username", ignSignIn, user.Profile) // Gravatar service. avt := avatar.CacheServer("public/img/avatar/", "public/img/avatar_default.jpg") diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index 15d8028c..13be2fbd 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -565,6 +565,7 @@ create_repo = created repository %s commit_repo = pushed to %s at %s create_issue = opened issue %s#%s comment_issue = commented on issue %s#%s +transfer_repo = transfered repository %s to %s [tool] ago = ago diff --git a/conf/locale/locale_zh-CN.ini b/conf/locale/locale_zh-CN.ini index e479f5cd..7d65abd3 100644 --- a/conf/locale/locale_zh-CN.ini +++ b/conf/locale/locale_zh-CN.ini @@ -563,6 +563,7 @@ create_repo = 创建了仓库 %s commit_repo = 推送了 %s 分支的代码到 %s create_issue = 创建了工单 %s#%s comment_issue = 评论了工单 %s#%s +transfer_repo = 将仓库 %s 转移至 %s [tool] ago = 之前 diff --git a/gogs.go b/gogs.go index 6956b9f5..2f5b2417 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.4.0924 Beta" +const APP_VER = "0.5.4.0925 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/action.go b/models/action.go index 18c956bd..46500a92 100644 --- a/models/action.go +++ b/models/action.go @@ -351,8 +351,8 @@ func NewRepoAction(u *User, repo *Repository) (err error) { // TransferRepoAction adds new action for transfering repository. func TransferRepoAction(u, newUser *User, repo *Repository) (err error) { if err = NotifyWatchers(&Action{ActUserId: u.Id, ActUserName: u.Name, ActEmail: u.Email, - OpType: TRANSFER_REPO, RepoId: repo.Id, RepoUserName: repo.Owner.Name, - RepoName: repo.Name, Content: newUser.Name, + OpType: TRANSFER_REPO, RepoId: repo.Id, RepoUserName: newUser.Name, + RepoName: repo.Name, IsPrivate: repo.IsPrivate}); err != nil { log.Error(4, "NotifyWatchers: %d/%s", u.Id, repo.Name) return err diff --git a/models/repo.go b/models/repo.go index c0a581b9..093e3b7f 100644 --- a/models/repo.go +++ b/models/repo.go @@ -669,15 +669,23 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) error { return err } - if _, err = sess.Where("repo_name = ?", u.LowerName+"/"+repo.LowerName). - And("user_name = ?", u.LowerName).Update(&Access{UserName: newUser.LowerName}); err != nil { - sess.Rollback() - return err + curRepoLink := path.Join(u.LowerName, repo.LowerName) + // Delete all access first if current owner is an organization. + if u.IsOrganization() { + if _, err = sess.Where("repo_name=?", curRepoLink).Delete(new(Access)); err != nil { + sess.Rollback() + return fmt.Errorf("fail to delete current accesses: %v", err) + } + } else { + if _, err = sess.Where("repo_name=?", curRepoLink).And("user_name=?", u.LowerName). + Update(&Access{UserName: newUser.LowerName}); err != nil { + sess.Rollback() + return err + } } - if _, err = sess.Where("repo_name = ?", u.LowerName+"/"+repo.LowerName).Update(&Access{ - RepoName: newUser.LowerName + "/" + repo.LowerName, - }); err != nil { + if _, err = sess.Where("repo_name=?", curRepoLink). + Update(&Access{RepoName: path.Join(newUser.LowerName, repo.LowerName)}); err != nil { sess.Rollback() return err } @@ -700,12 +708,12 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) error { return err } + mode := WRITABLE + if repo.IsMirror { + mode = READABLE + } // New owner is organization. if newUser.IsOrganization() { - mode := WRITABLE - if repo.IsMirror { - mode = READABLE - } access := &Access{ RepoName: path.Join(newUser.LowerName, repo.LowerName), Mode: mode, @@ -737,6 +745,16 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) error { sess.Rollback() return err } + } else { + access := &Access{ + RepoName: path.Join(newUser.LowerName, repo.LowerName), + UserName: newUser.LowerName, + Mode: mode, + } + if _, err = sess.Insert(access); err != nil { + sess.Rollback() + return err + } } // Change repository directory name. diff --git a/modules/base/template.go b/modules/base/template.go index ec419149..b1c8c161 100644 --- a/modules/base/template.go +++ b/modules/base/template.go @@ -149,14 +149,12 @@ type Actioner interface { // and returns a icon class name. func ActionIcon(opType int) string { switch opType { - case 1: // Create repository. + case 1, 8: // Create, transfer repository. return "repo" case 5, 9: // Commit repository. return "git-commit" case 6: // Create issue. return "issue-opened" - case 8: // Transfer repository. - return "share" case 10: // Comment issue. return "comment" default: @@ -164,7 +162,7 @@ func ActionIcon(opType int) string { } } -// TODO: Legacy +// FIXME: Legacy const ( TPL_CREATE_REPO = `%s created repository %s` TPL_COMMIT_REPO = `%s pushed to %s at %s%s` @@ -197,7 +195,7 @@ func ActionContent2Commits(act Actioner) *PushCommits { return push } -// TODO: Legacy +// FIXME: Legacy // ActionDesc accepts int that represents action operation type // and returns the description. func ActionDesc(act Actioner) string { diff --git a/templates/.VERSION b/templates/.VERSION index 49d86b40..87b06b81 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.4.0924 Beta \ No newline at end of file +0.5.4.0925 Beta \ No newline at end of file diff --git a/templates/user/dashboard/dashboard.tmpl b/templates/user/dashboard/dashboard.tmpl index 0d728ef4..370173e4 100644 --- a/templates/user/dashboard/dashboard.tmpl +++ b/templates/user/dashboard/dashboard.tmpl @@ -20,6 +20,8 @@ {{else if eq .GetOpType 6}} {{ $index := index .GetIssueInfos 0}} {{$.i18n.Tr "action.create_issue" AppSubUrl .GetRepoLink $index .GetRepoLink $index | Str2html}} + {{else if eq .GetOpType 8}} + {{$.i18n.Tr "action.transfer_repo" .GetRepoName AppSubUrl .GetRepoLink .GetRepoLink | Str2html}} {{else if eq .GetOpType 10}} {{ $index := index .GetIssueInfos 0}} {{$.i18n.Tr "action.comment_issue" AppSubUrl .GetRepoLink $index .GetRepoLink $index | Str2html}} -- cgit v1.2.3 From 71e4689d118b3628a6ef7b93117c54265c4d83a5 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 25 Sep 2014 19:33:39 -0400 Subject: Page: User profile --- conf/locale/locale_en-US.ini | 9 ++ conf/locale/locale_zh-CN.ini | 9 ++ models/repo.go | 8 +- models/user.go | 3 +- public/ng/css/gogs.css | 53 +++++++++++ public/ng/js/gogs.js | 10 +++ public/ng/js/min/gogs-min.js | 4 +- public/ng/less/gogs.less | 3 +- public/ng/less/gogs/profile.less | 57 ++++++++++++ templates/user/dashboard/dashboard.tmpl | 2 +- templates/user/dashboard/feeds.tmpl | 42 +++++++++ templates/user/profile.tmpl | 154 +++++++++++++++++--------------- 12 files changed, 275 insertions(+), 79 deletions(-) create mode 100644 public/ng/less/gogs/profile.less create mode 100644 templates/user/dashboard/feeds.tmpl (limited to 'models') diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index 13be2fbd..6595cbe4 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -166,6 +166,15 @@ org_still_own_repo = This organization still have ownership of repository, you h still_own_user = This authentication still has used by some users, you should move them and then delete again. +[user] +change_avatar = Change your avatar at gravatar.com +join_on = Joined on +repositories = Repositories +activity = Public Activity +followers = Followers +starred = Starred +following = Following + [settings] profile = Profile password = Password diff --git a/conf/locale/locale_zh-CN.ini b/conf/locale/locale_zh-CN.ini index 7d65abd3..9b337621 100644 --- a/conf/locale/locale_zh-CN.ini +++ b/conf/locale/locale_zh-CN.ini @@ -166,6 +166,15 @@ org_still_own_repo = 该组织仍然是某些仓库的拥有者,您必须先 still_own_user = 该授权认证依旧被部分用户使用,请先删除该部分用户后再试! +[user] +change_avatar = 到 gravatar.com 上修改您的头像 +join_on = 加入于 +repositories = 仓库列表 +activity = 公开活动 +followers = 关注者 +starred = 已点赞 +following = 关注中 + [settings] profile = 个人信息 password = 修改密码 diff --git a/models/repo.go b/models/repo.go index 093e3b7f..8e7ab96b 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1197,16 +1197,20 @@ func StarRepo(uid, repoId int64, star bool) (err error) { } if _, err = x.Insert(&Star{Uid: uid, RepoId: repoId}); err != nil { return err + } else if _, err = x.Exec("UPDATE `repository` SET num_stars = num_stars + 1 WHERE id = ?", repoId); err != nil { + return err } - _, err = x.Exec("UPDATE `repository` SET num_stars = num_stars + 1 WHERE id = ?", repoId) + _, err = x.Exec("UPDATE `user` SET num_stars = num_stars + 1 WHERE id = ?", uid) } else { if !IsStaring(uid, repoId) { return nil } if _, err = x.Delete(&Star{0, uid, repoId}); err != nil { return err + } else if _, err = x.Exec("UPDATE `repository` SET num_stars = num_stars - 1 WHERE id = ?", repoId); err != nil { + return err } - _, err = x.Exec("UPDATE `repository` SET num_stars = num_stars - 1 WHERE id = ?", repoId) + _, err = x.Exec("UPDATE `user` SET num_stars = num_stars - 1 WHERE id = ?", uid) } return err } diff --git a/models/user.go b/models/user.go index 49f8387d..f327ed14 100644 --- a/models/user.go +++ b/models/user.go @@ -11,6 +11,7 @@ import ( "errors" "fmt" "os" + "path" "path/filepath" "strings" "time" @@ -90,7 +91,7 @@ func (u *User) DashboardLink() string { // HomeLink returns the user home page link. func (u *User) HomeLink() string { - return setting.AppSubUrl + "/user/" + u.Name + return "/" + path.Join(setting.AppSubUrl, u.Name) } // AvatarLink returns user gravatar link. diff --git a/public/ng/css/gogs.css b/public/ng/css/gogs.css index 662a737f..dbaa3db1 100644 --- a/public/ng/css/gogs.css +++ b/public/ng/css/gogs.css @@ -2074,3 +2074,56 @@ textarea#issue-add-content { .admin-dl-horizontal > dd { margin-left: 240px; } +.profile-avatar { + width: 200px; + height: 200px; + border-radius: 6px; +} +#profile-name { + padding: 10px 0; +} +#profile-fullname { + font-size: 1.6em; +} +#profile-username { + font-size: 1.6em; + font-weight: bold; +} +.profile-info { + padding: 0 50px; + font-size: 14px; +} +.profile-info ul { + padding-bottom: 10px; +} +.profile-info ul .list-group-item { + background-color: transparent; + padding-top: 5px; + color: #666; +} +.profile-info ul .profile-rel { + width: 31%; + text-align: center; + display: inline-block; +} +.profile-info ul .profile-rel strong { + display: block; + font-size: 28px; + font-weight: bold; + line-height: 1; +} +.profile-info ul .profile-rel p { + font-size: 12px; +} +#profile-header li a { + font-size: 1.2em; + color: #444444; + padding: .4em .8em; +} +#profile-header li a:hover { + background-color: transparent; + color: #d9453d; +} +#profile-header li .current { + border-bottom: 2px solid #D26911; +} diff --git a/public/ng/js/gogs.js b/public/ng/js/gogs.js index a81eb8ce..64bf42f3 100644 --- a/public/ng/js/gogs.js +++ b/public/ng/js/gogs.js @@ -608,6 +608,13 @@ function initInstall() { }()); } +function initProfile() { + // Avatar. + $('#profile-avatar').tipsy({ + fade: true + }); +} + $(document).ready(function () { Gogs.AppSubUrl = $('head').data('suburl'); initCore(); @@ -644,6 +651,9 @@ $(document).ready(function () { if ($('#install-form').length) { initInstall(); } + if ($('#user-profile-page').length) { + initProfile(); + } $('#dashboard-sidebar-menu').tabs(); $('#pull-issue-preview').markdown_preview(".issue-add-comment"); diff --git a/public/ng/js/min/gogs-min.js b/public/ng/js/min/gogs-min.js index bfe799d9..1a805b5f 100644 --- a/public/ng/js/min/gogs-min.js +++ b/public/ng/js/min/gogs-min.js @@ -1,5 +1,5 @@ -function Tabs(e){function t(e){console.log("hide",e),e.removeClass("js-tab-nav-show"),$(e.data("tab-target")).removeClass("js-tab-show").hide()}function n(e){console.log("show",e),e.addClass("js-tab-nav-show"),$(e.data("tab-target")).addClass("js-tab-show").show()}var r=$(e);if(r.length){var i=r.find(".js-tab-nav-show");i.length&&$(i.data("tab-target")).addClass("js-tab-show"),r.on("click",".js-tab-nav",function(e){e.preventDefault();var o=$(this);o.hasClass("js-tab-nav-show")||(i=r.find(".js-tab-nav-show").eq(0),t(i),n(o))}),console.log("init tabs @",e)}}function Preview(e,t){function n(e){return e.find(".js-preview-input").eq(0)}function r(e){return e.hasClass("js-preview-container")?e:e.find(".js-preview-container").eq(0)}var i=$(e),o=$(t),a=n(o);if(!a.length)return void console.log("[preview]: no preview input");var s=r(o);return s.length?(i.on("click",function(){$.post("/api/v1/markdown",{text:a.val()},function(e){s.html(e)})}),void console.log("[preview]: init preview @",e,"&",t)):void console.log("[preview]: no preview container")}function initCore(){Gogs.renderMarkdown(),Gogs.renderCodeView(),$(".js-tab-nav").click(function(e){$(this).hasClass("js-tab-nav-show")||($(this).parent().find(".js-tab-nav-show").each(function(){$(this).removeClass("js-tab-nav-show"),$($(this).data("tab-target")).hide()}),$(this).addClass("js-tab-nav-show"),$($(this).data("tab-target")).show()),e.preventDefault()})}function initUserSetting(){$("#user-profile-form").submit(function(e){var t=$("#username");return t.data("uname")==t.val()||confirm("Username has been changed, do you want to continue?")?void 0:(e.preventDefault(),!0)}),$("#ssh-add").click(function(){$("#user-ssh-add-form").removeClass("hide")}),$("#delete-account-button").click(function(e){return confirm("This account is going to be deleted, do you want to continue?")?void 0:(e.preventDefault(),!0)})}function initRepoCreate(){$("#repo-create-owner-list").on("click","li",function(){if(!$(this).hasClass("checked")){var e=$(this).data("uid");$("#repo-owner-id").val(e),$("#repo-owner-avatar").attr("src",$(this).find("img").attr("src")),$("#repo-owner-name").text($(this).text().trim()),$(this).parent().find(".checked").removeClass("checked"),$(this).addClass("checked"),console.log("set repo owner to uid :",e,$(this).text().trim())}}),$("#auth-button").click(function(e){$("#repo-migrate-auth").slideToggle("fast"),e.preventDefault()}),console.log("initRepoCreate")}function initRepo(){$("#repo-clone-ssh").click(function(){$(this).removeClass("btn-gray").addClass("btn-blue"),$("#repo-clone-https").removeClass("btn-blue").addClass("btn-gray"),$("#repo-clone-url").val($(this).data("link")),$(".clone-url").text($(this).data("link"))}),$("#repo-clone-https").click(function(){$(this).removeClass("btn-gray").addClass("btn-blue"),$("#repo-clone-ssh").removeClass("btn-blue").addClass("btn-gray"),$("#repo-clone-url").val($(this).data("link")),$(".clone-url").text($(this).data("link"))});var e=$("#repo-clone-copy");e.hover(function(){Gogs.bindCopy($(this))}),e.tipsy({fade:!0})}function initHookTypeChange(){$("select#hook-type").on("change",function(){hookTypes=["Gogs","Slack"];var e=$(this).val();hookTypes.forEach(function(t){e===t?$("div#"+t.toLowerCase()).toggleShow():$("div#"+t.toLowerCase()).toggleHide()})})}function initRepoSetting(){$("#repo-setting-form").submit(function(e){var t=$("#repo_name");return t.data("repo-name")==t.val()||confirm("Repository name has been changed, do you want to continue?")?void 0:(e.preventDefault(),!0)}),initHookTypeChange(),$("#transfer-button").click(function(){$("#transfer-form").show()}),$("#delete-button").click(function(){$("#delete-form").show()}),$("#repo-collab-list hr:last-child").remove();var e=$("#repo-collaborator").next().next().find("ul");$("#repo-collaborator").on("keyup",function(){var t=$(this);return t.val()?void Gogs.searchUsers(t.val(),e):void e.toggleHide()}).on("focus",function(){$(this).val()?e.toggleShow():e.toggleHide()}).next().next().find("ul").on("click","li",function(){$("#repo-collaborator").val($(this).text()),e.toggleHide()})}function initOrgSetting(){$("#org-setting-form").submit(function(e){var t=$("#orgname");return t.data("orgname")==t.val()||confirm("Organization name has been changed, do you want to continue?")?void 0:(e.preventDefault(),!0)}),$("#delete-org-button").click(function(e){return confirm("This organization is going to be deleted, do you want to continue?")?void 0:(e.preventDefault(),!0)}),initHookTypeChange()}function initInvite(){var e=$("#org-member-invite-list");$("#org-member-invite").on("keyup",function(){var t=$(this);return t.val()?void Gogs.searchUsers(t.val(),e):void e.toggleHide()}).on("focus",function(){$(this).val()?e.toggleShow():e.toggleHide()}).next().next().find("ul").on("click","li",function(){$("#org-member-invite").val($(this).text()),e.toggleHide()})}function initOrgTeamCreate(){$("#org-team-delete").click(function(e){if(!confirm("This team is going to be deleted, do you want to continue?"))return e.preventDefault(),!0;var t=$("#team-create-form");t.attr("action",t.data("delete-url"))})}function initTeamMembersList(){var e=$("#org-team-members-list");$("#org-team-members-add").on("keyup",function(){var t=$(this);return t.val()?void Gogs.searchUsers(t.val(),e):void e.toggleHide()}).on("focus",function(){$(this).val()?e.toggleShow():e.toggleHide()}).next().next().find("ul").on("click","li",function(){$("#org-team-members-add").val($(this).text()),e.toggleHide()})}function initTeamRepositoriesList(){var e=$("#org-team-repositories-list");$("#org-team-repositories-add").on("keyup",function(){var t=$(this);return t.val()?void Gogs.searchRepos(t.val(),e,"uid="+t.data("uid")):void e.toggleHide()}).on("focus",function(){$(this).val()?e.toggleShow():e.toggleHide()}).next().next().find("ul").on("click","li",function(){$("#org-team-repositories-add").val($(this).text()),e.toggleHide()})}function initAdmin(){$("#login-type").on("change",function(){var e=$(this).val();e.indexOf("0-")+1?($(".auth-name").toggleHide(),$(".pwd").find("input").attr("required","required").end().toggleShow()):($(".pwd").find("input").removeAttr("required").end().toggleHide(),$(".auth-name").toggleShow())}),$("#user-delete").click(function(e){if(!confirm("This account is going to be deleted, do you want to continue?"))return e.preventDefault(),!0;var t=$("#user-profile-form");t.attr("action",t.data("delete-url"))}),$("#auth-type").on("change",function(){var e=$(this).val();2==e&&($(".ldap").toggleShow(),$(".smtp").toggleHide()),3==e&&($(".smtp").toggleShow(),$(".ldap").toggleHide())}),$("#auth-delete").click(function(e){if(!confirm("This authorization is going to be deleted, do you want to continue?"))return e.preventDefault(),!0;var t=$("auth-setting-form");t.attr("action",t.data("delete-url"))})}function initInstall(){!function(){var e="127.0.0.1:3306",t="127.0.0.1:5432";$("#install-database").on("change",function(){var n=$(this).val();"SQLite3"!=n?($(".server-sql").show(),$(".sqlite-setting").addClass("hide"),"PostgreSQL"==n?($(".pgsql-setting").removeClass("hide"),$("#database-host").val()==e&&$("#database-host").val(t)):"MySQL"==n?($(".pgsql-setting").addClass("hide"),$("#database-host").val()==t&&$("#database-host").val(e)):$(".pgsql-setting").addClass("hide")):($(".server-sql").hide(),$(".pgsql-setting").hide(),$(".sqlite-setting").removeClass("hide"))})}()}function homepage(){$("#promo-form").submit(function(e){return""===$("#username").val()?(e.preventDefault(),window.location.href=Gogs.AppSubUrl+"/user/login",!0):void 0}),$("#register-button").click(function(e){return""===$("#username").val()?(e.preventDefault(),window.location.href=Gogs.AppSubUrl+"/user/sign_up",!0):void $("#promo-form").attr("action",Gogs.AppSubUrl+"/user/sign_up")})}!function(e,t){"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(e,t){function n(e){var t=e.length,n=ot.type(e);return"function"===n||ot.isWindow(e)?!1:1===e.nodeType&&t?!0:"array"===n||0===t||"number"==typeof t&&t>0&&t-1 in e}function r(e,t,n){if(ot.isFunction(t))return ot.grep(e,function(e,r){return!!t.call(e,r,e)!==n});if(t.nodeType)return ot.grep(e,function(e){return e===t!==n});if("string"==typeof t){if(pt.test(t))return ot.filter(t,e,n);t=ot.filter(t,e)}return ot.grep(e,function(e){return ot.inArray(e,t)>=0!==n})}function i(e,t){do e=e[t];while(e&&1!==e.nodeType);return e}function o(e){var t=wt[e]={};return ot.each(e.match(xt)||[],function(e,n){t[n]=!0}),t}function a(){mt.addEventListener?(mt.removeEventListener("DOMContentLoaded",s,!1),e.removeEventListener("load",s,!1)):(mt.detachEvent("onreadystatechange",s),e.detachEvent("onload",s))}function s(){(mt.addEventListener||"load"===event.type||"complete"===mt.readyState)&&(a(),ot.ready())}function l(e,t,n){if(void 0===n&&1===e.nodeType){var r="data-"+t.replace(Et,"-$1").toLowerCase();if(n=e.getAttribute(r),"string"==typeof n){try{n="true"===n?!0:"false"===n?!1:"null"===n?null:+n+""===n?+n:kt.test(n)?ot.parseJSON(n):n}catch(i){}ot.data(e,t,n)}else n=void 0}return n}function u(e){var t;for(t in e)if(("data"!==t||!ot.isEmptyObject(e[t]))&&"toJSON"!==t)return!1;return!0}function c(e,t,n,r){if(ot.acceptData(e)){var i,o,a=ot.expando,s=e.nodeType,l=s?ot.cache:e,u=s?e[a]:e[a]&&a;if(u&&l[u]&&(r||l[u].data)||void 0!==n||"string"!=typeof t)return u||(u=s?e[a]=V.pop()||ot.guid++:a),l[u]||(l[u]=s?{}:{toJSON:ot.noop}),("object"==typeof t||"function"==typeof t)&&(r?l[u]=ot.extend(l[u],t):l[u].data=ot.extend(l[u].data,t)),o=l[u],r||(o.data||(o.data={}),o=o.data),void 0!==n&&(o[ot.camelCase(t)]=n),"string"==typeof t?(i=o[t],null==i&&(i=o[ot.camelCase(t)])):i=o,i}}function d(e,t,n){if(ot.acceptData(e)){var r,i,o=e.nodeType,a=o?ot.cache:e,s=o?e[ot.expando]:ot.expando;if(a[s]){if(t&&(r=n?a[s]:a[s].data)){ot.isArray(t)?t=t.concat(ot.map(t,ot.camelCase)):t in r?t=[t]:(t=ot.camelCase(t),t=t in r?[t]:t.split(" ")),i=t.length;for(;i--;)delete r[t[i]];if(n?!u(r):!ot.isEmptyObject(r))return}(n||(delete a[s].data,u(a[s])))&&(o?ot.cleanData([e],!0):rt.deleteExpando||a!=a.window?delete a[s]:a[s]=null)}}}function f(){return!0}function p(){return!1}function h(){try{return mt.activeElement}catch(e){}}function m(e){var t=Pt.split("|"),n=e.createDocumentFragment();if(n.createElement)for(;t.length;)n.createElement(t.pop());return n}function g(e,t){var n,r,i=0,o=typeof e.getElementsByTagName!==St?e.getElementsByTagName(t||"*"):typeof e.querySelectorAll!==St?e.querySelectorAll(t||"*"):void 0;if(!o)for(o=[],n=e.childNodes||e;null!=(r=n[i]);i++)!t||ot.nodeName(r,t)?o.push(r):ot.merge(o,g(r,t));return void 0===t||t&&ot.nodeName(e,t)?ot.merge([e],o):o}function v(e){jt.test(e.type)&&(e.defaultChecked=e.checked)}function y(e,t){return ot.nodeName(e,"table")&&ot.nodeName(11!==t.nodeType?t:t.firstChild,"tr")?e.getElementsByTagName("tbody")[0]||e.appendChild(e.ownerDocument.createElement("tbody")):e}function b(e){return e.type=(null!==ot.find.attr(e,"type"))+"/"+e.type,e}function x(e){var t=Zt.exec(e.type);return t?e.type=t[1]:e.removeAttribute("type"),e}function w(e,t){for(var n,r=0;null!=(n=e[r]);r++)ot._data(n,"globalEval",!t||ot._data(t[r],"globalEval"))}function C(e,t){if(1===t.nodeType&&ot.hasData(e)){var n,r,i,o=ot._data(e),a=ot._data(t,o),s=o.events;if(s){delete a.handle,a.events={};for(n in s)for(r=0,i=s[n].length;i>r;r++)ot.event.add(t,n,s[n][r])}a.data&&(a.data=ot.extend({},a.data))}}function S(e,t){var n,r,i;if(1===t.nodeType){if(n=t.nodeName.toLowerCase(),!rt.noCloneEvent&&t[ot.expando]){i=ot._data(t);for(r in i.events)ot.removeEvent(t,r,i.handle);t.removeAttribute(ot.expando)}"script"===n&&t.text!==e.text?(b(t).text=e.text,x(t)):"object"===n?(t.parentNode&&(t.outerHTML=e.outerHTML),rt.html5Clone&&e.innerHTML&&!ot.trim(t.innerHTML)&&(t.innerHTML=e.innerHTML)):"input"===n&&jt.test(e.type)?(t.defaultChecked=t.checked=e.checked,t.value!==e.value&&(t.value=e.value)):"option"===n?t.defaultSelected=t.selected=e.defaultSelected:("input"===n||"textarea"===n)&&(t.defaultValue=e.defaultValue)}}function T(t,n){var r,i=ot(n.createElement(t)).appendTo(n.body),o=e.getDefaultComputedStyle&&(r=e.getDefaultComputedStyle(i[0]))?r.display:ot.css(i[0],"display");return i.detach(),o}function k(e){var t=mt,n=Jt[e];return n||(n=T(e,t),"none"!==n&&n||(Kt=(Kt||ot("