mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git), so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form used by the handful of files that had ours. Shape is now: // Copyright 2026 Hanzo AI, Inc. All rights reserved. // Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT Ours on top, theirs retained verbatim. Retained because MIT requires it, and separately because they are true — those authors did write that code. Not renamed to "The Git Authors": Git is a different project under a different license, and putting its name here would attribute this code to people who have nothing to do with it. Adding our line is the fix; overwriting theirs would have been both a licence violation and a false statement. gofmt still reports import-order drift in some of these files. It predates this change (verified against a stash) and is left alone rather than burying a one-line-per-file legal change under 3000 files of unrelated reordering. Build clean. Co-authored-by: Hanzo Dev <[email protected]>
82 lines
2.4 KiB
Go
82 lines
2.4 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package user
|
|
|
|
import (
|
|
"errors"
|
|
|
|
user_model "github.com/hanzoai/git/models/user"
|
|
"github.com/hanzoai/git/modules/setting"
|
|
"github.com/hanzoai/git/modules/util"
|
|
"github.com/hanzoai/git/modules/web"
|
|
"github.com/hanzoai/git/services/context"
|
|
"github.com/hanzoai/git/services/forms"
|
|
user_service "github.com/hanzoai/git/services/user"
|
|
)
|
|
|
|
func BlockedUsers(ctx *context.Context, blocker *user_model.User) {
|
|
blocks, _, err := user_model.FindBlockings(ctx, &user_model.FindBlockingOptions{
|
|
BlockerID: blocker.ID,
|
|
})
|
|
if err != nil {
|
|
ctx.ServerError("FindBlockings", err)
|
|
return
|
|
}
|
|
if err := user_model.BlockingList(blocks).LoadAttributes(ctx); err != nil {
|
|
ctx.ServerError("LoadAttributes", err)
|
|
return
|
|
}
|
|
ctx.Data["UserBlocks"] = blocks
|
|
}
|
|
|
|
func blockedUsersPost(ctx *context.Context, form *forms.BlockUserForm, blocker *user_model.User) error {
|
|
blockee, err := user_model.GetUserByName(ctx, form.Blockee)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
switch form.Action {
|
|
case "block":
|
|
err = user_service.BlockUser(ctx, ctx.Doer, blocker, blockee, form.Note)
|
|
if errors.Is(err, util.ErrInvalidArgument) {
|
|
return util.ErrorWrapTranslatable(err, "user.block.block.failure", err.Error())
|
|
}
|
|
return err
|
|
case "unblock":
|
|
err = user_service.UnblockUser(ctx, ctx.Doer, blocker, blockee)
|
|
if errors.Is(err, util.ErrInvalidArgument) {
|
|
return util.ErrorWrapTranslatable(err, "user.block.unblock.failure", err.Error())
|
|
}
|
|
return err
|
|
case "note":
|
|
block, err := user_model.GetBlocking(ctx, blocker.ID, blockee.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return user_model.UpdateBlockingNote(ctx, block.ID, form.Note)
|
|
}
|
|
setting.PanicInDevOrTesting("Unknown action: %q", form.Action)
|
|
return errors.New("unknown action")
|
|
}
|
|
|
|
func BlockedUsersPost(ctx *context.Context, blocker *user_model.User, redirect string) {
|
|
if ctx.HasError() {
|
|
ctx.JSONError(ctx.GetErrMsg())
|
|
return
|
|
}
|
|
|
|
form := web.GetForm(ctx).(*forms.BlockUserForm)
|
|
err := blockedUsersPost(ctx, form, blocker)
|
|
if err == nil {
|
|
ctx.JSONRedirect(redirect)
|
|
} else if errTr := util.ErrorAsTranslatable(err); errTr != nil {
|
|
ctx.JSONError(errTr.Translate(ctx.Locale))
|
|
} else if errors.Is(err, util.ErrNotExist) {
|
|
ctx.JSONError(ctx.Locale.Tr("error.not_found"))
|
|
} else {
|
|
ctx.ServerError("BlockedUsersPost", err)
|
|
}
|
|
}
|