mirror of
https://codeberg.org/forgejo-aneksajo/forgejo-aneksajo.git
synced 2025-10-04 11:00:05 +02:00

**Backport: https://codeberg.org/forgejo/forgejo/pulls/9072** Co-authored-by: Gusted <postmaster@gusted.xyz> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9091
30 lines
849 B
Go
30 lines
849 B
Go
// Copyright 2025 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
package redirect
|
|
|
|
import (
|
|
"context"
|
|
|
|
user_model "forgejo.org/models/user"
|
|
)
|
|
|
|
// LookupUserRedirect returns the userID if there's a redirect registered for the
|
|
// username. It additionally checks if the doer has permission to view the new
|
|
// user.
|
|
func LookupUserRedirect(ctx context.Context, doer *user_model.User, userName string) (int64, error) {
|
|
redirect, err := user_model.GetUserRedirect(ctx, userName)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
redirectUser, err := user_model.GetUserByID(ctx, redirect.RedirectUserID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
if !user_model.IsUserVisibleToViewer(ctx, redirectUser, doer) {
|
|
return 0, user_model.ErrUserRedirectNotExist{Name: userName, MissingPermission: true}
|
|
}
|
|
|
|
return redirect.RedirectUserID, nil
|
|
}
|