Implement delete for inbox
This commit is contained in:
parent
73b37d0aec
commit
9669b2c017
@ -7,8 +7,8 @@ function handle_outbox( $actor, $activity ) {
|
||||
if ( !array_key_exists( 'object', $activity ) ) {
|
||||
return new \WP_Error(
|
||||
'invalid_activity',
|
||||
__( 'Expected an object', 'activitypub' ),
|
||||
array( 'status' => 40 )
|
||||
__( 'Expected an object', 'pterotype' ),
|
||||
array( 'status' => 400 )
|
||||
);
|
||||
}
|
||||
$object = $activity['object'];
|
||||
@ -18,4 +18,52 @@ function handle_outbox( $actor, $activity ) {
|
||||
}
|
||||
return $activity;
|
||||
}
|
||||
|
||||
function handle_inbox( $actor_slug, $activity ) {
|
||||
if ( !array_key_exists( 'object', $activity ) ) {
|
||||
return new \WP_Error(
|
||||
'invalid_activity',
|
||||
__( 'Expected an object', 'pterotype' ),
|
||||
array( 'status' => 400 )
|
||||
);
|
||||
}
|
||||
if ( !array_key_exists( 'id', $activity ) ) {
|
||||
return new \WP_Error(
|
||||
'invalid_activity',
|
||||
__( 'Expected an id', 'pterotype' ),
|
||||
array( 'status' => 400 )
|
||||
);
|
||||
}
|
||||
$object = $activity['object'];
|
||||
if ( !array_key_exists( 'id', $object ) ) {
|
||||
return new \WP_Error(
|
||||
'invalid_activity',
|
||||
__( 'Expected an id', 'pterotype' ),
|
||||
array( 'status' => 400 )
|
||||
);
|
||||
}
|
||||
$authorized = check_authorization( $activity );
|
||||
if ( is_wp_error( $authorized ) ) {
|
||||
return $authorized;
|
||||
}
|
||||
$res = \objects\delete_object( $object );
|
||||
if ( is_wp_error( $res ) ) {
|
||||
return $res;
|
||||
}
|
||||
return $activity;
|
||||
}
|
||||
|
||||
function check_authorization( $activity ) {
|
||||
$object = $activity['object'];
|
||||
$activity_origin = parse_url( $activity['id'] )['host'];
|
||||
$object_origin = parse_url( $object['id'] )['host'];
|
||||
if ( ( !$activity_origin || !$object_origin ) || $activity_origin !== $object_origin ) {
|
||||
return new \WP_Error(
|
||||
'unauthorized',
|
||||
__( 'Unauthorized Update activity', 'pterotype' ),
|
||||
array( 'status' => 403 )
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
?>
|
||||
|
@ -11,6 +11,8 @@ namespace inbox;
|
||||
|
||||
require_once plugin_dir_path( __FILE__ ) . '/activities.php';
|
||||
require_once plugin_dir_path( __FILE__ ) . '/activities/create.php';
|
||||
require_once plugin_dir_path( __FILE__ ) . '/activities/update.php';
|
||||
require_once plugin_dir_path( __FILE__ ) . '/activities/delete.php';
|
||||
|
||||
function handle_activity( $actor_slug, $activity ) {
|
||||
if ( !array_key_exists( 'type', $activity ) ) {
|
||||
@ -29,6 +31,7 @@ function handle_activity( $actor_slug, $activity ) {
|
||||
$activity = \update\handle_inbox( $actor_slug, $activity );
|
||||
break;
|
||||
case 'Delete':
|
||||
$activity = \delete\handle_inbox( $actor_slug, $activity );
|
||||
break;
|
||||
case 'Follow':
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user