9a5720e8ad
Universal: PR Check / Branch Policy (pull_request) Successful in 1s
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
PR RC Release / Build RC Release (pull_request) Successful in 3s
Universal: PR Check / Validate PR (pull_request) Failing after 6s
Branch Cleanup / Delete merged branch (pull_request) Successful in 1s
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Full namespace migration: update the Go module path and all import statements from git.mokoconsulting.tech to code.mokoconsulting.tech. Also updates all URL references in templates, workflows, configs, tests, and documentation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
99 lines
2.8 KiB
Go
99 lines
2.8 KiB
Go
// Copyright 2024 The Gitea Authors.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package shared
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
user_model "code.mokoconsulting.tech/MokoConsulting/MokoGitea/models/user"
|
|
api "code.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/structs"
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/util"
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGitea/routers/api/v1/utils"
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGitea/services/context"
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGitea/services/convert"
|
|
user_service "code.mokoconsulting.tech/MokoConsulting/MokoGitea/services/user"
|
|
)
|
|
|
|
func ListBlocks(ctx *context.APIContext, blocker *user_model.User) {
|
|
listOptions := utils.GetListOptions(ctx)
|
|
blocks, total, err := user_model.FindBlockings(ctx, &user_model.FindBlockingOptions{
|
|
ListOptions: listOptions,
|
|
BlockerID: blocker.ID,
|
|
})
|
|
if err != nil {
|
|
ctx.APIErrorInternal(err)
|
|
return
|
|
}
|
|
|
|
if err := user_model.BlockingList(blocks).LoadAttributes(ctx); err != nil {
|
|
ctx.APIErrorInternal(err)
|
|
return
|
|
}
|
|
|
|
users := make([]*api.User, 0, len(blocks))
|
|
for _, b := range blocks {
|
|
users = append(users, convert.ToUser(ctx, b.Blockee, blocker))
|
|
}
|
|
|
|
ctx.SetLinkHeader(total, listOptions.PageSize)
|
|
ctx.SetTotalCountHeader(total)
|
|
ctx.JSON(http.StatusOK, &users)
|
|
}
|
|
|
|
func CheckUserBlock(ctx *context.APIContext, blocker *user_model.User) {
|
|
blockee, err := user_model.GetUserByName(ctx, ctx.PathParam("username"))
|
|
if err != nil {
|
|
ctx.APIErrorNotFound("GetUserByName", err)
|
|
return
|
|
}
|
|
|
|
_, err = user_model.GetBlocking(ctx, blocker.ID, blockee.ID)
|
|
if errors.Is(err, util.ErrNotExist) {
|
|
ctx.Status(http.StatusNotFound)
|
|
} else if err == nil {
|
|
ctx.Status(http.StatusNoContent)
|
|
} else {
|
|
ctx.APIErrorInternal(err)
|
|
}
|
|
}
|
|
|
|
func BlockUser(ctx *context.APIContext, blocker *user_model.User) {
|
|
blockee, err := user_model.GetUserByName(ctx, ctx.PathParam("username"))
|
|
if err != nil {
|
|
ctx.APIErrorNotFound("GetUserByName", err)
|
|
return
|
|
}
|
|
|
|
if err := user_service.BlockUser(ctx, ctx.Doer, blocker, blockee, ctx.FormString("note")); err != nil {
|
|
if errors.Is(err, user_model.ErrCanNotBlock) || errors.Is(err, user_model.ErrBlockOrganization) {
|
|
ctx.APIError(http.StatusBadRequest, err)
|
|
} else {
|
|
ctx.APIErrorInternal(err)
|
|
}
|
|
return
|
|
}
|
|
|
|
ctx.Status(http.StatusNoContent)
|
|
}
|
|
|
|
func UnblockUser(ctx *context.APIContext, doer, blocker *user_model.User) {
|
|
blockee, err := user_model.GetUserByName(ctx, ctx.PathParam("username"))
|
|
if err != nil {
|
|
ctx.APIErrorNotFound("GetUserByName", err)
|
|
return
|
|
}
|
|
|
|
if err := user_service.UnblockUser(ctx, doer, blocker, blockee); err != nil {
|
|
if errors.Is(err, user_model.ErrCanNotUnblock) || errors.Is(err, user_model.ErrBlockOrganization) {
|
|
ctx.APIError(http.StatusBadRequest, err)
|
|
} else {
|
|
ctx.APIErrorInternal(err)
|
|
}
|
|
return
|
|
}
|
|
|
|
ctx.Status(http.StatusNoContent)
|
|
}
|