Implement Delete activity for deleting users
This commit is contained in:
parent
c40dd620a3
commit
3aba06d429
31
routers/api/v1/activitypub/delete.go
Normal file
31
routers/api/v1/activitypub/delete.go
Normal 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
|
||||||
|
}
|
|
@ -138,6 +138,9 @@ func PersonInbox(ctx *context.APIContext) {
|
||||||
n.Context = ap.IRI(strings.TrimSuffix(noteIRI, "/"+noteIRISplit[len(noteIRISplit)-1]))
|
n.Context = ap.IRI(strings.TrimSuffix(noteIRI, "/"+noteIRISplit[len(noteIRISplit)-1]))
|
||||||
return createComment(ctx, n)
|
return createComment(ctx, n)
|
||||||
})
|
})
|
||||||
|
case ap.DeleteType:
|
||||||
|
// Deleting a user
|
||||||
|
delete(ctx, activity)
|
||||||
default:
|
default:
|
||||||
err = fmt.Errorf("unsupported ActivityStreams activity type: %s", activity.GetType())
|
err = fmt.Errorf("unsupported ActivityStreams activity type: %s", activity.GetType())
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue