diff options
author | Michael Boke <michael@mbict.nl> | 2014-10-03 22:51:07 +0200 |
---|---|---|
committer | Michael Boke <michael@mbict.nl> | 2014-10-03 22:51:07 +0200 |
commit | ba1270df2d3d835b397317f133963e7b517242f1 (patch) | |
tree | 1265a142a1fd9951d30ae11648e7fbfb5806e594 /modules/middleware | |
parent | ba0feadc34400cb91ff23f66096884d862651cdd (diff) | |
parent | 405ee14711ab946bd709ec28a526890c40cbc03b (diff) |
Merge remote-tracking branch 'upstream/master'
Conflicts:
conf/app.ini
Diffstat (limited to 'modules/middleware')
-rw-r--r-- | modules/middleware/auth.go | 10 | ||||
-rw-r--r-- | modules/middleware/context.go | 20 | ||||
-rw-r--r-- | modules/middleware/org.go | 7 | ||||
-rw-r--r-- | modules/middleware/repo.go | 29 |
4 files changed, 25 insertions, 41 deletions
diff --git a/modules/middleware/auth.go b/modules/middleware/auth.go index 37e3aec4..2bc05697 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.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("/") + ctx.Redirect(setting.AppSubUrl + "/") return } @@ -48,12 +48,12 @@ 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.AppSubUrl+ctx.Req.RequestURI), 0, setting.AppSubUrl) + ctx.Redirect(setting.AppSubUrl + "/user/login") return } else if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm { ctx.Data["Title"] = ctx.Tr("auth.active_your_account") - ctx.HTML(200, "user/activate") + ctx.HTML(200, "user/auth/activate") return } } diff --git a/modules/middleware/context.go b/modules/middleware/context.go index 3ef1b1d6..90716d2c 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -9,7 +9,6 @@ import ( "html/template" "io" "net/http" - "path" "strings" "time" @@ -140,23 +139,6 @@ func (ctx *Context) Handle(status int, title string, err error) { ctx.HTML(status, base.TplName(fmt.Sprintf("status/%d", status))) } -func (ctx *Context) ServeFile(file string, names ...string) { - var name string - if len(names) > 0 { - name = names[0] - } else { - name = path.Base(file) - } - ctx.Resp.Header().Set("Content-Description", "File Transfer") - ctx.Resp.Header().Set("Content-Type", "application/octet-stream") - ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+name) - ctx.Resp.Header().Set("Content-Transfer-Encoding", "binary") - ctx.Resp.Header().Set("Expires", "0") - ctx.Resp.Header().Set("Cache-Control", "must-revalidate") - ctx.Resp.Header().Set("Pragma", "public") - http.ServeFile(ctx.Resp, ctx.Req, file) -} - func (ctx *Context) ServeContent(name string, r io.ReadSeeker, params ...interface{}) { modtime := time.Now() for _, p := range params { @@ -187,7 +169,7 @@ func Contexter() macaron.Handler { Session: sess, } // Compute current URL for real-time change language. - link := 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 7bb24ab7..be102989 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.AppSubUrl + "/") } 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.AppSubUrl + "/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.AppSubUrl + "/") } else { ctx.Handle(500, "GetTeam", err) } diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index 68a9a2d7..c6250f6d 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.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("/") + 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("/") + ctx.Redirect(setting.AppSubUrl + "/") return } ctx.Handle(500, "GetRepositoryByName", err) @@ -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 @@ -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.AppSubUrl + "/" + u.Name + "/" + repo.Name ctx.Data["RepoLink"] = ctx.Repo.RepoLink tags, err := ctx.Repo.GitRepo.GetTags() @@ -168,6 +168,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { ctx.Handle(500, "GetTags", err) return } + ctx.Data["Tags"] = tags ctx.Repo.Repository.NumTags = len(tags) ctx.Data["Title"] = u.Name + "/" + repo.Name @@ -199,7 +200,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { ctx.Repo.Commit, err = gitRepo.GetCommitOfBranch(refName) if err != nil { - ctx.Handle(404, "RepoAssignment invalid branch", nil) + ctx.Handle(500, "RepoAssignment invalid branch", err) return } ctx.Repo.CommitId = ctx.Repo.Commit.Id.String() @@ -207,13 +208,11 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { } else if gitRepo.IsTagExist(refName) { ctx.Repo.IsTag = true ctx.Repo.BranchName = refName - - ctx.Repo.Tag, err = gitRepo.GetTag(refName) + ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommitOfTag(refName) if err != nil { - ctx.Handle(404, "RepoAssignment invalid tag", nil) + ctx.Handle(500, "Fail to get tag commit", err) return } - ctx.Repo.Commit, _ = ctx.Repo.Tag.Commit() ctx.Repo.CommitId = ctx.Repo.Commit.Id.String() } else if len(refName) == 40 { ctx.Repo.IsCommit = true @@ -226,7 +225,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { return } } else { - ctx.Handle(404, "RepoAssignment invalid repo", errors.New("branch or tag not exist")) + ctx.Handle(404, "RepoAssignment invalid repo", fmt.Errorf("branch or tag not exist: %s", refName)) return } @@ -247,6 +246,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { } ctx.Data["IsBranch"] = ctx.Repo.IsBranch + ctx.Data["IsTag"] = ctx.Repo.IsTag ctx.Data["IsCommit"] = ctx.Repo.IsCommit ctx.Repo.CommitsCount, err = ctx.Repo.Commit.CommitsCount() @@ -274,7 +274,8 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { ctx.Data["TagName"] = ctx.Repo.TagName brs, err := ctx.Repo.GitRepo.GetBranches() if err != nil { - log.Error(4, "GetBranches: %v", err) + ctx.Handle(500, "GetBranches", err) + return } ctx.Data["Branches"] = brs ctx.Data["BrancheCount"] = len(brs) @@ -298,8 +299,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.AppSubUrl+ctx.Req.RequestURI), 0, setting.AppSubUrl) + ctx.Redirect(setting.AppSubUrl + "/user/login") return } ctx.Handle(404, ctx.Req.RequestURI, nil) |