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 ] );
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user