diff --git a/routers/api/v1/activitypub/delete.go b/routers/api/v1/activitypub/delete.go new file mode 100644 index 0000000000..5aa5c83268 --- /dev/null +++ b/routers/api/v1/activitypub/delete.go @@ -0,0 +1,31 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package activitypub + +import ( + "context" + + user_service "code.gitea.io/gitea/services/user" + "code.gitea.io/gitea/services/activitypub" + + ap "github.com/go-ap/activitypub" +) + +// Process an incoming Delete activity +func delete(ctx context.Context, delete ap.Delete) error { + actorIRI := delete.Actor.GetLink() + objectIRI := delete.Object.GetLink() + // Make sure actor matches the object getting deleted + if actorIRI != objectIRI { + return nil + } + + // Object is the user getting deleted + objectUser, err := activitypub.PersonIRIToUser(ctx, objectIRI) + if err != nil { + return err + } + user_service.DeleteUser(ctx, objectUser, true) + return nil +} diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 6a1088ddb4..b4cb28576d 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -138,6 +138,9 @@ func PersonInbox(ctx *context.APIContext) { n.Context = ap.IRI(strings.TrimSuffix(noteIRI, "/"+noteIRISplit[len(noteIRISplit)-1])) return createComment(ctx, n) }) + case ap.DeleteType: + // Deleting a user + delete(ctx, activity) default: err = fmt.Errorf("unsupported ActivityStreams activity type: %s", activity.GetType()) }