summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
Diffstat (limited to 'routers')
-rw-r--r--routers/admin/admin.go10
-rw-r--r--routers/admin/auths.go14
-rw-r--r--routers/admin/notice.go8
-rw-r--r--routers/admin/orgs.go14
-rw-r--r--routers/admin/repos.go6
-rw-r--r--routers/admin/users.go16
-rw-r--r--routers/api/v1/admin/orgs.go4
-rw-r--r--routers/api/v1/admin/repos.go4
-rw-r--r--routers/api/v1/admin/users.go12
-rw-r--r--routers/api/v1/api.go18
-rw-r--r--routers/api/v1/misc/markdown.go6
-rw-r--r--routers/api/v1/org/org.go12
-rw-r--r--routers/api/v1/repo/branch.go6
-rw-r--r--routers/api/v1/repo/file.go6
-rw-r--r--routers/api/v1/repo/hooks.go8
-rw-r--r--routers/api/v1/repo/keys.go14
-rw-r--r--routers/api/v1/repo/repo.go20
-rw-r--r--routers/api/v1/user/app.go6
-rw-r--r--routers/api/v1/user/email.go8
-rw-r--r--routers/api/v1/user/followers.go26
-rw-r--r--routers/api/v1/user/keys.go20
-rw-r--r--routers/api/v1/user/user.go6
-rw-r--r--routers/dev/template.go4
-rw-r--r--routers/home.go8
-rw-r--r--routers/install.go8
-rw-r--r--routers/org/members.go8
-rw-r--r--routers/org/org.go6
-rw-r--r--routers/org/setting.go16
-rw-r--r--routers/org/teams.go22
-rw-r--r--routers/repo/branch.go4
-rw-r--r--routers/repo/commit.go14
-rw-r--r--routers/repo/download.go8
-rw-r--r--routers/repo/http.go8
-rw-r--r--routers/repo/issue.go70
-rw-r--r--routers/repo/pull.go30
-rw-r--r--routers/repo/release.go16
-rw-r--r--routers/repo/repo.go20
-rw-r--r--routers/repo/setting.go28
-rw-r--r--routers/repo/view.go12
-rw-r--r--routers/repo/webhook.go26
-rw-r--r--routers/repo/wiki.go20
-rw-r--r--routers/user/auth.go66
-rw-r--r--routers/user/home.go18
-rw-r--r--routers/user/profile.go16
-rw-r--r--routers/user/setting.go38
45 files changed, 375 insertions, 335 deletions
diff --git a/routers/admin/admin.go b/routers/admin/admin.go
index 35d40bf2bc..1608b73b11 100644
--- a/routers/admin/admin.go
+++ b/routers/admin/admin.go
@@ -15,9 +15,9 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/cron"
"github.com/gogits/gogs/modules/mailer"
- "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/process"
"github.com/gogits/gogs/modules/setting"
)
@@ -124,7 +124,7 @@ const (
REINIT_MISSING_REPOSITORY
)
-func Dashboard(ctx *middleware.Context) {
+func Dashboard(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.dashboard")
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminDashboard"] = true
@@ -175,7 +175,7 @@ func Dashboard(ctx *middleware.Context) {
ctx.HTML(200, DASHBOARD)
}
-func SendTestMail(ctx *middleware.Context) {
+func SendTestMail(ctx *context.Context) {
email := ctx.Query("email")
// Send a test email to the user's email address and redirect back to Config
if err := mailer.SendTestMail(email); err != nil {
@@ -187,7 +187,7 @@ func SendTestMail(ctx *middleware.Context) {
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["PageIsAdmin"] = true
ctx.Data["PageIsAdminConfig"] = true
@@ -236,7 +236,7 @@ func Config(ctx *middleware.Context) {
ctx.HTML(200, CONFIG)
}
-func Monitor(ctx *middleware.Context) {
+func Monitor(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.monitor")
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminMonitor"] = true
diff --git a/routers/admin/auths.go b/routers/admin/auths.go
index b9e86a1ef5..4a26532bf4 100644
--- a/routers/admin/auths.go
+++ b/routers/admin/auths.go
@@ -14,8 +14,8 @@ import (
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/auth/ldap"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
- "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
)
@@ -25,7 +25,7 @@ const (
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["PageIsAdmin"] = true
ctx.Data["PageIsAdminAuthentications"] = true
@@ -53,7 +53,7 @@ var authSources = []AuthSource{
{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["PageIsAdmin"] = 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["PageIsAdmin"] = true
ctx.Data["PageIsAdminAuthentications"] = true
@@ -147,7 +147,7 @@ func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
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["PageIsAdmin"] = true
ctx.Data["PageIsAdminAuthentications"] = true
@@ -163,7 +163,7 @@ func EditAuthSource(ctx *middleware.Context) {
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["PageIsAdmin"] = 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))
}
-func DeleteAuthSource(ctx *middleware.Context) {
+func DeleteAuthSource(ctx *context.Context) {
source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid"))
if err != nil {
ctx.Handle(500, "GetLoginSourceByID", err)
diff --git a/routers/admin/notice.go b/routers/admin/notice.go
index 39d0abc736..09222eb84e 100644
--- a/routers/admin/notice.go
+++ b/routers/admin/notice.go
@@ -10,8 +10,8 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
- "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
)
@@ -19,7 +19,7 @@ const (
NOTICES base.TplName = "admin/notice"
)
-func Notices(ctx *middleware.Context) {
+func Notices(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.notices")
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminNotices"] = true
@@ -42,7 +42,7 @@ func Notices(ctx *middleware.Context) {
ctx.HTML(200, NOTICES)
}
-func DeleteNotices(ctx *middleware.Context) {
+func DeleteNotices(ctx *context.Context) {
strs := ctx.QueryStrings("ids[]")
ids := make([]int64, 0, len(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 {
ctx.Handle(500, "DeleteNotices", err)
return
diff --git a/routers/admin/orgs.go b/routers/admin/orgs.go
index ae68b872d0..829e78e83c 100644
--- a/routers/admin/orgs.go
+++ b/routers/admin/orgs.go
@@ -9,7 +9,7 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
- "github.com/gogits/gogs/modules/middleware"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/setting"
)
@@ -17,7 +17,7 @@ const (
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["PageIsAdmin"] = true
ctx.Data["PageIsAdminOrganizations"] = true
@@ -28,15 +28,15 @@ func Organizations(ctx *middleware.Context) {
page = 1
}
ctx.Data["Page"] = paginater.New(int(total), setting.AdminOrgPagingNum, page, 5)
-
- orgs, err := models.Organizations(page, setting.AdminOrgPagingNum)
-
+
+ orgs, err := models.Organizations(page, setting.AdminOrgPagingNum)
+
if err != nil {
ctx.Handle(500, "Organizations", err)
return
}
-
- ctx.Data["Orgs"] = orgs
+
+ ctx.Data["Orgs"] = orgs
ctx.Data["Total"] = total
ctx.HTML(200, ORGS)
diff --git a/routers/admin/repos.go b/routers/admin/repos.go
index a16a9adec6..47b6032a65 100644
--- a/routers/admin/repos.go
+++ b/routers/admin/repos.go
@@ -9,8 +9,8 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
- "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
)
@@ -18,7 +18,7 @@ const (
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["PageIsAdmin"] = true
ctx.Data["PageIsAdminRepositories"] = true
@@ -41,7 +41,7 @@ func Repos(ctx *middleware.Context) {
ctx.HTML(200, REPOS)
}
-func DeleteRepo(ctx *middleware.Context) {
+func DeleteRepo(ctx *context.Context) {
repo, err := models.GetRepositoryByID(ctx.QueryInt64("id"))
if err != nil {
ctx.Handle(500, "GetRepositoryByID", err)
diff --git a/routers/admin/users.go b/routers/admin/users.go
index ada0df5905..274effc4b6 100644
--- a/routers/admin/users.go
+++ b/routers/admin/users.go
@@ -13,9 +13,9 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/mailer"
- "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
)
@@ -25,7 +25,7 @@ const (
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["PageIsAdmin"] = true
ctx.Data["PageIsAdminUsers"] = true
@@ -48,7 +48,7 @@ func Users(ctx *middleware.Context) {
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["PageIsAdmin"] = true
ctx.Data["PageIsAdminUsers"] = true
@@ -66,7 +66,7 @@ func NewUser(ctx *middleware.Context) {
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["PageIsAdmin"] = 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))
}
-func prepareUserInfo(ctx *middleware.Context) *models.User {
+func prepareUserInfo(ctx *context.Context) *models.User {
u, err := models.GetUserByID(ctx.ParamsInt64(":userid"))
if err != nil {
ctx.Handle(500, "GetUserByID", err)
@@ -160,7 +160,7 @@ func prepareUserInfo(ctx *middleware.Context) *models.User {
return u
}
-func EditUser(ctx *middleware.Context) {
+func EditUser(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.users.edit_account")
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminUsers"] = true
@@ -173,7 +173,7 @@ func EditUser(ctx *middleware.Context) {
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["PageIsAdmin"] = 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"))
}
-func DeleteUser(ctx *middleware.Context) {
+func DeleteUser(ctx *context.Context) {
u, err := models.GetUserByID(ctx.ParamsInt64(":userid"))
if err != nil {
ctx.Handle(500, "GetUserByID", err)
diff --git a/routers/api/v1/admin/orgs.go b/routers/api/v1/admin/orgs.go
index 5b5302ca15..fbfcd400ae 100644
--- a/routers/api/v1/admin/orgs.go
+++ b/routers/api/v1/admin/orgs.go
@@ -8,13 +8,13 @@ import (
api "github.com/gogits/go-gogs-client"
"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/user"
)
// 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)
if ctx.Written() {
return
diff --git a/routers/api/v1/admin/repos.go b/routers/api/v1/admin/repos.go
index 7a6b2af20b..27f46c51c5 100644
--- a/routers/api/v1/admin/repos.go
+++ b/routers/api/v1/admin/repos.go
@@ -7,13 +7,13 @@ package admin
import (
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/user"
)
// 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)
if ctx.Written() {
return
diff --git a/routers/api/v1/admin/users.go b/routers/api/v1/admin/users.go
index 9a8c906f29..f0a6c293e5 100644
--- a/routers/api/v1/admin/users.go
+++ b/routers/api/v1/admin/users.go
@@ -8,15 +8,15 @@ import (
api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/models"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/mailer"
- "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/routers/api/v1/convert"
"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 {
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
-func CreateUser(ctx *middleware.Context, form api.CreateUserOption) {
+func CreateUser(ctx *context.Context, form api.CreateUserOption) {
u := &models.User{
Name: form.Username,
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
-func EditUser(ctx *middleware.Context, form api.EditUserOption) {
+func EditUser(ctx *context.Context, form api.EditUserOption) {
u := user.GetUserByParams(ctx)
if ctx.Written() {
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
-func DeleteUser(ctx *middleware.Context) {
+func DeleteUser(ctx *context.Context) {
u := user.GetUserByParams(ctx)
if ctx.Written() {
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
-func CreatePublicKey(ctx *middleware.Context, form api.CreateKeyOption) {
+func CreatePublicKey(ctx *context.Context, form api.CreateKeyOption) {
u := user.GetUserByParams(ctx)
if ctx.Written() {
return
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index 04b392fc9b..c314d7a036 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -14,7 +14,7 @@ import (
"github.com/gogits/gogs/models"
"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/misc"
"github.com/gogits/gogs/routers/api/v1/org"
@@ -23,7 +23,7 @@ import (
)
func RepoAssignment() macaron.Handler {
- return func(ctx *middleware.Context) {
+ return func(ctx *context.Context) {
userName := ctx.Params(":username")
repoName := ctx.Params(":reponame")
@@ -82,7 +82,7 @@ func RepoAssignment() macaron.Handler {
// Contexter middleware already checks token for user sign in process.
func ReqToken() macaron.Handler {
- return func(ctx *middleware.Context) {
+ return func(ctx *context.Context) {
if !ctx.IsSigned {
ctx.Error(401)
return
@@ -91,7 +91,7 @@ func ReqToken() macaron.Handler {
}
func ReqBasicAuth() macaron.Handler {
- return func(ctx *middleware.Context) {
+ return func(ctx *context.Context) {
if !ctx.IsBasicAuth {
ctx.Error(401)
return
@@ -100,7 +100,7 @@ func ReqBasicAuth() macaron.Handler {
}
func ReqAdmin() macaron.Handler {
- return func(ctx *middleware.Context) {
+ return func(ctx *context.Context) {
if !ctx.User.IsAdmin {
ctx.Error(403)
return
@@ -181,11 +181,11 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Combo("/hooks").Get(repo.ListHooks).
Post(bind(api.CreateHookOption{}), repo.CreateHook)
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.Group("/branches", func() {
- m.Get("",repo.ListBranches)
- m.Get("/:branchname",repo.GetBranch)
+ m.Get("", repo.ListBranches)
+ m.Get("/:branchname", repo.GetBranch)
})
m.Group("/keys", func() {
m.Combo("").Get(repo.ListDeployKeys).
@@ -201,7 +201,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/users/:username/orgs", org.ListUserOrgs)
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)
})
diff --git a/routers/api/v1/misc/markdown.go b/routers/api/v1/misc/markdown.go
index b98a362c3d..658f495ee5 100644
--- a/routers/api/v1/misc/markdown.go
+++ b/routers/api/v1/misc/markdown.go
@@ -7,12 +7,12 @@ package misc
import (
api "github.com/gogits/go-gogs-client"
+ "github.com/gogits/gogs/modules/context"
"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
-func Markdown(ctx *middleware.Context, form api.MarkdownOption) {
+func Markdown(ctx *context.Context, form api.MarkdownOption) {
if ctx.HasApiError() {
ctx.APIError(422, "", ctx.GetErrMsg())
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
-func MarkdownRaw(ctx *middleware.Context) {
+func MarkdownRaw(ctx *context.Context) {
body, err := ctx.Req.Body().Bytes()
if err != nil {
ctx.APIError(422, "", err)
diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go
index 2c6d6fd3f8..fe99f10548 100644
--- a/routers/api/v1/org/org.go
+++ b/routers/api/v1/org/org.go
@@ -8,12 +8,12 @@ import (
api "github.com/gogits/go-gogs-client"
"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/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 {
ctx.APIError(500, "GetOrganizations", err)
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
-func ListMyOrgs(ctx *middleware.Context) {
+func ListMyOrgs(ctx *context.Context) {
listUserOrgs(ctx, ctx.User, true)
}
// 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)
if ctx.Written() {
return
@@ -41,7 +41,7 @@ func ListUserOrgs(ctx *middleware.Context) {
}
// 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")
if ctx.Written() {
return
@@ -50,7 +50,7 @@ func Get(ctx *middleware.Context) {
}
// 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")
if ctx.Written() {
return
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go
index e2f15ff5e5..511f50057d 100644
--- a/routers/api/v1/repo/branch.go
+++ b/routers/api/v1/repo/branch.go
@@ -7,12 +7,12 @@ package repo
import (
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"
)
// 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"))
if err != nil {
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
-func ListBranches(ctx *middleware.Context) {
+func ListBranches(ctx *context.Context) {
branches, err := ctx.Repo.Repository.GetBranches()
if err != nil {
ctx.APIError(500, "GetBranches", err)
diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go
index f64e663466..7939a58424 100644
--- a/routers/api/v1/repo/file.go
+++ b/routers/api/v1/repo/file.go
@@ -8,12 +8,12 @@ import (
"github.com/gogits/git-module"
"github.com/gogits/gogs/models"
- "github.com/gogits/gogs/modules/middleware"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/repo"
)
// 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() {
ctx.Error(404)
return
@@ -34,7 +34,7 @@ func GetRawFile(ctx *middleware.Context) {
}
// 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"))
gitRepo, err := git.OpenRepository(repoPath)
if err != nil {
diff --git a/routers/api/v1/repo/hooks.go b/routers/api/v1/repo/hooks.go
index e0893a014c..954e36be62 100644
--- a/routers/api/v1/repo/hooks.go
+++ b/routers/api/v1/repo/hooks.go
@@ -12,12 +12,12 @@ import (
api "github.com/gogits/go-gogs-client"
"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"
)
// 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)
if err != nil {
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
-func CreateHook(ctx *middleware.Context, form api.CreateHookOption) {
+func CreateHook(ctx *context.Context, form api.CreateHookOption) {
if !models.IsValidHookTaskType(form.Type) {
ctx.APIError(422, "", "Invalid hook type")
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
-func EditHook(ctx *middleware.Context, form api.EditHookOption) {
+func EditHook(ctx *context.Context, form api.EditHookOption) {
w, err := models.GetWebhookByID(ctx.ParamsInt64(":id"))
if err != nil {
if models.IsErrWebhookNotExist(err) {
diff --git a/routers/api/v1/repo/keys.go b/routers/api/v1/repo/keys.go
index 2ec0b754f2..9de16ff0b4 100644
--- a/routers/api/v1/repo/keys.go
+++ b/routers/api/v1/repo/keys.go
@@ -10,7 +10,7 @@ import (
api "github.com/gogits/go-gogs-client"
"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/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
-func ListDeployKeys(ctx *middleware.Context) {
+func ListDeployKeys(ctx *context.Context) {
keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID)
if err != nil {
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
-func GetDeployKey(ctx *middleware.Context) {
+func GetDeployKey(ctx *context.Context) {
key, err := models.GetDeployKeyByID(ctx.ParamsInt64(":id"))
if err != nil {
if models.IsErrDeployKeyNotExist(err) {
@@ -61,7 +61,7 @@ func GetDeployKey(ctx *middleware.Context) {
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) {
ctx.APIError(422, "", "Unable to verify key content")
} 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 {
case models.IsErrKeyAlreadyExist(err):
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
-func CreateDeployKey(ctx *middleware.Context, form api.CreateKeyOption) {
+func CreateDeployKey(ctx *context.Context, form api.CreateKeyOption) {
content, err := models.CheckPublicKeyString(form.Key)
if err != nil {
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
-func DeleteDeploykey(ctx *middleware.Context) {
+func DeleteDeploykey(ctx *context.Context) {
if err := models.DeleteDeployKey(ctx.User, ctx.ParamsInt64(":id")); err != nil {
if models.IsErrKeyAccessDenied(err) {
ctx.APIError(403, "", "You do not have access to this key")
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index eb00aa886f..fc7a9cd442 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -13,14 +13,14 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
- "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/routers/api/v1/convert"
)
// https://github.com/gogits/go-gogs-client/wiki/Repositories#search-repositories
-func Search(ctx *middleware.Context) {
+func Search(ctx *context.Context) {
opt := models.SearchOption{
Keyword: path.Base(ctx.Query("q")),
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
-func ListMyRepos(ctx *middleware.Context) {
+func ListMyRepos(ctx *context.Context) {
ownRepos, err := models.GetRepositories(ctx.User.Id, true)
if err != nil {
ctx.APIError(500, "GetRepositories", err)
@@ -113,7 +113,7 @@ func ListMyRepos(ctx *middleware.Context) {
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{
Name: opt.Name,
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
-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.
if ctx.User.IsOrganization() {
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)
}
-func CreateOrgRepo(ctx *middleware.Context, opt api.CreateRepoOption) {
+func CreateOrgRepo(ctx *context.Context, opt api.CreateRepoOption) {
org, err := models.GetOrgByName(ctx.Params(":org"))
if err != nil {
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
-func Migrate(ctx *middleware.Context, form auth.MigrateRepoForm) {
+func Migrate(ctx *context.Context, form auth.MigrateRepoForm) {
ctxUser := ctx.User
// Not equal means context user is an organization,
// 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}))
}
-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"))
if err != nil {
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
-func Get(ctx *middleware.Context) {
+func Get(ctx *context.Context) {
owner, repo := parseOwnerAndRepo(ctx)
if ctx.Written() {
return
@@ -277,7 +277,7 @@ func Get(ctx *middleware.Context) {
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories#delete
-func Delete(ctx *middleware.Context) {
+func Delete(ctx *context.Context) {
owner, repo := parseOwnerAndRepo(ctx)
if ctx.Written() {
return
diff --git a/routers/api/v1/user/app.go b/routers/api/v1/user/app.go
index 00aacbdc1b..87413becf0 100644
--- a/routers/api/v1/user/app.go
+++ b/routers/api/v1/user/app.go
@@ -8,11 +8,11 @@ import (
api "github.com/gogits/go-gogs-client"
"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
-func ListAccessTokens(ctx *middleware.Context) {
+func ListAccessTokens(ctx *context.Context) {
tokens, err := models.ListAccessTokens(ctx.User.Id)
if err != nil {
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
-func CreateAccessToken(ctx *middleware.Context, form api.CreateAccessTokenOption) {
+func CreateAccessToken(ctx *context.Context, form api.CreateAccessTokenOption) {
t := &models.AccessToken{
UID: ctx.User.Id,
Name: form.Name,
diff --git a/routers/api/v1/user/email.go b/routers/api/v1/user/email.go
index fd9193bd74..66bddd24cf 100644
--- a/routers/api/v1/user/email.go
+++ b/routers/api/v1/user/email.go
@@ -8,13 +8,13 @@ import (
api "github.com/gogits/go-gogs-client"
"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/routers/api/v1/convert"
)
// 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)
if err != nil {
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
-func AddEmail(ctx *middleware.Context, form api.CreateEmailOption) {
+func AddEmail(ctx *context.Context, form api.CreateEmailOption) {
if len(form.Emails) == 0 {
ctx.Status(422)
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
-func DeleteEmail(ctx *middleware.Context, form api.CreateEmailOption) {
+func DeleteEmail(ctx *context.Context, form api.CreateEmailOption) {
if len(form.Emails) == 0 {
ctx.Status(204)
return
diff --git a/routers/api/v1/user/followers.go b/routers/api/v1/user/followers.go
index 0a28979647..b7166abb3e 100644
--- a/routers/api/v1/user/followers.go
+++ b/routers/api/v1/user/followers.go
@@ -8,11 +8,11 @@ import (
api "github.com/gogits/go-gogs-client"
"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"
)
-func responseApiUsers(ctx *middleware.Context, users []*models.User) {
+func responseApiUsers(ctx *context.Context, users []*models.User) {
apiUsers := make([]*api.User, len(users))
for i := range users {
apiUsers[i] = convert.ToApiUser(users[i])
@@ -20,7 +20,7 @@ func responseApiUsers(ctx *middleware.Context, users []*models.User) {
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"))
if err != nil {
ctx.APIError(500, "GetUserFollowers", err)
@@ -29,12 +29,12 @@ func listUserFollowers(ctx *middleware.Context, u *models.User) {
responseApiUsers(ctx, users)
}
-func ListMyFollowers(ctx *middleware.Context) {
+func ListMyFollowers(ctx *context.Context) {
listUserFollowers(ctx, ctx.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)
if ctx.Written() {
return
@@ -42,7 +42,7 @@ func ListFollowers(ctx *middleware.Context) {
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"))
if err != nil {
ctx.APIError(500, "GetFollowing", err)
@@ -51,12 +51,12 @@ func listUserFollowing(ctx *middleware.Context, u *models.User) {
responseApiUsers(ctx, users)
}
-func ListMyFollowing(ctx *middleware.Context) {
+func ListMyFollowing(ctx *context.Context) {
listUserFollowing(ctx, ctx.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)
if ctx.Written() {
return
@@ -64,7 +64,7 @@ func ListFollowing(ctx *middleware.Context) {
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) {
ctx.Status(204)
} 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
-func CheckMyFollowing(ctx *middleware.Context) {
+func CheckMyFollowing(ctx *context.Context) {
target := GetUserByParams(ctx)
if ctx.Written() {
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
-func CheckFollowing(ctx *middleware.Context) {
+func CheckFollowing(ctx *context.Context) {
u := GetUserByParams(ctx)
if ctx.Written() {
return
@@ -95,7 +95,7 @@ func CheckFollowing(ctx *middleware.Context) {
}
// 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)
if ctx.Written() {
return
@@ -108,7 +108,7 @@ func Follow(ctx *middleware.Context) {
}
// 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)
if ctx.Written() {
return
diff --git a/routers/api/v1/user/keys.go b/routers/api/v1/user/keys.go
index 8ba73d9934..6f387edcb1 100644
--- a/routers/api/v1/user/keys.go
+++ b/routers/api/v1/user/keys.go
@@ -8,13 +8,13 @@ import (
api "github.com/gogits/go-gogs-client"
"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/routers/api/v1/convert"
"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))
if err != nil {
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.
-func GetUserByParams(ctx *middleware.Context) *models.User {
+func GetUserByParams(ctx *context.Context) *models.User {
return GetUserByParamsName(ctx, ":username")
}
@@ -36,7 +36,7 @@ func composePublicKeysAPILink() string {
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)
if err != nil {
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
-func ListMyPublicKeys(ctx *middleware.Context) {
+func ListMyPublicKeys(ctx *context.Context) {
listPublicKeys(ctx, ctx.User.Id)
}
// 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)
if ctx.Written() {
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
-func GetPublicKey(ctx *middleware.Context) {
+func GetPublicKey(ctx *context.Context) {
key, err := models.GetPublicKeyByID(ctx.ParamsInt64(":id"))
if err != nil {
if models.IsErrKeyNotExist(err) {
@@ -83,7 +83,7 @@ func GetPublicKey(ctx *middleware.Context) {
}
// 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)
if err != nil {
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
-func CreatePublicKey(ctx *middleware.Context, form api.CreateKeyOption) {
+func CreatePublicKey(ctx *context.Context, form api.CreateKeyOption) {
CreateUserPublicKey(ctx, form, ctx.User.Id)
}
// 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 models.IsErrKeyAccessDenied(err) {
ctx.APIError(403, "", "You do not have access to this key")
diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go
index 6d4b52ffdb..d08fd20241 100644
--- a/routers/api/v1/user/user.go
+++ b/routers/api/v1/user/user.go
@@ -10,11 +10,11 @@ import (
api "github.com/gogits/go-gogs-client"
"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
-func Search(ctx *middleware.Context) {
+func Search(ctx *context.Context) {
opt := models.SearchOption{
Keyword: ctx.Query("q"),
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
-func GetInfo(ctx *middleware.Context) {
+func GetInfo(ctx *context.Context) {
u, err := models.GetUserByName(ctx.Params(":username"))
if err != nil {
if models.IsErrUserNotExist(err) {
diff --git a/routers/dev/template.go b/routers/dev/template.go
index 5548f51478..ee81f3804a 100644
--- a/routers/dev/template.go
+++ b/routers/dev/template.go
@@ -7,11 +7,11 @@ package dev
import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
- "github.com/gogits/gogs/modules/middleware"
+ "github.com/gogits/gogs/modules/context"
"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["AppName"] = setting.AppName
ctx.Data["AppVer"] = setting.AppVer
diff --git a/routers/home.go b/routers/home.go
index 4e1ebe9896..298b4f409b 100644
--- a/routers/home.go
+++ b/routers/home.go
@@ -11,7 +11,7 @@ import (
"github.com/gogits/gogs/models"
"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/routers/user"
)
@@ -21,7 +21,7 @@ const (
EXPLORE_REPOS base.TplName = "explore/repos"
)
-func Home(ctx *middleware.Context) {
+func Home(ctx *context.Context) {
if ctx.IsSigned {
if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
@@ -43,7 +43,7 @@ func Home(ctx *middleware.Context) {
ctx.HTML(200, HOME)
}
-func Explore(ctx *middleware.Context) {
+func Explore(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("explore")
ctx.Data["PageIsExplore"] = true
ctx.Data["PageIsExploreRepositories"] = true
@@ -71,7 +71,7 @@ func Explore(ctx *middleware.Context) {
ctx.HTML(200, EXPLORE_REPOS)
}
-func NotFound(ctx *middleware.Context) {
+func NotFound(ctx *context.Context) {
ctx.Data["Title"] = "Page Not Found"
ctx.Handle(404, "home.NotFound", nil)
}
diff --git a/routers/install.go b/routers/install.go
index 844f48bd04..99380e1b92 100644
--- a/routers/install.go
+++ b/routers/install.go
@@ -22,11 +22,11 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/cron"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/mailer"
"github.com/gogits/gogs/modules/markdown"
- "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/modules/ssh"
"github.com/gogits/gogs/modules/template/highlight"
@@ -97,7 +97,7 @@ func GlobalInit() {
markdown.BuildSanitizer()
}
-func InstallInit(ctx *middleware.Context) {
+func InstallInit(ctx *context.Context) {
if setting.InstallLock {
ctx.Handle(404, "Install", errors.New("Installation is prohibited"))
return
@@ -116,7 +116,7 @@ func InstallInit(ctx *middleware.Context) {
ctx.Data["DbOptions"] = dbOpts
}
-func Install(ctx *middleware.Context) {
+func Install(ctx *context.Context) {
form := auth.InstallForm{}
// Database settings
@@ -177,7 +177,7 @@ func Install(ctx *middleware.Context) {
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
if ctx.HasError() {
diff --git a/routers/org/members.go b/routers/org/members.go
index a0a3051d4e..1d720ce617 100644
--- a/routers/org/members.go
+++ b/routers/org/members.go
@@ -9,8 +9,8 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
- "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
)
@@ -19,7 +19,7 @@ const (
MEMBER_INVITE base.TplName = "org/member/invite"
)
-func Members(ctx *middleware.Context) {
+func Members(ctx *context.Context) {
org := ctx.Org.Organization
ctx.Data["Title"] = org.FullName
ctx.Data["PageIsOrgMembers"] = true
@@ -33,7 +33,7 @@ func Members(ctx *middleware.Context) {
ctx.HTML(200, MEMBERS)
}
-func MembersAction(ctx *middleware.Context) {
+func MembersAction(ctx *context.Context) {
uid := com.StrTo(ctx.Query("uid")).MustInt64()
if uid == 0 {
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
ctx.Data["Title"] = org.FullName
ctx.Data["PageIsOrgMembers"] = true
diff --git a/routers/org/org.go b/routers/org/org.go
index dff11be47f..1257c108d0 100644
--- a/routers/org/org.go
+++ b/routers/org/org.go
@@ -8,8 +8,8 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
- "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
)
@@ -17,12 +17,12 @@ const (
CREATE base.TplName = "org/create"
)
-func Create(ctx *middleware.Context) {
+func Create(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("new_org")
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")
if ctx.HasError() {
diff --git a/routers/org/setting.go b/routers/org/setting.go
index 29ce34f5d9..c50e18d7c9 100644
--- a/routers/org/setting.go
+++ b/routers/org/setting.go
@@ -12,8 +12,8 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
- "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/routers/user"
)
@@ -24,13 +24,13 @@ const (
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["PageIsSettingsOptions"] = true
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["PageIsSettingsOptions"] = true
@@ -85,7 +85,7 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateOrgSettingForm) {
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
if err := user.UpdateAvatarSetting(ctx, form, ctx.Org.Organization); err != nil {
ctx.Flash.Error(err.Error())
@@ -96,7 +96,7 @@ func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) {
ctx.Redirect(ctx.Org.OrgLink + "/settings")
}
-func SettingsDeleteAvatar(ctx *middleware.Context) {
+func SettingsDeleteAvatar(ctx *context.Context) {
if err := ctx.Org.Organization.DeleteAvatar(); err != nil {
ctx.Flash.Error(err.Error())
}
@@ -104,7 +104,7 @@ func SettingsDeleteAvatar(ctx *middleware.Context) {
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["PageIsSettingsDelete"] = true
@@ -136,7 +136,7 @@ func SettingsDelete(ctx *middleware.Context) {
ctx.HTML(200, SETTINGS_DELETE)
}
-func Webhooks(ctx *middleware.Context) {
+func Webhooks(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("org.settings")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["BaseLink"] = ctx.Org.OrgLink
@@ -164,7 +164,7 @@ func Webhooks(ctx *middleware.Context) {
ctx.HTML(200, SETTINGS_HOOKS)
}
-func DeleteWebhook(ctx *middleware.Context) {
+func DeleteWebhook(ctx *context.Context) {
if err := models.DeleteWebhook(ctx.QueryInt64("id")); err != nil {
ctx.Flash.Error("DeleteWebhook: " + err.Error())
} else {
diff --git a/routers/org/teams.go b/routers/org/teams.go
index e4a6afcf45..e8ae8291b7 100644
--- a/routers/org/teams.go
+++ b/routers/org/teams.go
@@ -12,8 +12,8 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
- "github.com/gogits/gogs/modules/middleware"
)
const (
@@ -23,7 +23,7 @@ const (
TEAM_REPOSITORIES base.TplName = "org/team/repositories"
)
-func Teams(ctx *middleware.Context) {
+func Teams(ctx *context.Context) {
org := ctx.Org.Organization
ctx.Data["Title"] = org.FullName
ctx.Data["PageIsOrgTeams"] = true
@@ -39,7 +39,7 @@ func Teams(ctx *middleware.Context) {
ctx.HTML(200, TEAMS)
}
-func TeamsAction(ctx *middleware.Context) {
+func TeamsAction(ctx *context.Context) {
uid := com.StrTo(ctx.Query("uid")).MustInt64()
if uid == 0 {
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 {
ctx.Error(404)
return
@@ -141,7 +141,7 @@ func TeamsRepoAction(ctx *middleware.Context) {
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["PageIsOrgTeams"] = true
ctx.Data["PageIsOrgTeamsNew"] = true
@@ -149,7 +149,7 @@ func NewTeam(ctx *middleware.Context) {
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["PageIsOrgTeams"] = 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)
}
-func TeamMembers(ctx *middleware.Context) {
+func TeamMembers(ctx *context.Context) {
ctx.Data["Title"] = ctx.Org.Team.Name
ctx.Data["PageIsOrgTeams"] = true
if err := ctx.Org.Team.GetMembers(); err != nil {
@@ -205,7 +205,7 @@ func TeamMembers(ctx *middleware.Context) {
ctx.HTML(200, TEAM_MEMBERS)
}
-func TeamRepositories(ctx *middleware.Context) {
+func TeamRepositories(ctx *context.Context) {
ctx.Data["Title"] = ctx.Org.Team.Name
ctx.Data["PageIsOrgTeams"] = true
if err := ctx.Org.Team.GetRepositories(); err != nil {
@@ -215,7 +215,7 @@ func TeamRepositories(ctx *middleware.Context) {
ctx.HTML(200, TEAM_REPOSITORIES)
}
-func EditTeam(ctx *middleware.Context) {
+func EditTeam(ctx *context.Context) {
ctx.Data["Title"] = ctx.Org.Organization.FullName
ctx.Data["PageIsOrgTeams"] = true
ctx.Data["team_name"] = ctx.Org.Team.Name
@@ -223,7 +223,7 @@ func EditTeam(ctx *middleware.Context) {
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
ctx.Data["Title"] = ctx.Org.Organization.FullName
ctx.Data["PageIsOrgTeams"] = true
@@ -270,7 +270,7 @@ func EditTeamPost(ctx *middleware.Context, form auth.CreateTeamForm) {
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 {
ctx.Flash.Error("DeleteTeam: " + err.Error())
} else {
diff --git a/routers/repo/branch.go b/routers/repo/branch.go
index c340b2bf6b..00f30b0f13 100644
--- a/routers/repo/branch.go
+++ b/routers/repo/branch.go
@@ -6,14 +6,14 @@ package repo
import (
"github.com/gogits/gogs/modules/base"
- "github.com/gogits/gogs/modules/middleware"
+ "github.com/gogits/gogs/modules/context"
)
const (
BRANCH base.TplName = "repo/branch"
)
-func Branches(ctx *middleware.Context) {
+func Branches(ctx *context.Context) {
ctx.Data["Title"] = "Branches"
ctx.Data["IsRepoToolbarBranches"] = true
diff --git a/routers/repo/commit.go b/routers/repo/commit.go
index 781c3da946..97584c4d1a 100644
--- a/routers/repo/commit.go
+++ b/routers/repo/commit.go
@@ -14,7 +14,7 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
- "github.com/gogits/gogs/modules/middleware"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/setting"
)
@@ -23,7 +23,7 @@ const (
DIFF base.TplName = "repo/diff"
)
-func RefCommits(ctx *middleware.Context) {
+func RefCommits(ctx *context.Context) {
switch {
case len(ctx.Repo.TreeName) == 0:
Commits(ctx)
@@ -43,7 +43,7 @@ func RenderIssueLinks(oldCommits *list.List, repoLink string) *list.List {
return newCommits
}
-func Commits(ctx *middleware.Context) {
+func Commits(ctx *context.Context) {
ctx.Data["PageIsCommits"] = true
commitsCount, err := ctx.Repo.Commit.CommitsCount()
@@ -75,7 +75,7 @@ func Commits(ctx *middleware.Context) {
ctx.HTML(200, COMMITS)
}
-func SearchCommits(ctx *middleware.Context) {
+func SearchCommits(ctx *context.Context) {
ctx.Data["PageIsCommits"] = true
keyword := ctx.Query("q")
@@ -101,7 +101,7 @@ func SearchCommits(ctx *middleware.Context) {
ctx.HTML(200, COMMITS)
}
-func FileHistory(ctx *middleware.Context) {
+func FileHistory(ctx *context.Context) {
ctx.Data["IsRepoToolbarCommits"] = true
fileName := ctx.Repo.TreeName
@@ -143,7 +143,7 @@ func FileHistory(ctx *middleware.Context) {
ctx.HTML(200, COMMITS)
}
-func Diff(ctx *middleware.Context) {
+func Diff(ctx *context.Context) {
ctx.Data["PageIsDiff"] = true
userName := ctx.Repo.Owner.Name
@@ -187,7 +187,7 @@ func Diff(ctx *middleware.Context) {
ctx.HTML(200, DIFF)
}
-func CompareDiff(ctx *middleware.Context) {
+func CompareDiff(ctx *context.Context) {
ctx.Data["IsRepoToolbarCommits"] = true
ctx.Data["IsDiffCompare"] = true
userName := ctx.Repo.Owner.Name
diff --git a/routers/repo/download.go b/routers/repo/download.go
index a10792b87f..3329073e0c 100644
--- a/routers/repo/download.go
+++ b/routers/repo/download.go
@@ -11,10 +11,10 @@ import (
"github.com/gogits/git-module"
"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)
n, _ := reader.Read(buf)
if n > 0 {
@@ -36,7 +36,7 @@ func ServeData(ctx *middleware.Context, name string, reader io.Reader) error {
return err
}
-func ServeBlob(ctx *middleware.Context, blob *git.Blob) error {
+func ServeBlob(ctx *context.Context, blob *git.Blob) error {
dataRc, err := blob.Data()
if err != nil {
return err
@@ -45,7 +45,7 @@ func ServeBlob(ctx *middleware.Context, blob *git.Blob) error {
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)
if err != nil {
if git.IsErrNotExist(err) {
diff --git a/routers/repo/http.go b/routers/repo/http.go
index f9600c94de..b273b2334e 100644
--- a/routers/repo/http.go
+++ b/routers/repo/http.go
@@ -23,18 +23,18 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
- "github.com/gogits/gogs/modules/middleware"
"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.Data["ErrorMsg"] = "no basic auth and digit auth"
ctx.Error(401)
}
-func HTTP(ctx *middleware.Context) {
+func HTTP(ctx *context.Context) {
username := ctx.Params(":username")
reponame := strings.TrimSuffix(ctx.Params(":reponame"), ".git")
@@ -293,7 +293,7 @@ func getGitDir(config *Config, fPath string) (string, error) {
}
// 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) {
for _, route := range routes {
r.URL.Path = strings.ToLower(r.URL.Path) // blue: In case some repo name has upper case name
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 3a1049e65d..d66123f912 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -20,10 +20,10 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/mailer"
"github.com/gogits/gogs/modules/markdown"
- "github.com/gogits/gogs/modules/middleware"
"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 {
ctx.Handle(404, "MustEnableIssues", nil)
return
}
}
-func MustAllowPulls(ctx *middleware.Context) {
+func MustAllowPulls(ctx *context.Context) {
if !ctx.Repo.Repository.AllowsPulls() {
ctx.Handle(404, "MustAllowPulls", nil)
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)
if err != nil {
ctx.Handle(500, "RetrieveLabels.GetLabels: %v", err)
@@ -85,7 +85,7 @@ func RetrieveLabels(ctx *middleware.Context) {
ctx.Data["NumLabels"] = len(labels)
}
-func Issues(ctx *middleware.Context) {
+func Issues(ctx *context.Context) {
isPullList := ctx.Params(":type") == "pulls"
if isPullList {
MustAllowPulls(ctx)
@@ -250,7 +250,7 @@ func Issues(ctx *middleware.Context) {
ctx.HTML(200, ISSUES)
}
-func renderAttachmentSettings(ctx *middleware.Context) {
+func renderAttachmentSettings(ctx *context.Context) {
ctx.Data["RequireDropzone"] = true
ctx.Data["IsAttachmentEnabled"] = setting.AttachmentEnabled
ctx.Data["AttachmentAllowedTypes"] = setting.AttachmentAllowedTypes
@@ -258,7 +258,7 @@ func renderAttachmentSettings(ctx *middleware.Context) {
ctx.Data["AttachmentMaxFiles"] = setting.AttachmentMaxFiles
}
-func RetrieveRepoMilestonesAndAssignees(ctx *middleware.Context, repo *models.Repository) {
+func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repository) {
var err error
ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false)
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() {
return nil
}
@@ -298,7 +298,7 @@ func RetrieveRepoMetas(ctx *middleware.Context, repo *models.Repository) []*mode
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 bytes []byte
@@ -325,7 +325,7 @@ func getFileContentFromDefaultBranch(ctx *middleware.Context, filename string) (
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 {
content, found := getFileContentFromDefaultBranch(ctx, filename)
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["PageIsIssueList"] = true
setTemplateIfExists(ctx, ISSUE_TEMPLATE_KEY, IssueTemplateCandidates)
@@ -351,7 +351,7 @@ func NewIssue(ctx *middleware.Context) {
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 (
repo = ctx.Repo.Repository
err error
@@ -405,7 +405,7 @@ func ValidateRepoMetas(ctx *middleware.Context, form auth.CreateIssueForm) ([]in
return labelIDs, milestoneID, assigneeID
}
-func notifyWatchersAndMentions(ctx *middleware.Context, issue *models.Issue) {
+func notifyWatchersAndMentions(ctx *context.Context, issue *models.Issue) {
// Update mentions
mentions := markdown.MentionPattern.FindAllString(issue.Content, -1)
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["PageIsIssueList"] = true
renderAttachmentSettings(ctx)
@@ -494,7 +494,7 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
}
-func UploadIssueAttachment(ctx *middleware.Context) {
+func UploadIssueAttachment(ctx *context.Context) {
if !setting.AttachmentEnabled {
ctx.Error(404, "attachment is not enabled")
return
@@ -541,7 +541,7 @@ func UploadIssueAttachment(ctx *middleware.Context) {
})
}
-func ViewIssue(ctx *middleware.Context) {
+func ViewIssue(ctx *context.Context) {
ctx.Data["RequireDropzone"] = true
renderAttachmentSettings(ctx)
@@ -706,7 +706,7 @@ func ViewIssue(ctx *middleware.Context) {
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"))
if err != nil {
if models.IsErrIssueNotExist(err) {
@@ -719,7 +719,7 @@ func getActionIssue(ctx *middleware.Context) *models.Issue {
return issue
}
-func UpdateIssueTitle(ctx *middleware.Context) {
+func UpdateIssueTitle(ctx *context.Context) {
issue := getActionIssue(ctx)
if ctx.Written() {
return
@@ -746,7 +746,7 @@ func UpdateIssueTitle(ctx *middleware.Context) {
})
}
-func UpdateIssueContent(ctx *middleware.Context) {
+func UpdateIssueContent(ctx *context.Context) {
issue := getActionIssue(ctx)
if ctx.Written() {
return
@@ -768,7 +768,7 @@ func UpdateIssueContent(ctx *middleware.Context) {
})
}
-func UpdateIssueLabel(ctx *middleware.Context) {
+func UpdateIssueLabel(ctx *context.Context) {
issue := getActionIssue(ctx)
if ctx.Written() {
return
@@ -809,7 +809,7 @@ func UpdateIssueLabel(ctx *middleware.Context) {
})
}
-func UpdateIssueMilestone(ctx *middleware.Context) {
+func UpdateIssueMilestone(ctx *context.Context) {
issue := getActionIssue(ctx)
if ctx.Written() {
return
@@ -836,7 +836,7 @@ func UpdateIssueMilestone(ctx *middleware.Context) {
})
}
-func UpdateIssueAssignee(ctx *middleware.Context) {
+func UpdateIssueAssignee(ctx *context.Context) {
issue := getActionIssue(ctx)
if ctx.Written() {
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"))
if err != nil {
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)
}
-func UpdateCommentContent(ctx *middleware.Context) {
+func UpdateCommentContent(ctx *context.Context) {
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
if err != nil {
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["PageIsIssueList"] = true
ctx.Data["PageIsLabels"] = true
@@ -1012,7 +1012,7 @@ func Labels(ctx *middleware.Context) {
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["PageIsLabels"] = true
@@ -1034,7 +1034,7 @@ func NewLabel(ctx *middleware.Context, form auth.CreateLabelForm) {
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)
if err != nil {
switch {
@@ -1056,7 +1056,7 @@ func UpdateLabel(ctx *middleware.Context, form auth.CreateLabelForm) {
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 {
ctx.Flash.Error("DeleteLabel: " + err.Error())
} else {
@@ -1069,7 +1069,7 @@ func DeleteLabel(ctx *middleware.Context) {
return
}
-func Milestones(ctx *middleware.Context) {
+func Milestones(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.milestones")
ctx.Data["PageIsIssueList"] = true
ctx.Data["PageIsMilestones"] = true
@@ -1113,7 +1113,7 @@ func Milestones(ctx *middleware.Context) {
ctx.HTML(200, MILESTONE)
}
-func NewMilestone(ctx *middleware.Context) {
+func NewMilestone(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.milestones.new")
ctx.Data["PageIsIssueList"] = true
ctx.Data["PageIsMilestones"] = true
@@ -1122,7 +1122,7 @@ func NewMilestone(ctx *middleware.Context) {
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["PageIsIssueList"] = true
ctx.Data["PageIsMilestones"] = true
@@ -1158,7 +1158,7 @@ func NewMilestonePost(ctx *middleware.Context, form auth.CreateMilestoneForm) {
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["PageIsMilestones"] = true
ctx.Data["PageIsEditMilestone"] = true
@@ -1182,7 +1182,7 @@ func EditMilestone(ctx *middleware.Context) {
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["PageIsMilestones"] = true
ctx.Data["PageIsEditMilestone"] = true
@@ -1225,7 +1225,7 @@ func EditMilestonePost(ctx *middleware.Context, form auth.CreateMilestoneForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/milestones")
}
-func ChangeMilestonStatus(ctx *middleware.Context) {
+func ChangeMilestonStatus(ctx *context.Context) {
m, err := models.GetMilestoneByID(ctx.ParamsInt64(":id"))
if err != nil {
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 {
ctx.Flash.Error("DeleteMilestoneByID: " + err.Error())
} else {
diff --git a/routers/repo/pull.go b/routers/repo/pull.go
index fd4f6f69c5..c2147bbaf5 100644
--- a/routers/repo/pull.go
+++ b/routers/repo/pull.go
@@ -16,8 +16,8 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
- "github.com/gogits/gogs/modules/middleware"
"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"))
if err != nil {
if models.IsErrRepoNotExist(err) {
@@ -73,7 +73,7 @@ func getForkRepository(ctx *middleware.Context) *models.Repository {
return forkRepo
}
-func Fork(ctx *middleware.Context) {
+func Fork(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("new_fork")
getForkRepository(ctx)
@@ -85,7 +85,7 @@ func Fork(ctx *middleware.Context) {
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")
forkRepo := getForkRepository(ctx)
@@ -138,7 +138,7 @@ func ForkPost(ctx *middleware.Context, form auth.CreateRepoForm) {
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"))
if err != nil {
if models.IsErrIssueNotExist(err) {
@@ -178,7 +178,7 @@ func checkPullInfo(ctx *middleware.Context) *models.Issue {
return issue
}
-func PrepareMergedViewPullInfo(ctx *middleware.Context, pull *models.Issue) {
+func PrepareMergedViewPullInfo(ctx *context.Context, pull *models.Issue) {
ctx.Data["HasMerged"] = true
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
ctx.Data["HeadTarget"] = pull.HeadUserName + "/" + pull.HeadBranch
@@ -246,7 +246,7 @@ func PrepareViewPullInfo(ctx *middleware.Context, pull *models.Issue) *git.PullR
return prInfo
}
-func ViewPullCommits(ctx *middleware.Context) {
+func ViewPullCommits(ctx *context.Context) {
ctx.Data["PageIsPullCommits"] = true
pull := checkPullInfo(ctx)
@@ -296,7 +296,7 @@ func ViewPullCommits(ctx *middleware.Context) {
ctx.HTML(200, PULL_COMMITS)
}
-func ViewPullFiles(ctx *middleware.Context) {
+func ViewPullFiles(ctx *context.Context) {
ctx.Data["PageIsPullFiles"] = true
pull := checkPullInfo(ctx)
@@ -377,7 +377,7 @@ func ViewPullFiles(ctx *middleware.Context) {
ctx.HTML(200, PULL_FILES)
}
-func MergePullRequest(ctx *middleware.Context) {
+func MergePullRequest(ctx *context.Context) {
issue := checkPullInfo(ctx)
if ctx.Written() {
return
@@ -413,7 +413,7 @@ func MergePullRequest(ctx *middleware.Context) {
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
// Get compared branches information
@@ -520,7 +520,7 @@ func ParseCompareInfo(ctx *middleware.Context) (*models.User, *models.Repository
}
func PrepareCompareDiff(
- ctx *middleware.Context,
+ ctx *context.Context,
headUser *models.User,
headRepo *models.Repository,
headGitRepo *git.Repository,
@@ -576,7 +576,7 @@ func PrepareCompareDiff(
return false
}
-func CompareAndPullRequest(ctx *middleware.Context) {
+func CompareAndPullRequest(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes")
ctx.Data["PageIsComparePull"] = true
ctx.Data["IsDiffCompare"] = true
@@ -618,7 +618,7 @@ func CompareAndPullRequest(ctx *middleware.Context) {
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["PageIsComparePull"] = 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))
}
-func TriggerTask(ctx *middleware.Context) {
+func TriggerTask(ctx *context.Context) {
branch := ctx.Query("branch")
secret := ctx.Query("secret")
if len(branch) == 0 || len(secret) == 0 {
diff --git a/routers/repo/release.go b/routers/repo/release.go
index 4073fde82e..8985cdb8f5 100644
--- a/routers/repo/release.go
+++ b/routers/repo/release.go
@@ -10,9 +10,9 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/markdown"
- "github.com/gogits/gogs/modules/middleware"
)
const (
@@ -21,7 +21,7 @@ const (
)
// 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.
if repoCtx.BranchName == release.Target {
release.NumCommitsBehind = repoCtx.CommitsCount - release.NumCommits
@@ -43,7 +43,7 @@ func calReleaseNumCommitsBehind(repoCtx *middleware.RepoContext, release *models
return nil
}
-func Releases(ctx *middleware.Context) {
+func Releases(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.release.releases")
ctx.Data["PageIsReleaseList"] = true
@@ -141,14 +141,14 @@ func Releases(ctx *middleware.Context) {
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["PageIsReleaseList"] = true
ctx.Data["tag_target"] = ctx.Repo.Repository.DefaultBranch
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["PageIsReleaseList"] = true
@@ -201,7 +201,7 @@ func NewReleasePost(ctx *middleware.Context, form auth.NewReleaseForm) {
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["PageIsReleaseList"] = true
ctx.Data["PageIsEditRelease"] = true
@@ -226,7 +226,7 @@ func EditRelease(ctx *middleware.Context) {
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["PageIsReleaseList"] = true
ctx.Data["PageIsEditRelease"] = true
@@ -263,7 +263,7 @@ func EditReleasePost(ctx *middleware.Context, form auth.EditReleaseForm) {
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 {
ctx.Flash.Error("DeleteReleaseByID: " + err.Error())
} else {
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index eb944acebc..f9835bd2f9 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -17,8 +17,8 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
- "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
)
@@ -27,13 +27,13 @@ const (
MIGRATE base.TplName = "repo/migrate"
)
-func MustBeNotBare(ctx *middleware.Context) {
+func MustBeNotBare(ctx *context.Context) {
if ctx.Repo.Repository.IsBare {
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")
if err != nil {
ctx.Handle(500, "GetOwnedOrgsByUserIDDesc", err)
@@ -64,7 +64,7 @@ func checkContextUser(ctx *middleware.Context, uid int64) *models.User {
return org
}
-func Create(ctx *middleware.Context) {
+func Create(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("new_repo")
// Give default value for template to render.
@@ -84,7 +84,7 @@ func Create(ctx *middleware.Context) {
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 {
case models.IsErrReachLimitOfRepo(err):
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["Gitignores"] = models.Gitignores
@@ -144,7 +144,7 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) {
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["private"] = ctx.User.LastRepoVisibility
ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate
@@ -159,7 +159,7 @@ func Migrate(ctx *middleware.Context) {
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")
ctxUser := checkContextUser(ctx, form.Uid)
@@ -227,7 +227,7 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) {
handleCreateError(ctx, ctxUser, err, "MigratePost", MIGRATE, &form)
}
-func Action(ctx *middleware.Context) {
+func Action(ctx *context.Context) {
var err error
switch ctx.Params(":action") {
case "watch":
@@ -261,7 +261,7 @@ func Action(ctx *middleware.Context) {
ctx.Redirect(redirectTo)
}
-func Download(ctx *middleware.Context) {
+func Download(ctx *context.Context) {
var (
uri = ctx.Params("*")
refName string
diff --git a/routers/repo/setting.go b/routers/repo/setting.go
index cf6f6a11c7..6785722422 100644
--- a/routers/repo/setting.go
+++ b/routers/repo/setting.go
@@ -13,9 +13,9 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/mailer"
- "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
)
@@ -27,13 +27,13 @@ const (
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["PageIsSettingsOptions"] = true
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["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["PageIsSettingsCollaboration"] = true
@@ -285,7 +285,7 @@ func Collaboration(ctx *middleware.Context) {
ctx.HTML(200, COLLABORATION)
}
-func CollaborationPost(ctx *middleware.Context) {
+func CollaborationPost(ctx *context.Context) {
name := strings.ToLower(ctx.Query("collaborator"))
if len(name) == 0 || ctx.Repo.Owner.LowerName == name {
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)
}
-func ChangeCollaborationAccessMode(ctx *middleware.Context) {
+func ChangeCollaborationAccessMode(ctx *context.Context) {
if err := ctx.Repo.Repository.ChangeCollaborationAccessMode(
ctx.QueryInt64("uid"),
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 {
ctx.Flash.Error("DeleteCollaboration: " + err.Error())
} 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"))
if err != nil {
if models.IsErrUserNotExist(err) {
@@ -377,7 +377,7 @@ func parseOwnerAndRepo(ctx *middleware.Context) (*models.User, *models.Repositor
return owner, repo
}
-func GitHooks(ctx *middleware.Context) {
+func GitHooks(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.githooks")
ctx.Data["PageIsSettingsGitHooks"] = true
@@ -391,7 +391,7 @@ func GitHooks(ctx *middleware.Context) {
ctx.HTML(200, GITHOOKS)
}
-func GitHooksEdit(ctx *middleware.Context) {
+func GitHooksEdit(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.githooks")
ctx.Data["PageIsSettingsGitHooks"] = true
@@ -409,7 +409,7 @@ func GitHooksEdit(ctx *middleware.Context) {
ctx.HTML(200, GITHOOK_EDIT)
}
-func GitHooksEditPost(ctx *middleware.Context) {
+func GitHooksEditPost(ctx *context.Context) {
name := ctx.Params(":name")
hook, err := ctx.Repo.GitRepo.GetHook(name)
if err != nil {
@@ -428,7 +428,7 @@ func GitHooksEditPost(ctx *middleware.Context) {
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["PageIsSettingsKeys"] = true
@@ -442,7 +442,7 @@ func DeployKeys(ctx *middleware.Context) {
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["PageIsSettingsKeys"] = true
@@ -492,7 +492,7 @@ func DeployKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) {
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 {
ctx.Flash.Error("DeleteDeployKey: " + err.Error())
} else {
diff --git a/routers/repo/view.go b/routers/repo/view.go
index efff31a9a0..f4242cd52d 100644
--- a/routers/repo/view.go
+++ b/routers/repo/view.go
@@ -16,9 +16,9 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/markdown"
- "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/template"
"github.com/gogits/gogs/modules/template/highlight"
)
@@ -29,7 +29,7 @@ const (
FORKS base.TplName = "repo/forks"
)
-func Home(ctx *middleware.Context) {
+func Home(ctx *context.Context) {
ctx.Data["Title"] = ctx.Repo.Repository.Name
ctx.Data["PageIsViewCode"] = true
ctx.Data["RequireHighlightJS"] = true
@@ -219,7 +219,7 @@ func Home(ctx *middleware.Context) {
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")
if page <= 0 {
page = 1
@@ -237,21 +237,21 @@ func RenderUserCards(ctx *middleware.Context, total int, getter func(page int) (
ctx.HTML(200, tpl)
}
-func Watchers(ctx *middleware.Context) {
+func Watchers(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.watchers")
ctx.Data["CardsTitle"] = ctx.Tr("repo.watchers")
ctx.Data["PageIsWatchers"] = true
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["CardsTitle"] = ctx.Tr("repo.stargazers")
ctx.Data["PageIsStargazers"] = true
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")
forks, err := ctx.Repo.Repository.GetForks()
diff --git a/routers/repo/webhook.go b/routers/repo/webhook.go
index 6d271a4fe0..16aa3821a8 100644
--- a/routers/repo/webhook.go
+++ b/routers/repo/webhook.go
@@ -18,7 +18,7 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
- "github.com/gogits/gogs/modules/middleware"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/setting"
)
@@ -28,7 +28,7 @@ const (
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["PageIsSettingsHooks"] = true
ctx.Data["BaseLink"] = ctx.Repo.RepoLink
@@ -52,7 +52,7 @@ type OrgRepoCtx struct {
}
// 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 {
return &OrgRepoCtx{
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")
}
-func checkHookType(ctx *middleware.Context) string {
+func checkHookType(ctx *context.Context) string {
hookType := strings.ToLower(ctx.Params(":type"))
if !com.IsSliceContainsStr(setting.Webhook.Types, hookType) {
ctx.Handle(404, "checkHookType", nil)
@@ -81,7 +81,7 @@ func checkHookType(ctx *middleware.Context) string {
return hookType
}
-func WebhooksNew(ctx *middleware.Context) {
+func WebhooksNew(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook")
ctx.Data["PageIsSettingsHooks"] = 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["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksNew"] = true
@@ -160,7 +160,7 @@ func WebHooksNewPost(ctx *middleware.Context, form auth.NewWebhookForm) {
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["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksNew"] = true
@@ -210,7 +210,7 @@ func SlackHooksNewPost(ctx *middleware.Context, form auth.NewSlackHookForm) {
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
orCtx, err := getOrgRepoCtx(ctx)
@@ -245,7 +245,7 @@ func checkWebhook(ctx *middleware.Context) (*OrgRepoCtx, *models.Webhook) {
return orCtx, w
}
-func WebHooksEdit(ctx *middleware.Context) {
+func WebHooksEdit(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksEdit"] = true
@@ -259,7 +259,7 @@ func WebHooksEdit(ctx *middleware.Context) {
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["PageIsSettingsHooks"] = 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))
}
-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["PageIsSettingsHooks"] = 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))
}
-func TestWebhook(ctx *middleware.Context) {
+func TestWebhook(ctx *context.Context) {
p := &api.PushPayload{
Ref: git.BRANCH_PREFIX + ctx.Repo.Repository.DefaultBranch,
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 {
ctx.Flash.Error("DeleteWebhook: " + err.Error())
} else {
diff --git a/routers/repo/wiki.go b/routers/repo/wiki.go
index 4975080d20..e0b3e692c1 100644
--- a/routers/repo/wiki.go
+++ b/routers/repo/wiki.go
@@ -14,8 +14,8 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/markdown"
- "github.com/gogits/gogs/modules/middleware"
)
const (
@@ -25,7 +25,7 @@ const (
WIKI_PAGES base.TplName = "repo/wiki/pages"
)
-func MustEnableWiki(ctx *middleware.Context) {
+func MustEnableWiki(ctx *context.Context) {
if !ctx.Repo.Repository.EnableWiki {
ctx.Handle(404, "MustEnableWiki", nil)
return
@@ -43,7 +43,7 @@ type PageMeta struct {
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())
if err != nil {
ctx.Handle(500, "OpenRepository", err)
@@ -115,7 +115,7 @@ func renderWikiPage(ctx *middleware.Context, isViewPage bool) (*git.Repository,
return wikiRepo, pageName
}
-func Wiki(ctx *middleware.Context) {
+func Wiki(ctx *context.Context) {
ctx.Data["PageIsWiki"] = true
if !ctx.Repo.Repository.HasWiki() {
@@ -140,7 +140,7 @@ func Wiki(ctx *middleware.Context) {
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["PageIsWiki"] = true
@@ -186,7 +186,7 @@ func WikiPages(ctx *middleware.Context) {
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["PageIsWiki"] = true
ctx.Data["RequireSimpleMDE"] = true
@@ -198,7 +198,7 @@ func NewWiki(ctx *middleware.Context) {
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["PageIsWiki"] = 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))
}
-func EditWiki(ctx *middleware.Context) {
+func EditWiki(ctx *context.Context) {
ctx.Data["PageIsWiki"] = true
ctx.Data["PageIsWikiEdit"] = true
ctx.Data["RequireSimpleMDE"] = true
@@ -239,7 +239,7 @@ func EditWiki(ctx *middleware.Context) {
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["PageIsWiki"] = 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))
}
-func DeleteWikiPagePost(ctx *middleware.Context) {
+func DeleteWikiPagePost(ctx *context.Context) {
pageURL := ctx.Params(":page")
if len(pageURL) == 0 {
pageURL = "Home"
diff --git a/routers/user/auth.go b/routers/user/auth.go
index 3f37b09059..3af87c5844 100644
--- a/routers/user/auth.go
+++ b/routers/user/auth.go
@@ -5,6 +5,7 @@
package user
import (
+ "fmt"
"net/url"
"github.com/go-macaron/captcha"
@@ -12,9 +13,9 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/mailer"
- "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
)
@@ -26,11 +27,50 @@ const (
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")
// Check auto-login.
- isSucceed, err := middleware.AutoSignIn(ctx)
+ isSucceed, err := AutoSignIn(ctx)
if err != nil {
ctx.Handle(500, "AutoSignIn", err)
return
@@ -49,7 +89,7 @@ func SignIn(ctx *middleware.Context) {
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")
if ctx.HasError() {
@@ -85,7 +125,7 @@ func SignInPost(ctx *middleware.Context, form auth.SignInForm) {
ctx.Redirect(setting.AppSubUrl + "/")
}
-func SignOut(ctx *middleware.Context) {
+func SignOut(ctx *context.Context) {
ctx.Session.Delete("uid")
ctx.Session.Delete("uname")
ctx.Session.Delete("socialId")
@@ -96,7 +136,7 @@ func SignOut(ctx *middleware.Context) {
ctx.Redirect(setting.AppSubUrl + "/")
}
-func SignUp(ctx *middleware.Context) {
+func SignUp(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("sign_up")
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
@@ -110,7 +150,7 @@ func SignUp(ctx *middleware.Context) {
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["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")
}
-func Activate(ctx *middleware.Context) {
+func Activate(ctx *context.Context) {
code := ctx.Query("code")
if len(code) == 0 {
ctx.Data["IsActivatePage"] = true
@@ -243,7 +283,7 @@ func Activate(ctx *middleware.Context) {
ctx.HTML(200, ACTIVATE)
}
-func ActivateEmail(ctx *middleware.Context) {
+func ActivateEmail(ctx *context.Context) {
code := ctx.Query("code")
email_string := ctx.Query("email")
@@ -261,7 +301,7 @@ func ActivateEmail(ctx *middleware.Context) {
return
}
-func ForgotPasswd(ctx *middleware.Context) {
+func ForgotPasswd(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("auth.forgot_password")
if setting.MailService == nil {
@@ -274,7 +314,7 @@ func ForgotPasswd(ctx *middleware.Context) {
ctx.HTML(200, FORGOT_PASSWORD)
}
-func ForgotPasswdPost(ctx *middleware.Context) {
+func ForgotPasswdPost(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("auth.forgot_password")
if setting.MailService == nil {
@@ -313,7 +353,7 @@ func ForgotPasswdPost(ctx *middleware.Context) {
ctx.HTML(200, FORGOT_PASSWORD)
}
-func ResetPasswd(ctx *middleware.Context) {
+func ResetPasswd(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("auth.reset_password")
code := ctx.Query("code")
@@ -326,7 +366,7 @@ func ResetPasswd(ctx *middleware.Context) {
ctx.HTML(200, RESET_PASSWORD)
}
-func ResetPasswdPost(ctx *middleware.Context) {
+func ResetPasswdPost(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("auth.reset_password")
code := ctx.Query("code")
diff --git a/routers/user/home.go b/routers/user/home.go
index e021a6142b..2a7f219e49 100644
--- a/routers/user/home.go
+++ b/routers/user/home.go
@@ -13,7 +13,7 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
- "github.com/gogits/gogs/modules/middleware"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/setting"
)
@@ -24,7 +24,7 @@ const (
ORG_HOME base.TplName = "org/home"
)
-func getDashboardContextUser(ctx *middleware.Context) *models.User {
+func getDashboardContextUser(ctx *context.Context) *models.User {
ctxUser := ctx.User
orgName := ctx.Params(":org")
if len(orgName) > 0 {
@@ -51,7 +51,7 @@ func getDashboardContextUser(ctx *middleware.Context) *models.User {
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)
if err != nil {
ctx.Handle(500, "GetFeeds", err)
@@ -82,7 +82,7 @@ func retrieveFeeds(ctx *middleware.Context, ctxUserID, userID, offset int64, isP
ctx.Data["Feeds"] = feeds
}
-func Dashboard(ctx *middleware.Context) {
+func Dashboard(ctx *context.Context) {
ctxUser := getDashboardContextUser(ctx)
ctx.Data["Title"] = ctxUser.DisplayName() + " - " + ctx.Tr("dashboard")
ctx.Data["PageIsDashboard"] = true
@@ -147,7 +147,7 @@ func Dashboard(ctx *middleware.Context) {
ctx.HTML(200, DASHBOARD)
}
-func Issues(ctx *middleware.Context) {
+func Issues(ctx *context.Context) {
isPullList := ctx.Params(":type") == "pulls"
if isPullList {
ctx.Data["Title"] = ctx.Tr("pull_requests")
@@ -306,7 +306,7 @@ func Issues(ctx *middleware.Context) {
ctx.HTML(200, ISSUES)
}
-func ShowSSHKeys(ctx *middleware.Context, uid int64) {
+func ShowSSHKeys(ctx *context.Context, uid int64) {
keys, err := models.ListPublicKeys(uid)
if err != nil {
ctx.Handle(500, "ListPublicKeys", err)
@@ -321,9 +321,9 @@ func ShowSSHKeys(ctx *middleware.Context, uid int64) {
ctx.PlainText(200, buf.Bytes())
}
-func showOrgProfile(ctx *middleware.Context) {
+func showOrgProfile(ctx *context.Context) {
ctx.SetParams(":org", ctx.Params(":username"))
- middleware.HandleOrgAssignment(ctx)
+ context.HandleOrgAssignment(ctx)
if ctx.Written() {
return
}
@@ -366,7 +366,7 @@ func showOrgProfile(ctx *middleware.Context) {
ctx.HTML(200, ORG_HOME)
}
-func Email2User(ctx *middleware.Context) {
+func Email2User(ctx *context.Context) {
u, err := models.GetUserByEmail(ctx.Query("email"))
if err != nil {
if models.IsErrUserNotExist(err) {
diff --git a/routers/user/profile.go b/routers/user/profile.go
index d0f41262d1..847cffdd4e 100644
--- a/routers/user/profile.go
+++ b/routers/user/profile.go
@@ -11,7 +11,7 @@ import (
"github.com/gogits/gogs/models"
"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/routers/repo"
)
@@ -21,7 +21,7 @@ const (
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)
if err != nil {
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.
-func GetUserByParams(ctx *middleware.Context) *models.User {
+func GetUserByParams(ctx *context.Context) *models.User {
return GetUserByName(ctx, ctx.Params(":username"))
}
-func Profile(ctx *middleware.Context) {
+func Profile(ctx *context.Context) {
uname := ctx.Params(":username")
// Special handle for FireFox requests favicon.ico.
if uname == "favicon.ico" {
@@ -103,7 +103,7 @@ func Profile(ctx *middleware.Context) {
ctx.HTML(200, PROFILE)
}
-func Followers(ctx *middleware.Context) {
+func Followers(ctx *context.Context) {
u := GetUserByParams(ctx)
if ctx.Written() {
return
@@ -115,7 +115,7 @@ func Followers(ctx *middleware.Context) {
repo.RenderUserCards(ctx, u.NumFollowers, u.GetFollowers, FOLLOWERS)
}
-func Following(ctx *middleware.Context) {
+func Following(ctx *context.Context) {
u := GetUserByParams(ctx)
if ctx.Written() {
return
@@ -127,11 +127,11 @@ func Following(ctx *middleware.Context) {
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)
if ctx.Written() {
return
diff --git a/routers/user/setting.go b/routers/user/setting.go
index c704b67ce0..4b62bb11cc 100644
--- a/routers/user/setting.go
+++ b/routers/user/setting.go
@@ -15,9 +15,9 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/mailer"
- "github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
)
@@ -33,13 +33,13 @@ const (
SECURITY base.TplName = "user/security"
)
-func Settings(ctx *middleware.Context) {
+func Settings(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsProfile"] = true
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.
if len(newName) == 0 || !ctx.User.IsLocal() {
return
@@ -74,7 +74,7 @@ func handleUsernameChange(ctx *middleware.Context, newName string) {
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["PageIsSettingsProfile"] = true
@@ -107,7 +107,7 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) {
}
// 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
if form.Avatar != nil {
@@ -144,7 +144,7 @@ func UpdateAvatarSetting(ctx *middleware.Context, form auth.UploadAvatarForm, ct
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 {
ctx.Flash.Error(err.Error())
} else {
@@ -154,7 +154,7 @@ func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) {
ctx.Redirect(setting.AppSubUrl + "/user/settings")
}
-func SettingsDeleteAvatar(ctx *middleware.Context) {
+func SettingsDeleteAvatar(ctx *context.Context) {
if err := ctx.User.DeleteAvatar(); err != nil {
ctx.Flash.Error(err.Error())
}
@@ -162,13 +162,13 @@ func SettingsDeleteAvatar(ctx *middleware.Context) {
ctx.Redirect(setting.AppSubUrl + "/user/settings")
}
-func SettingsPassword(ctx *middleware.Context) {
+func SettingsPassword(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsPassword"] = true
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["PageIsSettingsPassword"] = true
@@ -196,7 +196,7 @@ func SettingsPasswordPost(ctx *middleware.Context, form auth.ChangePasswordForm)
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["PageIsSettingsEmails"] = true
@@ -210,7 +210,7 @@ func SettingsEmails(ctx *middleware.Context) {
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["PageIsSettingsEmails"] = true
@@ -269,7 +269,7 @@ func SettingsEmailPost(ctx *middleware.Context, form auth.AddEmailForm) {
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 {
ctx.Handle(500, "DeleteEmail", err)
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["PageIsSettingsSSHKeys"] = true
@@ -296,7 +296,7 @@ func SettingsSSHKeys(ctx *middleware.Context) {
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["PageIsSettingsSSHKeys"] = true
@@ -342,7 +342,7 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) {
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 {
ctx.Flash.Error("DeletePublicKey: " + err.Error())
} 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["PageIsSettingsApplications"] = true
@@ -368,7 +368,7 @@ func SettingsApplications(ctx *middleware.Context) {
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["PageIsSettingsApplications"] = true
@@ -398,7 +398,7 @@ func SettingsApplicationsPost(ctx *middleware.Context, form auth.NewAccessTokenF
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 {
ctx.Flash.Error("DeleteAccessTokenByID: " + err.Error())
} 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["PageIsSettingsDelete"] = true