some refactorings
This commit is contained in:
parent
0ab61b6441
commit
a461ea3b1f
4 changed files with 16 additions and 6 deletions
|
@ -7,6 +7,8 @@ use Activitypub\Model\User;
|
||||||
use Activitypub\Model\Blog_User;
|
use Activitypub\Model\Blog_User;
|
||||||
use Activitypub\Model\Application_User;
|
use Activitypub\Model\Application_User;
|
||||||
|
|
||||||
|
use function Activitypub\is_user_disabled;
|
||||||
|
|
||||||
class Users {
|
class Users {
|
||||||
/**
|
/**
|
||||||
* The ID of the Blog User
|
* The ID of the Blog User
|
||||||
|
@ -34,6 +36,14 @@ class Users {
|
||||||
$user_id = (int) $user_id;
|
$user_id = (int) $user_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( is_user_disabled( $user_id ) ) {
|
||||||
|
return new WP_Error(
|
||||||
|
'activitypub_user_not_found',
|
||||||
|
\__( 'User not found', 'activitypub' ),
|
||||||
|
array( 'status' => 404 )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if ( self::BLOG_USER_ID === $user_id ) {
|
if ( self::BLOG_USER_ID === $user_id ) {
|
||||||
return Blog_User::from_wp_user( $user_id );
|
return Blog_User::from_wp_user( $user_id );
|
||||||
} elseif ( self::APPLICATION_USER_ID === $user_id ) {
|
} elseif ( self::APPLICATION_USER_ID === $user_id ) {
|
||||||
|
|
|
@ -299,6 +299,11 @@ function is_user_disabled( $user_id ) {
|
||||||
break;
|
break;
|
||||||
// if the user is any other user, it's enabled if it can publish posts.
|
// if the user is any other user, it's enabled if it can publish posts.
|
||||||
default:
|
default:
|
||||||
|
if ( ! \get_user_by( 'id', $user_id ) ) {
|
||||||
|
$return = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if ( defined( 'ACTIVITYPUB_DISABLE_USER' ) ) {
|
if ( defined( 'ACTIVITYPUB_DISABLE_USER' ) ) {
|
||||||
$return = ACTIVITYPUB_DISABLE_USER;
|
$return = ACTIVITYPUB_DISABLE_USER;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -26,10 +26,7 @@ class User extends Actor {
|
||||||
protected $type = 'Person';
|
protected $type = 'Person';
|
||||||
|
|
||||||
public static function from_wp_user( $user_id ) {
|
public static function from_wp_user( $user_id ) {
|
||||||
if (
|
if ( is_user_disabled( $user_id ) ) {
|
||||||
is_user_disabled( $user_id ) ||
|
|
||||||
! get_user_by( 'id', $user_id )
|
|
||||||
) {
|
|
||||||
return new WP_Error(
|
return new WP_Error(
|
||||||
'activitypub_user_not_found',
|
'activitypub_user_not_found',
|
||||||
\__( 'User not found', 'activitypub' ),
|
\__( 'User not found', 'activitypub' ),
|
||||||
|
|
|
@ -124,7 +124,6 @@ class Inbox {
|
||||||
* @return WP_REST_Response
|
* @return WP_REST_Response
|
||||||
*/
|
*/
|
||||||
public static function user_inbox_post( $request ) {
|
public static function user_inbox_post( $request ) {
|
||||||
|
|
||||||
$user_id = $request->get_param( 'user_id' );
|
$user_id = $request->get_param( 'user_id' );
|
||||||
$user = User_Collection::get_by_various( $user_id );
|
$user = User_Collection::get_by_various( $user_id );
|
||||||
|
|
||||||
|
@ -150,7 +149,6 @@ class Inbox {
|
||||||
* @return WP_REST_Response
|
* @return WP_REST_Response
|
||||||
*/
|
*/
|
||||||
public static function shared_inbox_post( $request ) {
|
public static function shared_inbox_post( $request ) {
|
||||||
|
|
||||||
$data = $request->get_params();
|
$data = $request->get_params();
|
||||||
$type = $request->get_param( 'type' );
|
$type = $request->get_param( 'type' );
|
||||||
$users = self::extract_recipients( $data );
|
$users = self::extract_recipients( $data );
|
||||||
|
|
Loading…
Reference in a new issue