2020-10-29 13:07:56 +00:00
< ? php
namespace Appwrite\Utopia\Response\Model ;
2022-11-15 10:19:35 +00:00
use Appwrite\Auth\Auth ;
2020-10-29 13:07:56 +00:00
use Appwrite\Utopia\Response ;
use Appwrite\Utopia\Response\Model ;
use Utopia\Config\Config ;
2021-07-31 19:07:05 +00:00
use Utopia\Database\Document ;
2020-10-29 13:07:56 +00:00
class Project extends Model
{
2020-11-12 05:12:14 +00:00
/**
* @ var bool
*/
2022-08-01 10:22:04 +00:00
protected bool $public = false ;
2022-05-23 14:54:50 +00:00
2020-10-29 13:07:56 +00:00
public function __construct ()
{
$this
-> addRule ( '$id' , [
2020-11-07 22:14:48 +00:00
'type' => self :: TYPE_STRING ,
2020-10-29 13:07:56 +00:00
'description' => 'Project ID.' ,
2021-01-13 15:06:36 +00:00
'default' => '' ,
2020-10-29 13:07:56 +00:00
'example' => '5e5ea5c16897e' ,
])
2022-06-15 12:46:52 +00:00
-> addRule ( '$createdAt' , [
2022-07-04 09:55:11 +00:00
'type' => self :: TYPE_DATETIME ,
2022-09-04 21:26:16 +00:00
'description' => 'Project creation date in ISO 8601 format.' ,
2022-07-04 09:55:11 +00:00
'default' => '' ,
2022-08-14 10:27:07 +00:00
'example' => self :: TYPE_DATETIME_EXAMPLE ,
2022-06-15 12:46:52 +00:00
])
-> addRule ( '$updatedAt' , [
2022-07-04 09:55:11 +00:00
'type' => self :: TYPE_DATETIME ,
2022-09-04 21:26:16 +00:00
'description' => 'Project update date in ISO 8601 format.' ,
2022-07-04 09:55:11 +00:00
'default' => '' ,
2022-08-14 10:27:07 +00:00
'example' => self :: TYPE_DATETIME_EXAMPLE ,
2022-06-15 12:46:52 +00:00
])
2020-10-29 13:07:56 +00:00
-> addRule ( 'name' , [
2020-11-07 22:14:48 +00:00
'type' => self :: TYPE_STRING ,
2020-10-29 13:07:56 +00:00
'description' => 'Project name.' ,
'default' => '' ,
'example' => 'New Project' ,
])
-> addRule ( 'description' , [
2020-11-07 22:14:48 +00:00
'type' => self :: TYPE_STRING ,
2020-10-29 13:07:56 +00:00
'description' => 'Project description.' ,
'default' => '' ,
'example' => 'This is a new project.' ,
])
-> addRule ( 'teamId' , [
2020-11-07 22:14:48 +00:00
'type' => self :: TYPE_STRING ,
2020-10-29 13:07:56 +00:00
'description' => 'Project team ID.' ,
2021-01-13 15:06:36 +00:00
'default' => '' ,
2020-10-29 13:07:56 +00:00
'example' => '1592981250' ,
])
-> addRule ( 'logo' , [
2020-11-07 22:14:48 +00:00
'type' => self :: TYPE_STRING ,
2020-10-29 13:07:56 +00:00
'description' => 'Project logo file ID.' ,
'default' => '' ,
'example' => '5f5c451b403cb' ,
])
-> addRule ( 'url' , [
2020-11-07 22:14:48 +00:00
'type' => self :: TYPE_STRING ,
2020-10-29 13:07:56 +00:00
'description' => 'Project website URL.' ,
'default' => '' ,
'example' => '5f5c451b403cb' ,
])
-> addRule ( 'legalName' , [
2020-11-07 22:14:48 +00:00
'type' => self :: TYPE_STRING ,
2020-10-29 13:07:56 +00:00
'description' => 'Company legal name.' ,
'default' => '' ,
'example' => 'Company LTD.' ,
])
-> addRule ( 'legalCountry' , [
2020-11-07 22:14:48 +00:00
'type' => self :: TYPE_STRING ,
2020-10-29 13:07:56 +00:00
'description' => 'Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) two-character format.' ,
'default' => '' ,
'example' => 'US' ,
])
-> addRule ( 'legalState' , [
2020-11-07 22:14:48 +00:00
'type' => self :: TYPE_STRING ,
2020-10-29 13:07:56 +00:00
'description' => 'State name.' ,
'default' => '' ,
'example' => 'New York' ,
])
-> addRule ( 'legalCity' , [
2020-11-07 22:14:48 +00:00
'type' => self :: TYPE_STRING ,
2020-10-29 13:07:56 +00:00
'description' => 'City name.' ,
'default' => '' ,
'example' => 'New York City.' ,
])
-> addRule ( 'legalAddress' , [
2020-11-07 22:14:48 +00:00
'type' => self :: TYPE_STRING ,
2020-10-29 13:07:56 +00:00
'description' => 'Company Address.' ,
'default' => '' ,
'example' => '620 Eighth Avenue, New York, NY 10018' ,
])
-> addRule ( 'legalTaxId' , [
2020-11-07 22:14:48 +00:00
'type' => self :: TYPE_STRING ,
2020-10-29 13:07:56 +00:00
'description' => 'Company Tax ID.' ,
'default' => '' ,
'example' => '131102020' ,
2022-10-31 14:54:15 +00:00
])
2022-11-01 14:43:18 +00:00
-> addRule ( 'authDuration' , [
2022-11-15 10:19:35 +00:00
'type' => self :: TYPE_INTEGER ,
2022-11-04 14:48:29 +00:00
'description' => 'Session duration in seconds.' ,
2022-11-15 10:19:35 +00:00
'default' => Auth :: TOKEN_EXPIRATION_LOGIN_LONG ,
'example' => 60 ,
2020-10-29 13:07:56 +00:00
])
2021-08-06 08:34:17 +00:00
-> addRule ( 'authLimit' , [
2021-06-03 06:54:41 +00:00
'type' => self :: TYPE_INTEGER ,
2021-02-28 11:40:59 +00:00
'description' => 'Max users allowed. 0 is unlimited.' ,
'default' => 0 ,
'example' => 100 ,
])
2022-12-11 07:15:18 +00:00
-> addRule ( 'authSessionsLimit' , [
'type' => self :: TYPE_INTEGER ,
'description' => 'Max sessions allowed per user. 100 maximum.' ,
2022-12-13 06:26:25 +00:00
'default' => 10 ,
2022-12-11 07:15:18 +00:00
'example' => 10 ,
])
2022-12-18 06:27:41 +00:00
-> addRule ( 'authPasswordHistory' , [
'type' => self :: TYPE_INTEGER ,
2022-12-19 05:09:56 +00:00
'description' => 'Max allowed passwords in the history list per user. Max passwords limit allowed in history is 20. Use 0 for disabling password history.' ,
2022-12-18 06:27:41 +00:00
'default' => 0 ,
'example' => 5 ,
])
2022-12-26 05:58:16 +00:00
-> addRule ( 'authPasswordDictionary' , [
'type' => self :: TYPE_BOOLEAN ,
'description' => 'Whether or not to check user\'s password against most commonly used passwords.' ,
'default' => false ,
'example' => true ,
])
2023-07-19 22:24:32 +00:00
-> addRule ( 'authPersonalDataCheck' , [
2023-04-11 23:01:50 +00:00
'type' => self :: TYPE_BOOLEAN ,
'description' => 'Whether or not to check the user password for similarity with their personal data.' ,
'default' => false ,
'example' => true ,
])
2024-02-11 14:51:19 +00:00
-> addRule ( 'authMockNumbers' , [
2024-07-03 11:36:56 +00:00
'type' => Response :: MODEL_MOCK_NUMBER ,
2024-07-03 08:27:54 +00:00
'description' => 'An array of mock numbers and their corresponding verification codes (OTPs).' ,
2024-06-16 22:41:13 +00:00
'default' => [],
2024-07-03 11:36:56 +00:00
'array' => true ,
'example' => [ new \stdClass ()],
2024-02-11 14:51:19 +00:00
])
2024-06-24 13:12:09 +00:00
-> addRule ( 'authSessionAlerts' , [
2024-06-21 18:21:05 +00:00
'type' => self :: TYPE_BOOLEAN ,
2024-06-24 13:12:09 +00:00
'description' => 'Whether or not to send session alert emails to users.' ,
2024-06-21 18:21:05 +00:00
'default' => false ,
'example' => true ,
])
2023-10-25 17:33:23 +00:00
-> addRule ( 'oAuthProviders' , [
2023-08-07 10:49:55 +00:00
'type' => Response :: MODEL_AUTH_PROVIDER ,
'description' => 'List of Auth Providers.' ,
2022-08-19 09:21:51 +00:00
'default' => [],
2023-07-20 22:54:38 +00:00
'example' => [ new \stdClass ()],
2022-08-19 09:21:51 +00:00
'array' => true ,
])
2020-10-29 13:07:56 +00:00
-> addRule ( 'platforms' , [
'type' => Response :: MODEL_PLATFORM ,
'description' => 'List of Platforms.' ,
'default' => [],
2022-05-23 14:54:50 +00:00
'example' => new \stdClass (),
2020-10-29 13:07:56 +00:00
'array' => true ,
])
-> addRule ( 'webhooks' , [
'type' => Response :: MODEL_WEBHOOK ,
'description' => 'List of Webhooks.' ,
'default' => [],
2022-05-23 14:54:50 +00:00
'example' => new \stdClass (),
2020-10-29 13:07:56 +00:00
'array' => true ,
])
-> addRule ( 'keys' , [
'type' => Response :: MODEL_KEY ,
'description' => 'List of API Keys.' ,
'default' => [],
2022-05-23 14:54:50 +00:00
'example' => new \stdClass (),
2020-10-29 13:07:56 +00:00
'array' => true ,
])
2023-03-09 01:59:17 +00:00
-> addRule ( 'smtpEnabled' , [
'type' => self :: TYPE_BOOLEAN ,
'description' => 'Status for custom SMTP' ,
'default' => false ,
'example' => false ,
'array' => false
])
2023-08-28 12:19:37 +00:00
-> addRule ( 'smtpSenderName' , [
'type' => self :: TYPE_STRING ,
'description' => 'SMTP sender name' ,
'default' => '' ,
'example' => 'John Appwrite' ,
])
-> addRule ( 'smtpSenderEmail' , [
2023-03-09 01:59:17 +00:00
'type' => self :: TYPE_STRING ,
'description' => 'SMTP sender email' ,
'default' => '' ,
'example' => 'john@appwrite.io' ,
])
2023-08-28 12:19:37 +00:00
-> addRule ( 'smtpReplyTo' , [
'type' => self :: TYPE_STRING ,
'description' => 'SMTP reply to email' ,
'default' => '' ,
'example' => 'support@appwrite.io' ,
])
2023-03-09 01:59:17 +00:00
-> addRule ( 'smtpHost' , [
'type' => self :: TYPE_STRING ,
'description' => 'SMTP server host name' ,
'default' => '' ,
'example' => 'mail.appwrite.io' ,
])
-> addRule ( 'smtpPort' , [
'type' => self :: TYPE_INTEGER ,
'description' => 'SMTP server port' ,
'default' => '' ,
'example' => 25 ,
])
-> addRule ( 'smtpUsername' , [
'type' => self :: TYPE_STRING ,
'description' => 'SMTP server username' ,
'default' => '' ,
'example' => 'emailuser' ,
])
-> addRule ( 'smtpPassword' , [
'type' => self :: TYPE_STRING ,
'description' => 'SMTP server password' ,
'default' => '' ,
'example' => 'securepassword' ,
])
-> addRule ( 'smtpSecure' , [
'type' => self :: TYPE_STRING ,
'description' => 'SMTP server secure protocol' ,
'default' => '' ,
'example' => 'tls' ,
])
2024-10-04 22:23:18 +00:00
-> addRule ( 'pingCount' , [
'type' => self :: TYPE_INTEGER ,
'description' => 'Number of times the ping was received for this project.' ,
'default' => 0 ,
'example' => 1 ,
])
-> addRule ( 'pingedAt' , [
'type' => self :: TYPE_DATETIME ,
'description' => 'Last ping datetime in ISO 8601 format.' ,
'default' => '' ,
'example' => self :: TYPE_DATETIME_EXAMPLE ,
])
2020-10-29 13:07:56 +00:00
;
2021-07-31 04:58:33 +00:00
$services = Config :: getParam ( 'services' , []);
2021-02-28 11:40:59 +00:00
$auth = Config :: getParam ( 'auth' , []);
2020-10-29 13:07:56 +00:00
2021-02-28 11:40:59 +00:00
foreach ( $auth as $index => $method ) {
$name = $method [ 'name' ] ? ? '' ;
$key = $method [ 'key' ] ? ? '' ;
$this
2021-08-06 08:01:53 +00:00
-> addRule ( 'auth' . ucfirst ( $key ), [
2021-02-28 11:40:59 +00:00
'type' => self :: TYPE_BOOLEAN ,
2022-05-23 14:54:50 +00:00
'description' => $name . ' auth method status' ,
2021-02-28 11:40:59 +00:00
'example' => true ,
'default' => true ,
])
;
}
2021-07-31 04:58:33 +00:00
2021-07-31 19:07:05 +00:00
foreach ( $services as $service ) {
2022-05-23 14:54:50 +00:00
if ( ! $service [ 'optional' ]) {
2021-07-31 19:07:05 +00:00
continue ;
}
$name = $service [ 'name' ] ? ? '' ;
$key = $service [ 'key' ] ? ? '' ;
2021-07-31 04:58:33 +00:00
$this
2022-05-23 14:54:50 +00:00
-> addRule ( 'serviceStatusFor' . ucfirst ( $key ), [
2021-07-31 04:58:33 +00:00
'type' => self :: TYPE_BOOLEAN ,
2022-05-23 14:54:50 +00:00
'description' => $name . ' service status' ,
2021-07-31 04:58:33 +00:00
'example' => true ,
'default' => true ,
])
;
}
2020-10-29 13:07:56 +00:00
}
/**
* Get Name
2021-10-06 14:22:38 +00:00
*
2020-10-29 13:07:56 +00:00
* @ return string
*/
2022-05-23 14:54:50 +00:00
public function getName () : string
2020-10-29 13:07:56 +00:00
{
return 'Project' ;
}
/**
2021-12-15 10:19:29 +00:00
* Get Type
2021-10-06 14:22:38 +00:00
*
2020-10-29 13:07:56 +00:00
* @ return string
*/
2022-05-23 14:54:50 +00:00
public function getType () : string
2020-10-29 13:07:56 +00:00
{
return Response :: MODEL_PROJECT ;
}
2021-10-25 14:51:39 +00:00
/**
* Get Collection
2022-05-23 14:54:50 +00:00
*
2021-10-25 14:51:39 +00:00
* @ return string
*/
public function filter ( Document $document ) : Document
{
2023-03-09 01:59:17 +00:00
// SMTP
$smtp = $document -> getAttribute ( 'smtp' , []);
$document -> setAttribute ( 'smtpEnabled' , $smtp [ 'enabled' ] ? ? false );
2023-08-28 12:19:37 +00:00
$document -> setAttribute ( 'smtpSenderEmail' , $smtp [ 'senderEmail' ] ? ? '' );
$document -> setAttribute ( 'smtpSenderName' , $smtp [ 'senderName' ] ? ? '' );
$document -> setAttribute ( 'smtpReplyTo' , $smtp [ 'replyTo' ] ? ? '' );
2023-03-09 01:59:17 +00:00
$document -> setAttribute ( 'smtpHost' , $smtp [ 'host' ] ? ? '' );
$document -> setAttribute ( 'smtpPort' , $smtp [ 'port' ] ? ? '' );
$document -> setAttribute ( 'smtpUsername' , $smtp [ 'username' ] ? ? '' );
$document -> setAttribute ( 'smtpPassword' , $smtp [ 'password' ] ? ? '' );
$document -> setAttribute ( 'smtpSecure' , $smtp [ 'secure' ] ? ? '' );
2022-08-19 09:21:51 +00:00
// Services
2021-10-25 14:51:39 +00:00
$values = $document -> getAttribute ( 'services' , []);
$services = Config :: getParam ( 'services' , []);
2022-05-23 14:54:50 +00:00
foreach ( $services as $service ) {
if ( ! $service [ 'optional' ]) {
2021-10-25 14:51:39 +00:00
continue ;
}
$key = $service [ 'key' ] ? ? '' ;
$value = $values [ $key ] ? ? true ;
2022-05-23 14:54:50 +00:00
$document -> setAttribute ( 'serviceStatusFor' . ucfirst ( $key ), $value );
2021-10-25 14:51:39 +00:00
}
2022-08-19 09:21:51 +00:00
// Auth
2022-05-23 14:54:50 +00:00
$authValues = $document -> getAttribute ( 'auths' , []);
2021-10-25 14:51:39 +00:00
$auth = Config :: getParam ( 'auth' , []);
$document -> setAttribute ( 'authLimit' , $authValues [ 'limit' ] ? ? 0 );
2022-11-15 10:19:35 +00:00
$document -> setAttribute ( 'authDuration' , $authValues [ 'duration' ] ? ? Auth :: TOKEN_EXPIRATION_LOGIN_LONG );
2023-01-16 09:46:53 +00:00
$document -> setAttribute ( 'authSessionsLimit' , $authValues [ 'maxSessions' ] ? ? APP_LIMIT_USER_SESSIONS_DEFAULT );
2022-12-18 06:27:41 +00:00
$document -> setAttribute ( 'authPasswordHistory' , $authValues [ 'passwordHistory' ] ? ? 0 );
2022-12-26 05:31:49 +00:00
$document -> setAttribute ( 'authPasswordDictionary' , $authValues [ 'passwordDictionary' ] ? ? false );
2023-07-19 22:24:32 +00:00
$document -> setAttribute ( 'authPersonalDataCheck' , $authValues [ 'personalDataCheck' ] ? ? false );
2024-06-16 22:41:13 +00:00
$document -> setAttribute ( 'authMockNumbers' , $authValues [ 'mockNumbers' ] ? ? []);
2024-06-24 13:12:09 +00:00
$document -> setAttribute ( 'authSessionAlerts' , $authValues [ 'sessionAlerts' ] ? ? false );
2021-10-25 14:51:39 +00:00
foreach ( $auth as $index => $method ) {
$key = $method [ 'key' ];
$value = $authValues [ $key ] ? ? true ;
$document -> setAttribute ( 'auth' . ucfirst ( $key ), $value );
}
2023-10-25 17:33:23 +00:00
// OAuth Providers
$providers = Config :: getParam ( 'oAuthProviders' , []);
$providerValues = $document -> getAttribute ( 'oAuthProviders' , []);
2022-08-19 09:21:51 +00:00
$projectProviders = [];
2021-10-25 14:51:39 +00:00
foreach ( $providers as $key => $provider ) {
if ( ! $provider [ 'enabled' ]) {
2022-08-19 09:21:51 +00:00
// Disabled by Appwrite configuration, exclude from response
2021-10-25 14:51:39 +00:00
continue ;
}
2022-08-19 09:21:51 +00:00
$projectProviders [] = new Document ([
2023-07-20 22:54:38 +00:00
'key' => $key ,
'name' => $provider [ 'name' ] ? ? '' ,
2022-08-19 09:21:51 +00:00
'appId' => $providerValues [ $key . 'Appid' ] ? ? '' ,
'secret' => $providerValues [ $key . 'Secret' ] ? ? '' ,
'enabled' => $providerValues [ $key . 'Enabled' ] ? ? false ,
]);
2021-10-25 14:51:39 +00:00
}
2022-08-19 09:21:51 +00:00
2023-10-25 17:33:23 +00:00
$document -> setAttribute ( 'oAuthProviders' , $projectProviders );
2022-08-19 09:21:51 +00:00
2021-10-25 14:51:39 +00:00
return $document ;
}
2021-10-06 14:22:38 +00:00
}