mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Rename module: middleware -> context
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
})
|
||||
|
||||
|
@@ -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)
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
|
@@ -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 {
|
||||
|
@@ -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) {
|
||||
|
@@ -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")
|
||||
|
@@ -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
|
||||
|
@@ -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,
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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")
|
||||
|
@@ -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) {
|
||||
|
Reference in New Issue
Block a user