Rename module: middleware -> context

This commit is contained in:
Unknwon 2016-03-11 11:56:52 -05:00
parent cb1eadc276
commit 514382e2eb
54 changed files with 666 additions and 669 deletions

View file

@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true) ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
##### Current version: 0.9.4 ##### Current version: 0.9.5
| Web | UI | Preview | | Web | UI | Preview |
|:-------------:|:-------:|:-------:| |:-------------:|:-------:|:-------:|

View file

@ -34,8 +34,8 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/bindata" "github.com/gogits/gogs/modules/bindata"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/modules/template" "github.com/gogits/gogs/modules/template"
"github.com/gogits/gogs/routers" "github.com/gogits/gogs/routers"
@ -169,7 +169,7 @@ func newMacaron() *macaron.Macaron {
}, },
}, },
})) }))
m.Use(middleware.Contexter()) m.Use(context.Contexter())
return m return m
} }
@ -182,10 +182,10 @@ func runWeb(ctx *cli.Context) {
m := newMacaron() m := newMacaron()
reqSignIn := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: true}) reqSignIn := context.Toggle(&context.ToggleOptions{SignInRequired: true})
ignSignIn := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: setting.Service.RequireSignInView}) ignSignIn := context.Toggle(&context.ToggleOptions{SignInRequired: setting.Service.RequireSignInView})
ignSignInAndCsrf := middleware.Toggle(&middleware.ToggleOptions{DisableCsrf: true}) ignSignInAndCsrf := context.Toggle(&context.ToggleOptions{DisableCSRF: true})
reqSignOut := middleware.Toggle(&middleware.ToggleOptions{SignOutRequire: true}) reqSignOut := context.Toggle(&context.ToggleOptions{SignOutRequired: true})
bindIgnErr := binding.BindIgnErr bindIgnErr := binding.BindIgnErr
@ -231,7 +231,7 @@ func runWeb(ctx *cli.Context) {
Post(bindIgnErr(auth.NewAccessTokenForm{}), user.SettingsApplicationsPost) Post(bindIgnErr(auth.NewAccessTokenForm{}), user.SettingsApplicationsPost)
m.Post("/applications/delete", user.SettingsDeleteApplication) m.Post("/applications/delete", user.SettingsDeleteApplication)
m.Route("/delete", "GET,POST", user.SettingsDelete) m.Route("/delete", "GET,POST", user.SettingsDelete)
}, reqSignIn, func(ctx *middleware.Context) { }, reqSignIn, func(ctx *context.Context) {
ctx.Data["PageIsUserSettings"] = true ctx.Data["PageIsUserSettings"] = true
}) })
@ -246,7 +246,7 @@ func runWeb(ctx *cli.Context) {
}) })
// ***** END: User ***** // ***** END: User *****
adminReq := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: true, AdminRequire: true}) adminReq := context.Toggle(&context.ToggleOptions{SignInRequired: true, AdminRequired: true})
// ***** START: Admin ***** // ***** START: Admin *****
m.Group("/admin", func() { m.Group("/admin", func() {
@ -295,7 +295,7 @@ func runWeb(ctx *cli.Context) {
m.Get("/stars", user.Stars) m.Get("/stars", user.Stars)
}) })
m.Get("/attachments/:uuid", func(ctx *middleware.Context) { m.Get("/attachments/:uuid", func(ctx *context.Context) {
attach, err := models.GetAttachmentByUUID(ctx.Params(":uuid")) attach, err := models.GetAttachmentByUUID(ctx.Params(":uuid"))
if err != nil { if err != nil {
if models.IsErrAttachmentNotExist(err) { if models.IsErrAttachmentNotExist(err) {
@ -332,8 +332,8 @@ func runWeb(ctx *cli.Context) {
m.Get("/template/*", dev.TemplatePreview) m.Get("/template/*", dev.TemplatePreview)
} }
reqRepoAdmin := middleware.RequireRepoAdmin() reqRepoAdmin := context.RequireRepoAdmin()
reqRepoWriter := middleware.RequireRepoWriter() reqRepoWriter := context.RequireRepoWriter()
// ***** START: Organization ***** // ***** START: Organization *****
m.Group("/org", func() { m.Group("/org", func() {
@ -347,14 +347,14 @@ func runWeb(ctx *cli.Context) {
m.Get("/members/action/:action", org.MembersAction) m.Get("/members/action/:action", org.MembersAction)
m.Get("/teams", org.Teams) m.Get("/teams", org.Teams)
}, middleware.OrgAssignment(true)) }, context.OrgAssignment(true))
m.Group("/:org", func() { m.Group("/:org", func() {
m.Get("/teams/:team", org.TeamMembers) m.Get("/teams/:team", org.TeamMembers)
m.Get("/teams/:team/repositories", org.TeamRepositories) m.Get("/teams/:team/repositories", org.TeamRepositories)
m.Route("/teams/:team/action/:action", "GET,POST", org.TeamsAction) m.Route("/teams/:team/action/:action", "GET,POST", org.TeamsAction)
m.Route("/teams/:team/action/repo/:action", "GET,POST", org.TeamsRepoAction) m.Route("/teams/:team/action/repo/:action", "GET,POST", org.TeamsRepoAction)
}, middleware.OrgAssignment(true, false, true)) }, context.OrgAssignment(true, false, true))
m.Group("/:org", func() { m.Group("/:org", func() {
m.Get("/teams/new", org.NewTeam) m.Get("/teams/new", org.NewTeam)
@ -384,7 +384,7 @@ func runWeb(ctx *cli.Context) {
}) })
m.Route("/invitations/new", "GET,POST", org.Invitation) m.Route("/invitations/new", "GET,POST", org.Invitation)
}, middleware.OrgAssignment(true, true)) }, context.OrgAssignment(true, true))
}, reqSignIn) }, reqSignIn)
// ***** END: Organization ***** // ***** END: Organization *****
@ -423,7 +423,7 @@ func runWeb(ctx *cli.Context) {
m.Get("", repo.GitHooks) m.Get("", repo.GitHooks)
m.Combo("/:name").Get(repo.GitHooksEdit). m.Combo("/:name").Get(repo.GitHooksEdit).
Post(repo.GitHooksEditPost) Post(repo.GitHooksEditPost)
}, middleware.GitHookService()) }, context.GitHookService())
}) })
m.Group("/keys", func() { m.Group("/keys", func() {
@ -432,15 +432,15 @@ func runWeb(ctx *cli.Context) {
m.Post("/delete", repo.DeleteDeployKey) m.Post("/delete", repo.DeleteDeployKey)
}) })
}, func(ctx *middleware.Context) { }, func(ctx *context.Context) {
ctx.Data["PageIsSettings"] = true ctx.Data["PageIsSettings"] = true
}) })
}, reqSignIn, middleware.RepoAssignment(), reqRepoAdmin, middleware.RepoRef()) }, reqSignIn, context.RepoAssignment(), reqRepoAdmin, context.RepoRef())
m.Get("/:username/:reponame/action/:action", reqSignIn, middleware.RepoAssignment(), repo.Action) m.Get("/:username/:reponame/action/:action", reqSignIn, context.RepoAssignment(), repo.Action)
m.Group("/:username/:reponame", func() { m.Group("/:username/:reponame", func() {
m.Group("/issues", func() { m.Group("/issues", func() {
m.Combo("/new", repo.MustEnableIssues).Get(middleware.RepoRef(), repo.NewIssue). m.Combo("/new", repo.MustEnableIssues).Get(context.RepoRef(), repo.NewIssue).
Post(bindIgnErr(auth.CreateIssueForm{}), repo.NewIssuePost) Post(bindIgnErr(auth.CreateIssueForm{}), repo.NewIssuePost)
m.Combo("/:index/comments").Post(bindIgnErr(auth.CreateCommentForm{}), repo.NewComment) m.Combo("/:index/comments").Post(bindIgnErr(auth.CreateCommentForm{}), repo.NewComment)
@ -460,7 +460,7 @@ func runWeb(ctx *cli.Context) {
m.Post("/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel) m.Post("/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel)
m.Post("/edit", bindIgnErr(auth.CreateLabelForm{}), repo.UpdateLabel) m.Post("/edit", bindIgnErr(auth.CreateLabelForm{}), repo.UpdateLabel)
m.Post("/delete", repo.DeleteLabel) m.Post("/delete", repo.DeleteLabel)
}, reqRepoWriter, middleware.RepoRef()) }, reqRepoWriter, context.RepoRef())
m.Group("/milestones", func() { m.Group("/milestones", func() {
m.Combo("/new").Get(repo.NewMilestone). m.Combo("/new").Get(repo.NewMilestone).
Post(bindIgnErr(auth.CreateMilestoneForm{}), repo.NewMilestonePost) Post(bindIgnErr(auth.CreateMilestoneForm{}), repo.NewMilestonePost)
@ -468,7 +468,7 @@ func runWeb(ctx *cli.Context) {
m.Post("/:id/edit", bindIgnErr(auth.CreateMilestoneForm{}), repo.EditMilestonePost) m.Post("/:id/edit", bindIgnErr(auth.CreateMilestoneForm{}), repo.EditMilestonePost)
m.Get("/:id/:action", repo.ChangeMilestonStatus) m.Get("/:id/:action", repo.ChangeMilestonStatus)
m.Post("/delete", repo.DeleteMilestone) m.Post("/delete", repo.DeleteMilestone)
}, reqRepoWriter, middleware.RepoRef()) }, reqRepoWriter, context.RepoRef())
m.Group("/releases", func() { m.Group("/releases", func() {
m.Get("/new", repo.NewRelease) m.Get("/new", repo.NewRelease)
@ -476,11 +476,11 @@ func runWeb(ctx *cli.Context) {
m.Get("/edit/:tagname", repo.EditRelease) m.Get("/edit/:tagname", repo.EditRelease)
m.Post("/edit/:tagname", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost) m.Post("/edit/:tagname", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost)
m.Post("/delete", repo.DeleteRelease) m.Post("/delete", repo.DeleteRelease)
}, reqRepoWriter, middleware.RepoRef()) }, reqRepoWriter, context.RepoRef())
m.Combo("/compare/*", repo.MustAllowPulls).Get(repo.CompareAndPullRequest). m.Combo("/compare/*", repo.MustAllowPulls).Get(repo.CompareAndPullRequest).
Post(bindIgnErr(auth.CreateIssueForm{}), repo.CompareAndPullRequestPost) Post(bindIgnErr(auth.CreateIssueForm{}), repo.CompareAndPullRequestPost)
}, reqSignIn, middleware.RepoAssignment(), repo.MustBeNotBare) }, reqSignIn, context.RepoAssignment(), repo.MustBeNotBare)
m.Group("/:username/:reponame", func() { m.Group("/:username/:reponame", func() {
m.Group("", func() { m.Group("", func() {
@ -489,7 +489,7 @@ func runWeb(ctx *cli.Context) {
m.Get("/^:type(issues|pulls)$/:index", repo.ViewIssue) m.Get("/^:type(issues|pulls)$/:index", repo.ViewIssue)
m.Get("/labels/", repo.RetrieveLabels, repo.Labels) m.Get("/labels/", repo.RetrieveLabels, repo.Labels)
m.Get("/milestones", repo.Milestones) m.Get("/milestones", repo.Milestones)
}, middleware.RepoRef()) }, context.RepoRef())
// m.Get("/branches", repo.Branches) // m.Get("/branches", repo.Branches)
@ -504,13 +504,13 @@ func runWeb(ctx *cli.Context) {
Post(bindIgnErr(auth.NewWikiForm{}), repo.EditWikiPost) Post(bindIgnErr(auth.NewWikiForm{}), repo.EditWikiPost)
m.Post("/:page/delete", repo.DeleteWikiPagePost) m.Post("/:page/delete", repo.DeleteWikiPagePost)
}, reqSignIn, reqRepoWriter) }, reqSignIn, reqRepoWriter)
}, repo.MustEnableWiki, middleware.RepoRef()) }, repo.MustEnableWiki, context.RepoRef())
m.Get("/archive/*", repo.Download) m.Get("/archive/*", repo.Download)
m.Group("/pulls/:index", func() { m.Group("/pulls/:index", func() {
m.Get("/commits", middleware.RepoRef(), repo.ViewPullCommits) m.Get("/commits", context.RepoRef(), repo.ViewPullCommits)
m.Get("/files", middleware.RepoRef(), repo.ViewPullFiles) m.Get("/files", context.RepoRef(), repo.ViewPullFiles)
m.Post("/merge", reqRepoWriter, repo.MergePullRequest) m.Post("/merge", reqRepoWriter, repo.MergePullRequest)
}, repo.MustAllowPulls) }, repo.MustAllowPulls)
@ -520,20 +520,20 @@ func runWeb(ctx *cli.Context) {
m.Get("/commits/*", repo.RefCommits) m.Get("/commits/*", repo.RefCommits)
m.Get("/commit/*", repo.Diff) m.Get("/commit/*", repo.Diff)
m.Get("/forks", repo.Forks) m.Get("/forks", repo.Forks)
}, middleware.RepoRef()) }, context.RepoRef())
m.Get("/compare/:before([a-z0-9]{40})\\.\\.\\.:after([a-z0-9]{40})", repo.CompareDiff) m.Get("/compare/:before([a-z0-9]{40})\\.\\.\\.:after([a-z0-9]{40})", repo.CompareDiff)
}, ignSignIn, middleware.RepoAssignment(), repo.MustBeNotBare) }, ignSignIn, context.RepoAssignment(), repo.MustBeNotBare)
m.Group("/:username/:reponame", func() { m.Group("/:username/:reponame", func() {
m.Get("/stars", repo.Stars) m.Get("/stars", repo.Stars)
m.Get("/watchers", repo.Watchers) m.Get("/watchers", repo.Watchers)
}, ignSignIn, middleware.RepoAssignment(), middleware.RepoRef()) }, ignSignIn, context.RepoAssignment(), context.RepoRef())
m.Group("/:username", func() { m.Group("/:username", func() {
m.Group("/:reponame", func() { m.Group("/:reponame", func() {
m.Get("", repo.Home) m.Get("", repo.Home)
m.Get("\\.git$", repo.Home) m.Get("\\.git$", repo.Home)
}, ignSignIn, middleware.RepoAssignment(true), middleware.RepoRef()) }, ignSignIn, context.RepoAssignment(true), context.RepoRef())
m.Group("/:reponame", func() { m.Group("/:reponame", func() {
m.Any("/*", ignSignInAndCsrf, repo.HTTP) m.Any("/*", ignSignInAndCsrf, repo.HTTP)
@ -543,7 +543,7 @@ func runWeb(ctx *cli.Context) {
// ***** END: Repository ***** // ***** END: Repository *****
// robots.txt // robots.txt
m.Get("/robots.txt", func(ctx *middleware.Context) { m.Get("/robots.txt", func(ctx *context.Context) {
if setting.HasRobotsTxt { if setting.HasRobotsTxt {
ctx.ServeFileContent(path.Join(setting.CustomPath, "robots.txt")) ctx.ServeFileContent(path.Join(setting.CustomPath, "robots.txt"))
} else { } else {

View file

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.9.4.0311" const APP_VER = "0.9.5.0311"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

File diff suppressed because it is too large Load diff

View file

@ -2,66 +2,23 @@
// Use of this source code is governed by a MIT-style // Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package middleware package context
import ( import (
"fmt"
"net/url" "net/url"
"github.com/go-macaron/csrf" "github.com/go-macaron/csrf"
"gopkg.in/macaron.v1" "gopkg.in/macaron.v1"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
type ToggleOptions struct { type ToggleOptions struct {
SignInRequire bool SignInRequired bool
SignOutRequire bool SignOutRequired bool
AdminRequire bool AdminRequired bool
DisableCsrf bool DisableCSRF bool
}
// AutoSignIn reads cookie and try to auto-login.
func AutoSignIn(ctx *Context) (bool, error) {
if !models.HasEngine {
return false, nil
}
uname := ctx.GetCookie(setting.CookieUserName)
if len(uname) == 0 {
return false, nil
}
isSucceed := false
defer func() {
if !isSucceed {
log.Trace("auto-login cookie cleared: %s", uname)
ctx.SetCookie(setting.CookieUserName, "", -1, setting.AppSubUrl)
ctx.SetCookie(setting.CookieRememberName, "", -1, setting.AppSubUrl)
}
}()
u, err := models.GetUserByName(uname)
if err != nil {
if !models.IsErrUserNotExist(err) {
return false, fmt.Errorf("GetUserByName: %v", err)
}
return false, nil
}
if val, _ := ctx.GetSuperSecureCookie(
base.EncodeMD5(u.Rands+u.Passwd), setting.CookieRememberName); val != u.Name {
return false, nil
}
isSucceed = true
ctx.Session.Set("uid", u.Id)
ctx.Session.Set("uname", u.Name)
return true, nil
} }
func Toggle(options *ToggleOptions) macaron.Handler { func Toggle(options *ToggleOptions) macaron.Handler {
@ -79,19 +36,19 @@ func Toggle(options *ToggleOptions) macaron.Handler {
} }
// Redirect to dashboard if user tries to visit any non-login page. // Redirect to dashboard if user tries to visit any non-login page.
if options.SignOutRequire && ctx.IsSigned && ctx.Req.RequestURI != "/" { if options.SignOutRequired && ctx.IsSigned && ctx.Req.RequestURI != "/" {
ctx.Redirect(setting.AppSubUrl + "/") ctx.Redirect(setting.AppSubUrl + "/")
return return
} }
if !options.SignOutRequire && !options.DisableCsrf && ctx.Req.Method == "POST" && !auth.IsAPIPath(ctx.Req.URL.Path) { if !options.SignOutRequired && !options.DisableCSRF && ctx.Req.Method == "POST" && !auth.IsAPIPath(ctx.Req.URL.Path) {
csrf.Validate(ctx.Context, ctx.csrf) csrf.Validate(ctx.Context, ctx.csrf)
if ctx.Written() { if ctx.Written() {
return return
} }
} }
if options.SignInRequire { if options.SignInRequired {
if !ctx.IsSigned { if !ctx.IsSigned {
// Restrict API calls with error message. // Restrict API calls with error message.
if auth.IsAPIPath(ctx.Req.URL.Path) { if auth.IsAPIPath(ctx.Req.URL.Path) {
@ -109,15 +66,15 @@ func Toggle(options *ToggleOptions) macaron.Handler {
} }
} }
// Auto-signin info is provided and has not signed in. // Redirect to log in page if auto-signin info is provided and has not signed in.
if !options.SignOutRequire && !ctx.IsSigned && !auth.IsAPIPath(ctx.Req.URL.Path) && if !options.SignOutRequired && !ctx.IsSigned && !auth.IsAPIPath(ctx.Req.URL.Path) &&
len(ctx.GetCookie(setting.CookieUserName)) > 0 { len(ctx.GetCookie(setting.CookieUserName)) > 0 {
ctx.SetCookie("redirect_to", url.QueryEscape(setting.AppSubUrl+ctx.Req.RequestURI), 0, setting.AppSubUrl) ctx.SetCookie("redirect_to", url.QueryEscape(setting.AppSubUrl+ctx.Req.RequestURI), 0, setting.AppSubUrl)
ctx.Redirect(setting.AppSubUrl + "/user/login") ctx.Redirect(setting.AppSubUrl + "/user/login")
return return
} }
if options.AdminRequire { if options.AdminRequired {
if !ctx.User.IsAdmin { if !ctx.User.IsAdmin {
ctx.Error(403) ctx.Error(403)
return return

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style // Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package middleware package context
import ( import (
"fmt" "fmt"
@ -27,14 +27,14 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
type PullRequestContext struct { type PullRequest struct {
BaseRepo *models.Repository BaseRepo *models.Repository
Allowed bool Allowed bool
SameRepo bool SameRepo bool
HeadInfo string // [<user>:]<branch> HeadInfo string // [<user>:]<branch>
} }
type RepoContext struct { type Repository struct {
AccessMode models.AccessMode AccessMode models.AccessMode
IsWatching bool IsWatching bool
IsViewBranch bool IsViewBranch bool
@ -54,7 +54,27 @@ type RepoContext struct {
CommitsCount int64 CommitsCount int64
Mirror *models.Mirror Mirror *models.Mirror
PullRequest *PullRequestContext PullRequest *PullRequest
}
// IsOwner returns true if current user is the owner of repository.
func (r *Repository) IsOwner() bool {
return r.AccessMode >= models.ACCESS_MODE_OWNER
}
// IsAdmin returns true if current user has admin or higher access of repository.
func (r *Repository) IsAdmin() bool {
return r.AccessMode >= models.ACCESS_MODE_ADMIN
}
// IsWriter returns true if current user has write or higher access of repository.
func (r *Repository) IsWriter() bool {
return r.AccessMode >= models.ACCESS_MODE_WRITE
}
// HasAccess returns true if the current user has at least read access for this repository
func (r *Repository) HasAccess() bool {
return r.AccessMode >= models.ACCESS_MODE_READ
} }
// Context represents context of a request. // Context represents context of a request.
@ -69,7 +89,7 @@ type Context struct {
IsSigned bool IsSigned bool
IsBasicAuth bool IsBasicAuth bool
Repo *RepoContext Repo *Repository
Org struct { Org struct {
IsOwner bool IsOwner bool
@ -83,26 +103,6 @@ type Context struct {
} }
} }
// IsOwner returns true if current user is the owner of repository.
func (r *RepoContext) IsOwner() bool {
return r.AccessMode >= models.ACCESS_MODE_OWNER
}
// IsAdmin returns true if current user has admin or higher access of repository.
func (r *RepoContext) IsAdmin() bool {
return r.AccessMode >= models.ACCESS_MODE_ADMIN
}
// IsWriter returns true if current user has write or higher access of repository.
func (r *RepoContext) IsWriter() bool {
return r.AccessMode >= models.ACCESS_MODE_WRITE
}
// HasAccess returns true if the current user has at least read access for this repository
func (r *RepoContext) HasAccess() bool {
return r.AccessMode >= models.ACCESS_MODE_READ
}
// HasError returns true if error occurs in form validation. // HasError returns true if error occurs in form validation.
func (ctx *Context) HasApiError() bool { func (ctx *Context) HasApiError() bool {
hasErr, ok := ctx.Data["HasError"] hasErr, ok := ctx.Data["HasError"]
@ -220,8 +220,8 @@ func Contexter() macaron.Handler {
csrf: x, csrf: x,
Flash: f, Flash: f,
Session: sess, Session: sess,
Repo: &RepoContext{ Repo: &Repository{
PullRequest: &PullRequestContext{}, PullRequest: &PullRequest{},
}, },
} }
// Compute current URL for real-time change language. // Compute current URL for real-time change language.

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style // Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package middleware package context
import ( import (
"strings" "strings"

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style // Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package middleware package context
import ( import (
"fmt" "fmt"

View file

@ -15,9 +15,9 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/cron" "github.com/gogits/gogs/modules/cron"
"github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/mailer"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/process" "github.com/gogits/gogs/modules/process"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -124,7 +124,7 @@ const (
REINIT_MISSING_REPOSITORY REINIT_MISSING_REPOSITORY
) )
func Dashboard(ctx *middleware.Context) { func Dashboard(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.dashboard") ctx.Data["Title"] = ctx.Tr("admin.dashboard")
ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminDashboard"] = true ctx.Data["PageIsAdminDashboard"] = true
@ -175,7 +175,7 @@ func Dashboard(ctx *middleware.Context) {
ctx.HTML(200, DASHBOARD) ctx.HTML(200, DASHBOARD)
} }
func SendTestMail(ctx *middleware.Context) { func SendTestMail(ctx *context.Context) {
email := ctx.Query("email") email := ctx.Query("email")
// Send a test email to the user's email address and redirect back to Config // Send a test email to the user's email address and redirect back to Config
if err := mailer.SendTestMail(email); err != nil { if err := mailer.SendTestMail(email); err != nil {
@ -187,7 +187,7 @@ func SendTestMail(ctx *middleware.Context) {
ctx.Redirect(setting.AppSubUrl + "/admin/config") ctx.Redirect(setting.AppSubUrl + "/admin/config")
} }
func Config(ctx *middleware.Context) { func Config(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.config") ctx.Data["Title"] = ctx.Tr("admin.config")
ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminConfig"] = true ctx.Data["PageIsAdminConfig"] = true
@ -236,7 +236,7 @@ func Config(ctx *middleware.Context) {
ctx.HTML(200, CONFIG) ctx.HTML(200, CONFIG)
} }
func Monitor(ctx *middleware.Context) { func Monitor(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.monitor") ctx.Data["Title"] = ctx.Tr("admin.monitor")
ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminMonitor"] = true ctx.Data["PageIsAdminMonitor"] = true

View file

@ -14,8 +14,8 @@ import (
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/auth/ldap" "github.com/gogits/gogs/modules/auth/ldap"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -25,7 +25,7 @@ const (
AUTH_EDIT base.TplName = "admin/auth/edit" AUTH_EDIT base.TplName = "admin/auth/edit"
) )
func Authentications(ctx *middleware.Context) { func Authentications(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.authentication") ctx.Data["Title"] = ctx.Tr("admin.authentication")
ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminAuthentications"] = true ctx.Data["PageIsAdminAuthentications"] = true
@ -53,7 +53,7 @@ var authSources = []AuthSource{
{models.LoginNames[models.LOGIN_PAM], models.LOGIN_PAM}, {models.LoginNames[models.LOGIN_PAM], models.LOGIN_PAM},
} }
func NewAuthSource(ctx *middleware.Context) { func NewAuthSource(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.auths.new") ctx.Data["Title"] = ctx.Tr("admin.auths.new")
ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminAuthentications"] = true ctx.Data["PageIsAdminAuthentications"] = true
@ -102,7 +102,7 @@ func parseSMTPConfig(form auth.AuthenticationForm) *models.SMTPConfig {
} }
} }
func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) { func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
ctx.Data["Title"] = ctx.Tr("admin.auths.new") ctx.Data["Title"] = ctx.Tr("admin.auths.new")
ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminAuthentications"] = true ctx.Data["PageIsAdminAuthentications"] = true
@ -147,7 +147,7 @@ func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
ctx.Redirect(setting.AppSubUrl + "/admin/auths") ctx.Redirect(setting.AppSubUrl + "/admin/auths")
} }
func EditAuthSource(ctx *middleware.Context) { func EditAuthSource(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.auths.edit") ctx.Data["Title"] = ctx.Tr("admin.auths.edit")
ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminAuthentications"] = true ctx.Data["PageIsAdminAuthentications"] = true
@ -163,7 +163,7 @@ func EditAuthSource(ctx *middleware.Context) {
ctx.HTML(200, AUTH_EDIT) ctx.HTML(200, AUTH_EDIT)
} }
func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) { func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
ctx.Data["Title"] = ctx.Tr("admin.auths.edit") ctx.Data["Title"] = ctx.Tr("admin.auths.edit")
ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminAuthentications"] = true ctx.Data["PageIsAdminAuthentications"] = true
@ -210,7 +210,7 @@ func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
ctx.Redirect(setting.AppSubUrl + "/admin/auths/" + com.ToStr(form.ID)) ctx.Redirect(setting.AppSubUrl + "/admin/auths/" + com.ToStr(form.ID))
} }
func DeleteAuthSource(ctx *middleware.Context) { func DeleteAuthSource(ctx *context.Context) {
source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid")) source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid"))
if err != nil { if err != nil {
ctx.Handle(500, "GetLoginSourceByID", err) ctx.Handle(500, "GetLoginSourceByID", err)

View file

@ -10,8 +10,8 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -19,7 +19,7 @@ const (
NOTICES base.TplName = "admin/notice" NOTICES base.TplName = "admin/notice"
) )
func Notices(ctx *middleware.Context) { func Notices(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.notices") ctx.Data["Title"] = ctx.Tr("admin.notices")
ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminNotices"] = true ctx.Data["PageIsAdminNotices"] = true
@ -42,7 +42,7 @@ func Notices(ctx *middleware.Context) {
ctx.HTML(200, NOTICES) ctx.HTML(200, NOTICES)
} }
func DeleteNotices(ctx *middleware.Context) { func DeleteNotices(ctx *context.Context) {
strs := ctx.QueryStrings("ids[]") strs := ctx.QueryStrings("ids[]")
ids := make([]int64, 0, len(strs)) ids := make([]int64, 0, len(strs))
for i := range strs { for i := range strs {
@ -61,7 +61,7 @@ func DeleteNotices(ctx *middleware.Context) {
} }
} }
func EmptyNotices(ctx *middleware.Context) { func EmptyNotices(ctx *context.Context) {
if err := models.DeleteNotices(0, 0); err != nil { if err := models.DeleteNotices(0, 0); err != nil {
ctx.Handle(500, "DeleteNotices", err) ctx.Handle(500, "DeleteNotices", err)
return return

View file

@ -9,7 +9,7 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -17,7 +17,7 @@ const (
ORGS base.TplName = "admin/org/list" ORGS base.TplName = "admin/org/list"
) )
func Organizations(ctx *middleware.Context) { func Organizations(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.organizations") ctx.Data["Title"] = ctx.Tr("admin.organizations")
ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminOrganizations"] = true ctx.Data["PageIsAdminOrganizations"] = true

View file

@ -9,8 +9,8 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -18,7 +18,7 @@ const (
REPOS base.TplName = "admin/repo/list" REPOS base.TplName = "admin/repo/list"
) )
func Repos(ctx *middleware.Context) { func Repos(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.repositories") ctx.Data["Title"] = ctx.Tr("admin.repositories")
ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminRepositories"] = true ctx.Data["PageIsAdminRepositories"] = true
@ -41,7 +41,7 @@ func Repos(ctx *middleware.Context) {
ctx.HTML(200, REPOS) ctx.HTML(200, REPOS)
} }
func DeleteRepo(ctx *middleware.Context) { func DeleteRepo(ctx *context.Context) {
repo, err := models.GetRepositoryByID(ctx.QueryInt64("id")) repo, err := models.GetRepositoryByID(ctx.QueryInt64("id"))
if err != nil { if err != nil {
ctx.Handle(500, "GetRepositoryByID", err) ctx.Handle(500, "GetRepositoryByID", err)

View file

@ -13,9 +13,9 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/mailer"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -25,7 +25,7 @@ const (
USER_EDIT base.TplName = "admin/user/edit" USER_EDIT base.TplName = "admin/user/edit"
) )
func Users(ctx *middleware.Context) { func Users(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.users") ctx.Data["Title"] = ctx.Tr("admin.users")
ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminUsers"] = true ctx.Data["PageIsAdminUsers"] = true
@ -48,7 +48,7 @@ func Users(ctx *middleware.Context) {
ctx.HTML(200, USERS) ctx.HTML(200, USERS)
} }
func NewUser(ctx *middleware.Context) { func NewUser(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.users.new_account") ctx.Data["Title"] = ctx.Tr("admin.users.new_account")
ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminUsers"] = true ctx.Data["PageIsAdminUsers"] = true
@ -66,7 +66,7 @@ func NewUser(ctx *middleware.Context) {
ctx.HTML(200, USER_NEW) ctx.HTML(200, USER_NEW)
} }
func NewUserPost(ctx *middleware.Context, form auth.AdminCrateUserForm) { func NewUserPost(ctx *context.Context, form auth.AdminCrateUserForm) {
ctx.Data["Title"] = ctx.Tr("admin.users.new_account") ctx.Data["Title"] = ctx.Tr("admin.users.new_account")
ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminUsers"] = true ctx.Data["PageIsAdminUsers"] = true
@ -132,7 +132,7 @@ func NewUserPost(ctx *middleware.Context, form auth.AdminCrateUserForm) {
ctx.Redirect(setting.AppSubUrl + "/admin/users/" + com.ToStr(u.Id)) ctx.Redirect(setting.AppSubUrl + "/admin/users/" + com.ToStr(u.Id))
} }
func prepareUserInfo(ctx *middleware.Context) *models.User { func prepareUserInfo(ctx *context.Context) *models.User {
u, err := models.GetUserByID(ctx.ParamsInt64(":userid")) u, err := models.GetUserByID(ctx.ParamsInt64(":userid"))
if err != nil { if err != nil {
ctx.Handle(500, "GetUserByID", err) ctx.Handle(500, "GetUserByID", err)
@ -160,7 +160,7 @@ func prepareUserInfo(ctx *middleware.Context) *models.User {
return u return u
} }
func EditUser(ctx *middleware.Context) { func EditUser(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.users.edit_account") ctx.Data["Title"] = ctx.Tr("admin.users.edit_account")
ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminUsers"] = true ctx.Data["PageIsAdminUsers"] = true
@ -173,7 +173,7 @@ func EditUser(ctx *middleware.Context) {
ctx.HTML(200, USER_EDIT) ctx.HTML(200, USER_EDIT)
} }
func EditUserPost(ctx *middleware.Context, form auth.AdminEditUserForm) { func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
ctx.Data["Title"] = ctx.Tr("admin.users.edit_account") ctx.Data["Title"] = ctx.Tr("admin.users.edit_account")
ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminUsers"] = true ctx.Data["PageIsAdminUsers"] = true
@ -231,7 +231,7 @@ func EditUserPost(ctx *middleware.Context, form auth.AdminEditUserForm) {
ctx.Redirect(setting.AppSubUrl + "/admin/users/" + ctx.Params(":userid")) ctx.Redirect(setting.AppSubUrl + "/admin/users/" + ctx.Params(":userid"))
} }
func DeleteUser(ctx *middleware.Context) { func DeleteUser(ctx *context.Context) {
u, err := models.GetUserByID(ctx.ParamsInt64(":userid")) u, err := models.GetUserByID(ctx.ParamsInt64(":userid"))
if err != nil { if err != nil {
ctx.Handle(500, "GetUserByID", err) ctx.Handle(500, "GetUserByID", err)

View file

@ -8,13 +8,13 @@ import (
api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/api/v1/convert" "github.com/gogits/gogs/routers/api/v1/convert"
"github.com/gogits/gogs/routers/api/v1/user" "github.com/gogits/gogs/routers/api/v1/user"
) )
// https://github.com/gogits/go-gogs-client/wiki/Administration-Organizations#create-a-new-organization // https://github.com/gogits/go-gogs-client/wiki/Administration-Organizations#create-a-new-organization
func CreateOrg(ctx *middleware.Context, form api.CreateOrgOption) { func CreateOrg(ctx *context.Context, form api.CreateOrgOption) {
u := user.GetUserByParams(ctx) u := user.GetUserByParams(ctx)
if ctx.Written() { if ctx.Written() {
return return

View file

@ -7,13 +7,13 @@ package admin
import ( import (
api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/api/v1/repo" "github.com/gogits/gogs/routers/api/v1/repo"
"github.com/gogits/gogs/routers/api/v1/user" "github.com/gogits/gogs/routers/api/v1/user"
) )
// https://github.com/gogits/go-gogs-client/wiki/Administration-Repositories#create-a-new-repository // https://github.com/gogits/go-gogs-client/wiki/Administration-Repositories#create-a-new-repository
func CreateRepo(ctx *middleware.Context, form api.CreateRepoOption) { func CreateRepo(ctx *context.Context, form api.CreateRepoOption) {
owner := user.GetUserByParams(ctx) owner := user.GetUserByParams(ctx)
if ctx.Written() { if ctx.Written() {
return return

View file

@ -8,15 +8,15 @@ import (
api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/mailer"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/routers/api/v1/convert" "github.com/gogits/gogs/routers/api/v1/convert"
"github.com/gogits/gogs/routers/api/v1/user" "github.com/gogits/gogs/routers/api/v1/user"
) )
func parseLoginSource(ctx *middleware.Context, u *models.User, sourceID int64, loginName string) { func parseLoginSource(ctx *context.Context, u *models.User, sourceID int64, loginName string) {
if sourceID == 0 { if sourceID == 0 {
return return
} }
@ -37,7 +37,7 @@ func parseLoginSource(ctx *middleware.Context, u *models.User, sourceID int64, l
} }
// https://github.com/gogits/go-gogs-client/wiki/Administration-Users#create-a-new-user // https://github.com/gogits/go-gogs-client/wiki/Administration-Users#create-a-new-user
func CreateUser(ctx *middleware.Context, form api.CreateUserOption) { func CreateUser(ctx *context.Context, form api.CreateUserOption) {
u := &models.User{ u := &models.User{
Name: form.Username, Name: form.Username,
Email: form.Email, Email: form.Email,
@ -73,7 +73,7 @@ func CreateUser(ctx *middleware.Context, form api.CreateUserOption) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Administration-Users#edit-an-existing-user // https://github.com/gogits/go-gogs-client/wiki/Administration-Users#edit-an-existing-user
func EditUser(ctx *middleware.Context, form api.EditUserOption) { func EditUser(ctx *context.Context, form api.EditUserOption) {
u := user.GetUserByParams(ctx) u := user.GetUserByParams(ctx)
if ctx.Written() { if ctx.Written() {
return return
@ -122,7 +122,7 @@ func EditUser(ctx *middleware.Context, form api.EditUserOption) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Administration-Users#delete-a-user // https://github.com/gogits/go-gogs-client/wiki/Administration-Users#delete-a-user
func DeleteUser(ctx *middleware.Context) { func DeleteUser(ctx *context.Context) {
u := user.GetUserByParams(ctx) u := user.GetUserByParams(ctx)
if ctx.Written() { if ctx.Written() {
return return
@ -143,7 +143,7 @@ func DeleteUser(ctx *middleware.Context) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Administration-Users#create-a-public-key-for-user // https://github.com/gogits/go-gogs-client/wiki/Administration-Users#create-a-public-key-for-user
func CreatePublicKey(ctx *middleware.Context, form api.CreateKeyOption) { func CreatePublicKey(ctx *context.Context, form api.CreateKeyOption) {
u := user.GetUserByParams(ctx) u := user.GetUserByParams(ctx)
if ctx.Written() { if ctx.Written() {
return return

View file

@ -14,7 +14,7 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/api/v1/admin" "github.com/gogits/gogs/routers/api/v1/admin"
"github.com/gogits/gogs/routers/api/v1/misc" "github.com/gogits/gogs/routers/api/v1/misc"
"github.com/gogits/gogs/routers/api/v1/org" "github.com/gogits/gogs/routers/api/v1/org"
@ -23,7 +23,7 @@ import (
) )
func RepoAssignment() macaron.Handler { func RepoAssignment() macaron.Handler {
return func(ctx *middleware.Context) { return func(ctx *context.Context) {
userName := ctx.Params(":username") userName := ctx.Params(":username")
repoName := ctx.Params(":reponame") repoName := ctx.Params(":reponame")
@ -82,7 +82,7 @@ func RepoAssignment() macaron.Handler {
// Contexter middleware already checks token for user sign in process. // Contexter middleware already checks token for user sign in process.
func ReqToken() macaron.Handler { func ReqToken() macaron.Handler {
return func(ctx *middleware.Context) { return func(ctx *context.Context) {
if !ctx.IsSigned { if !ctx.IsSigned {
ctx.Error(401) ctx.Error(401)
return return
@ -91,7 +91,7 @@ func ReqToken() macaron.Handler {
} }
func ReqBasicAuth() macaron.Handler { func ReqBasicAuth() macaron.Handler {
return func(ctx *middleware.Context) { return func(ctx *context.Context) {
if !ctx.IsBasicAuth { if !ctx.IsBasicAuth {
ctx.Error(401) ctx.Error(401)
return return
@ -100,7 +100,7 @@ func ReqBasicAuth() macaron.Handler {
} }
func ReqAdmin() macaron.Handler { func ReqAdmin() macaron.Handler {
return func(ctx *middleware.Context) { return func(ctx *context.Context) {
if !ctx.User.IsAdmin { if !ctx.User.IsAdmin {
ctx.Error(403) ctx.Error(403)
return return
@ -181,11 +181,11 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Combo("/hooks").Get(repo.ListHooks). m.Combo("/hooks").Get(repo.ListHooks).
Post(bind(api.CreateHookOption{}), repo.CreateHook) Post(bind(api.CreateHookOption{}), repo.CreateHook)
m.Patch("/hooks/:id:int", bind(api.EditHookOption{}), repo.EditHook) m.Patch("/hooks/:id:int", bind(api.EditHookOption{}), repo.EditHook)
m.Get("/raw/*", middleware.RepoRef(), repo.GetRawFile) m.Get("/raw/*", context.RepoRef(), repo.GetRawFile)
m.Get("/archive/*", repo.GetArchive) m.Get("/archive/*", repo.GetArchive)
m.Group("/branches", func() { m.Group("/branches", func() {
m.Get("",repo.ListBranches) m.Get("", repo.ListBranches)
m.Get("/:branchname",repo.GetBranch) m.Get("/:branchname", repo.GetBranch)
}) })
m.Group("/keys", func() { m.Group("/keys", func() {
m.Combo("").Get(repo.ListDeployKeys). m.Combo("").Get(repo.ListDeployKeys).
@ -201,7 +201,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/users/:username/orgs", org.ListUserOrgs) m.Get("/users/:username/orgs", org.ListUserOrgs)
m.Combo("/orgs/:orgname").Get(org.Get).Patch(bind(api.EditOrgOption{}), org.Edit) m.Combo("/orgs/:orgname").Get(org.Get).Patch(bind(api.EditOrgOption{}), org.Edit)
m.Any("/*", func(ctx *middleware.Context) { m.Any("/*", func(ctx *context.Context) {
ctx.Error(404) ctx.Error(404)
}) })

View file

@ -7,12 +7,12 @@ package misc
import ( import (
api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/markdown" "github.com/gogits/gogs/modules/markdown"
"github.com/gogits/gogs/modules/middleware"
) )
// https://github.com/gogits/go-gogs-client/wiki/Miscellaneous#render-an-arbitrary-markdown-document // https://github.com/gogits/go-gogs-client/wiki/Miscellaneous#render-an-arbitrary-markdown-document
func Markdown(ctx *middleware.Context, form api.MarkdownOption) { func Markdown(ctx *context.Context, form api.MarkdownOption) {
if ctx.HasApiError() { if ctx.HasApiError() {
ctx.APIError(422, "", ctx.GetErrMsg()) ctx.APIError(422, "", ctx.GetErrMsg())
return return
@ -32,7 +32,7 @@ func Markdown(ctx *middleware.Context, form api.MarkdownOption) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Miscellaneous#render-a-markdown-document-in-raw-mode // https://github.com/gogits/go-gogs-client/wiki/Miscellaneous#render-a-markdown-document-in-raw-mode
func MarkdownRaw(ctx *middleware.Context) { func MarkdownRaw(ctx *context.Context) {
body, err := ctx.Req.Body().Bytes() body, err := ctx.Req.Body().Bytes()
if err != nil { if err != nil {
ctx.APIError(422, "", err) ctx.APIError(422, "", err)

View file

@ -8,12 +8,12 @@ import (
api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/api/v1/convert" "github.com/gogits/gogs/routers/api/v1/convert"
"github.com/gogits/gogs/routers/api/v1/user" "github.com/gogits/gogs/routers/api/v1/user"
) )
func listUserOrgs(ctx *middleware.Context, u *models.User, all bool) { func listUserOrgs(ctx *context.Context, u *models.User, all bool) {
if err := u.GetOrganizations(all); err != nil { if err := u.GetOrganizations(all); err != nil {
ctx.APIError(500, "GetOrganizations", err) ctx.APIError(500, "GetOrganizations", err)
return return
@ -27,12 +27,12 @@ func listUserOrgs(ctx *middleware.Context, u *models.User, all bool) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Organizations#list-your-organizations // https://github.com/gogits/go-gogs-client/wiki/Organizations#list-your-organizations
func ListMyOrgs(ctx *middleware.Context) { func ListMyOrgs(ctx *context.Context) {
listUserOrgs(ctx, ctx.User, true) listUserOrgs(ctx, ctx.User, true)
} }
// https://github.com/gogits/go-gogs-client/wiki/Organizations#list-user-organizations // https://github.com/gogits/go-gogs-client/wiki/Organizations#list-user-organizations
func ListUserOrgs(ctx *middleware.Context) { func ListUserOrgs(ctx *context.Context) {
u := user.GetUserByParams(ctx) u := user.GetUserByParams(ctx)
if ctx.Written() { if ctx.Written() {
return return
@ -41,7 +41,7 @@ func ListUserOrgs(ctx *middleware.Context) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Organizations#get-an-organization // https://github.com/gogits/go-gogs-client/wiki/Organizations#get-an-organization
func Get(ctx *middleware.Context) { func Get(ctx *context.Context) {
org := user.GetUserByParamsName(ctx, ":orgname") org := user.GetUserByParamsName(ctx, ":orgname")
if ctx.Written() { if ctx.Written() {
return return
@ -50,7 +50,7 @@ func Get(ctx *middleware.Context) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Organizations#edit-an-organization // https://github.com/gogits/go-gogs-client/wiki/Organizations#edit-an-organization
func Edit(ctx *middleware.Context, form api.EditOrgOption) { func Edit(ctx *context.Context, form api.EditOrgOption) {
org := user.GetUserByParamsName(ctx, ":orgname") org := user.GetUserByParamsName(ctx, ":orgname")
if ctx.Written() { if ctx.Written() {
return return

View file

@ -7,12 +7,12 @@ package repo
import ( import (
api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/api/v1/convert" "github.com/gogits/gogs/routers/api/v1/convert"
) )
// https://github.com/gogits/go-gogs-client/wiki/Repositories#get-branch // https://github.com/gogits/go-gogs-client/wiki/Repositories#get-branch
func GetBranch(ctx *middleware.Context) { func GetBranch(ctx *context.Context) {
branch, err := ctx.Repo.Repository.GetBranch(ctx.Params(":branchname")) branch, err := ctx.Repo.Repository.GetBranch(ctx.Params(":branchname"))
if err != nil { if err != nil {
ctx.APIError(500, "GetBranch", err) ctx.APIError(500, "GetBranch", err)
@ -29,7 +29,7 @@ func GetBranch(ctx *middleware.Context) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-branches // https://github.com/gogits/go-gogs-client/wiki/Repositories#list-branches
func ListBranches(ctx *middleware.Context) { func ListBranches(ctx *context.Context) {
branches, err := ctx.Repo.Repository.GetBranches() branches, err := ctx.Repo.Repository.GetBranches()
if err != nil { if err != nil {
ctx.APIError(500, "GetBranches", err) ctx.APIError(500, "GetBranches", err)

View file

@ -8,12 +8,12 @@ import (
"github.com/gogits/git-module" "github.com/gogits/git-module"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/repo" "github.com/gogits/gogs/routers/repo"
) )
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-raw-content // https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-raw-content
func GetRawFile(ctx *middleware.Context) { func GetRawFile(ctx *context.Context) {
if !ctx.Repo.HasAccess() { if !ctx.Repo.HasAccess() {
ctx.Error(404) ctx.Error(404)
return return
@ -34,7 +34,7 @@ func GetRawFile(ctx *middleware.Context) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-archive // https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-archive
func GetArchive(ctx *middleware.Context) { func GetArchive(ctx *context.Context) {
repoPath := models.RepoPath(ctx.Params(":username"), ctx.Params(":reponame")) repoPath := models.RepoPath(ctx.Params(":username"), ctx.Params(":reponame"))
gitRepo, err := git.OpenRepository(repoPath) gitRepo, err := git.OpenRepository(repoPath)
if err != nil { if err != nil {

View file

@ -12,12 +12,12 @@ import (
api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/api/v1/convert" "github.com/gogits/gogs/routers/api/v1/convert"
) )
// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-hooks // https://github.com/gogits/go-gogs-client/wiki/Repositories#list-hooks
func ListHooks(ctx *middleware.Context) { func ListHooks(ctx *context.Context) {
hooks, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID) hooks, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID)
if err != nil { if err != nil {
ctx.APIError(500, "GetWebhooksByRepoID", err) ctx.APIError(500, "GetWebhooksByRepoID", err)
@ -33,7 +33,7 @@ func ListHooks(ctx *middleware.Context) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Repositories#create-a-hook // https://github.com/gogits/go-gogs-client/wiki/Repositories#create-a-hook
func CreateHook(ctx *middleware.Context, form api.CreateHookOption) { func CreateHook(ctx *context.Context, form api.CreateHookOption) {
if !models.IsValidHookTaskType(form.Type) { if !models.IsValidHookTaskType(form.Type) {
ctx.APIError(422, "", "Invalid hook type") ctx.APIError(422, "", "Invalid hook type")
return return
@ -98,7 +98,7 @@ func CreateHook(ctx *middleware.Context, form api.CreateHookOption) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Repositories#edit-a-hook // https://github.com/gogits/go-gogs-client/wiki/Repositories#edit-a-hook
func EditHook(ctx *middleware.Context, form api.EditHookOption) { func EditHook(ctx *context.Context, form api.EditHookOption) {
w, err := models.GetWebhookByID(ctx.ParamsInt64(":id")) w, err := models.GetWebhookByID(ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
if models.IsErrWebhookNotExist(err) { if models.IsErrWebhookNotExist(err) {

View file

@ -10,7 +10,7 @@ import (
api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/routers/api/v1/convert" "github.com/gogits/gogs/routers/api/v1/convert"
) )
@ -20,7 +20,7 @@ func composeDeployKeysAPILink(repoPath string) string {
} }
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#list-deploy-keys // https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#list-deploy-keys
func ListDeployKeys(ctx *middleware.Context) { func ListDeployKeys(ctx *context.Context) {
keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID) keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID)
if err != nil { if err != nil {
ctx.Handle(500, "ListDeployKeys", err) ctx.Handle(500, "ListDeployKeys", err)
@ -41,7 +41,7 @@ func ListDeployKeys(ctx *middleware.Context) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#get-a-deploy-key // https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#get-a-deploy-key
func GetDeployKey(ctx *middleware.Context) { func GetDeployKey(ctx *context.Context) {
key, err := models.GetDeployKeyByID(ctx.ParamsInt64(":id")) key, err := models.GetDeployKeyByID(ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
if models.IsErrDeployKeyNotExist(err) { if models.IsErrDeployKeyNotExist(err) {
@ -61,7 +61,7 @@ func GetDeployKey(ctx *middleware.Context) {
ctx.JSON(200, convert.ToApiDeployKey(apiLink, key)) ctx.JSON(200, convert.ToApiDeployKey(apiLink, key))
} }
func HandleCheckKeyStringError(ctx *middleware.Context, err error) { func HandleCheckKeyStringError(ctx *context.Context, err error) {
if models.IsErrKeyUnableVerify(err) { if models.IsErrKeyUnableVerify(err) {
ctx.APIError(422, "", "Unable to verify key content") ctx.APIError(422, "", "Unable to verify key content")
} else { } else {
@ -69,7 +69,7 @@ func HandleCheckKeyStringError(ctx *middleware.Context, err error) {
} }
} }
func HandleAddKeyError(ctx *middleware.Context, err error) { func HandleAddKeyError(ctx *context.Context, err error) {
switch { switch {
case models.IsErrKeyAlreadyExist(err): case models.IsErrKeyAlreadyExist(err):
ctx.APIError(422, "", "Key content has been used as non-deploy key") ctx.APIError(422, "", "Key content has been used as non-deploy key")
@ -81,7 +81,7 @@ func HandleAddKeyError(ctx *middleware.Context, err error) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#add-a-new-deploy-key // https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#add-a-new-deploy-key
func CreateDeployKey(ctx *middleware.Context, form api.CreateKeyOption) { func CreateDeployKey(ctx *context.Context, form api.CreateKeyOption) {
content, err := models.CheckPublicKeyString(form.Key) content, err := models.CheckPublicKeyString(form.Key)
if err != nil { if err != nil {
HandleCheckKeyStringError(ctx, err) HandleCheckKeyStringError(ctx, err)
@ -100,7 +100,7 @@ func CreateDeployKey(ctx *middleware.Context, form api.CreateKeyOption) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#remove-a-deploy-key // https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#remove-a-deploy-key
func DeleteDeploykey(ctx *middleware.Context) { func DeleteDeploykey(ctx *context.Context) {
if err := models.DeleteDeployKey(ctx.User, ctx.ParamsInt64(":id")); err != nil { if err := models.DeleteDeployKey(ctx.User, ctx.ParamsInt64(":id")); err != nil {
if models.IsErrKeyAccessDenied(err) { if models.IsErrKeyAccessDenied(err) {
ctx.APIError(403, "", "You do not have access to this key") ctx.APIError(403, "", "You do not have access to this key")

View file

@ -13,14 +13,14 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/routers/api/v1/convert" "github.com/gogits/gogs/routers/api/v1/convert"
) )
// https://github.com/gogits/go-gogs-client/wiki/Repositories#search-repositories // https://github.com/gogits/go-gogs-client/wiki/Repositories#search-repositories
func Search(ctx *middleware.Context) { func Search(ctx *context.Context) {
opt := models.SearchOption{ opt := models.SearchOption{
Keyword: path.Base(ctx.Query("q")), Keyword: path.Base(ctx.Query("q")),
Uid: com.StrTo(ctx.Query("uid")).MustInt64(), Uid: com.StrTo(ctx.Query("uid")).MustInt64(),
@ -81,7 +81,7 @@ func Search(ctx *middleware.Context) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-your-repositories // https://github.com/gogits/go-gogs-client/wiki/Repositories#list-your-repositories
func ListMyRepos(ctx *middleware.Context) { func ListMyRepos(ctx *context.Context) {
ownRepos, err := models.GetRepositories(ctx.User.Id, true) ownRepos, err := models.GetRepositories(ctx.User.Id, true)
if err != nil { if err != nil {
ctx.APIError(500, "GetRepositories", err) ctx.APIError(500, "GetRepositories", err)
@ -113,7 +113,7 @@ func ListMyRepos(ctx *middleware.Context) {
ctx.JSON(200, &repos) ctx.JSON(200, &repos)
} }
func CreateUserRepo(ctx *middleware.Context, owner *models.User, opt api.CreateRepoOption) { func CreateUserRepo(ctx *context.Context, owner *models.User, opt api.CreateRepoOption) {
repo, err := models.CreateRepository(owner, models.CreateRepoOptions{ repo, err := models.CreateRepository(owner, models.CreateRepoOptions{
Name: opt.Name, Name: opt.Name,
Description: opt.Description, Description: opt.Description,
@ -143,7 +143,7 @@ func CreateUserRepo(ctx *middleware.Context, owner *models.User, opt api.CreateR
} }
// https://github.com/gogits/go-gogs-client/wiki/Repositories#create // https://github.com/gogits/go-gogs-client/wiki/Repositories#create
func Create(ctx *middleware.Context, opt api.CreateRepoOption) { func Create(ctx *context.Context, opt api.CreateRepoOption) {
// Shouldn't reach this condition, but just in case. // Shouldn't reach this condition, but just in case.
if ctx.User.IsOrganization() { if ctx.User.IsOrganization() {
ctx.APIError(422, "", "not allowed creating repository for organization") ctx.APIError(422, "", "not allowed creating repository for organization")
@ -152,7 +152,7 @@ func Create(ctx *middleware.Context, opt api.CreateRepoOption) {
CreateUserRepo(ctx, ctx.User, opt) CreateUserRepo(ctx, ctx.User, opt)
} }
func CreateOrgRepo(ctx *middleware.Context, opt api.CreateRepoOption) { func CreateOrgRepo(ctx *context.Context, opt api.CreateRepoOption) {
org, err := models.GetOrgByName(ctx.Params(":org")) org, err := models.GetOrgByName(ctx.Params(":org"))
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
@ -171,7 +171,7 @@ func CreateOrgRepo(ctx *middleware.Context, opt api.CreateRepoOption) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Repositories#migrate // https://github.com/gogits/go-gogs-client/wiki/Repositories#migrate
func Migrate(ctx *middleware.Context, form auth.MigrateRepoForm) { func Migrate(ctx *context.Context, form auth.MigrateRepoForm) {
ctxUser := ctx.User ctxUser := ctx.User
// Not equal means context user is an organization, // Not equal means context user is an organization,
// or is another user/organization if current user is admin. // or is another user/organization if current user is admin.
@ -242,7 +242,7 @@ func Migrate(ctx *middleware.Context, form auth.MigrateRepoForm) {
ctx.JSON(201, convert.ToApiRepository(ctxUser, repo, api.Permission{true, true, true})) ctx.JSON(201, convert.ToApiRepository(ctxUser, repo, api.Permission{true, true, true}))
} }
func parseOwnerAndRepo(ctx *middleware.Context) (*models.User, *models.Repository) { func parseOwnerAndRepo(ctx *context.Context) (*models.User, *models.Repository) {
owner, err := models.GetUserByName(ctx.Params(":username")) owner, err := models.GetUserByName(ctx.Params(":username"))
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
@ -267,7 +267,7 @@ func parseOwnerAndRepo(ctx *middleware.Context) (*models.User, *models.Repositor
} }
// https://github.com/gogits/go-gogs-client/wiki/Repositories#get // https://github.com/gogits/go-gogs-client/wiki/Repositories#get
func Get(ctx *middleware.Context) { func Get(ctx *context.Context) {
owner, repo := parseOwnerAndRepo(ctx) owner, repo := parseOwnerAndRepo(ctx)
if ctx.Written() { if ctx.Written() {
return return
@ -277,7 +277,7 @@ func Get(ctx *middleware.Context) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Repositories#delete // https://github.com/gogits/go-gogs-client/wiki/Repositories#delete
func Delete(ctx *middleware.Context) { func Delete(ctx *context.Context) {
owner, repo := parseOwnerAndRepo(ctx) owner, repo := parseOwnerAndRepo(ctx)
if ctx.Written() { if ctx.Written() {
return return

View file

@ -8,11 +8,11 @@ import (
api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
) )
// https://github.com/gogits/go-gogs-client/wiki/Users#list-access-tokens-for-a-user // https://github.com/gogits/go-gogs-client/wiki/Users#list-access-tokens-for-a-user
func ListAccessTokens(ctx *middleware.Context) { func ListAccessTokens(ctx *context.Context) {
tokens, err := models.ListAccessTokens(ctx.User.Id) tokens, err := models.ListAccessTokens(ctx.User.Id)
if err != nil { if err != nil {
ctx.APIError(500, "ListAccessTokens", err) ctx.APIError(500, "ListAccessTokens", err)
@ -27,7 +27,7 @@ func ListAccessTokens(ctx *middleware.Context) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Users#create-a-access-token // https://github.com/gogits/go-gogs-client/wiki/Users#create-a-access-token
func CreateAccessToken(ctx *middleware.Context, form api.CreateAccessTokenOption) { func CreateAccessToken(ctx *context.Context, form api.CreateAccessTokenOption) {
t := &models.AccessToken{ t := &models.AccessToken{
UID: ctx.User.Id, UID: ctx.User.Id,
Name: form.Name, Name: form.Name,

View file

@ -8,13 +8,13 @@ import (
api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/routers/api/v1/convert" "github.com/gogits/gogs/routers/api/v1/convert"
) )
// https://github.com/gogits/go-gogs-client/wiki/Users-Emails#list-email-addresses-for-a-user // https://github.com/gogits/go-gogs-client/wiki/Users-Emails#list-email-addresses-for-a-user
func ListEmails(ctx *middleware.Context) { func ListEmails(ctx *context.Context) {
emails, err := models.GetEmailAddresses(ctx.User.Id) emails, err := models.GetEmailAddresses(ctx.User.Id)
if err != nil { if err != nil {
ctx.Handle(500, "GetEmailAddresses", err) ctx.Handle(500, "GetEmailAddresses", err)
@ -28,7 +28,7 @@ func ListEmails(ctx *middleware.Context) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Users-Emails#add-email-addresses // https://github.com/gogits/go-gogs-client/wiki/Users-Emails#add-email-addresses
func AddEmail(ctx *middleware.Context, form api.CreateEmailOption) { func AddEmail(ctx *context.Context, form api.CreateEmailOption) {
if len(form.Emails) == 0 { if len(form.Emails) == 0 {
ctx.Status(422) ctx.Status(422)
return return
@ -60,7 +60,7 @@ func AddEmail(ctx *middleware.Context, form api.CreateEmailOption) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Users-Emails#delete-email-addresses // https://github.com/gogits/go-gogs-client/wiki/Users-Emails#delete-email-addresses
func DeleteEmail(ctx *middleware.Context, form api.CreateEmailOption) { func DeleteEmail(ctx *context.Context, form api.CreateEmailOption) {
if len(form.Emails) == 0 { if len(form.Emails) == 0 {
ctx.Status(204) ctx.Status(204)
return return

View file

@ -8,11 +8,11 @@ import (
api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/api/v1/convert" "github.com/gogits/gogs/routers/api/v1/convert"
) )
func responseApiUsers(ctx *middleware.Context, users []*models.User) { func responseApiUsers(ctx *context.Context, users []*models.User) {
apiUsers := make([]*api.User, len(users)) apiUsers := make([]*api.User, len(users))
for i := range users { for i := range users {
apiUsers[i] = convert.ToApiUser(users[i]) apiUsers[i] = convert.ToApiUser(users[i])
@ -20,7 +20,7 @@ func responseApiUsers(ctx *middleware.Context, users []*models.User) {
ctx.JSON(200, &apiUsers) ctx.JSON(200, &apiUsers)
} }
func listUserFollowers(ctx *middleware.Context, u *models.User) { func listUserFollowers(ctx *context.Context, u *models.User) {
users, err := u.GetFollowers(ctx.QueryInt("page")) users, err := u.GetFollowers(ctx.QueryInt("page"))
if err != nil { if err != nil {
ctx.APIError(500, "GetUserFollowers", err) ctx.APIError(500, "GetUserFollowers", err)
@ -29,12 +29,12 @@ func listUserFollowers(ctx *middleware.Context, u *models.User) {
responseApiUsers(ctx, users) responseApiUsers(ctx, users)
} }
func ListMyFollowers(ctx *middleware.Context) { func ListMyFollowers(ctx *context.Context) {
listUserFollowers(ctx, ctx.User) listUserFollowers(ctx, ctx.User)
} }
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#list-followers-of-a-user // https://github.com/gogits/go-gogs-client/wiki/Users-Followers#list-followers-of-a-user
func ListFollowers(ctx *middleware.Context) { func ListFollowers(ctx *context.Context) {
u := GetUserByParams(ctx) u := GetUserByParams(ctx)
if ctx.Written() { if ctx.Written() {
return return
@ -42,7 +42,7 @@ func ListFollowers(ctx *middleware.Context) {
listUserFollowers(ctx, u) listUserFollowers(ctx, u)
} }
func listUserFollowing(ctx *middleware.Context, u *models.User) { func listUserFollowing(ctx *context.Context, u *models.User) {
users, err := u.GetFollowing(ctx.QueryInt("page")) users, err := u.GetFollowing(ctx.QueryInt("page"))
if err != nil { if err != nil {
ctx.APIError(500, "GetFollowing", err) ctx.APIError(500, "GetFollowing", err)
@ -51,12 +51,12 @@ func listUserFollowing(ctx *middleware.Context, u *models.User) {
responseApiUsers(ctx, users) responseApiUsers(ctx, users)
} }
func ListMyFollowing(ctx *middleware.Context) { func ListMyFollowing(ctx *context.Context) {
listUserFollowing(ctx, ctx.User) listUserFollowing(ctx, ctx.User)
} }
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#list-users-followed-by-another-user // https://github.com/gogits/go-gogs-client/wiki/Users-Followers#list-users-followed-by-another-user
func ListFollowing(ctx *middleware.Context) { func ListFollowing(ctx *context.Context) {
u := GetUserByParams(ctx) u := GetUserByParams(ctx)
if ctx.Written() { if ctx.Written() {
return return
@ -64,7 +64,7 @@ func ListFollowing(ctx *middleware.Context) {
listUserFollowing(ctx, u) listUserFollowing(ctx, u)
} }
func checkUserFollowing(ctx *middleware.Context, u *models.User, followID int64) { func checkUserFollowing(ctx *context.Context, u *models.User, followID int64) {
if u.IsFollowing(followID) { if u.IsFollowing(followID) {
ctx.Status(204) ctx.Status(204)
} else { } else {
@ -73,7 +73,7 @@ func checkUserFollowing(ctx *middleware.Context, u *models.User, followID int64)
} }
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#check-if-you-are-following-a-user // https://github.com/gogits/go-gogs-client/wiki/Users-Followers#check-if-you-are-following-a-user
func CheckMyFollowing(ctx *middleware.Context) { func CheckMyFollowing(ctx *context.Context) {
target := GetUserByParams(ctx) target := GetUserByParams(ctx)
if ctx.Written() { if ctx.Written() {
return return
@ -82,7 +82,7 @@ func CheckMyFollowing(ctx *middleware.Context) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#check-if-one-user-follows-another // https://github.com/gogits/go-gogs-client/wiki/Users-Followers#check-if-one-user-follows-another
func CheckFollowing(ctx *middleware.Context) { func CheckFollowing(ctx *context.Context) {
u := GetUserByParams(ctx) u := GetUserByParams(ctx)
if ctx.Written() { if ctx.Written() {
return return
@ -95,7 +95,7 @@ func CheckFollowing(ctx *middleware.Context) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#follow-a-user // https://github.com/gogits/go-gogs-client/wiki/Users-Followers#follow-a-user
func Follow(ctx *middleware.Context) { func Follow(ctx *context.Context) {
target := GetUserByParams(ctx) target := GetUserByParams(ctx)
if ctx.Written() { if ctx.Written() {
return return
@ -108,7 +108,7 @@ func Follow(ctx *middleware.Context) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#unfollow-a-user // https://github.com/gogits/go-gogs-client/wiki/Users-Followers#unfollow-a-user
func Unfollow(ctx *middleware.Context) { func Unfollow(ctx *context.Context) {
target := GetUserByParams(ctx) target := GetUserByParams(ctx)
if ctx.Written() { if ctx.Written() {
return return

View file

@ -8,13 +8,13 @@ import (
api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/routers/api/v1/convert" "github.com/gogits/gogs/routers/api/v1/convert"
"github.com/gogits/gogs/routers/api/v1/repo" "github.com/gogits/gogs/routers/api/v1/repo"
) )
func GetUserByParamsName(ctx *middleware.Context, name string) *models.User { func GetUserByParamsName(ctx *context.Context, name string) *models.User {
user, err := models.GetUserByName(ctx.Params(name)) user, err := models.GetUserByName(ctx.Params(name))
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
@ -28,7 +28,7 @@ func GetUserByParamsName(ctx *middleware.Context, name string) *models.User {
} }
// GetUserByParams returns user whose name is presented in URL paramenter. // GetUserByParams returns user whose name is presented in URL paramenter.
func GetUserByParams(ctx *middleware.Context) *models.User { func GetUserByParams(ctx *context.Context) *models.User {
return GetUserByParamsName(ctx, ":username") return GetUserByParamsName(ctx, ":username")
} }
@ -36,7 +36,7 @@ func composePublicKeysAPILink() string {
return setting.AppUrl + "api/v1/user/keys/" return setting.AppUrl + "api/v1/user/keys/"
} }
func listPublicKeys(ctx *middleware.Context, uid int64) { func listPublicKeys(ctx *context.Context, uid int64) {
keys, err := models.ListPublicKeys(uid) keys, err := models.ListPublicKeys(uid)
if err != nil { if err != nil {
ctx.APIError(500, "ListPublicKeys", err) ctx.APIError(500, "ListPublicKeys", err)
@ -53,12 +53,12 @@ func listPublicKeys(ctx *middleware.Context, uid int64) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#list-your-public-keys // https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#list-your-public-keys
func ListMyPublicKeys(ctx *middleware.Context) { func ListMyPublicKeys(ctx *context.Context) {
listPublicKeys(ctx, ctx.User.Id) listPublicKeys(ctx, ctx.User.Id)
} }
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#list-public-keys-for-a-user // https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#list-public-keys-for-a-user
func ListPublicKeys(ctx *middleware.Context) { func ListPublicKeys(ctx *context.Context) {
user := GetUserByParams(ctx) user := GetUserByParams(ctx)
if ctx.Written() { if ctx.Written() {
return return
@ -67,7 +67,7 @@ func ListPublicKeys(ctx *middleware.Context) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#get-a-single-public-key // https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#get-a-single-public-key
func GetPublicKey(ctx *middleware.Context) { func GetPublicKey(ctx *context.Context) {
key, err := models.GetPublicKeyByID(ctx.ParamsInt64(":id")) key, err := models.GetPublicKeyByID(ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
if models.IsErrKeyNotExist(err) { if models.IsErrKeyNotExist(err) {
@ -83,7 +83,7 @@ func GetPublicKey(ctx *middleware.Context) {
} }
// CreateUserPublicKey creates new public key to given user by ID. // CreateUserPublicKey creates new public key to given user by ID.
func CreateUserPublicKey(ctx *middleware.Context, form api.CreateKeyOption, uid int64) { func CreateUserPublicKey(ctx *context.Context, form api.CreateKeyOption, uid int64) {
content, err := models.CheckPublicKeyString(form.Key) content, err := models.CheckPublicKeyString(form.Key)
if err != nil { if err != nil {
repo.HandleCheckKeyStringError(ctx, err) repo.HandleCheckKeyStringError(ctx, err)
@ -100,12 +100,12 @@ func CreateUserPublicKey(ctx *middleware.Context, form api.CreateKeyOption, uid
} }
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#create-a-public-key // https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#create-a-public-key
func CreatePublicKey(ctx *middleware.Context, form api.CreateKeyOption) { func CreatePublicKey(ctx *context.Context, form api.CreateKeyOption) {
CreateUserPublicKey(ctx, form, ctx.User.Id) CreateUserPublicKey(ctx, form, ctx.User.Id)
} }
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#delete-a-public-key // https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#delete-a-public-key
func DeletePublicKey(ctx *middleware.Context) { func DeletePublicKey(ctx *context.Context) {
if err := models.DeletePublicKey(ctx.User, ctx.ParamsInt64(":id")); err != nil { if err := models.DeletePublicKey(ctx.User, ctx.ParamsInt64(":id")); err != nil {
if models.IsErrKeyAccessDenied(err) { if models.IsErrKeyAccessDenied(err) {
ctx.APIError(403, "", "You do not have access to this key") ctx.APIError(403, "", "You do not have access to this key")

View file

@ -10,11 +10,11 @@ import (
api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
) )
// https://github.com/gogits/go-gogs-client/wiki/Users#search-users // https://github.com/gogits/go-gogs-client/wiki/Users#search-users
func Search(ctx *middleware.Context) { func Search(ctx *context.Context) {
opt := models.SearchOption{ opt := models.SearchOption{
Keyword: ctx.Query("q"), Keyword: ctx.Query("q"),
Limit: com.StrTo(ctx.Query("limit")).MustInt(), Limit: com.StrTo(ctx.Query("limit")).MustInt(),
@ -52,7 +52,7 @@ func Search(ctx *middleware.Context) {
} }
// https://github.com/gogits/go-gogs-client/wiki/Users#get-a-single-user // https://github.com/gogits/go-gogs-client/wiki/Users#get-a-single-user
func GetInfo(ctx *middleware.Context) { func GetInfo(ctx *context.Context) {
u, err := models.GetUserByName(ctx.Params(":username")) u, err := models.GetUserByName(ctx.Params(":username"))
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {

View file

@ -7,11 +7,11 @@ package dev
import ( import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
func TemplatePreview(ctx *middleware.Context) { func TemplatePreview(ctx *context.Context) {
ctx.Data["User"] = models.User{Name: "Unknown"} ctx.Data["User"] = models.User{Name: "Unknown"}
ctx.Data["AppName"] = setting.AppName ctx.Data["AppName"] = setting.AppName
ctx.Data["AppVer"] = setting.AppVer ctx.Data["AppVer"] = setting.AppVer

View file

@ -11,7 +11,7 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/routers/user" "github.com/gogits/gogs/routers/user"
) )
@ -21,7 +21,7 @@ const (
EXPLORE_REPOS base.TplName = "explore/repos" EXPLORE_REPOS base.TplName = "explore/repos"
) )
func Home(ctx *middleware.Context) { func Home(ctx *context.Context) {
if ctx.IsSigned { if ctx.IsSigned {
if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm { if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
ctx.Data["Title"] = ctx.Tr("auth.active_your_account") ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
@ -43,7 +43,7 @@ func Home(ctx *middleware.Context) {
ctx.HTML(200, HOME) ctx.HTML(200, HOME)
} }
func Explore(ctx *middleware.Context) { func Explore(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("explore") ctx.Data["Title"] = ctx.Tr("explore")
ctx.Data["PageIsExplore"] = true ctx.Data["PageIsExplore"] = true
ctx.Data["PageIsExploreRepositories"] = true ctx.Data["PageIsExploreRepositories"] = true
@ -71,7 +71,7 @@ func Explore(ctx *middleware.Context) {
ctx.HTML(200, EXPLORE_REPOS) ctx.HTML(200, EXPLORE_REPOS)
} }
func NotFound(ctx *middleware.Context) { func NotFound(ctx *context.Context) {
ctx.Data["Title"] = "Page Not Found" ctx.Data["Title"] = "Page Not Found"
ctx.Handle(404, "home.NotFound", nil) ctx.Handle(404, "home.NotFound", nil)
} }

View file

@ -22,11 +22,11 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/cron" "github.com/gogits/gogs/modules/cron"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/mailer"
"github.com/gogits/gogs/modules/markdown" "github.com/gogits/gogs/modules/markdown"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/modules/ssh" "github.com/gogits/gogs/modules/ssh"
"github.com/gogits/gogs/modules/template/highlight" "github.com/gogits/gogs/modules/template/highlight"
@ -97,7 +97,7 @@ func GlobalInit() {
markdown.BuildSanitizer() markdown.BuildSanitizer()
} }
func InstallInit(ctx *middleware.Context) { func InstallInit(ctx *context.Context) {
if setting.InstallLock { if setting.InstallLock {
ctx.Handle(404, "Install", errors.New("Installation is prohibited")) ctx.Handle(404, "Install", errors.New("Installation is prohibited"))
return return
@ -116,7 +116,7 @@ func InstallInit(ctx *middleware.Context) {
ctx.Data["DbOptions"] = dbOpts ctx.Data["DbOptions"] = dbOpts
} }
func Install(ctx *middleware.Context) { func Install(ctx *context.Context) {
form := auth.InstallForm{} form := auth.InstallForm{}
// Database settings // Database settings
@ -177,7 +177,7 @@ func Install(ctx *middleware.Context) {
ctx.HTML(200, INSTALL) ctx.HTML(200, INSTALL)
} }
func InstallPost(ctx *middleware.Context, form auth.InstallForm) { func InstallPost(ctx *context.Context, form auth.InstallForm) {
ctx.Data["CurDbOption"] = form.DbType ctx.Data["CurDbOption"] = form.DbType
if ctx.HasError() { if ctx.HasError() {

View file

@ -9,8 +9,8 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -19,7 +19,7 @@ const (
MEMBER_INVITE base.TplName = "org/member/invite" MEMBER_INVITE base.TplName = "org/member/invite"
) )
func Members(ctx *middleware.Context) { func Members(ctx *context.Context) {
org := ctx.Org.Organization org := ctx.Org.Organization
ctx.Data["Title"] = org.FullName ctx.Data["Title"] = org.FullName
ctx.Data["PageIsOrgMembers"] = true ctx.Data["PageIsOrgMembers"] = true
@ -33,7 +33,7 @@ func Members(ctx *middleware.Context) {
ctx.HTML(200, MEMBERS) ctx.HTML(200, MEMBERS)
} }
func MembersAction(ctx *middleware.Context) { func MembersAction(ctx *context.Context) {
uid := com.StrTo(ctx.Query("uid")).MustInt64() uid := com.StrTo(ctx.Query("uid")).MustInt64()
if uid == 0 { if uid == 0 {
ctx.Redirect(ctx.Org.OrgLink + "/members") ctx.Redirect(ctx.Org.OrgLink + "/members")
@ -91,7 +91,7 @@ func MembersAction(ctx *middleware.Context) {
} }
} }
func Invitation(ctx *middleware.Context) { func Invitation(ctx *context.Context) {
org := ctx.Org.Organization org := ctx.Org.Organization
ctx.Data["Title"] = org.FullName ctx.Data["Title"] = org.FullName
ctx.Data["PageIsOrgMembers"] = true ctx.Data["PageIsOrgMembers"] = true

View file

@ -8,8 +8,8 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -17,12 +17,12 @@ const (
CREATE base.TplName = "org/create" CREATE base.TplName = "org/create"
) )
func Create(ctx *middleware.Context) { func Create(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("new_org") ctx.Data["Title"] = ctx.Tr("new_org")
ctx.HTML(200, CREATE) ctx.HTML(200, CREATE)
} }
func CreatePost(ctx *middleware.Context, form auth.CreateOrgForm) { func CreatePost(ctx *context.Context, form auth.CreateOrgForm) {
ctx.Data["Title"] = ctx.Tr("new_org") ctx.Data["Title"] = ctx.Tr("new_org")
if ctx.HasError() { if ctx.HasError() {

View file

@ -12,8 +12,8 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/routers/user" "github.com/gogits/gogs/routers/user"
) )
@ -24,13 +24,13 @@ const (
SETTINGS_HOOKS base.TplName = "org/settings/hooks" SETTINGS_HOOKS base.TplName = "org/settings/hooks"
) )
func Settings(ctx *middleware.Context) { func Settings(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("org.settings") ctx.Data["Title"] = ctx.Tr("org.settings")
ctx.Data["PageIsSettingsOptions"] = true ctx.Data["PageIsSettingsOptions"] = true
ctx.HTML(200, SETTINGS_OPTIONS) ctx.HTML(200, SETTINGS_OPTIONS)
} }
func SettingsPost(ctx *middleware.Context, form auth.UpdateOrgSettingForm) { func SettingsPost(ctx *context.Context, form auth.UpdateOrgSettingForm) {
ctx.Data["Title"] = ctx.Tr("org.settings") ctx.Data["Title"] = ctx.Tr("org.settings")
ctx.Data["PageIsSettingsOptions"] = true ctx.Data["PageIsSettingsOptions"] = true
@ -85,7 +85,7 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateOrgSettingForm) {
ctx.Redirect(ctx.Org.OrgLink + "/settings") ctx.Redirect(ctx.Org.OrgLink + "/settings")
} }
func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) { func SettingsAvatar(ctx *context.Context, form auth.UploadAvatarForm) {
form.Enable = true form.Enable = true
if err := user.UpdateAvatarSetting(ctx, form, ctx.Org.Organization); err != nil { if err := user.UpdateAvatarSetting(ctx, form, ctx.Org.Organization); err != nil {
ctx.Flash.Error(err.Error()) ctx.Flash.Error(err.Error())
@ -96,7 +96,7 @@ func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) {
ctx.Redirect(ctx.Org.OrgLink + "/settings") ctx.Redirect(ctx.Org.OrgLink + "/settings")
} }
func SettingsDeleteAvatar(ctx *middleware.Context) { func SettingsDeleteAvatar(ctx *context.Context) {
if err := ctx.Org.Organization.DeleteAvatar(); err != nil { if err := ctx.Org.Organization.DeleteAvatar(); err != nil {
ctx.Flash.Error(err.Error()) ctx.Flash.Error(err.Error())
} }
@ -104,7 +104,7 @@ func SettingsDeleteAvatar(ctx *middleware.Context) {
ctx.Redirect(ctx.Org.OrgLink + "/settings") ctx.Redirect(ctx.Org.OrgLink + "/settings")
} }
func SettingsDelete(ctx *middleware.Context) { func SettingsDelete(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("org.settings") ctx.Data["Title"] = ctx.Tr("org.settings")
ctx.Data["PageIsSettingsDelete"] = true ctx.Data["PageIsSettingsDelete"] = true
@ -136,7 +136,7 @@ func SettingsDelete(ctx *middleware.Context) {
ctx.HTML(200, SETTINGS_DELETE) ctx.HTML(200, SETTINGS_DELETE)
} }
func Webhooks(ctx *middleware.Context) { func Webhooks(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("org.settings") ctx.Data["Title"] = ctx.Tr("org.settings")
ctx.Data["PageIsSettingsHooks"] = true ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["BaseLink"] = ctx.Org.OrgLink ctx.Data["BaseLink"] = ctx.Org.OrgLink
@ -164,7 +164,7 @@ func Webhooks(ctx *middleware.Context) {
ctx.HTML(200, SETTINGS_HOOKS) ctx.HTML(200, SETTINGS_HOOKS)
} }
func DeleteWebhook(ctx *middleware.Context) { func DeleteWebhook(ctx *context.Context) {
if err := models.DeleteWebhook(ctx.QueryInt64("id")); err != nil { if err := models.DeleteWebhook(ctx.QueryInt64("id")); err != nil {
ctx.Flash.Error("DeleteWebhook: " + err.Error()) ctx.Flash.Error("DeleteWebhook: " + err.Error())
} else { } else {

View file

@ -12,8 +12,8 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
) )
const ( const (
@ -23,7 +23,7 @@ const (
TEAM_REPOSITORIES base.TplName = "org/team/repositories" TEAM_REPOSITORIES base.TplName = "org/team/repositories"
) )
func Teams(ctx *middleware.Context) { func Teams(ctx *context.Context) {
org := ctx.Org.Organization org := ctx.Org.Organization
ctx.Data["Title"] = org.FullName ctx.Data["Title"] = org.FullName
ctx.Data["PageIsOrgTeams"] = true ctx.Data["PageIsOrgTeams"] = true
@ -39,7 +39,7 @@ func Teams(ctx *middleware.Context) {
ctx.HTML(200, TEAMS) ctx.HTML(200, TEAMS)
} }
func TeamsAction(ctx *middleware.Context) { func TeamsAction(ctx *context.Context) {
uid := com.StrTo(ctx.Query("uid")).MustInt64() uid := com.StrTo(ctx.Query("uid")).MustInt64()
if uid == 0 { if uid == 0 {
ctx.Redirect(ctx.Org.OrgLink + "/teams") ctx.Redirect(ctx.Org.OrgLink + "/teams")
@ -107,7 +107,7 @@ func TeamsAction(ctx *middleware.Context) {
} }
} }
func TeamsRepoAction(ctx *middleware.Context) { func TeamsRepoAction(ctx *context.Context) {
if !ctx.Org.IsOwner { if !ctx.Org.IsOwner {
ctx.Error(404) ctx.Error(404)
return return
@ -141,7 +141,7 @@ func TeamsRepoAction(ctx *middleware.Context) {
ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories") ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories")
} }
func NewTeam(ctx *middleware.Context) { func NewTeam(ctx *context.Context) {
ctx.Data["Title"] = ctx.Org.Organization.FullName ctx.Data["Title"] = ctx.Org.Organization.FullName
ctx.Data["PageIsOrgTeams"] = true ctx.Data["PageIsOrgTeams"] = true
ctx.Data["PageIsOrgTeamsNew"] = true ctx.Data["PageIsOrgTeamsNew"] = true
@ -149,7 +149,7 @@ func NewTeam(ctx *middleware.Context) {
ctx.HTML(200, TEAM_NEW) ctx.HTML(200, TEAM_NEW)
} }
func NewTeamPost(ctx *middleware.Context, form auth.CreateTeamForm) { func NewTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
ctx.Data["Title"] = ctx.Org.Organization.FullName ctx.Data["Title"] = ctx.Org.Organization.FullName
ctx.Data["PageIsOrgTeams"] = true ctx.Data["PageIsOrgTeams"] = true
ctx.Data["PageIsOrgTeamsNew"] = true ctx.Data["PageIsOrgTeamsNew"] = true
@ -195,7 +195,7 @@ func NewTeamPost(ctx *middleware.Context, form auth.CreateTeamForm) {
ctx.Redirect(ctx.Org.OrgLink + "/teams/" + t.LowerName) ctx.Redirect(ctx.Org.OrgLink + "/teams/" + t.LowerName)
} }
func TeamMembers(ctx *middleware.Context) { func TeamMembers(ctx *context.Context) {
ctx.Data["Title"] = ctx.Org.Team.Name ctx.Data["Title"] = ctx.Org.Team.Name
ctx.Data["PageIsOrgTeams"] = true ctx.Data["PageIsOrgTeams"] = true
if err := ctx.Org.Team.GetMembers(); err != nil { if err := ctx.Org.Team.GetMembers(); err != nil {
@ -205,7 +205,7 @@ func TeamMembers(ctx *middleware.Context) {
ctx.HTML(200, TEAM_MEMBERS) ctx.HTML(200, TEAM_MEMBERS)
} }
func TeamRepositories(ctx *middleware.Context) { func TeamRepositories(ctx *context.Context) {
ctx.Data["Title"] = ctx.Org.Team.Name ctx.Data["Title"] = ctx.Org.Team.Name
ctx.Data["PageIsOrgTeams"] = true ctx.Data["PageIsOrgTeams"] = true
if err := ctx.Org.Team.GetRepositories(); err != nil { if err := ctx.Org.Team.GetRepositories(); err != nil {
@ -215,7 +215,7 @@ func TeamRepositories(ctx *middleware.Context) {
ctx.HTML(200, TEAM_REPOSITORIES) ctx.HTML(200, TEAM_REPOSITORIES)
} }
func EditTeam(ctx *middleware.Context) { func EditTeam(ctx *context.Context) {
ctx.Data["Title"] = ctx.Org.Organization.FullName ctx.Data["Title"] = ctx.Org.Organization.FullName
ctx.Data["PageIsOrgTeams"] = true ctx.Data["PageIsOrgTeams"] = true
ctx.Data["team_name"] = ctx.Org.Team.Name ctx.Data["team_name"] = ctx.Org.Team.Name
@ -223,7 +223,7 @@ func EditTeam(ctx *middleware.Context) {
ctx.HTML(200, TEAM_NEW) ctx.HTML(200, TEAM_NEW)
} }
func EditTeamPost(ctx *middleware.Context, form auth.CreateTeamForm) { func EditTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
t := ctx.Org.Team t := ctx.Org.Team
ctx.Data["Title"] = ctx.Org.Organization.FullName ctx.Data["Title"] = ctx.Org.Organization.FullName
ctx.Data["PageIsOrgTeams"] = true ctx.Data["PageIsOrgTeams"] = true
@ -270,7 +270,7 @@ func EditTeamPost(ctx *middleware.Context, form auth.CreateTeamForm) {
ctx.Redirect(ctx.Org.OrgLink + "/teams/" + t.LowerName) ctx.Redirect(ctx.Org.OrgLink + "/teams/" + t.LowerName)
} }
func DeleteTeam(ctx *middleware.Context) { func DeleteTeam(ctx *context.Context) {
if err := models.DeleteTeam(ctx.Org.Team); err != nil { if err := models.DeleteTeam(ctx.Org.Team); err != nil {
ctx.Flash.Error("DeleteTeam: " + err.Error()) ctx.Flash.Error("DeleteTeam: " + err.Error())
} else { } else {

View file

@ -6,14 +6,14 @@ package repo
import ( import (
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
) )
const ( const (
BRANCH base.TplName = "repo/branch" BRANCH base.TplName = "repo/branch"
) )
func Branches(ctx *middleware.Context) { func Branches(ctx *context.Context) {
ctx.Data["Title"] = "Branches" ctx.Data["Title"] = "Branches"
ctx.Data["IsRepoToolbarBranches"] = true ctx.Data["IsRepoToolbarBranches"] = true

View file

@ -14,7 +14,7 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -23,7 +23,7 @@ const (
DIFF base.TplName = "repo/diff" DIFF base.TplName = "repo/diff"
) )
func RefCommits(ctx *middleware.Context) { func RefCommits(ctx *context.Context) {
switch { switch {
case len(ctx.Repo.TreeName) == 0: case len(ctx.Repo.TreeName) == 0:
Commits(ctx) Commits(ctx)
@ -43,7 +43,7 @@ func RenderIssueLinks(oldCommits *list.List, repoLink string) *list.List {
return newCommits return newCommits
} }
func Commits(ctx *middleware.Context) { func Commits(ctx *context.Context) {
ctx.Data["PageIsCommits"] = true ctx.Data["PageIsCommits"] = true
commitsCount, err := ctx.Repo.Commit.CommitsCount() commitsCount, err := ctx.Repo.Commit.CommitsCount()
@ -75,7 +75,7 @@ func Commits(ctx *middleware.Context) {
ctx.HTML(200, COMMITS) ctx.HTML(200, COMMITS)
} }
func SearchCommits(ctx *middleware.Context) { func SearchCommits(ctx *context.Context) {
ctx.Data["PageIsCommits"] = true ctx.Data["PageIsCommits"] = true
keyword := ctx.Query("q") keyword := ctx.Query("q")
@ -101,7 +101,7 @@ func SearchCommits(ctx *middleware.Context) {
ctx.HTML(200, COMMITS) ctx.HTML(200, COMMITS)
} }
func FileHistory(ctx *middleware.Context) { func FileHistory(ctx *context.Context) {
ctx.Data["IsRepoToolbarCommits"] = true ctx.Data["IsRepoToolbarCommits"] = true
fileName := ctx.Repo.TreeName fileName := ctx.Repo.TreeName
@ -143,7 +143,7 @@ func FileHistory(ctx *middleware.Context) {
ctx.HTML(200, COMMITS) ctx.HTML(200, COMMITS)
} }
func Diff(ctx *middleware.Context) { func Diff(ctx *context.Context) {
ctx.Data["PageIsDiff"] = true ctx.Data["PageIsDiff"] = true
userName := ctx.Repo.Owner.Name userName := ctx.Repo.Owner.Name
@ -187,7 +187,7 @@ func Diff(ctx *middleware.Context) {
ctx.HTML(200, DIFF) ctx.HTML(200, DIFF)
} }
func CompareDiff(ctx *middleware.Context) { func CompareDiff(ctx *context.Context) {
ctx.Data["IsRepoToolbarCommits"] = true ctx.Data["IsRepoToolbarCommits"] = true
ctx.Data["IsDiffCompare"] = true ctx.Data["IsDiffCompare"] = true
userName := ctx.Repo.Owner.Name userName := ctx.Repo.Owner.Name

View file

@ -11,10 +11,10 @@ import (
"github.com/gogits/git-module" "github.com/gogits/git-module"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
) )
func ServeData(ctx *middleware.Context, name string, reader io.Reader) error { func ServeData(ctx *context.Context, name string, reader io.Reader) error {
buf := make([]byte, 1024) buf := make([]byte, 1024)
n, _ := reader.Read(buf) n, _ := reader.Read(buf)
if n > 0 { if n > 0 {
@ -36,7 +36,7 @@ func ServeData(ctx *middleware.Context, name string, reader io.Reader) error {
return err return err
} }
func ServeBlob(ctx *middleware.Context, blob *git.Blob) error { func ServeBlob(ctx *context.Context, blob *git.Blob) error {
dataRc, err := blob.Data() dataRc, err := blob.Data()
if err != nil { if err != nil {
return err return err
@ -45,7 +45,7 @@ func ServeBlob(ctx *middleware.Context, blob *git.Blob) error {
return ServeData(ctx, ctx.Repo.TreeName, dataRc) return ServeData(ctx, ctx.Repo.TreeName, dataRc)
} }
func SingleDownload(ctx *middleware.Context) { func SingleDownload(ctx *context.Context) {
blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreeName) blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreeName)
if err != nil { if err != nil {
if git.IsErrNotExist(err) { if git.IsErrNotExist(err) {

View file

@ -23,18 +23,18 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
func authRequired(ctx *middleware.Context) { func authRequired(ctx *context.Context) {
ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=\".\"") ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=\".\"")
ctx.Data["ErrorMsg"] = "no basic auth and digit auth" ctx.Data["ErrorMsg"] = "no basic auth and digit auth"
ctx.Error(401) ctx.Error(401)
} }
func HTTP(ctx *middleware.Context) { func HTTP(ctx *context.Context) {
username := ctx.Params(":username") username := ctx.Params(":username")
reponame := strings.TrimSuffix(ctx.Params(":reponame"), ".git") reponame := strings.TrimSuffix(ctx.Params(":reponame"), ".git")
@ -293,7 +293,7 @@ func getGitDir(config *Config, fPath string) (string, error) {
} }
// Request handling function // Request handling function
func HTTPBackend(ctx *middleware.Context, config *Config) http.HandlerFunc { func HTTPBackend(ctx *context.Context, config *Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
for _, route := range routes { for _, route := range routes {
r.URL.Path = strings.ToLower(r.URL.Path) // blue: In case some repo name has upper case name r.URL.Path = strings.ToLower(r.URL.Path) // blue: In case some repo name has upper case name

View file

@ -20,10 +20,10 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/mailer"
"github.com/gogits/gogs/modules/markdown" "github.com/gogits/gogs/modules/markdown"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -52,14 +52,14 @@ var (
} }
) )
func MustEnableIssues(ctx *middleware.Context) { func MustEnableIssues(ctx *context.Context) {
if !ctx.Repo.Repository.EnableIssues { if !ctx.Repo.Repository.EnableIssues {
ctx.Handle(404, "MustEnableIssues", nil) ctx.Handle(404, "MustEnableIssues", nil)
return return
} }
} }
func MustAllowPulls(ctx *middleware.Context) { func MustAllowPulls(ctx *context.Context) {
if !ctx.Repo.Repository.AllowsPulls() { if !ctx.Repo.Repository.AllowsPulls() {
ctx.Handle(404, "MustAllowPulls", nil) ctx.Handle(404, "MustAllowPulls", nil)
return return
@ -72,7 +72,7 @@ func MustAllowPulls(ctx *middleware.Context) {
} }
} }
func RetrieveLabels(ctx *middleware.Context) { func RetrieveLabels(ctx *context.Context) {
labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID) labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID)
if err != nil { if err != nil {
ctx.Handle(500, "RetrieveLabels.GetLabels: %v", err) ctx.Handle(500, "RetrieveLabels.GetLabels: %v", err)
@ -85,7 +85,7 @@ func RetrieveLabels(ctx *middleware.Context) {
ctx.Data["NumLabels"] = len(labels) ctx.Data["NumLabels"] = len(labels)
} }
func Issues(ctx *middleware.Context) { func Issues(ctx *context.Context) {
isPullList := ctx.Params(":type") == "pulls" isPullList := ctx.Params(":type") == "pulls"
if isPullList { if isPullList {
MustAllowPulls(ctx) MustAllowPulls(ctx)
@ -250,7 +250,7 @@ func Issues(ctx *middleware.Context) {
ctx.HTML(200, ISSUES) ctx.HTML(200, ISSUES)
} }
func renderAttachmentSettings(ctx *middleware.Context) { func renderAttachmentSettings(ctx *context.Context) {
ctx.Data["RequireDropzone"] = true ctx.Data["RequireDropzone"] = true
ctx.Data["IsAttachmentEnabled"] = setting.AttachmentEnabled ctx.Data["IsAttachmentEnabled"] = setting.AttachmentEnabled
ctx.Data["AttachmentAllowedTypes"] = setting.AttachmentAllowedTypes ctx.Data["AttachmentAllowedTypes"] = setting.AttachmentAllowedTypes
@ -258,7 +258,7 @@ func renderAttachmentSettings(ctx *middleware.Context) {
ctx.Data["AttachmentMaxFiles"] = setting.AttachmentMaxFiles ctx.Data["AttachmentMaxFiles"] = setting.AttachmentMaxFiles
} }
func RetrieveRepoMilestonesAndAssignees(ctx *middleware.Context, repo *models.Repository) { func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repository) {
var err error var err error
ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false) ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false)
if err != nil { if err != nil {
@ -278,7 +278,7 @@ func RetrieveRepoMilestonesAndAssignees(ctx *middleware.Context, repo *models.Re
} }
} }
func RetrieveRepoMetas(ctx *middleware.Context, repo *models.Repository) []*models.Label { func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository) []*models.Label {
if !ctx.Repo.IsWriter() { if !ctx.Repo.IsWriter() {
return nil return nil
} }
@ -298,7 +298,7 @@ func RetrieveRepoMetas(ctx *middleware.Context, repo *models.Repository) []*mode
return labels return labels
} }
func getFileContentFromDefaultBranch(ctx *middleware.Context, filename string) (string, bool) { func getFileContentFromDefaultBranch(ctx *context.Context, filename string) (string, bool) {
var r io.Reader var r io.Reader
var bytes []byte var bytes []byte
@ -325,7 +325,7 @@ func getFileContentFromDefaultBranch(ctx *middleware.Context, filename string) (
return string(bytes), true return string(bytes), true
} }
func setTemplateIfExists(ctx *middleware.Context, ctxDataKey string, possibleFiles []string) { func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleFiles []string) {
for _, filename := range possibleFiles { for _, filename := range possibleFiles {
content, found := getFileContentFromDefaultBranch(ctx, filename) content, found := getFileContentFromDefaultBranch(ctx, filename)
if found { if found {
@ -335,7 +335,7 @@ func setTemplateIfExists(ctx *middleware.Context, ctxDataKey string, possibleFil
} }
} }
func NewIssue(ctx *middleware.Context) { func NewIssue(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.issues.new") ctx.Data["Title"] = ctx.Tr("repo.issues.new")
ctx.Data["PageIsIssueList"] = true ctx.Data["PageIsIssueList"] = true
setTemplateIfExists(ctx, ISSUE_TEMPLATE_KEY, IssueTemplateCandidates) setTemplateIfExists(ctx, ISSUE_TEMPLATE_KEY, IssueTemplateCandidates)
@ -351,7 +351,7 @@ func NewIssue(ctx *middleware.Context) {
ctx.HTML(200, ISSUE_NEW) ctx.HTML(200, ISSUE_NEW)
} }
func ValidateRepoMetas(ctx *middleware.Context, form auth.CreateIssueForm) ([]int64, int64, int64) { func ValidateRepoMetas(ctx *context.Context, form auth.CreateIssueForm) ([]int64, int64, int64) {
var ( var (
repo = ctx.Repo.Repository repo = ctx.Repo.Repository
err error err error
@ -405,7 +405,7 @@ func ValidateRepoMetas(ctx *middleware.Context, form auth.CreateIssueForm) ([]in
return labelIDs, milestoneID, assigneeID return labelIDs, milestoneID, assigneeID
} }
func notifyWatchersAndMentions(ctx *middleware.Context, issue *models.Issue) { func notifyWatchersAndMentions(ctx *context.Context, issue *models.Issue) {
// Update mentions // Update mentions
mentions := markdown.MentionPattern.FindAllString(issue.Content, -1) mentions := markdown.MentionPattern.FindAllString(issue.Content, -1)
if len(mentions) > 0 { if len(mentions) > 0 {
@ -446,7 +446,7 @@ func notifyWatchersAndMentions(ctx *middleware.Context, issue *models.Issue) {
} }
} }
func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) { func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) {
ctx.Data["Title"] = ctx.Tr("repo.issues.new") ctx.Data["Title"] = ctx.Tr("repo.issues.new")
ctx.Data["PageIsIssueList"] = true ctx.Data["PageIsIssueList"] = true
renderAttachmentSettings(ctx) renderAttachmentSettings(ctx)
@ -494,7 +494,7 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index)) ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
} }
func UploadIssueAttachment(ctx *middleware.Context) { func UploadIssueAttachment(ctx *context.Context) {
if !setting.AttachmentEnabled { if !setting.AttachmentEnabled {
ctx.Error(404, "attachment is not enabled") ctx.Error(404, "attachment is not enabled")
return return
@ -541,7 +541,7 @@ func UploadIssueAttachment(ctx *middleware.Context) {
}) })
} }
func ViewIssue(ctx *middleware.Context) { func ViewIssue(ctx *context.Context) {
ctx.Data["RequireDropzone"] = true ctx.Data["RequireDropzone"] = true
renderAttachmentSettings(ctx) renderAttachmentSettings(ctx)
@ -706,7 +706,7 @@ func ViewIssue(ctx *middleware.Context) {
ctx.HTML(200, ISSUE_VIEW) ctx.HTML(200, ISSUE_VIEW)
} }
func getActionIssue(ctx *middleware.Context) *models.Issue { func getActionIssue(ctx *context.Context) *models.Issue {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrIssueNotExist(err) { if models.IsErrIssueNotExist(err) {
@ -719,7 +719,7 @@ func getActionIssue(ctx *middleware.Context) *models.Issue {
return issue return issue
} }
func UpdateIssueTitle(ctx *middleware.Context) { func UpdateIssueTitle(ctx *context.Context) {
issue := getActionIssue(ctx) issue := getActionIssue(ctx)
if ctx.Written() { if ctx.Written() {
return return
@ -746,7 +746,7 @@ func UpdateIssueTitle(ctx *middleware.Context) {
}) })
} }
func UpdateIssueContent(ctx *middleware.Context) { func UpdateIssueContent(ctx *context.Context) {
issue := getActionIssue(ctx) issue := getActionIssue(ctx)
if ctx.Written() { if ctx.Written() {
return return
@ -768,7 +768,7 @@ func UpdateIssueContent(ctx *middleware.Context) {
}) })
} }
func UpdateIssueLabel(ctx *middleware.Context) { func UpdateIssueLabel(ctx *context.Context) {
issue := getActionIssue(ctx) issue := getActionIssue(ctx)
if ctx.Written() { if ctx.Written() {
return return
@ -809,7 +809,7 @@ func UpdateIssueLabel(ctx *middleware.Context) {
}) })
} }
func UpdateIssueMilestone(ctx *middleware.Context) { func UpdateIssueMilestone(ctx *context.Context) {
issue := getActionIssue(ctx) issue := getActionIssue(ctx)
if ctx.Written() { if ctx.Written() {
return return
@ -836,7 +836,7 @@ func UpdateIssueMilestone(ctx *middleware.Context) {
}) })
} }
func UpdateIssueAssignee(ctx *middleware.Context) { func UpdateIssueAssignee(ctx *context.Context) {
issue := getActionIssue(ctx) issue := getActionIssue(ctx)
if ctx.Written() { if ctx.Written() {
return return
@ -862,7 +862,7 @@ func UpdateIssueAssignee(ctx *middleware.Context) {
}) })
} }
func NewComment(ctx *middleware.Context, form auth.CreateCommentForm) { func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrIssueNotExist(err) { if models.IsErrIssueNotExist(err) {
@ -968,7 +968,7 @@ func NewComment(ctx *middleware.Context, form auth.CreateCommentForm) {
log.Trace("Comment created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID) log.Trace("Comment created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID)
} }
func UpdateCommentContent(ctx *middleware.Context) { func UpdateCommentContent(ctx *context.Context) {
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id")) comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
if models.IsErrCommentNotExist(err) { if models.IsErrCommentNotExist(err) {
@ -1004,7 +1004,7 @@ func UpdateCommentContent(ctx *middleware.Context) {
}) })
} }
func Labels(ctx *middleware.Context) { func Labels(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.labels") ctx.Data["Title"] = ctx.Tr("repo.labels")
ctx.Data["PageIsIssueList"] = true ctx.Data["PageIsIssueList"] = true
ctx.Data["PageIsLabels"] = true ctx.Data["PageIsLabels"] = true
@ -1012,7 +1012,7 @@ func Labels(ctx *middleware.Context) {
ctx.HTML(200, LABELS) ctx.HTML(200, LABELS)
} }
func NewLabel(ctx *middleware.Context, form auth.CreateLabelForm) { func NewLabel(ctx *context.Context, form auth.CreateLabelForm) {
ctx.Data["Title"] = ctx.Tr("repo.labels") ctx.Data["Title"] = ctx.Tr("repo.labels")
ctx.Data["PageIsLabels"] = true ctx.Data["PageIsLabels"] = true
@ -1034,7 +1034,7 @@ func NewLabel(ctx *middleware.Context, form auth.CreateLabelForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/labels") ctx.Redirect(ctx.Repo.RepoLink + "/labels")
} }
func UpdateLabel(ctx *middleware.Context, form auth.CreateLabelForm) { func UpdateLabel(ctx *context.Context, form auth.CreateLabelForm) {
l, err := models.GetLabelByID(form.ID) l, err := models.GetLabelByID(form.ID)
if err != nil { if err != nil {
switch { switch {
@ -1056,7 +1056,7 @@ func UpdateLabel(ctx *middleware.Context, form auth.CreateLabelForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/labels") ctx.Redirect(ctx.Repo.RepoLink + "/labels")
} }
func DeleteLabel(ctx *middleware.Context) { func DeleteLabel(ctx *context.Context) {
if err := models.DeleteLabel(ctx.Repo.Repository.ID, ctx.QueryInt64("id")); err != nil { if err := models.DeleteLabel(ctx.Repo.Repository.ID, ctx.QueryInt64("id")); err != nil {
ctx.Flash.Error("DeleteLabel: " + err.Error()) ctx.Flash.Error("DeleteLabel: " + err.Error())
} else { } else {
@ -1069,7 +1069,7 @@ func DeleteLabel(ctx *middleware.Context) {
return return
} }
func Milestones(ctx *middleware.Context) { func Milestones(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.milestones") ctx.Data["Title"] = ctx.Tr("repo.milestones")
ctx.Data["PageIsIssueList"] = true ctx.Data["PageIsIssueList"] = true
ctx.Data["PageIsMilestones"] = true ctx.Data["PageIsMilestones"] = true
@ -1113,7 +1113,7 @@ func Milestones(ctx *middleware.Context) {
ctx.HTML(200, MILESTONE) ctx.HTML(200, MILESTONE)
} }
func NewMilestone(ctx *middleware.Context) { func NewMilestone(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.milestones.new") ctx.Data["Title"] = ctx.Tr("repo.milestones.new")
ctx.Data["PageIsIssueList"] = true ctx.Data["PageIsIssueList"] = true
ctx.Data["PageIsMilestones"] = true ctx.Data["PageIsMilestones"] = true
@ -1122,7 +1122,7 @@ func NewMilestone(ctx *middleware.Context) {
ctx.HTML(200, MILESTONE_NEW) ctx.HTML(200, MILESTONE_NEW)
} }
func NewMilestonePost(ctx *middleware.Context, form auth.CreateMilestoneForm) { func NewMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
ctx.Data["Title"] = ctx.Tr("repo.milestones.new") ctx.Data["Title"] = ctx.Tr("repo.milestones.new")
ctx.Data["PageIsIssueList"] = true ctx.Data["PageIsIssueList"] = true
ctx.Data["PageIsMilestones"] = true ctx.Data["PageIsMilestones"] = true
@ -1158,7 +1158,7 @@ func NewMilestonePost(ctx *middleware.Context, form auth.CreateMilestoneForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/milestones") ctx.Redirect(ctx.Repo.RepoLink + "/milestones")
} }
func EditMilestone(ctx *middleware.Context) { func EditMilestone(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.milestones.edit") ctx.Data["Title"] = ctx.Tr("repo.milestones.edit")
ctx.Data["PageIsMilestones"] = true ctx.Data["PageIsMilestones"] = true
ctx.Data["PageIsEditMilestone"] = true ctx.Data["PageIsEditMilestone"] = true
@ -1182,7 +1182,7 @@ func EditMilestone(ctx *middleware.Context) {
ctx.HTML(200, MILESTONE_NEW) ctx.HTML(200, MILESTONE_NEW)
} }
func EditMilestonePost(ctx *middleware.Context, form auth.CreateMilestoneForm) { func EditMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
ctx.Data["Title"] = ctx.Tr("repo.milestones.edit") ctx.Data["Title"] = ctx.Tr("repo.milestones.edit")
ctx.Data["PageIsMilestones"] = true ctx.Data["PageIsMilestones"] = true
ctx.Data["PageIsEditMilestone"] = true ctx.Data["PageIsEditMilestone"] = true
@ -1225,7 +1225,7 @@ func EditMilestonePost(ctx *middleware.Context, form auth.CreateMilestoneForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/milestones") ctx.Redirect(ctx.Repo.RepoLink + "/milestones")
} }
func ChangeMilestonStatus(ctx *middleware.Context) { func ChangeMilestonStatus(ctx *context.Context) {
m, err := models.GetMilestoneByID(ctx.ParamsInt64(":id")) m, err := models.GetMilestoneByID(ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
if models.IsErrMilestoneNotExist(err) { if models.IsErrMilestoneNotExist(err) {
@ -1259,7 +1259,7 @@ func ChangeMilestonStatus(ctx *middleware.Context) {
} }
} }
func DeleteMilestone(ctx *middleware.Context) { func DeleteMilestone(ctx *context.Context) {
if err := models.DeleteMilestoneByID(ctx.QueryInt64("id")); err != nil { if err := models.DeleteMilestoneByID(ctx.QueryInt64("id")); err != nil {
ctx.Flash.Error("DeleteMilestoneByID: " + err.Error()) ctx.Flash.Error("DeleteMilestoneByID: " + err.Error())
} else { } else {

View file

@ -16,8 +16,8 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -38,7 +38,7 @@ var (
} }
) )
func getForkRepository(ctx *middleware.Context) *models.Repository { func getForkRepository(ctx *context.Context) *models.Repository {
forkRepo, err := models.GetRepositoryByID(ctx.ParamsInt64(":repoid")) forkRepo, err := models.GetRepositoryByID(ctx.ParamsInt64(":repoid"))
if err != nil { if err != nil {
if models.IsErrRepoNotExist(err) { if models.IsErrRepoNotExist(err) {
@ -73,7 +73,7 @@ func getForkRepository(ctx *middleware.Context) *models.Repository {
return forkRepo return forkRepo
} }
func Fork(ctx *middleware.Context) { func Fork(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("new_fork") ctx.Data["Title"] = ctx.Tr("new_fork")
getForkRepository(ctx) getForkRepository(ctx)
@ -85,7 +85,7 @@ func Fork(ctx *middleware.Context) {
ctx.HTML(200, FORK) ctx.HTML(200, FORK)
} }
func ForkPost(ctx *middleware.Context, form auth.CreateRepoForm) { func ForkPost(ctx *context.Context, form auth.CreateRepoForm) {
ctx.Data["Title"] = ctx.Tr("new_fork") ctx.Data["Title"] = ctx.Tr("new_fork")
forkRepo := getForkRepository(ctx) forkRepo := getForkRepository(ctx)
@ -138,7 +138,7 @@ func ForkPost(ctx *middleware.Context, form auth.CreateRepoForm) {
ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + repo.Name) ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + repo.Name)
} }
func checkPullInfo(ctx *middleware.Context) *models.Issue { func checkPullInfo(ctx *context.Context) *models.Issue {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrIssueNotExist(err) { if models.IsErrIssueNotExist(err) {
@ -178,7 +178,7 @@ func checkPullInfo(ctx *middleware.Context) *models.Issue {
return issue return issue
} }
func PrepareMergedViewPullInfo(ctx *middleware.Context, pull *models.Issue) { func PrepareMergedViewPullInfo(ctx *context.Context, pull *models.Issue) {
ctx.Data["HasMerged"] = true ctx.Data["HasMerged"] = true
var err error var err error
@ -203,7 +203,7 @@ func PrepareMergedViewPullInfo(ctx *middleware.Context, pull *models.Issue) {
} }
} }
func PrepareViewPullInfo(ctx *middleware.Context, pull *models.Issue) *git.PullRequestInfo { func PrepareViewPullInfo(ctx *context.Context, pull *models.Issue) *git.PullRequestInfo {
repo := ctx.Repo.Repository repo := ctx.Repo.Repository
ctx.Data["HeadTarget"] = pull.HeadUserName + "/" + pull.HeadBranch ctx.Data["HeadTarget"] = pull.HeadUserName + "/" + pull.HeadBranch
@ -246,7 +246,7 @@ func PrepareViewPullInfo(ctx *middleware.Context, pull *models.Issue) *git.PullR
return prInfo return prInfo
} }
func ViewPullCommits(ctx *middleware.Context) { func ViewPullCommits(ctx *context.Context) {
ctx.Data["PageIsPullCommits"] = true ctx.Data["PageIsPullCommits"] = true
pull := checkPullInfo(ctx) pull := checkPullInfo(ctx)
@ -296,7 +296,7 @@ func ViewPullCommits(ctx *middleware.Context) {
ctx.HTML(200, PULL_COMMITS) ctx.HTML(200, PULL_COMMITS)
} }
func ViewPullFiles(ctx *middleware.Context) { func ViewPullFiles(ctx *context.Context) {
ctx.Data["PageIsPullFiles"] = true ctx.Data["PageIsPullFiles"] = true
pull := checkPullInfo(ctx) pull := checkPullInfo(ctx)
@ -377,7 +377,7 @@ func ViewPullFiles(ctx *middleware.Context) {
ctx.HTML(200, PULL_FILES) ctx.HTML(200, PULL_FILES)
} }
func MergePullRequest(ctx *middleware.Context) { func MergePullRequest(ctx *context.Context) {
issue := checkPullInfo(ctx) issue := checkPullInfo(ctx)
if ctx.Written() { if ctx.Written() {
return return
@ -413,7 +413,7 @@ func MergePullRequest(ctx *middleware.Context) {
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index)) ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
} }
func ParseCompareInfo(ctx *middleware.Context) (*models.User, *models.Repository, *git.Repository, *git.PullRequestInfo, string, string) { func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *git.Repository, *git.PullRequestInfo, string, string) {
baseRepo := ctx.Repo.Repository baseRepo := ctx.Repo.Repository
// Get compared branches information // Get compared branches information
@ -520,7 +520,7 @@ func ParseCompareInfo(ctx *middleware.Context) (*models.User, *models.Repository
} }
func PrepareCompareDiff( func PrepareCompareDiff(
ctx *middleware.Context, ctx *context.Context,
headUser *models.User, headUser *models.User,
headRepo *models.Repository, headRepo *models.Repository,
headGitRepo *git.Repository, headGitRepo *git.Repository,
@ -576,7 +576,7 @@ func PrepareCompareDiff(
return false return false
} }
func CompareAndPullRequest(ctx *middleware.Context) { func CompareAndPullRequest(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes") ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes")
ctx.Data["PageIsComparePull"] = true ctx.Data["PageIsComparePull"] = true
ctx.Data["IsDiffCompare"] = true ctx.Data["IsDiffCompare"] = true
@ -618,7 +618,7 @@ func CompareAndPullRequest(ctx *middleware.Context) {
ctx.HTML(200, COMPARE_PULL) ctx.HTML(200, COMPARE_PULL)
} }
func CompareAndPullRequestPost(ctx *middleware.Context, form auth.CreateIssueForm) { func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm) {
ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes") ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes")
ctx.Data["PageIsComparePull"] = true ctx.Data["PageIsComparePull"] = true
ctx.Data["IsDiffCompare"] = true ctx.Data["IsDiffCompare"] = true
@ -693,7 +693,7 @@ func CompareAndPullRequestPost(ctx *middleware.Context, form auth.CreateIssueFor
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pullIssue.Index)) ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pullIssue.Index))
} }
func TriggerTask(ctx *middleware.Context) { func TriggerTask(ctx *context.Context) {
branch := ctx.Query("branch") branch := ctx.Query("branch")
secret := ctx.Query("secret") secret := ctx.Query("secret")
if len(branch) == 0 || len(secret) == 0 { if len(branch) == 0 || len(secret) == 0 {

View file

@ -10,9 +10,9 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/markdown" "github.com/gogits/gogs/modules/markdown"
"github.com/gogits/gogs/modules/middleware"
) )
const ( const (
@ -21,7 +21,7 @@ const (
) )
// calReleaseNumCommitsBehind calculates given release has how many commits behind default branch. // calReleaseNumCommitsBehind calculates given release has how many commits behind default branch.
func calReleaseNumCommitsBehind(repoCtx *middleware.RepoContext, release *models.Release, countCache map[string]int64) error { func calReleaseNumCommitsBehind(repoCtx *context.Repository, release *models.Release, countCache map[string]int64) error {
// Fast return if release target is same as default branch. // Fast return if release target is same as default branch.
if repoCtx.BranchName == release.Target { if repoCtx.BranchName == release.Target {
release.NumCommitsBehind = repoCtx.CommitsCount - release.NumCommits release.NumCommitsBehind = repoCtx.CommitsCount - release.NumCommits
@ -43,7 +43,7 @@ func calReleaseNumCommitsBehind(repoCtx *middleware.RepoContext, release *models
return nil return nil
} }
func Releases(ctx *middleware.Context) { func Releases(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.release.releases") ctx.Data["Title"] = ctx.Tr("repo.release.releases")
ctx.Data["PageIsReleaseList"] = true ctx.Data["PageIsReleaseList"] = true
@ -141,14 +141,14 @@ func Releases(ctx *middleware.Context) {
ctx.HTML(200, RELEASES) ctx.HTML(200, RELEASES)
} }
func NewRelease(ctx *middleware.Context) { func NewRelease(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.release.new_release") ctx.Data["Title"] = ctx.Tr("repo.release.new_release")
ctx.Data["PageIsReleaseList"] = true ctx.Data["PageIsReleaseList"] = true
ctx.Data["tag_target"] = ctx.Repo.Repository.DefaultBranch ctx.Data["tag_target"] = ctx.Repo.Repository.DefaultBranch
ctx.HTML(200, RELEASE_NEW) ctx.HTML(200, RELEASE_NEW)
} }
func NewReleasePost(ctx *middleware.Context, form auth.NewReleaseForm) { func NewReleasePost(ctx *context.Context, form auth.NewReleaseForm) {
ctx.Data["Title"] = ctx.Tr("repo.release.new_release") ctx.Data["Title"] = ctx.Tr("repo.release.new_release")
ctx.Data["PageIsReleaseList"] = true ctx.Data["PageIsReleaseList"] = true
@ -201,7 +201,7 @@ func NewReleasePost(ctx *middleware.Context, form auth.NewReleaseForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/releases") ctx.Redirect(ctx.Repo.RepoLink + "/releases")
} }
func EditRelease(ctx *middleware.Context) { func EditRelease(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.release.edit_release") ctx.Data["Title"] = ctx.Tr("repo.release.edit_release")
ctx.Data["PageIsReleaseList"] = true ctx.Data["PageIsReleaseList"] = true
ctx.Data["PageIsEditRelease"] = true ctx.Data["PageIsEditRelease"] = true
@ -226,7 +226,7 @@ func EditRelease(ctx *middleware.Context) {
ctx.HTML(200, RELEASE_NEW) ctx.HTML(200, RELEASE_NEW)
} }
func EditReleasePost(ctx *middleware.Context, form auth.EditReleaseForm) { func EditReleasePost(ctx *context.Context, form auth.EditReleaseForm) {
ctx.Data["Title"] = ctx.Tr("repo.release.edit_release") ctx.Data["Title"] = ctx.Tr("repo.release.edit_release")
ctx.Data["PageIsReleaseList"] = true ctx.Data["PageIsReleaseList"] = true
ctx.Data["PageIsEditRelease"] = true ctx.Data["PageIsEditRelease"] = true
@ -263,7 +263,7 @@ func EditReleasePost(ctx *middleware.Context, form auth.EditReleaseForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/releases") ctx.Redirect(ctx.Repo.RepoLink + "/releases")
} }
func DeleteRelease(ctx *middleware.Context) { func DeleteRelease(ctx *context.Context) {
if err := models.DeleteReleaseByID(ctx.QueryInt64("id")); err != nil { if err := models.DeleteReleaseByID(ctx.QueryInt64("id")); err != nil {
ctx.Flash.Error("DeleteReleaseByID: " + err.Error()) ctx.Flash.Error("DeleteReleaseByID: " + err.Error())
} else { } else {

View file

@ -17,8 +17,8 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -27,13 +27,13 @@ const (
MIGRATE base.TplName = "repo/migrate" MIGRATE base.TplName = "repo/migrate"
) )
func MustBeNotBare(ctx *middleware.Context) { func MustBeNotBare(ctx *context.Context) {
if ctx.Repo.Repository.IsBare { if ctx.Repo.Repository.IsBare {
ctx.Handle(404, "MustBeNotBare", nil) ctx.Handle(404, "MustBeNotBare", nil)
} }
} }
func checkContextUser(ctx *middleware.Context, uid int64) *models.User { func checkContextUser(ctx *context.Context, uid int64) *models.User {
orgs, err := models.GetOwnedOrgsByUserIDDesc(ctx.User.Id, "updated_unix") orgs, err := models.GetOwnedOrgsByUserIDDesc(ctx.User.Id, "updated_unix")
if err != nil { if err != nil {
ctx.Handle(500, "GetOwnedOrgsByUserIDDesc", err) ctx.Handle(500, "GetOwnedOrgsByUserIDDesc", err)
@ -64,7 +64,7 @@ func checkContextUser(ctx *middleware.Context, uid int64) *models.User {
return org return org
} }
func Create(ctx *middleware.Context) { func Create(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("new_repo") ctx.Data["Title"] = ctx.Tr("new_repo")
// Give default value for template to render. // Give default value for template to render.
@ -84,7 +84,7 @@ func Create(ctx *middleware.Context) {
ctx.HTML(200, CREATE) ctx.HTML(200, CREATE)
} }
func handleCreateError(ctx *middleware.Context, owner *models.User, err error, name string, tpl base.TplName, form interface{}) { func handleCreateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form interface{}) {
switch { switch {
case models.IsErrReachLimitOfRepo(err): case models.IsErrReachLimitOfRepo(err):
ctx.RenderWithErr(ctx.Tr("repo.form.reach_limit_of_creation", owner.RepoCreationNum()), tpl, form) ctx.RenderWithErr(ctx.Tr("repo.form.reach_limit_of_creation", owner.RepoCreationNum()), tpl, form)
@ -102,7 +102,7 @@ func handleCreateError(ctx *middleware.Context, owner *models.User, err error, n
} }
} }
func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { func CreatePost(ctx *context.Context, form auth.CreateRepoForm) {
ctx.Data["Title"] = ctx.Tr("new_repo") ctx.Data["Title"] = ctx.Tr("new_repo")
ctx.Data["Gitignores"] = models.Gitignores ctx.Data["Gitignores"] = models.Gitignores
@ -144,7 +144,7 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) {
handleCreateError(ctx, ctxUser, err, "CreatePost", CREATE, &form) handleCreateError(ctx, ctxUser, err, "CreatePost", CREATE, &form)
} }
func Migrate(ctx *middleware.Context) { func Migrate(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("new_migrate") ctx.Data["Title"] = ctx.Tr("new_migrate")
ctx.Data["private"] = ctx.User.LastRepoVisibility ctx.Data["private"] = ctx.User.LastRepoVisibility
ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate
@ -159,7 +159,7 @@ func Migrate(ctx *middleware.Context) {
ctx.HTML(200, MIGRATE) ctx.HTML(200, MIGRATE)
} }
func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) {
ctx.Data["Title"] = ctx.Tr("new_migrate") ctx.Data["Title"] = ctx.Tr("new_migrate")
ctxUser := checkContextUser(ctx, form.Uid) ctxUser := checkContextUser(ctx, form.Uid)
@ -227,7 +227,7 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) {
handleCreateError(ctx, ctxUser, err, "MigratePost", MIGRATE, &form) handleCreateError(ctx, ctxUser, err, "MigratePost", MIGRATE, &form)
} }
func Action(ctx *middleware.Context) { func Action(ctx *context.Context) {
var err error var err error
switch ctx.Params(":action") { switch ctx.Params(":action") {
case "watch": case "watch":
@ -261,7 +261,7 @@ func Action(ctx *middleware.Context) {
ctx.Redirect(redirectTo) ctx.Redirect(redirectTo)
} }
func Download(ctx *middleware.Context) { func Download(ctx *context.Context) {
var ( var (
uri = ctx.Params("*") uri = ctx.Params("*")
refName string refName string

View file

@ -13,9 +13,9 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/mailer"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -27,13 +27,13 @@ const (
DEPLOY_KEYS base.TplName = "repo/settings/deploy_keys" DEPLOY_KEYS base.TplName = "repo/settings/deploy_keys"
) )
func Settings(ctx *middleware.Context) { func Settings(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsOptions"] = true ctx.Data["PageIsSettingsOptions"] = true
ctx.HTML(200, SETTINGS_OPTIONS) ctx.HTML(200, SETTINGS_OPTIONS)
} }
func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) { func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsOptions"] = true ctx.Data["PageIsSettingsOptions"] = true
@ -271,7 +271,7 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) {
} }
} }
func Collaboration(ctx *middleware.Context) { func Collaboration(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsCollaboration"] = true ctx.Data["PageIsSettingsCollaboration"] = true
@ -285,7 +285,7 @@ func Collaboration(ctx *middleware.Context) {
ctx.HTML(200, COLLABORATION) ctx.HTML(200, COLLABORATION)
} }
func CollaborationPost(ctx *middleware.Context) { func CollaborationPost(ctx *context.Context) {
name := strings.ToLower(ctx.Query("collaborator")) name := strings.ToLower(ctx.Query("collaborator"))
if len(name) == 0 || ctx.Repo.Owner.LowerName == name { if len(name) == 0 || ctx.Repo.Owner.LowerName == name {
ctx.Redirect(setting.AppSubUrl + ctx.Req.URL.Path) ctx.Redirect(setting.AppSubUrl + ctx.Req.URL.Path)
@ -333,7 +333,7 @@ func CollaborationPost(ctx *middleware.Context) {
ctx.Redirect(setting.AppSubUrl + ctx.Req.URL.Path) ctx.Redirect(setting.AppSubUrl + ctx.Req.URL.Path)
} }
func ChangeCollaborationAccessMode(ctx *middleware.Context) { func ChangeCollaborationAccessMode(ctx *context.Context) {
if err := ctx.Repo.Repository.ChangeCollaborationAccessMode( if err := ctx.Repo.Repository.ChangeCollaborationAccessMode(
ctx.QueryInt64("uid"), ctx.QueryInt64("uid"),
models.AccessMode(ctx.QueryInt("mode"))); err != nil { models.AccessMode(ctx.QueryInt("mode"))); err != nil {
@ -341,7 +341,7 @@ func ChangeCollaborationAccessMode(ctx *middleware.Context) {
} }
} }
func DeleteCollaboration(ctx *middleware.Context) { func DeleteCollaboration(ctx *context.Context) {
if err := ctx.Repo.Repository.DeleteCollaboration(ctx.QueryInt64("id")); err != nil { if err := ctx.Repo.Repository.DeleteCollaboration(ctx.QueryInt64("id")); err != nil {
ctx.Flash.Error("DeleteCollaboration: " + err.Error()) ctx.Flash.Error("DeleteCollaboration: " + err.Error())
} else { } else {
@ -353,7 +353,7 @@ func DeleteCollaboration(ctx *middleware.Context) {
}) })
} }
func parseOwnerAndRepo(ctx *middleware.Context) (*models.User, *models.Repository) { func parseOwnerAndRepo(ctx *context.Context) (*models.User, *models.Repository) {
owner, err := models.GetUserByName(ctx.Params(":username")) owner, err := models.GetUserByName(ctx.Params(":username"))
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
@ -377,7 +377,7 @@ func parseOwnerAndRepo(ctx *middleware.Context) (*models.User, *models.Repositor
return owner, repo return owner, repo
} }
func GitHooks(ctx *middleware.Context) { func GitHooks(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.githooks") ctx.Data["Title"] = ctx.Tr("repo.settings.githooks")
ctx.Data["PageIsSettingsGitHooks"] = true ctx.Data["PageIsSettingsGitHooks"] = true
@ -391,7 +391,7 @@ func GitHooks(ctx *middleware.Context) {
ctx.HTML(200, GITHOOKS) ctx.HTML(200, GITHOOKS)
} }
func GitHooksEdit(ctx *middleware.Context) { func GitHooksEdit(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.githooks") ctx.Data["Title"] = ctx.Tr("repo.settings.githooks")
ctx.Data["PageIsSettingsGitHooks"] = true ctx.Data["PageIsSettingsGitHooks"] = true
@ -409,7 +409,7 @@ func GitHooksEdit(ctx *middleware.Context) {
ctx.HTML(200, GITHOOK_EDIT) ctx.HTML(200, GITHOOK_EDIT)
} }
func GitHooksEditPost(ctx *middleware.Context) { func GitHooksEditPost(ctx *context.Context) {
name := ctx.Params(":name") name := ctx.Params(":name")
hook, err := ctx.Repo.GitRepo.GetHook(name) hook, err := ctx.Repo.GitRepo.GetHook(name)
if err != nil { if err != nil {
@ -428,7 +428,7 @@ func GitHooksEditPost(ctx *middleware.Context) {
ctx.Redirect(ctx.Repo.RepoLink + "/settings/hooks/git") ctx.Redirect(ctx.Repo.RepoLink + "/settings/hooks/git")
} }
func DeployKeys(ctx *middleware.Context) { func DeployKeys(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.deploy_keys") ctx.Data["Title"] = ctx.Tr("repo.settings.deploy_keys")
ctx.Data["PageIsSettingsKeys"] = true ctx.Data["PageIsSettingsKeys"] = true
@ -442,7 +442,7 @@ func DeployKeys(ctx *middleware.Context) {
ctx.HTML(200, DEPLOY_KEYS) ctx.HTML(200, DEPLOY_KEYS)
} }
func DeployKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { func DeployKeysPost(ctx *context.Context, form auth.AddSSHKeyForm) {
ctx.Data["Title"] = ctx.Tr("repo.settings.deploy_keys") ctx.Data["Title"] = ctx.Tr("repo.settings.deploy_keys")
ctx.Data["PageIsSettingsKeys"] = true ctx.Data["PageIsSettingsKeys"] = true
@ -492,7 +492,7 @@ func DeployKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/settings/keys") ctx.Redirect(ctx.Repo.RepoLink + "/settings/keys")
} }
func DeleteDeployKey(ctx *middleware.Context) { func DeleteDeployKey(ctx *context.Context) {
if err := models.DeleteDeployKey(ctx.User, ctx.QueryInt64("id")); err != nil { if err := models.DeleteDeployKey(ctx.User, ctx.QueryInt64("id")); err != nil {
ctx.Flash.Error("DeleteDeployKey: " + err.Error()) ctx.Flash.Error("DeleteDeployKey: " + err.Error())
} else { } else {

View file

@ -16,9 +16,9 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/markdown" "github.com/gogits/gogs/modules/markdown"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/template" "github.com/gogits/gogs/modules/template"
"github.com/gogits/gogs/modules/template/highlight" "github.com/gogits/gogs/modules/template/highlight"
) )
@ -29,7 +29,7 @@ const (
FORKS base.TplName = "repo/forks" FORKS base.TplName = "repo/forks"
) )
func Home(ctx *middleware.Context) { func Home(ctx *context.Context) {
ctx.Data["Title"] = ctx.Repo.Repository.Name ctx.Data["Title"] = ctx.Repo.Repository.Name
ctx.Data["PageIsViewCode"] = true ctx.Data["PageIsViewCode"] = true
ctx.Data["RequireHighlightJS"] = true ctx.Data["RequireHighlightJS"] = true
@ -219,7 +219,7 @@ func Home(ctx *middleware.Context) {
ctx.HTML(200, HOME) ctx.HTML(200, HOME)
} }
func RenderUserCards(ctx *middleware.Context, total int, getter func(page int) ([]*models.User, error), tpl base.TplName) { func RenderUserCards(ctx *context.Context, total int, getter func(page int) ([]*models.User, error), tpl base.TplName) {
page := ctx.QueryInt("page") page := ctx.QueryInt("page")
if page <= 0 { if page <= 0 {
page = 1 page = 1
@ -237,21 +237,21 @@ func RenderUserCards(ctx *middleware.Context, total int, getter func(page int) (
ctx.HTML(200, tpl) ctx.HTML(200, tpl)
} }
func Watchers(ctx *middleware.Context) { func Watchers(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.watchers") ctx.Data["Title"] = ctx.Tr("repo.watchers")
ctx.Data["CardsTitle"] = ctx.Tr("repo.watchers") ctx.Data["CardsTitle"] = ctx.Tr("repo.watchers")
ctx.Data["PageIsWatchers"] = true ctx.Data["PageIsWatchers"] = true
RenderUserCards(ctx, ctx.Repo.Repository.NumWatches, ctx.Repo.Repository.GetWatchers, WATCHERS) RenderUserCards(ctx, ctx.Repo.Repository.NumWatches, ctx.Repo.Repository.GetWatchers, WATCHERS)
} }
func Stars(ctx *middleware.Context) { func Stars(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.stargazers") ctx.Data["Title"] = ctx.Tr("repo.stargazers")
ctx.Data["CardsTitle"] = ctx.Tr("repo.stargazers") ctx.Data["CardsTitle"] = ctx.Tr("repo.stargazers")
ctx.Data["PageIsStargazers"] = true ctx.Data["PageIsStargazers"] = true
RenderUserCards(ctx, ctx.Repo.Repository.NumStars, ctx.Repo.Repository.GetStargazers, WATCHERS) RenderUserCards(ctx, ctx.Repo.Repository.NumStars, ctx.Repo.Repository.GetStargazers, WATCHERS)
} }
func Forks(ctx *middleware.Context) { func Forks(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repos.forks") ctx.Data["Title"] = ctx.Tr("repos.forks")
forks, err := ctx.Repo.Repository.GetForks() forks, err := ctx.Repo.Repository.GetForks()

View file

@ -18,7 +18,7 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -28,7 +28,7 @@ const (
ORG_HOOK_NEW base.TplName = "org/settings/hook_new" ORG_HOOK_NEW base.TplName = "org/settings/hook_new"
) )
func Webhooks(ctx *middleware.Context) { func Webhooks(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.hooks") ctx.Data["Title"] = ctx.Tr("repo.settings.hooks")
ctx.Data["PageIsSettingsHooks"] = true ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["BaseLink"] = ctx.Repo.RepoLink ctx.Data["BaseLink"] = ctx.Repo.RepoLink
@ -52,7 +52,7 @@ type OrgRepoCtx struct {
} }
// getOrgRepoCtx determines whether this is a repo context or organization context. // getOrgRepoCtx determines whether this is a repo context or organization context.
func getOrgRepoCtx(ctx *middleware.Context) (*OrgRepoCtx, error) { func getOrgRepoCtx(ctx *context.Context) (*OrgRepoCtx, error) {
if len(ctx.Repo.RepoLink) > 0 { if len(ctx.Repo.RepoLink) > 0 {
return &OrgRepoCtx{ return &OrgRepoCtx{
RepoID: ctx.Repo.Repository.ID, RepoID: ctx.Repo.Repository.ID,
@ -72,7 +72,7 @@ func getOrgRepoCtx(ctx *middleware.Context) (*OrgRepoCtx, error) {
return nil, errors.New("Unable to set OrgRepo context") return nil, errors.New("Unable to set OrgRepo context")
} }
func checkHookType(ctx *middleware.Context) string { func checkHookType(ctx *context.Context) string {
hookType := strings.ToLower(ctx.Params(":type")) hookType := strings.ToLower(ctx.Params(":type"))
if !com.IsSliceContainsStr(setting.Webhook.Types, hookType) { if !com.IsSliceContainsStr(setting.Webhook.Types, hookType) {
ctx.Handle(404, "checkHookType", nil) ctx.Handle(404, "checkHookType", nil)
@ -81,7 +81,7 @@ func checkHookType(ctx *middleware.Context) string {
return hookType return hookType
} }
func WebhooksNew(ctx *middleware.Context) { func WebhooksNew(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook") ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook")
ctx.Data["PageIsSettingsHooks"] = true ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksNew"] = true ctx.Data["PageIsSettingsHooksNew"] = true
@ -114,7 +114,7 @@ func ParseHookEvent(form auth.WebhookForm) *models.HookEvent {
} }
} }
func WebHooksNewPost(ctx *middleware.Context, form auth.NewWebhookForm) { func WebHooksNewPost(ctx *context.Context, form auth.NewWebhookForm) {
ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook") ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook")
ctx.Data["PageIsSettingsHooks"] = true ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksNew"] = true ctx.Data["PageIsSettingsHooksNew"] = true
@ -160,7 +160,7 @@ func WebHooksNewPost(ctx *middleware.Context, form auth.NewWebhookForm) {
ctx.Redirect(orCtx.Link + "/settings/hooks") ctx.Redirect(orCtx.Link + "/settings/hooks")
} }
func SlackHooksNewPost(ctx *middleware.Context, form auth.NewSlackHookForm) { func SlackHooksNewPost(ctx *context.Context, form auth.NewSlackHookForm) {
ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksNew"] = true ctx.Data["PageIsSettingsHooksNew"] = true
@ -210,7 +210,7 @@ func SlackHooksNewPost(ctx *middleware.Context, form auth.NewSlackHookForm) {
ctx.Redirect(orCtx.Link + "/settings/hooks") ctx.Redirect(orCtx.Link + "/settings/hooks")
} }
func checkWebhook(ctx *middleware.Context) (*OrgRepoCtx, *models.Webhook) { func checkWebhook(ctx *context.Context) (*OrgRepoCtx, *models.Webhook) {
ctx.Data["RequireHighlightJS"] = true ctx.Data["RequireHighlightJS"] = true
orCtx, err := getOrgRepoCtx(ctx) orCtx, err := getOrgRepoCtx(ctx)
@ -245,7 +245,7 @@ func checkWebhook(ctx *middleware.Context) (*OrgRepoCtx, *models.Webhook) {
return orCtx, w return orCtx, w
} }
func WebHooksEdit(ctx *middleware.Context) { func WebHooksEdit(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook") ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook")
ctx.Data["PageIsSettingsHooks"] = true ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksEdit"] = true ctx.Data["PageIsSettingsHooksEdit"] = true
@ -259,7 +259,7 @@ func WebHooksEdit(ctx *middleware.Context) {
ctx.HTML(200, orCtx.NewTemplate) ctx.HTML(200, orCtx.NewTemplate)
} }
func WebHooksEditPost(ctx *middleware.Context, form auth.NewWebhookForm) { func WebHooksEditPost(ctx *context.Context, form auth.NewWebhookForm) {
ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook") ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook")
ctx.Data["PageIsSettingsHooks"] = true ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksEdit"] = true ctx.Data["PageIsSettingsHooksEdit"] = true
@ -297,7 +297,7 @@ func WebHooksEditPost(ctx *middleware.Context, form auth.NewWebhookForm) {
ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID)) ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID))
} }
func SlackHooksEditPost(ctx *middleware.Context, form auth.NewSlackHookForm) { func SlackHooksEditPost(ctx *context.Context, form auth.NewSlackHookForm) {
ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksEdit"] = true ctx.Data["PageIsSettingsHooksEdit"] = true
@ -340,7 +340,7 @@ func SlackHooksEditPost(ctx *middleware.Context, form auth.NewSlackHookForm) {
ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID)) ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID))
} }
func TestWebhook(ctx *middleware.Context) { func TestWebhook(ctx *context.Context) {
p := &api.PushPayload{ p := &api.PushPayload{
Ref: git.BRANCH_PREFIX + ctx.Repo.Repository.DefaultBranch, Ref: git.BRANCH_PREFIX + ctx.Repo.Repository.DefaultBranch,
Before: ctx.Repo.CommitID, Before: ctx.Repo.CommitID,
@ -378,7 +378,7 @@ func TestWebhook(ctx *middleware.Context) {
} }
} }
func DeleteWebhook(ctx *middleware.Context) { func DeleteWebhook(ctx *context.Context) {
if err := models.DeleteWebhook(ctx.QueryInt64("id")); err != nil { if err := models.DeleteWebhook(ctx.QueryInt64("id")); err != nil {
ctx.Flash.Error("DeleteWebhook: " + err.Error()) ctx.Flash.Error("DeleteWebhook: " + err.Error())
} else { } else {

View file

@ -14,8 +14,8 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/markdown" "github.com/gogits/gogs/modules/markdown"
"github.com/gogits/gogs/modules/middleware"
) )
const ( const (
@ -25,7 +25,7 @@ const (
WIKI_PAGES base.TplName = "repo/wiki/pages" WIKI_PAGES base.TplName = "repo/wiki/pages"
) )
func MustEnableWiki(ctx *middleware.Context) { func MustEnableWiki(ctx *context.Context) {
if !ctx.Repo.Repository.EnableWiki { if !ctx.Repo.Repository.EnableWiki {
ctx.Handle(404, "MustEnableWiki", nil) ctx.Handle(404, "MustEnableWiki", nil)
return return
@ -43,7 +43,7 @@ type PageMeta struct {
Updated time.Time Updated time.Time
} }
func renderWikiPage(ctx *middleware.Context, isViewPage bool) (*git.Repository, string) { func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, string) {
wikiRepo, err := git.OpenRepository(ctx.Repo.Repository.WikiPath()) wikiRepo, err := git.OpenRepository(ctx.Repo.Repository.WikiPath())
if err != nil { if err != nil {
ctx.Handle(500, "OpenRepository", err) ctx.Handle(500, "OpenRepository", err)
@ -115,7 +115,7 @@ func renderWikiPage(ctx *middleware.Context, isViewPage bool) (*git.Repository,
return wikiRepo, pageName return wikiRepo, pageName
} }
func Wiki(ctx *middleware.Context) { func Wiki(ctx *context.Context) {
ctx.Data["PageIsWiki"] = true ctx.Data["PageIsWiki"] = true
if !ctx.Repo.Repository.HasWiki() { if !ctx.Repo.Repository.HasWiki() {
@ -140,7 +140,7 @@ func Wiki(ctx *middleware.Context) {
ctx.HTML(200, WIKI_VIEW) ctx.HTML(200, WIKI_VIEW)
} }
func WikiPages(ctx *middleware.Context) { func WikiPages(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.wiki.pages") ctx.Data["Title"] = ctx.Tr("repo.wiki.pages")
ctx.Data["PageIsWiki"] = true ctx.Data["PageIsWiki"] = true
@ -186,7 +186,7 @@ func WikiPages(ctx *middleware.Context) {
ctx.HTML(200, WIKI_PAGES) ctx.HTML(200, WIKI_PAGES)
} }
func NewWiki(ctx *middleware.Context) { func NewWiki(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page") ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
ctx.Data["PageIsWiki"] = true ctx.Data["PageIsWiki"] = true
ctx.Data["RequireSimpleMDE"] = true ctx.Data["RequireSimpleMDE"] = true
@ -198,7 +198,7 @@ func NewWiki(ctx *middleware.Context) {
ctx.HTML(200, WIKI_NEW) ctx.HTML(200, WIKI_NEW)
} }
func NewWikiPost(ctx *middleware.Context, form auth.NewWikiForm) { func NewWikiPost(ctx *context.Context, form auth.NewWikiForm) {
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page") ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
ctx.Data["PageIsWiki"] = true ctx.Data["PageIsWiki"] = true
ctx.Data["RequireSimpleMDE"] = true ctx.Data["RequireSimpleMDE"] = true
@ -221,7 +221,7 @@ func NewWikiPost(ctx *middleware.Context, form auth.NewWikiForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + models.ToWikiPageURL(form.Title)) ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + models.ToWikiPageURL(form.Title))
} }
func EditWiki(ctx *middleware.Context) { func EditWiki(ctx *context.Context) {
ctx.Data["PageIsWiki"] = true ctx.Data["PageIsWiki"] = true
ctx.Data["PageIsWikiEdit"] = true ctx.Data["PageIsWikiEdit"] = true
ctx.Data["RequireSimpleMDE"] = true ctx.Data["RequireSimpleMDE"] = true
@ -239,7 +239,7 @@ func EditWiki(ctx *middleware.Context) {
ctx.HTML(200, WIKI_NEW) ctx.HTML(200, WIKI_NEW)
} }
func EditWikiPost(ctx *middleware.Context, form auth.NewWikiForm) { func EditWikiPost(ctx *context.Context, form auth.NewWikiForm) {
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page") ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
ctx.Data["PageIsWiki"] = true ctx.Data["PageIsWiki"] = true
ctx.Data["RequireSimpleMDE"] = true ctx.Data["RequireSimpleMDE"] = true
@ -257,7 +257,7 @@ func EditWikiPost(ctx *middleware.Context, form auth.NewWikiForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + models.ToWikiPageURL(form.Title)) ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + models.ToWikiPageURL(form.Title))
} }
func DeleteWikiPagePost(ctx *middleware.Context) { func DeleteWikiPagePost(ctx *context.Context) {
pageURL := ctx.Params(":page") pageURL := ctx.Params(":page")
if len(pageURL) == 0 { if len(pageURL) == 0 {
pageURL = "Home" pageURL = "Home"

View file

@ -5,6 +5,7 @@
package user package user
import ( import (
"fmt"
"net/url" "net/url"
"github.com/go-macaron/captcha" "github.com/go-macaron/captcha"
@ -12,9 +13,9 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/mailer"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -26,11 +27,50 @@ const (
RESET_PASSWORD base.TplName = "user/auth/reset_passwd" RESET_PASSWORD base.TplName = "user/auth/reset_passwd"
) )
func SignIn(ctx *middleware.Context) { // AutoSignIn reads cookie and try to auto-login.
func AutoSignIn(ctx *context.Context) (bool, error) {
if !models.HasEngine {
return false, nil
}
uname := ctx.GetCookie(setting.CookieUserName)
if len(uname) == 0 {
return false, nil
}
isSucceed := false
defer func() {
if !isSucceed {
log.Trace("auto-login cookie cleared: %s", uname)
ctx.SetCookie(setting.CookieUserName, "", -1, setting.AppSubUrl)
ctx.SetCookie(setting.CookieRememberName, "", -1, setting.AppSubUrl)
}
}()
u, err := models.GetUserByName(uname)
if err != nil {
if !models.IsErrUserNotExist(err) {
return false, fmt.Errorf("GetUserByName: %v", err)
}
return false, nil
}
if val, _ := ctx.GetSuperSecureCookie(
base.EncodeMD5(u.Rands+u.Passwd), setting.CookieRememberName); val != u.Name {
return false, nil
}
isSucceed = true
ctx.Session.Set("uid", u.Id)
ctx.Session.Set("uname", u.Name)
return true, nil
}
func SignIn(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("sign_in") ctx.Data["Title"] = ctx.Tr("sign_in")
// Check auto-login. // Check auto-login.
isSucceed, err := middleware.AutoSignIn(ctx) isSucceed, err := AutoSignIn(ctx)
if err != nil { if err != nil {
ctx.Handle(500, "AutoSignIn", err) ctx.Handle(500, "AutoSignIn", err)
return return
@ -49,7 +89,7 @@ func SignIn(ctx *middleware.Context) {
ctx.HTML(200, SIGNIN) ctx.HTML(200, SIGNIN)
} }
func SignInPost(ctx *middleware.Context, form auth.SignInForm) { func SignInPost(ctx *context.Context, form auth.SignInForm) {
ctx.Data["Title"] = ctx.Tr("sign_in") ctx.Data["Title"] = ctx.Tr("sign_in")
if ctx.HasError() { if ctx.HasError() {
@ -85,7 +125,7 @@ func SignInPost(ctx *middleware.Context, form auth.SignInForm) {
ctx.Redirect(setting.AppSubUrl + "/") ctx.Redirect(setting.AppSubUrl + "/")
} }
func SignOut(ctx *middleware.Context) { func SignOut(ctx *context.Context) {
ctx.Session.Delete("uid") ctx.Session.Delete("uid")
ctx.Session.Delete("uname") ctx.Session.Delete("uname")
ctx.Session.Delete("socialId") ctx.Session.Delete("socialId")
@ -96,7 +136,7 @@ func SignOut(ctx *middleware.Context) {
ctx.Redirect(setting.AppSubUrl + "/") ctx.Redirect(setting.AppSubUrl + "/")
} }
func SignUp(ctx *middleware.Context) { func SignUp(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("sign_up") ctx.Data["Title"] = ctx.Tr("sign_up")
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
@ -110,7 +150,7 @@ func SignUp(ctx *middleware.Context) {
ctx.HTML(200, SIGNUP) ctx.HTML(200, SIGNUP)
} }
func SignUpPost(ctx *middleware.Context, cpt *captcha.Captcha, form auth.RegisterForm) { func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterForm) {
ctx.Data["Title"] = ctx.Tr("sign_up") ctx.Data["Title"] = ctx.Tr("sign_up")
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
@ -191,7 +231,7 @@ func SignUpPost(ctx *middleware.Context, cpt *captcha.Captcha, form auth.Registe
ctx.Redirect(setting.AppSubUrl + "/user/login") ctx.Redirect(setting.AppSubUrl + "/user/login")
} }
func Activate(ctx *middleware.Context) { func Activate(ctx *context.Context) {
code := ctx.Query("code") code := ctx.Query("code")
if len(code) == 0 { if len(code) == 0 {
ctx.Data["IsActivatePage"] = true ctx.Data["IsActivatePage"] = true
@ -243,7 +283,7 @@ func Activate(ctx *middleware.Context) {
ctx.HTML(200, ACTIVATE) ctx.HTML(200, ACTIVATE)
} }
func ActivateEmail(ctx *middleware.Context) { func ActivateEmail(ctx *context.Context) {
code := ctx.Query("code") code := ctx.Query("code")
email_string := ctx.Query("email") email_string := ctx.Query("email")
@ -261,7 +301,7 @@ func ActivateEmail(ctx *middleware.Context) {
return return
} }
func ForgotPasswd(ctx *middleware.Context) { func ForgotPasswd(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("auth.forgot_password") ctx.Data["Title"] = ctx.Tr("auth.forgot_password")
if setting.MailService == nil { if setting.MailService == nil {
@ -274,7 +314,7 @@ func ForgotPasswd(ctx *middleware.Context) {
ctx.HTML(200, FORGOT_PASSWORD) ctx.HTML(200, FORGOT_PASSWORD)
} }
func ForgotPasswdPost(ctx *middleware.Context) { func ForgotPasswdPost(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("auth.forgot_password") ctx.Data["Title"] = ctx.Tr("auth.forgot_password")
if setting.MailService == nil { if setting.MailService == nil {
@ -313,7 +353,7 @@ func ForgotPasswdPost(ctx *middleware.Context) {
ctx.HTML(200, FORGOT_PASSWORD) ctx.HTML(200, FORGOT_PASSWORD)
} }
func ResetPasswd(ctx *middleware.Context) { func ResetPasswd(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("auth.reset_password") ctx.Data["Title"] = ctx.Tr("auth.reset_password")
code := ctx.Query("code") code := ctx.Query("code")
@ -326,7 +366,7 @@ func ResetPasswd(ctx *middleware.Context) {
ctx.HTML(200, RESET_PASSWORD) ctx.HTML(200, RESET_PASSWORD)
} }
func ResetPasswdPost(ctx *middleware.Context) { func ResetPasswdPost(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("auth.reset_password") ctx.Data["Title"] = ctx.Tr("auth.reset_password")
code := ctx.Query("code") code := ctx.Query("code")

View file

@ -13,7 +13,7 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -24,7 +24,7 @@ const (
ORG_HOME base.TplName = "org/home" ORG_HOME base.TplName = "org/home"
) )
func getDashboardContextUser(ctx *middleware.Context) *models.User { func getDashboardContextUser(ctx *context.Context) *models.User {
ctxUser := ctx.User ctxUser := ctx.User
orgName := ctx.Params(":org") orgName := ctx.Params(":org")
if len(orgName) > 0 { if len(orgName) > 0 {
@ -51,7 +51,7 @@ func getDashboardContextUser(ctx *middleware.Context) *models.User {
return ctxUser return ctxUser
} }
func retrieveFeeds(ctx *middleware.Context, ctxUserID, userID, offset int64, isProfile bool) { func retrieveFeeds(ctx *context.Context, ctxUserID, userID, offset int64, isProfile bool) {
actions, err := models.GetFeeds(ctxUserID, userID, offset, isProfile) actions, err := models.GetFeeds(ctxUserID, userID, offset, isProfile)
if err != nil { if err != nil {
ctx.Handle(500, "GetFeeds", err) ctx.Handle(500, "GetFeeds", err)
@ -82,7 +82,7 @@ func retrieveFeeds(ctx *middleware.Context, ctxUserID, userID, offset int64, isP
ctx.Data["Feeds"] = feeds ctx.Data["Feeds"] = feeds
} }
func Dashboard(ctx *middleware.Context) { func Dashboard(ctx *context.Context) {
ctxUser := getDashboardContextUser(ctx) ctxUser := getDashboardContextUser(ctx)
ctx.Data["Title"] = ctxUser.DisplayName() + " - " + ctx.Tr("dashboard") ctx.Data["Title"] = ctxUser.DisplayName() + " - " + ctx.Tr("dashboard")
ctx.Data["PageIsDashboard"] = true ctx.Data["PageIsDashboard"] = true
@ -147,7 +147,7 @@ func Dashboard(ctx *middleware.Context) {
ctx.HTML(200, DASHBOARD) ctx.HTML(200, DASHBOARD)
} }
func Issues(ctx *middleware.Context) { func Issues(ctx *context.Context) {
isPullList := ctx.Params(":type") == "pulls" isPullList := ctx.Params(":type") == "pulls"
if isPullList { if isPullList {
ctx.Data["Title"] = ctx.Tr("pull_requests") ctx.Data["Title"] = ctx.Tr("pull_requests")
@ -306,7 +306,7 @@ func Issues(ctx *middleware.Context) {
ctx.HTML(200, ISSUES) ctx.HTML(200, ISSUES)
} }
func ShowSSHKeys(ctx *middleware.Context, uid int64) { func ShowSSHKeys(ctx *context.Context, uid int64) {
keys, err := models.ListPublicKeys(uid) keys, err := models.ListPublicKeys(uid)
if err != nil { if err != nil {
ctx.Handle(500, "ListPublicKeys", err) ctx.Handle(500, "ListPublicKeys", err)
@ -321,9 +321,9 @@ func ShowSSHKeys(ctx *middleware.Context, uid int64) {
ctx.PlainText(200, buf.Bytes()) ctx.PlainText(200, buf.Bytes())
} }
func showOrgProfile(ctx *middleware.Context) { func showOrgProfile(ctx *context.Context) {
ctx.SetParams(":org", ctx.Params(":username")) ctx.SetParams(":org", ctx.Params(":username"))
middleware.HandleOrgAssignment(ctx) context.HandleOrgAssignment(ctx)
if ctx.Written() { if ctx.Written() {
return return
} }
@ -366,7 +366,7 @@ func showOrgProfile(ctx *middleware.Context) {
ctx.HTML(200, ORG_HOME) ctx.HTML(200, ORG_HOME)
} }
func Email2User(ctx *middleware.Context) { func Email2User(ctx *context.Context) {
u, err := models.GetUserByEmail(ctx.Query("email")) u, err := models.GetUserByEmail(ctx.Query("email"))
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {

View file

@ -11,7 +11,7 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/routers/repo" "github.com/gogits/gogs/routers/repo"
) )
@ -21,7 +21,7 @@ const (
STARS base.TplName = "user/meta/stars" STARS base.TplName = "user/meta/stars"
) )
func GetUserByName(ctx *middleware.Context, name string) *models.User { func GetUserByName(ctx *context.Context, name string) *models.User {
user, err := models.GetUserByName(name) user, err := models.GetUserByName(name)
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
@ -35,11 +35,11 @@ func GetUserByName(ctx *middleware.Context, name string) *models.User {
} }
// GetUserByParams returns user whose name is presented in URL paramenter. // GetUserByParams returns user whose name is presented in URL paramenter.
func GetUserByParams(ctx *middleware.Context) *models.User { func GetUserByParams(ctx *context.Context) *models.User {
return GetUserByName(ctx, ctx.Params(":username")) return GetUserByName(ctx, ctx.Params(":username"))
} }
func Profile(ctx *middleware.Context) { func Profile(ctx *context.Context) {
uname := ctx.Params(":username") uname := ctx.Params(":username")
// Special handle for FireFox requests favicon.ico. // Special handle for FireFox requests favicon.ico.
if uname == "favicon.ico" { if uname == "favicon.ico" {
@ -103,7 +103,7 @@ func Profile(ctx *middleware.Context) {
ctx.HTML(200, PROFILE) ctx.HTML(200, PROFILE)
} }
func Followers(ctx *middleware.Context) { func Followers(ctx *context.Context) {
u := GetUserByParams(ctx) u := GetUserByParams(ctx)
if ctx.Written() { if ctx.Written() {
return return
@ -115,7 +115,7 @@ func Followers(ctx *middleware.Context) {
repo.RenderUserCards(ctx, u.NumFollowers, u.GetFollowers, FOLLOWERS) repo.RenderUserCards(ctx, u.NumFollowers, u.GetFollowers, FOLLOWERS)
} }
func Following(ctx *middleware.Context) { func Following(ctx *context.Context) {
u := GetUserByParams(ctx) u := GetUserByParams(ctx)
if ctx.Written() { if ctx.Written() {
return return
@ -127,11 +127,11 @@ func Following(ctx *middleware.Context) {
repo.RenderUserCards(ctx, u.NumFollowing, u.GetFollowing, FOLLOWERS) repo.RenderUserCards(ctx, u.NumFollowing, u.GetFollowing, FOLLOWERS)
} }
func Stars(ctx *middleware.Context) { func Stars(ctx *context.Context) {
} }
func Action(ctx *middleware.Context) { func Action(ctx *context.Context) {
u := GetUserByParams(ctx) u := GetUserByParams(ctx)
if ctx.Written() { if ctx.Written() {
return return

View file

@ -15,9 +15,9 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/mailer"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -33,13 +33,13 @@ const (
SECURITY base.TplName = "user/security" SECURITY base.TplName = "user/security"
) )
func Settings(ctx *middleware.Context) { func Settings(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsProfile"] = true ctx.Data["PageIsSettingsProfile"] = true
ctx.HTML(200, SETTINGS_PROFILE) ctx.HTML(200, SETTINGS_PROFILE)
} }
func handleUsernameChange(ctx *middleware.Context, newName string) { func handleUsernameChange(ctx *context.Context, newName string) {
// Non-local users are not allowed to change their username. // Non-local users are not allowed to change their username.
if len(newName) == 0 || !ctx.User.IsLocal() { if len(newName) == 0 || !ctx.User.IsLocal() {
return return
@ -74,7 +74,7 @@ func handleUsernameChange(ctx *middleware.Context, newName string) {
ctx.User.LowerName = strings.ToLower(newName) ctx.User.LowerName = strings.ToLower(newName)
} }
func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) { func SettingsPost(ctx *context.Context, form auth.UpdateProfileForm) {
ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsProfile"] = true ctx.Data["PageIsSettingsProfile"] = true
@ -107,7 +107,7 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) {
} }
// FIXME: limit size. // FIXME: limit size.
func UpdateAvatarSetting(ctx *middleware.Context, form auth.UploadAvatarForm, ctxUser *models.User) error { func UpdateAvatarSetting(ctx *context.Context, form auth.UploadAvatarForm, ctxUser *models.User) error {
ctxUser.UseCustomAvatar = form.Enable ctxUser.UseCustomAvatar = form.Enable
if form.Avatar != nil { if form.Avatar != nil {
@ -144,7 +144,7 @@ func UpdateAvatarSetting(ctx *middleware.Context, form auth.UploadAvatarForm, ct
return nil return nil
} }
func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) { func SettingsAvatar(ctx *context.Context, form auth.UploadAvatarForm) {
if err := UpdateAvatarSetting(ctx, form, ctx.User); err != nil { if err := UpdateAvatarSetting(ctx, form, ctx.User); err != nil {
ctx.Flash.Error(err.Error()) ctx.Flash.Error(err.Error())
} else { } else {
@ -154,7 +154,7 @@ func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) {
ctx.Redirect(setting.AppSubUrl + "/user/settings") ctx.Redirect(setting.AppSubUrl + "/user/settings")
} }
func SettingsDeleteAvatar(ctx *middleware.Context) { func SettingsDeleteAvatar(ctx *context.Context) {
if err := ctx.User.DeleteAvatar(); err != nil { if err := ctx.User.DeleteAvatar(); err != nil {
ctx.Flash.Error(err.Error()) ctx.Flash.Error(err.Error())
} }
@ -162,13 +162,13 @@ func SettingsDeleteAvatar(ctx *middleware.Context) {
ctx.Redirect(setting.AppSubUrl + "/user/settings") ctx.Redirect(setting.AppSubUrl + "/user/settings")
} }
func SettingsPassword(ctx *middleware.Context) { func SettingsPassword(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsPassword"] = true ctx.Data["PageIsSettingsPassword"] = true
ctx.HTML(200, SETTINGS_PASSWORD) ctx.HTML(200, SETTINGS_PASSWORD)
} }
func SettingsPasswordPost(ctx *middleware.Context, form auth.ChangePasswordForm) { func SettingsPasswordPost(ctx *context.Context, form auth.ChangePasswordForm) {
ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsPassword"] = true ctx.Data["PageIsSettingsPassword"] = true
@ -196,7 +196,7 @@ func SettingsPasswordPost(ctx *middleware.Context, form auth.ChangePasswordForm)
ctx.Redirect(setting.AppSubUrl + "/user/settings/password") ctx.Redirect(setting.AppSubUrl + "/user/settings/password")
} }
func SettingsEmails(ctx *middleware.Context) { func SettingsEmails(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsEmails"] = true ctx.Data["PageIsSettingsEmails"] = true
@ -210,7 +210,7 @@ func SettingsEmails(ctx *middleware.Context) {
ctx.HTML(200, SETTINGS_EMAILS) ctx.HTML(200, SETTINGS_EMAILS)
} }
func SettingsEmailPost(ctx *middleware.Context, form auth.AddEmailForm) { func SettingsEmailPost(ctx *context.Context, form auth.AddEmailForm) {
ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsEmails"] = true ctx.Data["PageIsSettingsEmails"] = true
@ -269,7 +269,7 @@ func SettingsEmailPost(ctx *middleware.Context, form auth.AddEmailForm) {
ctx.Redirect(setting.AppSubUrl + "/user/settings/email") ctx.Redirect(setting.AppSubUrl + "/user/settings/email")
} }
func DeleteEmail(ctx *middleware.Context) { func DeleteEmail(ctx *context.Context) {
if err := models.DeleteEmailAddress(&models.EmailAddress{ID: ctx.QueryInt64("id")}); err != nil { if err := models.DeleteEmailAddress(&models.EmailAddress{ID: ctx.QueryInt64("id")}); err != nil {
ctx.Handle(500, "DeleteEmail", err) ctx.Handle(500, "DeleteEmail", err)
return return
@ -282,7 +282,7 @@ func DeleteEmail(ctx *middleware.Context) {
}) })
} }
func SettingsSSHKeys(ctx *middleware.Context) { func SettingsSSHKeys(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsSSHKeys"] = true ctx.Data["PageIsSettingsSSHKeys"] = true
@ -296,7 +296,7 @@ func SettingsSSHKeys(ctx *middleware.Context) {
ctx.HTML(200, SETTINGS_SSH_KEYS) ctx.HTML(200, SETTINGS_SSH_KEYS)
} }
func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { func SettingsSSHKeysPost(ctx *context.Context, form auth.AddSSHKeyForm) {
ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsSSHKeys"] = true ctx.Data["PageIsSettingsSSHKeys"] = true
@ -342,7 +342,7 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) {
ctx.Redirect(setting.AppSubUrl + "/user/settings/ssh") ctx.Redirect(setting.AppSubUrl + "/user/settings/ssh")
} }
func DeleteSSHKey(ctx *middleware.Context) { func DeleteSSHKey(ctx *context.Context) {
if err := models.DeletePublicKey(ctx.User, ctx.QueryInt64("id")); err != nil { if err := models.DeletePublicKey(ctx.User, ctx.QueryInt64("id")); err != nil {
ctx.Flash.Error("DeletePublicKey: " + err.Error()) ctx.Flash.Error("DeletePublicKey: " + err.Error())
} else { } else {
@ -354,7 +354,7 @@ func DeleteSSHKey(ctx *middleware.Context) {
}) })
} }
func SettingsApplications(ctx *middleware.Context) { func SettingsApplications(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsApplications"] = true ctx.Data["PageIsSettingsApplications"] = true
@ -368,7 +368,7 @@ func SettingsApplications(ctx *middleware.Context) {
ctx.HTML(200, SETTINGS_APPLICATIONS) ctx.HTML(200, SETTINGS_APPLICATIONS)
} }
func SettingsApplicationsPost(ctx *middleware.Context, form auth.NewAccessTokenForm) { func SettingsApplicationsPost(ctx *context.Context, form auth.NewAccessTokenForm) {
ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsApplications"] = true ctx.Data["PageIsSettingsApplications"] = true
@ -398,7 +398,7 @@ func SettingsApplicationsPost(ctx *middleware.Context, form auth.NewAccessTokenF
ctx.Redirect(setting.AppSubUrl + "/user/settings/applications") ctx.Redirect(setting.AppSubUrl + "/user/settings/applications")
} }
func SettingsDeleteApplication(ctx *middleware.Context) { func SettingsDeleteApplication(ctx *context.Context) {
if err := models.DeleteAccessTokenByID(ctx.QueryInt64("id")); err != nil { if err := models.DeleteAccessTokenByID(ctx.QueryInt64("id")); err != nil {
ctx.Flash.Error("DeleteAccessTokenByID: " + err.Error()) ctx.Flash.Error("DeleteAccessTokenByID: " + err.Error())
} else { } else {
@ -410,7 +410,7 @@ func SettingsDeleteApplication(ctx *middleware.Context) {
}) })
} }
func SettingsDelete(ctx *middleware.Context) { func SettingsDelete(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsDelete"] = true ctx.Data["PageIsSettingsDelete"] = true

View file

@ -1 +1 @@
0.9.4.0311 0.9.5.0311