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,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