mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in NOTICE, alongside LICENSE. The header lint accepts any copyright line above the SPDX line, so it no longer demands an upstream one. Co-authored-by: Hanzo Dev <[email protected]>
35 lines
1.0 KiB
Go
35 lines
1.0 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package user
|
|
|
|
import (
|
|
user_model "github.com/hanzoai/git/models/user"
|
|
"github.com/hanzoai/git/services/context"
|
|
)
|
|
|
|
// GetUserByPathParam get user by the path param name
|
|
// it will redirect to the user's new name if the user's name has been changed
|
|
func GetUserByPathParam(ctx *context.APIContext, name string) *user_model.User {
|
|
username := ctx.PathParam(name)
|
|
user, err := user_model.GetUserByName(ctx, username)
|
|
if err != nil {
|
|
if user_model.IsErrUserNotExist(err) {
|
|
if redirectUserID, err2 := user_model.LookupUserRedirect(ctx, username); err2 == nil {
|
|
context.RedirectToUser(ctx.Base, ctx.Doer, username, redirectUserID)
|
|
} else {
|
|
ctx.APIErrorNotFound()
|
|
}
|
|
} else {
|
|
ctx.APIErrorInternal(err)
|
|
}
|
|
return nil
|
|
}
|
|
return user
|
|
}
|
|
|
|
// GetContextUserByPathParam returns user whose name is presented in URL (path param "username").
|
|
func GetContextUserByPathParam(ctx *context.APIContext) *user_model.User {
|
|
return GetUserByPathParam(ctx, "username")
|
|
}
|