From edd7fb77fd70cad1268cd8a92c03573515926d3f Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 1 Dec 2023 15:07:13 +0100 Subject: [PATCH] WIP create user if not exists --- routers/api/v1/activitypub/repository.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/routers/api/v1/activitypub/repository.go b/routers/api/v1/activitypub/repository.go index ccee2dc858..8dbfa4a57a 100644 --- a/routers/api/v1/activitypub/repository.go +++ b/routers/api/v1/activitypub/repository.go @@ -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