WIP create user if not exists

This commit is contained in:
erik 2023-12-01 15:07:13 +01:00 committed by Michael Jerger
parent 159f3dc3aa
commit edd7fb77fd

View file

@ -18,6 +18,7 @@ import (
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
user_model "code.gitea.io/gitea/models/user"
ap "github.com/go-ap/activitypub"
//f3 "lab.forgefriends.org/friendlyforgeformat/gof3"
)
@ -136,7 +137,9 @@ func RepositoryInbox(ctx *context.APIContext) {
// create_user_from_person (if not alreaydy present)
// ToDo
// Check if user already exists
// Create user
email := generateUUIDMail(person)
username := getUserName(person)
@ -150,17 +153,16 @@ func RepositoryInbox(ctx *context.APIContext) {
Type: UserType.UserTypeRemoteUser,
Location: getUserLocation(person),
Website: getAPUserID(person),
IsActive: false,
IsAdmin: false,
}
overwriteDefault := &user_model.CreateUserOverwriteOptions{
IsActive: util.OptionalBoolTrue,
IsRestricted: restricted,
IsActive: util.OptionalBoolFalse,
IsRestricted: util.OptionalBoolFalse,
}
if err := user_model.CreateUser(ctx, u, overwriteDefault); err != nil {
return fmt.Errorf("CreateUser: %w", err)
panic(fmt.Errorf("CreateUser: %w", err))
}
/*
@ -180,8 +182,6 @@ func RepositoryInbox(ctx *context.APIContext) {
We need a remote server with federation enabled to test this
The "if not already present" part might be easy:
Check the user database for given user id.
This could happen with something like: user_model.SearchUsers() as seen in routers/api/v1/user.go