diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index 5355b56721..dbf149fd31 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -107,11 +107,12 @@ App::post('/v1/messaging/providers/mailgun') ->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Provider name.') ->param('default', false, new Boolean(), 'Set as default provider.', true) + ->param('enabled', true, new Boolean(), 'Set as enabled.', true) ->param('apiKey', '', new Text(0), 'Mailgun API Key.') ->param('domain', '', new Text(0), 'Mailgun Domain.') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, bool $default, string $apiKey, string $domain, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, bool $default, bool $enabled, string $apiKey, string $domain, Database $dbForProject, Response $response) { $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = new Document([ @@ -120,6 +121,7 @@ App::post('/v1/messaging/providers/mailgun') 'provider' => 'mailgun', 'type' => 'email', 'default' => $default, + 'enabled' => $enabled, 'credentials' => [ 'apiKey' => $apiKey, 'domain' => $domain, @@ -161,11 +163,12 @@ App::patch('/v1/messaging/providers/:id/mailgun') ->label('sdk.response.model', Response::MODEL_PROVIDER) ->param('id', '', new UID(), 'Provider ID.') ->param('name', '', new Text(128), 'Provider name.', true) + ->param('enabled', true, new Boolean(), 'Set as enabled.', true) ->param('apiKey', '', new Text(0), 'Mailgun API Key.', true) ->param('domain', '', new Text(0), 'Mailgun Domain.', true) ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $apiKey, string $domain, Database $dbForProject, Response $response) { + ->action(function (string $id, string $name, bool $enabled, string $apiKey, string $domain, Database $dbForProject, Response $response) { $provider = $dbForProject->getDocument('providers', $id); if ($provider->isEmpty()) { @@ -181,8 +184,12 @@ App::patch('/v1/messaging/providers/:id/mailgun') $provider->setAttribute('name', $name); } + if ($enabled === false) { + $provider->setAttribute('enabled', $enabled); + } + if ($apiKey || $domain) { - // Check if all five variables are present + // Check if all credential variables are present if ($apiKey && $domain) { $provider->setAttribute('credentials', [ 'apiKey' => $apiKey, @@ -217,10 +224,11 @@ App::post('/v1/messaging/providers/sendgrid') ->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Provider name.') ->param('default', false, new Boolean(), 'Set as default provider.', true) + ->param('enabled', true, new Boolean(), 'Set as enabled.', true) ->param('apiKey', '', new Text(0), 'Sendgrid API key.') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, bool $default, string $apiKey, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, bool $default, bool $enabled, string $apiKey, Database $dbForProject, Response $response) { $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = new Document([ '$id' => $providerId, @@ -228,6 +236,7 @@ App::post('/v1/messaging/providers/sendgrid') 'provider' => 'sendgrid', 'type' => 'email', 'default' => $default, + 'enabled' => $enabled, 'credentials' => [ 'apiKey' => $apiKey, ], @@ -268,10 +277,11 @@ App::patch('/v1/messaging/providers/:id/sendgrid') ->label('sdk.response.model', Response::MODEL_PROVIDER) ->param('id', '', new UID(), 'Provider ID.') ->param('name', '', new Text(128), 'Provider name.', true) + ->param('enabled', true, new Boolean(), 'Set as enabled.', true) ->param('apiKey', '', new Text(0), 'Sendgrid API key.', true) ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $apiKey, Database $dbForProject, Response $response) { + ->action(function (string $id, string $name, bool $enabled, string $apiKey, Database $dbForProject, Response $response) { $provider = $dbForProject->getDocument('providers', $id); if ($provider->isEmpty()) { @@ -287,6 +297,10 @@ App::patch('/v1/messaging/providers/:id/sendgrid') $provider->setAttribute('name', $name); } + if ($enabled === false) { + $provider->setAttribute('enabled', $enabled); + } + if ($apiKey) { $provider->setAttribute('credentials', [ 'apiKey' => $apiKey, @@ -319,11 +333,12 @@ App::post('/v1/messaging/providers/msg91') ->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Provider name.') ->param('default', false, new Boolean(), 'Set as default provider.', true) + ->param('enabled', true, new Boolean(), 'Set as enabled.', true) ->param('senderId', '', new Text(0), 'Msg91 Sender ID.') ->param('authKey', '', new Text(0), 'Msg91 Auth Key.') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, bool $default, string $senderId, string $authKey, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, bool $default, bool $enabled, string $senderId, string $authKey, Database $dbForProject, Response $response) { $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = new Document([ '$id' => $providerId, @@ -331,6 +346,7 @@ App::post('/v1/messaging/providers/msg91') 'provider' => 'msg91', 'type' => 'sms', 'default' => $default, + 'enabled' => $enabled, 'credentials' => [ 'senderId' => $senderId, 'authKey' => $authKey, @@ -372,11 +388,12 @@ App::patch('/v1/messaging/providers/:id/msg91') ->label('sdk.response.model', Response::MODEL_PROVIDER) ->param('id', '', new UID(), 'Provider ID.') ->param('name', '', new Text(128), 'Provider name.', true) + ->param('enabled', true, new Boolean(), 'Set as enabled.', true) ->param('senderId', '', new Text(0), 'Msg91 Sender ID.', true) ->param('authKey', '', new Text(0), 'Msg91 Auth Key.', true) ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $senderId, string $authKey, Database $dbForProject, Response $response) { + ->action(function (string $id, string $name, bool $enabled, string $senderId, string $authKey, Database $dbForProject, Response $response) { $provider = $dbForProject->getDocument('providers', $id); if ($provider->isEmpty()) { @@ -392,8 +409,12 @@ App::patch('/v1/messaging/providers/:id/msg91') $provider->setAttribute('name', $name); } + if ($enabled === false) { + $provider->setAttribute('enabled', $enabled); + } + if ($senderId || $authKey) { - // Check if all five variables are present + // Check if all credential variables are present if ($senderId && $authKey) { $provider->setAttribute('credentials', [ 'senderId' => $senderId, @@ -428,11 +449,12 @@ App::post('/v1/messaging/providers/telesign') ->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Provider name.') ->param('default', false, new Boolean(), 'Set as default provider.', true) + ->param('enabled', true, new Boolean(), 'Set as enabled.', true) ->param('username', '', new Text(0), 'Telesign username.') ->param('password', '', new Text(0), 'Telesign password.') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, bool $default, string $username, string $password, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, bool $default, bool $enabled, string $username, string $password, Database $dbForProject, Response $response) { $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = new Document([ '$id' => $providerId, @@ -440,6 +462,7 @@ App::post('/v1/messaging/providers/telesign') 'provider' => 'telesign', 'type' => 'sms', 'default' => $default, + 'enabled' => $enabled, 'credentials' => [ 'username' => $username, 'password' => $password, @@ -481,11 +504,12 @@ App::patch('/v1/messaging/providers/:id/telesign') ->label('sdk.response.model', Response::MODEL_PROVIDER) ->param('id', '', new UID(), 'Provider ID.') ->param('name', '', new Text(128), 'Provider name.', true) + ->param('enabled', true, new Boolean(), 'Set as enabled.', true) ->param('username', '', new Text(0), 'Telesign username.', true) ->param('password', '', new Text(0), 'Telesign password.', true) ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $username, string $password, Database $dbForProject, Response $response) { + ->action(function (string $id, string $name, bool $enabled, string $username, string $password, Database $dbForProject, Response $response) { $provider = $dbForProject->getDocument('providers', $id); if ($provider->isEmpty()) { @@ -501,8 +525,12 @@ App::patch('/v1/messaging/providers/:id/telesign') $provider->setAttribute('name', $name); } + if ($enabled === false) { + $provider->setAttribute('enabled', $enabled); + } + if ($username || $password) { - // Check if all five variables are present + // Check if all credential variables are present if ($username && $password) { $provider->setAttribute('credentials', [ 'username' => $username, @@ -537,11 +565,12 @@ App::post('/v1/messaging/providers/textmagic') ->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Provider name.') ->param('default', false, new Boolean(), 'Set as default provider.', true) + ->param('enabled', true, new Boolean(), 'Set as enabled.', true) ->param('username', '', new Text(0), 'Textmagic username.') ->param('apiKey', '', new Text(0), 'Textmagic apiKey.') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, bool $default, string $username, string $apiKey, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, bool $default, bool $enabled, string $username, string $apiKey, Database $dbForProject, Response $response) { $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = new Document([ '$id' => $providerId, @@ -549,6 +578,7 @@ App::post('/v1/messaging/providers/textmagic') 'provider' => 'text-magic', 'type' => 'sms', 'default' => $default, + 'enabled' => $enabled, 'credentials' => [ 'username' => $username, 'apiKey' => $apiKey, @@ -590,11 +620,12 @@ App::patch('/v1/messaging/providers/:id/textmagic') ->label('sdk.response.model', Response::MODEL_PROVIDER) ->param('id', '', new UID(), 'Provider ID.') ->param('name', '', new Text(128), 'Provider name.', true) + ->param('enabled', true, new Boolean(), 'Set as enabled.', true) ->param('username', '', new Text(0), 'Textmagic username.', true) ->param('apiKey', '', new Text(0), 'Textmagic apiKey.', true) ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $username, string $apiKey, Database $dbForProject, Response $response) { + ->action(function (string $id, string $name, bool $enabled, string $username, string $apiKey, Database $dbForProject, Response $response) { $provider = $dbForProject->getDocument('providers', $id); if ($provider->isEmpty()) { @@ -610,8 +641,12 @@ App::patch('/v1/messaging/providers/:id/textmagic') $provider->setAttribute('name', $name); } + if ($enabled === false) { + $provider->setAttribute('enabled', $enabled); + } + if ($username || $apiKey) { - // Check if all five variables are present + // Check if all credential variables are present if ($username && $apiKey) { $provider->setAttribute('credentials', [ 'username' => $username, @@ -646,11 +681,12 @@ App::post('/v1/messaging/providers/twilio') ->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Provider name.') ->param('default', false, new Boolean(), 'Set as default provider.', true) + ->param('enabled', true, new Boolean(), 'Set as enabled.', true) ->param('accountSid', '', new Text(0), 'Twilio account secret ID.') ->param('authToken', '', new Text(0), 'Twilio authentication token.') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, bool $default, string $accountSid, string $authToken, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, bool $default, bool $enabled, string $accountSid, string $authToken, Database $dbForProject, Response $response) { $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = new Document([ '$id' => $providerId, @@ -658,6 +694,7 @@ App::post('/v1/messaging/providers/twilio') 'provider' => 'twilio', 'type' => 'sms', 'default' => $default, + 'enabled' => $enabled, 'credentials' => [ 'accountSid' => $accountSid, 'authToken' => $authToken, @@ -699,11 +736,12 @@ App::patch('/v1/messaging/providers/:id/twilio') ->label('sdk.response.model', Response::MODEL_PROVIDER) ->param('id', '', new UID(), 'Provider ID.') ->param('name', '', new Text(128), 'Provider name.', true) + ->param('enabled', true, new Boolean(), 'Set as enabled.', true) ->param('accountSid', null, new Text(0), 'Twilio account secret ID.', true) ->param('authToken', null, new Text(0), 'Twilio authentication token.', true) ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $accountSid, string $authToken, Database $dbForProject, Response $response) { + ->action(function (string $id, string $name, bool $enabled, string $accountSid, string $authToken, Database $dbForProject, Response $response) { $provider = $dbForProject->getDocument('providers', $id); if ($provider->isEmpty()) { @@ -719,8 +757,12 @@ App::patch('/v1/messaging/providers/:id/twilio') $provider->setAttribute('name', $name); } + if ($enabled === false) { + $provider->setAttribute('enabled', $enabled); + } + if ($accountSid || $authToken) { - // Check if all five variables are present + // Check if all credential variables are present if ($accountSid && $authToken) { $provider->setAttribute('credentials', [ 'accountSid' => $accountSid, @@ -755,11 +797,12 @@ App::post('/v1/messaging/providers/vonage') ->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Provider name.') ->param('default', false, new Boolean(), 'Set as default provider.', true) + ->param('enabled', true, new Boolean(), 'Set as enabled.', true) ->param('apiKey', '', new Text(0), 'Vonage API key.') ->param('apiSecret', '', new Text(0), 'Vonage API secret.') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, bool $default, string $apiKey, string $apiSecret, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, bool $default, bool $enabled, string $apiKey, string $apiSecret, Database $dbForProject, Response $response) { $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = new Document([ '$id' => $providerId, @@ -767,6 +810,7 @@ App::post('/v1/messaging/providers/vonage') 'provider' => 'vonage', 'type' => 'sms', 'default' => $default, + 'enabled' => $enabled, 'credentials' => [ 'apiKey' => $apiKey, 'apiSecret' => $apiSecret, @@ -808,11 +852,12 @@ App::patch('/v1/messaging/providers/:id/vonage') ->label('sdk.response.model', Response::MODEL_PROVIDER) ->param('id', '', new UID(), 'Provider ID.') ->param('name', '', new Text(128), 'Provider name.', true) + ->param('enabled', true, new Boolean(), 'Set as enabled.', true) ->param('apiKey', '', new Text(0), 'Vonage API key.', true) ->param('apiSecret', '', new Text(0), 'Vonage API secret.', true) ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $apiKey, string $apiSecret, Database $dbForProject, Response $response) { + ->action(function (string $id, string $name, bool $enabled, string $apiKey, string $apiSecret, Database $dbForProject, Response $response) { $provider = $dbForProject->getDocument('providers', $id); if ($provider->isEmpty()) { @@ -828,8 +873,12 @@ App::patch('/v1/messaging/providers/:id/vonage') $provider->setAttribute('name', $name); } + if ($enabled === false) { + $provider->setAttribute('enabled', $enabled); + } + if ($apiKey || $apiSecret) { - // Check if all five variables are present + // Check if all credential variables are present if ($apiKey && $apiSecret) { $provider->setAttribute('credentials', [ 'apiKey' => $apiKey, @@ -867,10 +916,11 @@ App::post('/v1/messaging/providers/fcm') ->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Provider name.') ->param('default', false, new Boolean(), 'Set as default provider.', true) + ->param('enabled', true, new Boolean(), 'Set as enabled.', true) ->param('serverKey', '', new Text(0), 'FCM Server Key.') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, bool $default, string $serverKey, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, bool $default, bool $enabled, string $serverKey, Database $dbForProject, Response $response) { $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = new Document([ '$id' => $providerId, @@ -878,6 +928,7 @@ App::post('/v1/messaging/providers/fcm') 'provider' => 'fcm', 'type' => 'push', 'default' => $default, + 'enabled' => $enabled, 'credentials' => [ 'serverKey' => $serverKey, ], @@ -918,10 +969,11 @@ App::patch('/v1/messaging/providers/:id/fcm') ->label('sdk.response.model', Response::MODEL_PROVIDER) ->param('id', '', new UID(), 'Provider ID.') ->param('name', '', new Text(128), 'Provider name.', true) + ->param('enabled', true, new Boolean(), 'Set as enabled.', true) ->param('serverKey', '', new Text(0), 'FCM Server Key.', true) ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $serverKey, Database $dbForProject, Response $response) { + ->action(function (string $id, string $name, bool $enabled, string $serverKey, Database $dbForProject, Response $response) { $provider = $dbForProject->getDocument('providers', $id); if ($provider->isEmpty()) { @@ -937,6 +989,10 @@ App::patch('/v1/messaging/providers/:id/fcm') $provider->setAttribute('name', $name); } + if ($enabled === false) { + $provider->setAttribute('enabled', $enabled); + } + if ($serverKey) { $provider->setAttribute('credentials', ['serverKey' => $serverKey]); } @@ -964,6 +1020,7 @@ App::post('/v1/messaging/providers/apns') ->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Provider name.') ->param('default', false, new Boolean(), 'Set as default provider.', true) + ->param('enabled', true, new Boolean(), 'Set as enabled.', true) ->param('authKey', '', new Text(0), 'APNS authentication key.') ->param('authKeyId', '', new Text(0), 'APNS authentication key ID.') ->param('teamId', '', new Text(0), 'APNS team ID.') @@ -971,7 +1028,7 @@ App::post('/v1/messaging/providers/apns') ->param('endpoint', '', new Text(0), 'APNS endpoint.') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, bool $default, string $authKey, string $authKeyId, string $teamId, string $bundleId, string $endpoint, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, bool $default, bool $enabled, string $authKey, string $authKeyId, string $teamId, string $bundleId, string $endpoint, Database $dbForProject, Response $response) { $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = new Document([ '$id' => $providerId, @@ -979,6 +1036,7 @@ App::post('/v1/messaging/providers/apns') 'provider' => 'apns', 'type' => 'push', 'default' => $default, + 'enabled' => $enabled, 'credentials' => [ 'authKey' => $authKey, 'authKeyId' => $authKeyId, @@ -1023,6 +1081,7 @@ App::patch('/v1/messaging/providers/:id/apns') ->label('sdk.response.model', Response::MODEL_PROVIDER) ->param('id', '', new UID(), 'Provider ID.') ->param('name', '', new Text(128), 'Provider name.', true) + ->param('enabled', true, new Boolean(), 'Set as enabled.', true) ->param('authKey', '', new Text(0), 'APNS authentication key.', true) ->param('authKeyId', '', new Text(0), 'APNS authentication key ID.', true) ->param('teamId', '', new Text(0), 'APNS team ID.', true) @@ -1030,7 +1089,7 @@ App::patch('/v1/messaging/providers/:id/apns') ->param('endpoint', '', new Text(0), 'APNS endpoint.', true) ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $authKey, string $authKeyId, string $teamId, string $bundleId, string $endpoint, Database $dbForProject, Response $response) { + ->action(function (string $id, string $name, bool $enabled, string $authKey, string $authKeyId, string $teamId, string $bundleId, string $endpoint, Database $dbForProject, Response $response) { $provider = $dbForProject->getDocument('providers', $id); if ($provider->isEmpty()) { @@ -1046,8 +1105,12 @@ App::patch('/v1/messaging/providers/:id/apns') $provider->setAttribute('name', $name); } + if ($enabled === false) { + $provider->setAttribute('enabled', $enabled); + } + if ($authKey || $authKeyId || $teamId || $bundleId || $endpoint) { - // Check if all five variables are present + // Check if all credential variables are present if ($authKey && $authKeyId && $teamId && $bundleId && $endpoint) { $provider->setAttribute('credentials', [ 'authKey' => $authKey, @@ -1090,10 +1153,11 @@ App::post('/v1/messaging/providers/general') ->param('name', '', new Text(128), 'Provider name.') ->param('type', '', new WhiteList(['push', 'email', 'sms']), 'Provider type.') ->param('default', false, new Boolean(), 'Set as default provider.', true) + ->param('enabled', true, new Boolean(), 'Set as enabled.', true) ->param('credentials', '', new JSON(), 'Provider credentials object.') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $provider, string $name, string $type, bool $default, array $credentials, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $provider, string $name, string $type, bool $default, bool $enabled, array $credentials, Database $dbForProject, Response $response) { $providerId = $providerId == 'unique()' ? ID::unique() : $providerId; $provider = new Document([ '$id' => $providerId, @@ -1101,6 +1165,7 @@ App::post('/v1/messaging/providers/general') 'provider' => $provider, 'type' => $type, 'default' => $default, + 'enabled' => $enabled, 'credentials' => $credentials, ]); @@ -1139,10 +1204,11 @@ App::patch('/v1/messaging/providers/:id/general') ->label('sdk.response.model', Response::MODEL_PROVIDER) ->param('id', '', new UID(), 'Provider ID.') ->param('name', '', new Text(128), 'Provider name.', true) + ->param('enabled', true, new Boolean(), 'Set as enabled.', true) ->param('credentials', '', new JSON(), 'Provider credentials.', true) ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, array $credentials, Database $dbForProject, Response $response) { + ->action(function (string $id, string $name, bool $enabled, array $credentials, Database $dbForProject, Response $response) { $provider = $dbForProject->getDocument('providers', $id); if ($provider->isEmpty()) { @@ -1153,6 +1219,10 @@ App::patch('/v1/messaging/providers/:id/general') $provider->setAttribute('name', $name); } + if ($enabled === false) { + $provider->setAttribute('enabled', $enabled); + } + if (!empty($credentials)) { $provider->setAttribute('credentials', $credentials); }