Implement Delete activity for deleting users

This commit is contained in:
Anthony Wang 2023-01-11 20:07:47 +00:00
parent c40dd620a3
commit 3aba06d429
No known key found for this signature in database
GPG Key ID: 42A5B952E6DD8D38
2 changed files with 34 additions and 0 deletions

View File

@ -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
}

View File

@ -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())
}