Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -10,25 +10,33 @@
|
||||
*/
|
||||
|
||||
namespace IPS\core\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Application;
|
||||
use IPS\core\api\GraphQL\Types\NotificationTypeType;
|
||||
use IPS\Db;
|
||||
use IPS\Member;
|
||||
use IPS\Notification;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change notification setting mutation for GraphQL API
|
||||
*/
|
||||
class _ChangeNotificationSetting
|
||||
class ChangeNotificationSetting
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Change a notification setting";
|
||||
public static string $description = "Change a notification setting";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -47,46 +55,47 @@ class _ChangeNotificationSetting
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return NotificationTypeType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : NotificationTypeType
|
||||
{
|
||||
return \IPS\core\Api\GraphQL\TypeRegistry::notificationType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves this mutation
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return array
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : array
|
||||
{
|
||||
if( !\IPS\Member::loggedIn()->member_id )
|
||||
if( !Member::loggedIn()->member_id )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NOT_LOGGED_IN', 'GQL/0003/1', 403 );
|
||||
throw new SafeException( 'NOT_LOGGED_IN', 'GQL/0003/1', 403 );
|
||||
}
|
||||
|
||||
$pieces = explode('_', $args['extension']);
|
||||
|
||||
if( \count( $pieces ) !== 2 )
|
||||
if( count( $pieces ) !== 2 )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_EXTENSION', 'GQL/0003/1', 403 );
|
||||
throw new SafeException( 'INVALID_EXTENSION', 'GQL/0003/1', 403 );
|
||||
}
|
||||
|
||||
$extensions = \IPS\Application::load( $pieces[0] )->extensions('core', 'Notifications');
|
||||
$extensions = Application::load( $pieces[0] )->extensions('core', 'Notifications');
|
||||
|
||||
if( !isset( $extensions[ $pieces[1] ] ) )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_EXTENSION', 'GQL/0003/1', 403 );
|
||||
throw new SafeException( 'INVALID_EXTENSION', 'GQL/0003/1', 403 );
|
||||
}
|
||||
|
||||
$extensionOptions = \IPS\Notification::availableOptions( \IPS\Member::loggedIn(), $extensions[ $pieces[1] ] );
|
||||
$extensionOptions = Notification::availableOptions( Member::loggedIn(), $extensions[ $pieces[1] ] );
|
||||
|
||||
if( !isset( $extensionOptions[ $args['type'] ] ) || $extensionOptions[ $args['type'] ]['type'] !== 'standard' ) // Only standard types supported right now
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_TYPE', 'GQL/0003/1', 403 );
|
||||
throw new SafeException( 'INVALID_TYPE', 'GQL/0003/1', 403 );
|
||||
}
|
||||
|
||||
$value = array();
|
||||
@@ -98,7 +107,7 @@ class _ChangeNotificationSetting
|
||||
// If the mutation is trying to change a setting...
|
||||
if( isset( $args[ $type ] ) )
|
||||
{
|
||||
if( $args[ $type ] === TRUE && $typeSettings['editable'] == TRUE && !\in_array( $type, $extensionType['disabled'] ) )
|
||||
if( $args[ $type ] === TRUE && $typeSettings['editable'] == TRUE && !in_array( $type, $extensionType['disabled'] ) )
|
||||
{
|
||||
$value[ $type ] = $type;
|
||||
}
|
||||
@@ -118,8 +127,8 @@ class _ChangeNotificationSetting
|
||||
|
||||
foreach ( $extensionType['notificationTypes'] as $notificationKey )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'core_notification_preferences', array(
|
||||
'member_id' => \IPS\Member::loggedIn()->member_id,
|
||||
Db::i()->insert( 'core_notification_preferences', array(
|
||||
'member_id' => Member::loggedIn()->member_id,
|
||||
'notification_key' => $notificationKey,
|
||||
'preference' => implode( ',', $value )
|
||||
), TRUE );
|
||||
@@ -136,8 +145,8 @@ class _ChangeNotificationSetting
|
||||
}
|
||||
|
||||
$option = $options[ $method ];
|
||||
$methods[ $method ]['default'] = isset( $option['default'] ) && \in_array( $method, $option['default'] );
|
||||
$methods[ $method ]['disabled'] = isset( $option['disabled'] ) && \in_array( $method, $option['disabled'] );
|
||||
$methods[ $method ]['default'] = isset( $option['default'] ) && in_array( $method, $option['default'] );
|
||||
$methods[ $method ]['disabled'] = isset( $option['disabled'] ) && in_array( $method, $option['disabled'] );
|
||||
$methods[ $method ]['member'] = isset( $value[ $method ] );
|
||||
}
|
||||
|
||||
|
||||
@@ -10,25 +10,32 @@
|
||||
*/
|
||||
|
||||
namespace IPS\core\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use Exception;
|
||||
use GraphQL\Type\Definition\BooleanType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Db;
|
||||
use IPS\File;
|
||||
use IPS\Member;
|
||||
use UnderflowException;
|
||||
use function defined;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete attachment mutation for GraphQL API
|
||||
*/
|
||||
class _DeleteAttachment
|
||||
class DeleteAttachment
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Delete an attachment";
|
||||
public static string $description = "Delete an attachment";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -46,8 +53,10 @@ class _DeleteAttachment
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return BooleanType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : BooleanType
|
||||
{
|
||||
return TypeRegistry::boolean();
|
||||
}
|
||||
@@ -55,21 +64,22 @@ class _DeleteAttachment
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return bool
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info ) : bool
|
||||
{
|
||||
/* Get the attachment */
|
||||
try
|
||||
{
|
||||
$attachment = \IPS\Db::i()->select( '*', 'core_attachments', array( 'attach_id=?', $args['id'] ) )->first();
|
||||
$attachment = Db::i()->select( '*', 'core_attachments', array( 'attach_id=?', $args['id'] ) )->first();
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
catch ( UnderflowException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_ATTACHMENT', 'GQL/0004/1', 404 );
|
||||
throw new SafeException( 'NO_ATTACHMENT', 'GQL/0004/1', 404 );
|
||||
}
|
||||
|
||||
/* Delete the maps - Only do this for attachments that have actually been saved (if they haven't been saved, there's nothing in core_attachments_map for us to delete */
|
||||
@@ -85,34 +95,34 @@ class _DeleteAttachment
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Db::i()->delete( 'core_attachments_map', $where );
|
||||
Db::i()->delete( 'core_attachments_map', $where );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If the attachment hasn't been claimed yet, it should only be deletable by the person who uploaded it */
|
||||
if( $attachment['attach_member_id'] != \IPS\Member::loggedIn()->member_id )
|
||||
if( $attachment['attach_member_id'] != Member::loggedIn()->member_id )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'CANNOT_DELETE_OTHERS_ATTACHMENTS', 'GQL/0004/2', 403 );
|
||||
throw new SafeException( 'CANNOT_DELETE_OTHERS_ATTACHMENTS', 'GQL/0004/2', 403 );
|
||||
}
|
||||
}
|
||||
|
||||
/* If there's no other maps, we can delete the attachment itself */
|
||||
$otherMaps = \IPS\Db::i()->select( 'COUNT(*)', 'core_attachments_map', array( 'attachment_id=?', $attachment['attach_id'] ) )->first();
|
||||
$otherMaps = Db::i()->select( 'COUNT(*)', 'core_attachments_map', array( 'attachment_id=?', $attachment['attach_id'] ) )->first();
|
||||
if ( !$otherMaps )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_attachments', array( 'attach_id=?', $attachment['attach_id'] ) );
|
||||
Db::i()->delete( 'core_attachments', array( 'attach_id=?', $attachment['attach_id'] ) );
|
||||
try
|
||||
{
|
||||
\IPS\File::get( 'core_Attachment', $attachment['attach_location'] )->delete();
|
||||
File::get( 'core_Attachment', $attachment['attach_location'] )->delete();
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
catch ( Exception $e ) { }
|
||||
if ( $attachment['attach_thumb_location'] )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\File::get( 'core_Attachment', $attachment['attach_thumb_location'] )->delete();
|
||||
File::get( 'core_Attachment', $attachment['attach_thumb_location'] )->delete();
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
catch ( Exception $e ) { }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,25 +10,40 @@
|
||||
*/
|
||||
|
||||
namespace IPS\core\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use InvalidArgumentException;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Api\GraphQL\Types\FollowType;
|
||||
use IPS\Application;
|
||||
use IPS\Content;
|
||||
use IPS\core\Followed\Follow as FollowClass;
|
||||
use IPS\Db;
|
||||
use IPS\IPS;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Notification;
|
||||
use OutOfRangeException;
|
||||
use UnderflowException;
|
||||
use function defined;
|
||||
use function get_class;
|
||||
use function in_array;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Follow something mutation for GraphQL API
|
||||
*/
|
||||
class _Follow
|
||||
class Follow
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Follow a node, item or member";
|
||||
public static string $description = "Follow a node, item or member";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -50,8 +65,10 @@ class _Follow
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return FollowType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : FollowType
|
||||
{
|
||||
return TypeRegistry::follow();
|
||||
}
|
||||
@@ -61,46 +78,45 @@ class _Follow
|
||||
* @todo this is basically copied and pasted from notifications.php which isn't ideal, so we
|
||||
* might want to consider refactoring to abstract this functionality.
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return array
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : array
|
||||
{
|
||||
if( !\IPS\Member::loggedIn()->member_id )
|
||||
if( !Member::loggedIn()->member_id )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NOT_LOGGED_IN', 'GQL/0001/6', 403 );
|
||||
throw new SafeException( 'NOT_LOGGED_IN', 'GQL/0001/6', 403 );
|
||||
}
|
||||
/* Get class */
|
||||
try
|
||||
{
|
||||
$class = \IPS\core\Followed\Follow::getClassToFollow( $args['app'], $args['area'] );
|
||||
$class = FollowClass::getClassToFollow( $args['app'], $args['area'] );
|
||||
}
|
||||
catch( \InvalidArgumentException $e )
|
||||
catch( InvalidArgumentException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NOT_FOUND', 'GQL/0001/4', 404 );
|
||||
throw new SafeException( 'NOT_FOUND', 'GQL/0001/4', 404 );
|
||||
}
|
||||
|
||||
if( $args['app'] == 'core' and $args['area'] == 'member' )
|
||||
{
|
||||
/* You can't follow yourself */
|
||||
if( $args['id'] == \IPS\Member::loggedIn()->member_id )
|
||||
if( $args['id'] == Member::loggedIn()->member_id )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'CANT_FOLLOW_SELF', 'GQL/0001/1', 403 );
|
||||
throw new SafeException( 'CANT_FOLLOW_SELF', 'GQL/0001/1', 403 );
|
||||
}
|
||||
|
||||
/* Following disabled */
|
||||
$member = \IPS\Member::load( $args['id'] );
|
||||
$member = Member::load( $args['id'] );
|
||||
|
||||
if( !$member->member_id )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'CANT_FOLLOW_MEMBER', 'GQL/0001/2', 403 );
|
||||
throw new SafeException( 'CANT_FOLLOW_MEMBER', 'GQL/0001/2', 403 );
|
||||
}
|
||||
|
||||
if( $member->members_bitoptions['pp_setting_moderate_followers'] and !\IPS\Member::loggedIn()->following( 'core', 'member', $member->member_id ) )
|
||||
if( $member->members_bitoptions['pp_setting_moderate_followers'] and !Member::loggedIn()->following( 'core', 'member', $member->member_id ) )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'CANT_FOLLOW_MEMBER', 'GQL/0001/3', 403 );
|
||||
throw new SafeException( 'CANT_FOLLOW_MEMBER', 'GQL/0001/3', 403 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,49 +131,54 @@ class _Follow
|
||||
$thing = NULL;
|
||||
try
|
||||
{
|
||||
if ( \in_array( 'IPS\Node\Model', class_parents( $class ) ) )
|
||||
if ( in_array( 'IPS\Node\Model', class_parents( $class ) ) )
|
||||
{
|
||||
/* @var Model $class */
|
||||
$thing = $class::loadAndCheckPerms( (int) $args['id'] );
|
||||
}
|
||||
elseif ( $class == 'IPS\Member\Club' )
|
||||
{
|
||||
/* @var Member\Club $class */
|
||||
$thing = $class::loadAndCheckPerms( (int) $args['id'] );
|
||||
}
|
||||
elseif ( $class != "IPS\Member" )
|
||||
{
|
||||
/* @var Content $class */
|
||||
$thing = $class::loadAndCheckPerms( (int) $args['id'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !$class instanceof \IPS\Content\Followable )
|
||||
if( !IPS::classUsesTrait( $class, 'IPS\Content\Followable' ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
/* @var Member $class */
|
||||
$thing = $class::load( (int) $args['id'] );
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NOT_FOUND', 'GQL/0001/5', 404 );
|
||||
throw new SafeException( 'NOT_FOUND', 'GQL/0001/5', 404 );
|
||||
}
|
||||
|
||||
/* Do we follow it? */
|
||||
try
|
||||
{
|
||||
$current = \IPS\Db::i()->select( '*', 'core_follow', array( 'follow_app=? AND follow_area=? AND follow_rel_id=? AND follow_member_id=?', $args['app'], $args['area'], $args['id'], \IPS\Member::loggedIn()->member_id ) )->first();
|
||||
$current = Db::i()->select( '*', 'core_follow', array( 'follow_app=? AND follow_area=? AND follow_rel_id=? AND follow_member_id=?', $args['app'], $args['area'], $args['id'], Member::loggedIn()->member_id ) )->first();
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
catch ( UnderflowException $e )
|
||||
{
|
||||
$current = FALSE;
|
||||
}
|
||||
|
||||
/* Insert */
|
||||
$save = array(
|
||||
'follow_id' => md5( $args['app'] . ';' . $args['area'] . ';' . $args['id'] . ';' . \IPS\Member::loggedIn()->member_id ),
|
||||
'follow_id' => md5( $args['app'] . ';' . $args['area'] . ';' . $args['id'] . ';' . Member::loggedIn()->member_id ),
|
||||
'follow_app' => $args['app'],
|
||||
'follow_area' => $args['area'],
|
||||
'follow_rel_id' => $args['id'],
|
||||
'follow_member_id' => \IPS\Member::loggedIn()->member_id,
|
||||
'follow_member_id' => Member::loggedIn()->member_id,
|
||||
'follow_is_anon' => $args['anonymous'],
|
||||
'follow_added' => time(),
|
||||
'follow_notify_do' => $args['type'] == 'NONE' ? 0 : 1,
|
||||
@@ -168,11 +189,11 @@ class _Follow
|
||||
);
|
||||
if ( $current )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_follow', $save, array( 'follow_id=?', $current['follow_id'] ) );
|
||||
Db::i()->update( 'core_follow', $save, array( 'follow_id=?', $current['follow_id'] ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Db::i()->insert( 'core_follow', $save );
|
||||
Db::i()->insert( 'core_follow', $save );
|
||||
}
|
||||
|
||||
/* Also follow all nodes if following club */
|
||||
@@ -185,11 +206,11 @@ class _Follow
|
||||
$followArea = mb_strtolower( mb_substr( $node['node_class'], mb_strrpos( $node['node_class'], '\\' ) + 1 ) );
|
||||
|
||||
$save = array(
|
||||
'follow_id' => md5( $followApp . ';' . $followArea . ';' . $node['node_id'] . ';' . \IPS\Member::loggedIn()->member_id ),
|
||||
'follow_id' => md5( $followApp . ';' . $followArea . ';' . $node['node_id'] . ';' . Member::loggedIn()->member_id ),
|
||||
'follow_app' => $followApp,
|
||||
'follow_area' => $followArea,
|
||||
'follow_rel_id' => $node['node_id'],
|
||||
'follow_member_id' => \IPS\Member::loggedIn()->member_id,
|
||||
'follow_member_id' => Member::loggedIn()->member_id,
|
||||
'follow_is_anon' => $args['anonymous'],
|
||||
'follow_added' => time(),
|
||||
'follow_notify_do' => $args['type'] == 'NONE' ? 0 : 1,
|
||||
@@ -198,25 +219,25 @@ class _Follow
|
||||
'follow_notify_sent' => 0,
|
||||
'follow_visible' => 1,
|
||||
);
|
||||
\IPS\Db::i()->insert( 'core_follow', $save, TRUE );
|
||||
Db::i()->insert( 'core_follow', $save, TRUE );
|
||||
}
|
||||
}
|
||||
|
||||
/* Send notification if following member */
|
||||
if( $class == "IPS\Member" )
|
||||
{
|
||||
$notification = new \IPS\Notification( \IPS\Application::load( 'core' ), 'member_follow', \IPS\Member::loggedIn(), array( \IPS\Member::loggedIn() ) );
|
||||
$notification = new Notification( Application::load( 'core' ), 'member_follow', Member::loggedIn(), array( Member::loggedIn() ) );
|
||||
$notification->recipients->attach( $thing );
|
||||
$notification->send();
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ( \in_array( 'IPS\Node\Model', class_parents( $class ) ) )
|
||||
if ( in_array( 'IPS\Node\Model', class_parents( $class ) ) )
|
||||
{
|
||||
$return = array_merge($return, array(
|
||||
'node' => $thing,
|
||||
'nodeClass' => \get_class( $thing )
|
||||
'nodeClass' => get_class( $thing )
|
||||
));
|
||||
}
|
||||
else if( $class == 'IPS\Member' )
|
||||
@@ -233,7 +254,7 @@ class _Follow
|
||||
{
|
||||
$return = array_merge($return, array(
|
||||
'item' => $thing,
|
||||
'itemClass' => \get_class( $thing )
|
||||
'itemClass' => get_class( $thing )
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -10,25 +10,31 @@
|
||||
*/
|
||||
|
||||
namespace IPS\core\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\core\api\GraphQL\Types\IgnoreOptionType;
|
||||
use IPS\core\Ignore;
|
||||
use IPS\Member;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignore user mutation for GraphQL API
|
||||
*/
|
||||
class _IgnoreUser
|
||||
class IgnoreUser
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Ignore a member";
|
||||
public static string $description = "Ignore a member";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -45,7 +51,7 @@ class _IgnoreUser
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*/
|
||||
public function type()
|
||||
public function type() : IgnoreOptionType
|
||||
{
|
||||
return \IPS\core\api\GraphQL\TypeRegistry::ignoreOption();
|
||||
}
|
||||
@@ -53,47 +59,46 @@ class _IgnoreUser
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return array
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : array
|
||||
{
|
||||
if ( !\in_array( $args['type'], \IPS\core\Ignore::types() ) )
|
||||
if ( !in_array( $args['type'], Ignore::types() ) )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_TYPE', 'GQL/0006/1', 404 );
|
||||
throw new SafeException( 'INVALID_TYPE', 'GQL/0006/1', 404 );
|
||||
}
|
||||
|
||||
$type = $args['type'];
|
||||
$member = \IPS\Member::load( $args['member'] );
|
||||
$member = Member::load( $args['member'] );
|
||||
|
||||
if( !$member->member_id )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_MEMBER', 'GQL/0006/2', 403 );
|
||||
throw new SafeException( 'INVALID_MEMBER', 'GQL/0006/2', 403 );
|
||||
}
|
||||
|
||||
if ( $member->member_id == \IPS\Member::loggedIn()->member_id )
|
||||
if ( $member->member_id == Member::loggedIn()->member_id )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_IGNORE_SELF', 'GQL/0006/3', 403 );
|
||||
throw new SafeException( 'NO_IGNORE_SELF', 'GQL/0006/3', 403 );
|
||||
}
|
||||
|
||||
if ( !$member->canBeIgnored() )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_IGNORE_MEMBER', 'GQL/0006/4', 403 );
|
||||
throw new SafeException( 'NO_IGNORE_MEMBER', 'GQL/0006/4', 403 );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$ignore = \IPS\core\Ignore::load( $member->member_id, 'ignore_ignore_id', array( 'ignore_owner_id=?', \IPS\Member::loggedIn()->member_id ) );
|
||||
$ignore = Ignore::load( $member->member_id, 'ignore_ignore_id', array( 'ignore_owner_id=?', Member::loggedIn()->member_id ) );
|
||||
$ignore->$type = $args['isIgnoring'];
|
||||
$ignore->save();
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
$ignore = new \IPS\core\Ignore;
|
||||
$ignore = new Ignore;
|
||||
$ignore->$type = $args['isIgnoring'];
|
||||
$ignore->owner_id = \IPS\Member::loggedIn()->member_id;
|
||||
$ignore->owner_id = Member::loggedIn()->member_id;
|
||||
$ignore->ignore_id = $member->member_id;
|
||||
$ignore->save();
|
||||
}
|
||||
@@ -103,8 +108,8 @@ class _IgnoreUser
|
||||
'is_being_ignored' => $args['isIgnoring']
|
||||
);
|
||||
|
||||
\IPS\Member::loggedIn()->members_bitoptions['has_no_ignored_users'] = FALSE;
|
||||
\IPS\Member::loggedIn()->save();
|
||||
Member::loggedIn()->members_bitoptions['has_no_ignored_users'] = FALSE;
|
||||
Member::loggedIn()->save();
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -10,25 +10,33 @@
|
||||
*/
|
||||
|
||||
namespace IPS\core\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Application;
|
||||
use IPS\core\api\GraphQL\Types\NotificationType;
|
||||
use IPS\Db;
|
||||
use IPS\Member;
|
||||
use IPS\Notification\Api;
|
||||
use UnderflowException;
|
||||
use function defined;
|
||||
use function intval;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark notification read mutation for GraphQL API
|
||||
*/
|
||||
class _MarkNotificationRead
|
||||
class MarkNotificationRead
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Mark a notification as read";
|
||||
public static string $description = "Mark a notification as read";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -43,7 +51,7 @@ class _MarkNotificationRead
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*/
|
||||
public function type()
|
||||
public function type() : NotificationType
|
||||
{
|
||||
return \IPS\core\Api\GraphQL\TypeRegistry::notification();
|
||||
}
|
||||
@@ -51,45 +59,44 @@ class _MarkNotificationRead
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return array|NULL
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : ?array
|
||||
{
|
||||
if( !\IPS\Member::loggedIn()->member_id )
|
||||
if( !Member::loggedIn()->member_id )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NOT_LOGGED_IN', 'GQL/0003/1', 403 );
|
||||
throw new SafeException( 'NOT_LOGGED_IN', 'GQL/0003/1', 403 );
|
||||
}
|
||||
|
||||
$where = array();
|
||||
$where[] = array( "notification_app IN('" . implode( "','", array_keys( \IPS\Application::enabledApplications() ) ) . "')" );
|
||||
$where[] = array( "member = ?", \IPS\Member::loggedIn()->member_id );
|
||||
$where[] = array( "notification_app IN('" . implode( "','", array_keys( Application::enabledApplications() ) ) . "')" );
|
||||
$where[] = array( "member = ?", Member::loggedIn()->member_id );
|
||||
|
||||
if( isset( $args['id'] ) && $args['id'] !== NULL )
|
||||
if( isset( $args['id'] ) )
|
||||
{
|
||||
$where[] = array( "id = ?", \intval( $args['id'] ) );
|
||||
$where[] = array( "id = ?", intval( $args['id'] ) );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$row = \IPS\Db::i()->select( '*', 'core_notifications', $where )->first();
|
||||
$notification = \IPS\Notification\Api::constructFromData( $row );
|
||||
$row = Db::i()->select( '*', 'core_notifications', $where )->first();
|
||||
$notification = Api::constructFromData( $row );
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
catch ( UnderflowException $e )
|
||||
{
|
||||
if( isset( $args['id'] ) && $args['id'] !== NULL )
|
||||
if( isset( $args['id'] ) )
|
||||
{
|
||||
// Only throw an error if we were trying to work on a specific notification
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_NOTIFICATION', 'GQL/0003/2', 403 );
|
||||
throw new SafeException( 'INVALID_NOTIFICATION', 'GQL/0003/2', 403 );
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Db::i()->update( 'core_notifications', array( 'read_time' => time() ), $where );
|
||||
\IPS\Member::loggedIn()->recountNotifications();
|
||||
Db::i()->update( 'core_notifications', array( 'read_time' => time() ), $where );
|
||||
Member::loggedIn()->recountNotifications();
|
||||
|
||||
if( $notification )
|
||||
if( isset( $notification ) )
|
||||
{
|
||||
return array( 'notification' => $notification, 'data' => $notification->getData() );
|
||||
}
|
||||
|
||||
@@ -10,25 +10,33 @@
|
||||
*/
|
||||
|
||||
namespace IPS\core\api\GraphQL\Mutations\Messenger;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Application;
|
||||
use IPS\Application\Module;
|
||||
use IPS\core\api\GraphQL\Types\MessengerConversationType;
|
||||
use IPS\core\Messenger\Conversation;
|
||||
use IPS\Member;
|
||||
use IPS\Notification;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add user to conversation mutation for GraphQL API
|
||||
*/
|
||||
class _AddConversationUser
|
||||
class AddConversationUser
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Add a user to a PM conversation";
|
||||
public static string $description = "Add a user to a PM conversation";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -44,7 +52,7 @@ class _AddConversationUser
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*/
|
||||
public function type()
|
||||
public function type() : MessengerConversationType
|
||||
{
|
||||
return \IPS\core\Api\GraphQL\TypeRegistry::messengerConversation();
|
||||
}
|
||||
@@ -52,38 +60,37 @@ class _AddConversationUser
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Forum
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return Conversation
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : Conversation
|
||||
{
|
||||
if( !\IPS\Member::loggedIn()->member_id )
|
||||
if( !Member::loggedIn()->member_id )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NOT_LOGGED_IN', 'GQL/0003/1', 403 );
|
||||
throw new SafeException( 'NOT_LOGGED_IN', 'GQL/0003/1', 403 );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$conversation = \IPS\core\Messenger\Conversation::loadAndCheckPerms( $args['id'] );
|
||||
$conversation = Conversation::loadAndCheckPerms( $args['id'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_MESSAGE', '1F294/2_graphql', 400 );
|
||||
throw new SafeException( 'NO_MESSAGE', '1F294/2_graphql', 400 );
|
||||
}
|
||||
|
||||
// Fetch our new member
|
||||
$member = \IPS\Member::load( $args['memberId'] );
|
||||
$member = Member::load( $args['memberId'] );
|
||||
|
||||
if( !$member->member_id ){
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_MEMBER', '1F294/2_graphql', 403 );
|
||||
throw new SafeException( 'INVALID_MEMBER', '1F294/2_graphql', 403 );
|
||||
}
|
||||
|
||||
// Check member limit
|
||||
if ( \IPS\Member::loggedIn()->group['g_max_mass_pm'] !== -1 AND $conversation->to_count + 1 > \IPS\Member::loggedIn()->group['g_max_mass_pm'] )
|
||||
if ( Member::loggedIn()->group['g_max_mass_pm'] !== -1 AND $conversation->to_count + 1 > Member::loggedIn()->group['g_max_mass_pm'] )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'TOO_MANY_RECIPIENTS', '1F294/2', 400 );
|
||||
throw new SafeException( 'TOO_MANY_RECIPIENTS', '1F294/2', 400 );
|
||||
}
|
||||
|
||||
$maps = $conversation->maps( TRUE );
|
||||
@@ -91,12 +98,12 @@ class _AddConversationUser
|
||||
// Authorize the member
|
||||
if ( array_key_exists( $member->member_id, $maps ) and !$maps[ $member->member_id ]['map_user_active'] AND !$maps[ $member->member_id ]['map_user_banned'] )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'MEMBER_LEFT', '1F294/2', 403 );
|
||||
throw new SafeException( 'MEMBER_LEFT', '1F294/2', 403 );
|
||||
}
|
||||
|
||||
if ( !$this->memberCanReceiveNewMessage( $member ) )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'BAD_RECIPIENT', '1F294/2', 403 );
|
||||
throw new SafeException( 'BAD_RECIPIENT', '1F294/2', 403 );
|
||||
}
|
||||
|
||||
//echo 'here';
|
||||
@@ -104,7 +111,7 @@ class _AddConversationUser
|
||||
$conversation->authorize( $member );
|
||||
$conversation->maps(TRUE); // Need to rebuild participant maps here to reflect this change
|
||||
|
||||
$notification = new \IPS\Notification( \IPS\Application::load('core'), 'private_message_added', $conversation, array( $conversation, \IPS\Member::loggedIn() ) );
|
||||
$notification = new Notification( Application::load('core'), 'private_message_added', $conversation, array( $conversation, Member::loggedIn() ) );
|
||||
$notification->recipients->attach( $member );
|
||||
$notification->send();
|
||||
|
||||
@@ -114,10 +121,10 @@ class _AddConversationUser
|
||||
/**
|
||||
* Can the member recieve new messages?
|
||||
*
|
||||
* @param \IPS\Member The member to check
|
||||
* @return boolean
|
||||
* @param Member $member The member to check
|
||||
* @return bool
|
||||
*/
|
||||
public function memberCanReceiveNewMessage( $member )
|
||||
public function memberCanReceiveNewMessage( Member $member ) : bool
|
||||
{
|
||||
if ( $member->members_disable_pm )
|
||||
{
|
||||
@@ -125,19 +132,19 @@ class _AddConversationUser
|
||||
}
|
||||
|
||||
/* Group can not use messenger */
|
||||
if ( !$member->canAccessModule( \IPS\Application\Module::get( 'core', 'messaging', 'front' ) ) )
|
||||
if ( !$member->canAccessModule( Module::get( 'core', 'messaging', 'front' ) ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Inbox is full */
|
||||
if ( ( $member->group['g_max_messages'] > 0 AND $member->msg_count_total >= $member->group['g_max_messages'] ) and !\IPS\Member::loggedIn()->group['gbw_pm_override_inbox_full'] )
|
||||
if ( ( $member->group['g_max_messages'] > 0 AND $member->msg_count_total >= $member->group['g_max_messages'] ) and !Member::loggedIn()->group['gbw_pm_override_inbox_full'] )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Is being ignored */
|
||||
if ( $member->isIgnoring( \IPS\Member::loggedIn(), 'messages' ) )
|
||||
if ( $member->isIgnoring( Member::loggedIn(), 'messages' ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -10,25 +10,30 @@
|
||||
*/
|
||||
|
||||
namespace IPS\core\api\GraphQL\Mutations\Messenger;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\core\api\GraphQL\Types\MessengerConversationType;
|
||||
use IPS\core\Messenger\Conversation;
|
||||
use IPS\Member;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Leave conversation mutation for GraphQL API
|
||||
*/
|
||||
class _LeaveConversation
|
||||
class LeaveConversation
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Leave a PM conversation";
|
||||
public static string $description = "Leave a PM conversation";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -43,7 +48,7 @@ class _LeaveConversation
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*/
|
||||
public function type()
|
||||
public function type() : MessengerConversationType
|
||||
{
|
||||
return \IPS\core\Api\GraphQL\TypeRegistry::messengerConversation();
|
||||
}
|
||||
@@ -51,26 +56,25 @@ class _LeaveConversation
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Forum
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return mixed
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : mixed
|
||||
{
|
||||
if( !\IPS\Member::loggedIn()->member_id )
|
||||
if( !Member::loggedIn()->member_id )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NOT_LOGGED_IN', 'GQL/0003/1', 403 );
|
||||
throw new SafeException( 'NOT_LOGGED_IN', 'GQL/0003/1', 403 );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$conversation = \IPS\core\Messenger\Conversation::loadAndCheckPerms( $args['id'] );
|
||||
$conversation->deauthorize( \IPS\Member::loggedIn() );
|
||||
$conversation = Conversation::loadAndCheckPerms( $args['id'] );
|
||||
$conversation->deauthorize( Member::loggedIn() );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_MESSAGE', '1F294/2_graphl', 400 );
|
||||
throw new SafeException( 'NO_MESSAGE', '1F294/2_graphl', 400 );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
@@ -10,25 +10,30 @@
|
||||
*/
|
||||
|
||||
namespace IPS\core\api\GraphQL\Mutations\Messenger;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\core\api\GraphQL\Types\MessengerConversationType;
|
||||
use IPS\core\Messenger\Conversation;
|
||||
use IPS\Member;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove user from conversation mutation for GraphQL API
|
||||
*/
|
||||
class _RemoveConversationUser
|
||||
class RemoveConversationUser
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Leave a PM conversation";
|
||||
public static string $description = "Leave a PM conversation";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -44,7 +49,7 @@ class _RemoveConversationUser
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*/
|
||||
public function type()
|
||||
public function type() : MessengerConversationType
|
||||
{
|
||||
return \IPS\core\Api\GraphQL\TypeRegistry::messengerConversation();
|
||||
}
|
||||
@@ -52,33 +57,32 @@ class _RemoveConversationUser
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Forum
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return Conversation
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : Conversation
|
||||
{
|
||||
if( !\IPS\Member::loggedIn()->member_id )
|
||||
if( !Member::loggedIn()->member_id )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NOT_LOGGED_IN', 'GQL/0003/1', 403 );
|
||||
throw new SafeException( 'NOT_LOGGED_IN', 'GQL/0003/1', 403 );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$conversation = \IPS\core\Messenger\Conversation::loadAndCheckPerms( $args['id'] );
|
||||
$conversation = Conversation::loadAndCheckPerms( $args['id'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_MESSAGE', '1F294/2_graphl', 400 );
|
||||
throw new SafeException( 'NO_MESSAGE', '1F294/2_graphl', 400 );
|
||||
}
|
||||
|
||||
if( $conversation->starter_id !== \IPS\Member::loggedIn()->member_id )
|
||||
if( $conversation->starter_id !== Member::loggedIn()->member_id )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NOT_OWNER', 'GQL/0003/1', 403 );
|
||||
throw new SafeException( 'NOT_OWNER', 'GQL/0003/1', 403 );
|
||||
}
|
||||
|
||||
$conversation->deauthorize( \IPS\Member::load( $args['memberId'] ), TRUE );
|
||||
$conversation->deauthorize( Member::load( $args['memberId'] ), TRUE );
|
||||
$conversation->maps(TRUE); // Need to rebuild participant maps here to reflect this change
|
||||
|
||||
return $conversation;
|
||||
|
||||
@@ -10,25 +10,34 @@
|
||||
*/
|
||||
|
||||
namespace IPS\core\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Api\GraphQL\Types\FollowType;
|
||||
use IPS\Application;
|
||||
use IPS\Db;
|
||||
use IPS\IPS;
|
||||
use IPS\Member;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use function get_class;
|
||||
use function in_array;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Follow something mutation for GraphQL API
|
||||
*/
|
||||
class _Unfollow
|
||||
class Unfollow
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Unfollow a node, item or member";
|
||||
public static string $description = "Unfollow a node, item or member";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -46,7 +55,7 @@ class _Unfollow
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*/
|
||||
public function type()
|
||||
public function type() : FollowType
|
||||
{
|
||||
return TypeRegistry::follow();
|
||||
}
|
||||
@@ -56,25 +65,27 @@ class _Unfollow
|
||||
* @todo this is basically copied and pasted from notifications.php which isn't ideal, so we
|
||||
* might want to consider refactoring to abstract this functionality.
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return array
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : array
|
||||
{
|
||||
if( !\IPS\Member::loggedIn()->member_id )
|
||||
if( !Member::loggedIn()->member_id )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NOT_LOGGED_IN', 'GQL/0002/6', 403 );
|
||||
throw new SafeException( 'NOT_LOGGED_IN', 'GQL/0002/6', 403 );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$follow = \IPS\Db::i()->select( '*', 'core_follow', array( 'follow_id=? AND follow_member_id=?', $args['followID'], \IPS\Member::loggedIn()->member_id ) )->first();
|
||||
$follow = Db::i()->select( '*', 'core_follow', array( 'follow_id=? AND follow_member_id=?', $args['followID'], Member::loggedIn()->member_id ) )->first();
|
||||
}
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new SafeException( 'NOT_FOUND', 'GQL/0002/7', 404 );
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) {}
|
||||
|
||||
\IPS\Db::i()->delete( 'core_follow', array( 'follow_id=? AND follow_member_id=?', $args['followID'], \IPS\Member::loggedIn()->member_id ) );
|
||||
Db::i()->delete( 'core_follow', array( 'follow_id=? AND follow_member_id=?', $args['followID'], Member::loggedIn()->member_id ) );
|
||||
|
||||
/* Get class */
|
||||
if( $args['app'] == 'core' and $args['area'] == 'member' )
|
||||
@@ -88,16 +99,16 @@ class _Unfollow
|
||||
else
|
||||
{
|
||||
$class = NULL;
|
||||
foreach ( \IPS\Application::load( $args['app'] )->extensions( 'core', 'ContentRouter' ) as $ext )
|
||||
foreach ( Application::load( $args['app'] )->extensions( 'core', 'ContentRouter' ) as $ext )
|
||||
{
|
||||
foreach ( $ext->classes as $classname )
|
||||
{
|
||||
if ( $classname == 'IPS\\' . $args['app'] . '\\' . mb_ucfirst( $args['area'] ) )
|
||||
if ( $classname == 'IPS\\' . $args['app'] . '\\' . IPS::mb_ucfirst( $args['area'] ) )
|
||||
{
|
||||
$class = $classname;
|
||||
break;
|
||||
}
|
||||
if ( isset( $classname::$containerNodeClass ) and $classname::$containerNodeClass == 'IPS\\' . $args['app'] . '\\' . mb_ucfirst( $args['area'] ) )
|
||||
if ( isset( $classname::$containerNodeClass ) and $classname::$containerNodeClass == 'IPS\\' . $args['app'] . '\\' . IPS::mb_ucfirst( $args['area'] ) )
|
||||
{
|
||||
$class = $classname::$containerNodeClass;
|
||||
break;
|
||||
@@ -106,7 +117,7 @@ class _Unfollow
|
||||
{
|
||||
foreach( $classname::$containerFollowClasses as $followClass )
|
||||
{
|
||||
if( $followClass == 'IPS\\' . $args['app'] . '\\' . mb_ucfirst( $args['area'] ) )
|
||||
if( $followClass == 'IPS\\' . $args['app'] . '\\' . IPS::mb_ucfirst( $args['area'] ) )
|
||||
{
|
||||
$class = $followClass;
|
||||
break;
|
||||
@@ -117,9 +128,9 @@ class _Unfollow
|
||||
}
|
||||
}
|
||||
|
||||
if ( !$class or !array_key_exists( $args['app'], \IPS\Application::applications() ) )
|
||||
if ( !$class or !array_key_exists( $args['app'], Application::applications() ) )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NOT_FOUND', 'GQL/0001/7', 404 );
|
||||
throw new SafeException( 'NOT_FOUND', 'GQL/0001/7', 404 );
|
||||
}
|
||||
|
||||
/* Get our return info ready */
|
||||
@@ -152,15 +163,15 @@ class _Unfollow
|
||||
$followApp = $itemClass::$application;
|
||||
$followArea = mb_strtolower( mb_substr( $node['node_class'], mb_strrpos( $node['node_class'], '\\' ) + 1 ) );
|
||||
|
||||
\IPS\Db::i()->delete( 'core_follow', array( 'follow_id=? AND follow_member_id=?', md5( $followApp . ';' . $followArea . ';' . $node['node_id'] . ';' . \IPS\Member::loggedIn()->member_id ), \IPS\Member::loggedIn()->member_id ) );
|
||||
Db::i()->delete( 'core_follow', array( 'follow_id=? AND follow_member_id=?', md5( $followApp . ';' . $followArea . ';' . $node['node_id'] . ';' . Member::loggedIn()->member_id ), Member::loggedIn()->member_id ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( \in_array( 'IPS\Node\Model', class_parents( $class ) ) )
|
||||
if ( in_array( 'IPS\Node\Model', class_parents( $class ) ) )
|
||||
{
|
||||
$return = array_merge($return, array(
|
||||
'node' => $thing,
|
||||
'nodeClass' => \get_class( $thing )
|
||||
'nodeClass' => get_class( $thing )
|
||||
));
|
||||
}
|
||||
else if( $class == 'IPS\Member' )
|
||||
@@ -177,11 +188,11 @@ class _Unfollow
|
||||
{
|
||||
$return = array_merge($return, array(
|
||||
'item' => $thing,
|
||||
'itemClass' => \get_class( $thing )
|
||||
'itemClass' => get_class( $thing )
|
||||
));
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -10,26 +10,34 @@
|
||||
*/
|
||||
|
||||
namespace IPS\core\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use Exception;
|
||||
use GraphQL\Type\Definition\UnionType;
|
||||
use InvalidArgumentException;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\File;
|
||||
use IPS\Helpers\Form\Editor;
|
||||
use IPS\Image;
|
||||
use IPS\Member;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload attachment mutation for GraphQL API
|
||||
*/
|
||||
class _UploadAttachment
|
||||
class UploadAttachment
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Upload a file to be an attachment";
|
||||
public static string $description = "Upload a file to be an attachment";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -49,7 +57,7 @@ class _UploadAttachment
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*/
|
||||
public function type()
|
||||
public function type() : UnionType
|
||||
{
|
||||
return new UnionType([
|
||||
'name' => 'core_UploadAttachment',
|
||||
@@ -73,23 +81,24 @@ class _UploadAttachment
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return array
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info ) : array
|
||||
{
|
||||
$storageClass = \IPS\File::getClass( 'core_Attachment' );
|
||||
$storageClass = File::getClass( 'core_Attachment' );
|
||||
$contents = base64_decode( $args['contents'] );
|
||||
|
||||
/* Check allowed types */
|
||||
$ext = mb_substr( $args['name'], mb_strrpos( $args['name'], '.' ) + 1 );
|
||||
if( $allowedFileTypes = \IPS\Helpers\Form\Editor::allowedFileExtensions() )
|
||||
if( $allowedFileTypes = Editor::allowedFileExtensions() )
|
||||
{
|
||||
if( !\in_array( mb_strtolower( $ext ), array_map( 'mb_strtolower', $allowedFileTypes ) ) )
|
||||
if( !in_array( mb_strtolower( $ext ), array_map( 'mb_strtolower', $allowedFileTypes ) ) )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'FILE_TYPE_NOT_ALLOWED', '2C399/1_graphql', 403 );
|
||||
throw new SafeException( 'FILE_TYPE_NOT_ALLOWED', '2C399/1_graphql', 403 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,15 +124,15 @@ class _UploadAttachment
|
||||
$file = $storageClass->chunkFinish( $ref, 'core_Attachment' );
|
||||
|
||||
/* If it's got an image extension, check it's actually a valid image */
|
||||
if ( \in_array( $ext, \IPS\Image::supportedExtensions() ) )
|
||||
if ( in_array( $ext, Image::supportedExtensions() ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$file->getImageDimensions();
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NOT_VALID_IMAGE', '2C399/2_graphql', 403 );
|
||||
throw new SafeException( 'NOT_VALID_IMAGE', '2C399/2_graphql', 403 );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,31 +150,30 @@ class _UploadAttachment
|
||||
else
|
||||
{
|
||||
/* If it's got an image extension, check it's actually a valid image */
|
||||
if ( \in_array( $ext, \IPS\Image::supportedExtensions() ) )
|
||||
if ( in_array( $ext, Image::supportedExtensions() ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$image = \IPS\Image::create( $contents );
|
||||
$image = Image::create( $contents );
|
||||
}
|
||||
catch ( \InvalidArgumentException $e )
|
||||
catch ( InvalidArgumentException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( $e->getMessage(), '2C399/2_graphql', 403 );
|
||||
throw new SafeException( $e->getMessage(), '2C399/2_graphql', 403 );
|
||||
}
|
||||
}
|
||||
|
||||
/* Create the file */
|
||||
try
|
||||
{
|
||||
$file = \IPS\File::create( 'core_Attachment', $args['name'], $contents );
|
||||
$file = File::create( 'core_Attachment', $args['name'], $contents );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'FILE_CREATION_FAILED', '2C399/3_graphql', 403 );
|
||||
throw new SafeException( 'FILE_CREATION_FAILED', '2C399/3_graphql', 403 );
|
||||
}
|
||||
}
|
||||
|
||||
/* Make it into an attachment */
|
||||
$attachment = $file->makeAttachment( $args['postKey'], \IPS\Member::loggedIn() );
|
||||
return $attachment;
|
||||
return $file->makeAttachment( $args['postKey'], Member::loggedIn() );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user