mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
946 lines
30 KiB
XML
946 lines
30 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.1">
|
|
<constants/>
|
|
<classes>
|
|
<class id="OAuthClient" _delta="define">
|
|
<parent>cmdbAbstractObject</parent>
|
|
<properties>
|
|
<category>grant_by_profile,application</category>
|
|
<abstract>true</abstract>
|
|
<key_type>autoincrement</key_type>
|
|
<db_table>priv_oauth_client</db_table>
|
|
<db_key_field>id</db_key_field>
|
|
<db_final_class_field/>
|
|
<naming>
|
|
<attributes>
|
|
<attribute id="provider"/>
|
|
<attribute id="name"/>
|
|
</attributes>
|
|
</naming>
|
|
<reconciliation>
|
|
<attributes>
|
|
<attribute id="provider"/>
|
|
<attribute id="name"/>
|
|
</attributes>
|
|
</reconciliation>
|
|
<style>
|
|
<icon/>
|
|
</style>
|
|
</properties>
|
|
<fields>
|
|
<field id="provider" xsi:type="AttributeString">
|
|
<sql>provider</sql>
|
|
<default_value/>
|
|
<is_null_allowed>false</is_null_allowed>
|
|
</field>
|
|
<field id="name" xsi:type="AttributeString">
|
|
<sql>name</sql>
|
|
<default_value/>
|
|
<is_null_allowed>false</is_null_allowed>
|
|
</field>
|
|
<field id="status" xsi:type="AttributeEnum">
|
|
<always_load_in_tables>true</always_load_in_tables>
|
|
<values>
|
|
<value id="active">
|
|
<code>active</code>
|
|
<style>
|
|
<main_color>$ibo-lifecycle-active-state-primary-color</main_color>
|
|
<complementary_color>$ibo-lifecycle-active-state-secondary-color</complementary_color>
|
|
<decoration_classes/>
|
|
</style>
|
|
</value>
|
|
<value id="inactive">
|
|
<code>inactive</code>
|
|
<style>
|
|
<main_color>$ibo-lifecycle-inactive-state-primary-color</main_color>
|
|
<complementary_color>$ibo-lifecycle-inactive-state-secondary-color</complementary_color>
|
|
<decoration_classes/>
|
|
</style>
|
|
</value>
|
|
</values>
|
|
<sql>status</sql>
|
|
<default_value>inactive</default_value>
|
|
<is_null_allowed>false</is_null_allowed>
|
|
</field>
|
|
<field id="description" xsi:type="AttributeText">
|
|
<sql>description</sql>
|
|
<default_value/>
|
|
<is_null_allowed>true</is_null_allowed>
|
|
</field>
|
|
<field id="client_id" xsi:type="AttributeText">
|
|
<sql>client_id</sql>
|
|
<default_value/>
|
|
<is_null_allowed>false</is_null_allowed>
|
|
</field>
|
|
<field id="client_secret" xsi:type="AttributeText">
|
|
<sql>client_secret</sql>
|
|
<default_value/>
|
|
<is_null_allowed>false</is_null_allowed>
|
|
</field>
|
|
<field id="refresh_token" xsi:type="AttributeText">
|
|
<sql>refresh_token</sql>
|
|
<default_value/>
|
|
<is_null_allowed>true</is_null_allowed>
|
|
<tracking_level>none</tracking_level>
|
|
</field>
|
|
<field id="refresh_token_expiration" xsi:type="AttributeDateTime">
|
|
<sql>refresh_token_expiration</sql>
|
|
<default_value/>
|
|
<is_null_allowed>true</is_null_allowed>
|
|
<tracking_level>none</tracking_level>
|
|
</field>
|
|
<field id="token" xsi:type="AttributeText">
|
|
<sql>token</sql>
|
|
<default_value/>
|
|
<is_null_allowed>true</is_null_allowed>
|
|
<tracking_level>none</tracking_level>
|
|
</field>
|
|
<field id="token_expiration" xsi:type="AttributeDateTime">
|
|
<sql>token_expiration</sql>
|
|
<default_value/>
|
|
<is_null_allowed>true</is_null_allowed>
|
|
<tracking_level>none</tracking_level>
|
|
</field>
|
|
<field id="redirect_url" xsi:type="AttributeURL">
|
|
<sql>redirect_url</sql>
|
|
<default_value/>
|
|
<target>_blank</target>
|
|
<is_null_allowed>true</is_null_allowed>
|
|
</field>
|
|
<field id="mailbox_list" xsi:type="AttributeLinkedSet">
|
|
<linked_class>MailInboxOAuth</linked_class>
|
|
<ext_key_to_me>oauth_client_id</ext_key_to_me>
|
|
<count_min>0</count_min>
|
|
<count_max>0</count_max>
|
|
<relation_type>link</relation_type>
|
|
<read_only>false</read_only>
|
|
</field>
|
|
</fields>
|
|
<methods>
|
|
<method id="DisplayBareHeader">
|
|
<static>false</static>
|
|
<access>public</access>
|
|
<type>Overload-DBObject</type>
|
|
<code><![CDATA[
|
|
public function DisplayBareHeader(WebPage $oPage, $bEditMode = false)
|
|
{
|
|
$aHeaderBlocks = parent::DisplayBareHeader($oPage, $bEditMode);
|
|
$aTags = [];
|
|
if (!$bEditMode) {
|
|
$oConfig = utils::GetConfig();
|
|
if ($this->Get('status') == 'inactive') {
|
|
$sLabel = Dict::S('itop-oauth-client:Message:MissingToken');
|
|
$sTitle = '';
|
|
$aTags['oauth-message'] = ['title' => $sTitle, 'css_classes' => 'ibo-object-details--tag--oauth-message', 'decoration_classes' => 'fas fa-exclamation-triangle', 'label' => $sLabel];
|
|
} elseif ($this->Get('used_for_smtp') == 'yes' && $oConfig->Get('email_transport_smtp.username') == $this->Get('name')) {
|
|
$sLabel = Dict::S('itop-oauth-client:UsedForSMTP');
|
|
$sTestLabel = Dict::S('itop-oauth-client:TestSMTP');
|
|
$sTestURL = utils::GetAbsoluteUrlAppRoot().'setup/email.test.php';
|
|
$sLabel = Dict::S('itop-oauth-client:UsedForSMTP')." <a href='$sTestURL' target='_blank'>$sTestLabel</a>";
|
|
$sTitle = '';
|
|
$aTags['oauth-message'] = ['title' => $sTitle, 'css_classes' => 'ibo-object-details--tag--oauth-message', 'decoration_classes' => 'fas fa-envelope', 'label' => $sLabel];
|
|
}
|
|
}
|
|
foreach ($aTags as $sIconId => $aIconData) {
|
|
$aHeaderBlocks['subtitle'][static::HEADER_BLOCKS_SUBTITLE_TAG_PREFIX.$sIconId] = new Combodo\iTop\Application\UI\Base\Component\Html\Html(<<<HTML
|
|
<span id="{$sIconId}" class="ibo-object-details--tag {$aIconData['css_classes']}"><span class="ibo-object-details--tag-icon"><span class="{$aIconData['decoration_classes']}"></span></span>{$aIconData['label']}</span>
|
|
HTML
|
|
);
|
|
}
|
|
|
|
return $aHeaderBlocks;
|
|
}
|
|
]]></code>
|
|
</method>
|
|
<method id="GetAttributeFlags">
|
|
<static>false</static>
|
|
<access>public</access>
|
|
<type>Overload-DBObject</type>
|
|
<code><![CDATA[
|
|
public function GetAttributeFlags($sAttCode, &$aReasons = array(), $sTargetState = '')
|
|
{
|
|
if ($sAttCode == 'status') {
|
|
return OPT_ATT_READONLY;
|
|
}
|
|
|
|
return parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState);
|
|
}
|
|
]]></code>
|
|
</method>
|
|
<method id="GetInitialStateAttributeFlags">
|
|
<static>false</static>
|
|
<access>public</access>
|
|
<type>Overload-DBObject</type>
|
|
<code><![CDATA[
|
|
public function GetInitialStateAttributeFlags($sAttCode, &$aReasons = array())
|
|
{
|
|
if ($sAttCode == 'status') {
|
|
return OPT_ATT_READONLY;
|
|
}
|
|
|
|
return parent::GetInitialStateAttributeFlags($sAttCode, $aReasons);
|
|
}
|
|
]]></code>
|
|
</method>
|
|
<method id="GetDefaultMailServer">
|
|
<static>false</static>
|
|
<access>public</access>
|
|
<code><![CDATA[
|
|
public function GetDefaultMailServer()
|
|
{
|
|
return 'imap.'.$this->Get('provider').'.com';
|
|
}
|
|
]]></code>
|
|
</method>
|
|
<method id="GetDefaultMailServerPort">
|
|
<static>false</static>
|
|
<access>public</access>
|
|
<code><![CDATA[
|
|
public function GetDefaultMailServerPort()
|
|
{
|
|
return 993;
|
|
}
|
|
]]></code>
|
|
</method>
|
|
<method id="GetAccessToken">
|
|
<static>false</static>
|
|
<access>public</access>
|
|
<code><![CDATA[
|
|
public function GetAccessToken()
|
|
{
|
|
if ($this->Get('status') == 'active') {
|
|
return new \League\OAuth2\Client\Token\AccessToken([
|
|
'access_token' => $this->Get('token'),
|
|
'expires_in' => date_format(new DateTime($this->Get('token_expiration')), 'U') - time(),
|
|
'refresh_token' => $this->Get('refresh_token'),
|
|
'token_type' => 'Bearer',
|
|
]);
|
|
}
|
|
return null;
|
|
}
|
|
]]></code>
|
|
</method>
|
|
<method id="SetAccessToken">
|
|
<static>false</static>
|
|
<access>public</access>
|
|
<code><![CDATA[
|
|
public function SetAccessToken(\League\OAuth2\Client\Token\AccessTokenInterface $oAccessToken)
|
|
{
|
|
$this->Set('token', $oAccessToken->getToken());
|
|
$this->Set('token_expiration', date(AttributeDateTime::GetSQLFormat(), $oAccessToken->getExpires()));
|
|
if (!empty($oAccessToken->getRefreshToken())) {
|
|
$this->Set('refresh_token', $oAccessToken->getRefreshToken());
|
|
}
|
|
$this->Set('status', 'active');
|
|
$this->DBUpdate();
|
|
}
|
|
]]></code>
|
|
</method>
|
|
</methods>
|
|
<presentation>
|
|
<details>
|
|
<items>
|
|
<item id="name">
|
|
<rank>1</rank>
|
|
</item>
|
|
<item id="description">
|
|
<rank>2</rank>
|
|
</item>
|
|
<item id="provider">
|
|
<rank>3</rank>
|
|
</item>
|
|
<item id="redirect_url">
|
|
<rank>5</rank>
|
|
</item>
|
|
<item id="client_id">
|
|
<rank>6</rank>
|
|
</item>
|
|
<item id="client_secret">
|
|
<rank>7</rank>
|
|
</item>
|
|
<item id="mailbox_list">
|
|
<rank>8</rank>
|
|
</item>
|
|
</items>
|
|
</details>
|
|
<list>
|
|
<items>
|
|
<item id="status">
|
|
<rank>1</rank>
|
|
</item>
|
|
<item id="provider">
|
|
<rank>3</rank>
|
|
</item>
|
|
</items>
|
|
</list>
|
|
<search>
|
|
<items>
|
|
<item id="name">
|
|
<rank>1</rank>
|
|
</item>
|
|
<item id="provider">
|
|
<rank>2</rank>
|
|
</item>
|
|
</items>
|
|
</search>
|
|
<default_search>
|
|
<items>
|
|
<item id="name">
|
|
<rank>1</rank>
|
|
</item>
|
|
<item id="provider">
|
|
<rank>2</rank>
|
|
</item>
|
|
</items>
|
|
</default_search>
|
|
</presentation>
|
|
</class>
|
|
<class id="OAuthClientAzure" _delta="define">
|
|
<parent>OAuthClient</parent>
|
|
<properties>
|
|
<category>grant_by_profile,application</category>
|
|
<abstract>false</abstract>
|
|
<key_type>autoincrement</key_type>
|
|
<db_table>priv_oauth_client_azure</db_table>
|
|
<db_key_field>id</db_key_field>
|
|
<db_final_class_field/>
|
|
<naming>
|
|
<attributes>
|
|
<attribute id="provider"/>
|
|
<attribute id="name"/>
|
|
</attributes>
|
|
</naming>
|
|
<reconciliation>
|
|
<attributes>
|
|
<attribute id="provider"/>
|
|
<attribute id="name"/>
|
|
</attributes>
|
|
</reconciliation>
|
|
<uniqueness_rules>
|
|
<rule id="server">
|
|
<attributes>
|
|
<attribute id="provider"/>
|
|
<attribute id="client_id"/>
|
|
<attribute id="client_secret"/>
|
|
</attributes>
|
|
<is_blocking>true</is_blocking>
|
|
</rule>
|
|
</uniqueness_rules>
|
|
<style>
|
|
<icon/>
|
|
</style>
|
|
</properties>
|
|
<fields>
|
|
<field id="scope" xsi:type="AttributeEnumSet">
|
|
<always_load_in_tables>true</always_load_in_tables>
|
|
<values>
|
|
<value id="SMTP">
|
|
<code>SMTP</code>
|
|
</value>
|
|
<value id="IMAP">
|
|
<code>IMAP</code>
|
|
</value>
|
|
</values>
|
|
<sql>scope</sql>
|
|
<default_value>SMTP,IMAP</default_value>
|
|
<is_null_allowed>true</is_null_allowed>
|
|
</field>
|
|
<field id="advanced_scope" xsi:type="AttributeString">
|
|
<sql>advanced_scope</sql>
|
|
<default_value/>
|
|
<is_null_allowed>true</is_null_allowed>
|
|
</field>
|
|
<field id="used_scope" xsi:type="AttributeEnum">
|
|
<always_load_in_tables>true</always_load_in_tables>
|
|
<values>
|
|
<value id="simple">
|
|
<code>simple</code>
|
|
</value>
|
|
<value id="advanced">
|
|
<code>advanced</code>
|
|
</value>
|
|
</values>
|
|
<sql>used_scope</sql>
|
|
<default_value>simple</default_value>
|
|
<is_null_allowed>false</is_null_allowed>
|
|
<dependencies>
|
|
<attribute id="scope"/>
|
|
<attribute id="advanced_scope"/>
|
|
</dependencies>
|
|
</field>
|
|
<field id="used_for_smtp" xsi:type="AttributeEnum">
|
|
<always_load_in_tables>true</always_load_in_tables>
|
|
<values>
|
|
<value id="yes">
|
|
<code>yes</code>
|
|
</value>
|
|
<value id="no">
|
|
<code>no</code>
|
|
</value>
|
|
</values>
|
|
<sql>used_for_smtp</sql>
|
|
<default_value>no</default_value>
|
|
<is_null_allowed>true</is_null_allowed>
|
|
</field>
|
|
</fields>
|
|
<presentation>
|
|
<details>
|
|
<items>
|
|
<item id="col:col1">
|
|
<rank>10</rank>
|
|
<items>
|
|
<item id="fieldset:OAuthClient:baseinfo">
|
|
<rank>10</rank>
|
|
<items>
|
|
<item id="name">
|
|
<rank>10</rank>
|
|
</item>
|
|
<item id="status">
|
|
<rank>20</rank>
|
|
</item>
|
|
<item id="description">
|
|
<rank>30</rank>
|
|
</item>
|
|
<item id="provider">
|
|
<rank>40</rank>
|
|
</item>
|
|
<item id="redirect_url">
|
|
<rank>50</rank>
|
|
</item>
|
|
<item id="client_id">
|
|
<rank>60</rank>
|
|
</item>
|
|
<item id="client_secret">
|
|
<rank>70</rank>
|
|
</item>
|
|
<item id="mailbox_list">
|
|
<rank>80</rank>
|
|
</item>
|
|
</items>
|
|
</item>
|
|
</items>
|
|
</item>
|
|
<item id="col:col2">
|
|
<rank>20</rank>
|
|
<items>
|
|
<item id="fieldset:OAuthClient:scope">
|
|
<rank>10</rank>
|
|
<items>
|
|
<item id="used_scope">
|
|
<rank>10</rank>
|
|
</item>
|
|
<item id="scope">
|
|
<rank>20</rank>
|
|
</item>
|
|
<item id="advanced_scope">
|
|
<rank>30</rank>
|
|
</item>
|
|
<item id="used_for_smtp">
|
|
<rank>40</rank>
|
|
</item>
|
|
</items>
|
|
</item>
|
|
</items>
|
|
</item>
|
|
</items>
|
|
</details>
|
|
<list>
|
|
<items>
|
|
<item id="provider">
|
|
<rank>10</rank>
|
|
</item>
|
|
<item id="status">
|
|
<rank>10</rank>
|
|
</item>
|
|
</items>
|
|
</list>
|
|
<standard_search>
|
|
<items>
|
|
<item id="name">
|
|
<rank>10</rank>
|
|
</item>
|
|
<item id="provider">
|
|
<rank>10</rank>
|
|
</item>
|
|
<item id="status">
|
|
<rank>10</rank>
|
|
</item>
|
|
</items>
|
|
</standard_search>
|
|
</presentation>
|
|
<methods>
|
|
<method id="PrefillCreationForm">
|
|
<static>false</static>
|
|
<access>public</access>
|
|
<type>Overload-DBObject</type>
|
|
<code><![CDATA[
|
|
public function PrefillCreationForm(&$aContextParam)
|
|
{
|
|
$this->Set('provider', 'Azure');
|
|
$this->Set('redirect_url', Combodo\iTop\Core\Authentication\Client\OAuth\OAuthClientProviderFactory::GetRedirectUri());
|
|
$this->Set('scope', 'SMTP, IMAP');
|
|
|
|
parent::PrefillCreationForm($aContextParam);
|
|
}
|
|
]]></code>
|
|
</method>
|
|
<method id="DoCheckToWrite">
|
|
<static>false</static>
|
|
<access>public</access>
|
|
<type>Overload-DBObject</type>
|
|
<code><![CDATA[ public function DoCheckToWrite()
|
|
{
|
|
parent::DoCheckToWrite();
|
|
|
|
$aChanges = $this->ListChanges();
|
|
if (array_key_exists('name', $aChanges) || array_key_exists('used_for_smtp', $aChanges))
|
|
{
|
|
$sNewName = $this->Get('name');
|
|
$sNewUseForSMTP = $this->Get('used_for_smtp');
|
|
if ($sNewUseForSMTP == 'yes') {
|
|
$oSearch = DBObjectSearch::FromOQL_AllData("SELECT OAuthClientGoogle WHERE name = :newname AND used_for_smtp = :newuseforsmtp AND id != :id UNION SELECT OAuthClientAzure WHERE name = :newname AND used_for_smtp = :newuseforsmtp AND id != :id");
|
|
$oSet = new DBObjectSet($oSearch, array(), ['id' => $this->GetKey(), 'newname' => $sNewName, 'newuseforsmtp' => $sNewUseForSMTP]);
|
|
if ($oSet->Count() > 0)
|
|
{
|
|
$this->m_aCheckIssues[] = Dict::Format('OAuthClient:Name/UseForSMTPMustBeUnique', $sNewName, $sNewUseForSMTP);
|
|
}
|
|
}
|
|
}
|
|
} ]]></code>
|
|
</method>
|
|
<method id="ComputeValues">
|
|
<static>false</static>
|
|
<access>public</access>
|
|
<type>Overload-DBObject</type>
|
|
<code><![CDATA[
|
|
public function ComputeValues()
|
|
{
|
|
parent::ComputeValues();
|
|
if (empty($this->Get('provider'))) {
|
|
$this->Set('provider', 'Azure');
|
|
}
|
|
if (empty($this->Get('redirect_url'))) {
|
|
$this->Set('redirect_url', Combodo\iTop\Core\Authentication\Client\OAuth\OAuthClientProviderFactory::GetRedirectUri());
|
|
}
|
|
if (empty($this->Get('advanced_scope'))) {
|
|
$this->Set('used_scope', 'simple');
|
|
if (count($this->Get('scope')->GetValues()) == 0) {
|
|
$this->Set('scope', 'SMTP, IMAP');
|
|
}
|
|
} else {
|
|
$this->Set('used_scope', 'advanced');
|
|
$this->Set('scope', '');
|
|
}
|
|
}
|
|
]]></code>
|
|
</method>
|
|
<method id="GetAttributeFlags">
|
|
<static>false</static>
|
|
<access>public</access>
|
|
<type>Overload-DBObject</type>
|
|
<code><![CDATA[
|
|
public function GetAttributeFlags($sAttCode, &$aReasons = array(), $sTargetState = '')
|
|
{
|
|
switch ($sAttCode) {
|
|
case 'provider':
|
|
case 'redirect_url':
|
|
case 'used_scope':
|
|
return OPT_ATT_READONLY;
|
|
}
|
|
|
|
return parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState);
|
|
}
|
|
]]></code>
|
|
</method>
|
|
<method id="GetInitialStateAttributeFlags">
|
|
<static>false</static>
|
|
<access>public</access>
|
|
<type>Overload-DBObject</type>
|
|
<code><![CDATA[
|
|
public function GetInitialStateAttributeFlags($sAttCode, &$aReasons = array())
|
|
{
|
|
switch ($sAttCode) {
|
|
case 'provider':
|
|
case 'redirect_url':
|
|
case 'used_scope':
|
|
return OPT_ATT_READONLY;
|
|
}
|
|
|
|
return parent::GetInitialStateAttributeFlags($sAttCode, $aReasons);
|
|
}
|
|
]]></code>
|
|
</method>
|
|
<method id="GetDefaultMailServer">
|
|
<static>false</static>
|
|
<access>public</access>
|
|
<code><![CDATA[
|
|
public function GetDefaultMailServer()
|
|
{
|
|
return 'outlook.office365.com';
|
|
}
|
|
]]></code>
|
|
</method>
|
|
<method id="GetScope">
|
|
<static>false</static>
|
|
<access>public</access>
|
|
<code><![CDATA[
|
|
public function GetScope()
|
|
{
|
|
if (!empty($this->Get('advanced_scope'))) {
|
|
return $this->Get('advanced_scope');
|
|
}
|
|
$aScopes = $this->Get('scope')->GetValues();
|
|
$aRawScopes = ['offline_access'];
|
|
foreach ($aScopes as $sScope) {
|
|
switch ($sScope) {
|
|
case 'SMTP':
|
|
$aRawScopes[] = 'https://outlook.office.com/SMTP.Send';
|
|
break;
|
|
|
|
case 'IMAP':
|
|
$aRawScopes[] = 'https://outlook.office.com/IMAP.AccessAsUser.All';
|
|
break;
|
|
}
|
|
}
|
|
return implode(' ', $aRawScopes);
|
|
}
|
|
]]></code>
|
|
</method>
|
|
</methods>
|
|
</class>
|
|
<class id="OAuthClientGoogle" _delta="define">
|
|
<parent>OAuthClient</parent>
|
|
<properties>
|
|
<category>grant_by_profile,application</category>
|
|
<abstract>false</abstract>
|
|
<key_type>autoincrement</key_type>
|
|
<db_table>priv_oauth_client_google</db_table>
|
|
<db_key_field>id</db_key_field>
|
|
<db_final_class_field/>
|
|
<naming>
|
|
<attributes>
|
|
<attribute id="provider"/>
|
|
<attribute id="name"/>
|
|
</attributes>
|
|
</naming>
|
|
<reconciliation>
|
|
<attributes>
|
|
<attribute id="provider"/>
|
|
<attribute id="name"/>
|
|
</attributes>
|
|
</reconciliation>
|
|
<uniqueness_rules>
|
|
<rule id="server">
|
|
<attributes>
|
|
<attribute id="provider"/>
|
|
<attribute id="client_id"/>
|
|
<attribute id="client_secret"/>
|
|
</attributes>
|
|
<is_blocking>true</is_blocking>
|
|
</rule>
|
|
</uniqueness_rules>
|
|
<style>
|
|
<icon/>
|
|
</style>
|
|
</properties>
|
|
<fields>
|
|
<field id="scope" xsi:type="AttributeEnumSet">
|
|
<always_load_in_tables>true</always_load_in_tables>
|
|
<values>
|
|
<value id="SMTP">
|
|
<code>SMTP</code>
|
|
</value>
|
|
<value id="IMAP">
|
|
<code>IMAP</code>
|
|
</value>
|
|
</values>
|
|
<sql>scope</sql>
|
|
<default_value>SMTP,IMAP</default_value>
|
|
<is_null_allowed>true</is_null_allowed>
|
|
</field>
|
|
<field id="advanced_scope" xsi:type="AttributeString">
|
|
<sql>advanced_scope</sql>
|
|
<default_value/>
|
|
<is_null_allowed>true</is_null_allowed>
|
|
</field>
|
|
<field id="used_scope" xsi:type="AttributeEnum">
|
|
<always_load_in_tables>true</always_load_in_tables>
|
|
<values>
|
|
<value id="simple">
|
|
<code>simple</code>
|
|
</value>
|
|
<value id="advanced">
|
|
<code>advanced</code>
|
|
</value>
|
|
</values>
|
|
<sql>used_scope</sql>
|
|
<default_value>simple</default_value>
|
|
<is_null_allowed>false</is_null_allowed>
|
|
<dependencies>
|
|
<attribute id="scope"/>
|
|
<attribute id="advanced_scope"/>
|
|
</dependencies>
|
|
</field>
|
|
<field id="used_for_smtp" xsi:type="AttributeEnum">
|
|
<always_load_in_tables>true</always_load_in_tables>
|
|
<values>
|
|
<value id="yes">
|
|
<code>yes</code>
|
|
</value>
|
|
<value id="no">
|
|
<code>no</code>
|
|
</value>
|
|
</values>
|
|
<sql>used_for_smtp</sql>
|
|
<default_value>no</default_value>
|
|
<is_null_allowed>true</is_null_allowed>
|
|
</field>
|
|
</fields>
|
|
<presentation>
|
|
<details>
|
|
<items>
|
|
<item id="col:col1">
|
|
<rank>10</rank>
|
|
<items>
|
|
<item id="fieldset:OAuthClient:baseinfo">
|
|
<rank>10</rank>
|
|
<items>
|
|
<item id="name">
|
|
<rank>10</rank>
|
|
</item>
|
|
<item id="status">
|
|
<rank>20</rank>
|
|
</item>
|
|
<item id="description">
|
|
<rank>30</rank>
|
|
</item>
|
|
<item id="provider">
|
|
<rank>40</rank>
|
|
</item>
|
|
<item id="redirect_url">
|
|
<rank>50</rank>
|
|
</item>
|
|
<item id="client_id">
|
|
<rank>60</rank>
|
|
</item>
|
|
<item id="client_secret">
|
|
<rank>70</rank>
|
|
</item>
|
|
<item id="mailbox_list">
|
|
<rank>80</rank>
|
|
</item>
|
|
</items>
|
|
</item>
|
|
</items>
|
|
</item>
|
|
<item id="col:col2">
|
|
<rank>20</rank>
|
|
<items>
|
|
<item id="fieldset:OAuthClient:scope">
|
|
<rank>10</rank>
|
|
<items>
|
|
<item id="used_scope">
|
|
<rank>10</rank>
|
|
</item>
|
|
<item id="scope">
|
|
<rank>20</rank>
|
|
</item>
|
|
<item id="advanced_scope">
|
|
<rank>30</rank>
|
|
</item>
|
|
<item id="used_for_smtp">
|
|
<rank>40</rank>
|
|
</item>
|
|
</items>
|
|
</item>
|
|
</items>
|
|
</item>
|
|
</items>
|
|
</details>
|
|
<list>
|
|
<items>
|
|
<item id="provider">
|
|
<rank>10</rank>
|
|
</item>
|
|
<item id="status">
|
|
<rank>10</rank>
|
|
</item>
|
|
</items>
|
|
</list>
|
|
<standard_search>
|
|
<items>
|
|
<item id="name">
|
|
<rank>10</rank>
|
|
</item>
|
|
<item id="provider">
|
|
<rank>10</rank>
|
|
</item>
|
|
<item id="status">
|
|
<rank>10</rank>
|
|
</item>
|
|
</items>
|
|
</standard_search>
|
|
</presentation>
|
|
<methods>
|
|
<method id="PrefillCreationForm">
|
|
<static>false</static>
|
|
<access>public</access>
|
|
<type>Overload-DBObject</type>
|
|
<code><![CDATA[
|
|
public function PrefillCreationForm(&$aContextParam)
|
|
{
|
|
$this->Set('provider', 'Google');
|
|
$this->Set('redirect_url', Combodo\iTop\Core\Authentication\Client\OAuth\OAuthClientProviderFactory::GetRedirectUri());
|
|
$this->Set('scope', 'SMTP, IMAP');
|
|
|
|
parent::PrefillCreationForm($aContextParam);
|
|
}
|
|
]]></code>
|
|
</method>
|
|
<method id="DoCheckToWrite">
|
|
<static>false</static>
|
|
<access>public</access>
|
|
<type>Overload-DBObject</type>
|
|
<code><![CDATA[ public function DoCheckToWrite()
|
|
{
|
|
parent::DoCheckToWrite();
|
|
|
|
$aChanges = $this->ListChanges();
|
|
if (array_key_exists('name', $aChanges) || array_key_exists('used_for_smtp', $aChanges))
|
|
{
|
|
$sNewName = $this->Get('name');
|
|
$sNewUseForSMTP = $this->Get('used_for_smtp');
|
|
if ($sNewUseForSMTP == 'yes') {
|
|
$oSearch = DBObjectSearch::FromOQL_AllData("SELECT OAuthClientGoogle WHERE name = :newname AND used_for_smtp = :newuseforsmtp AND id != :id UNION SELECT OAuthClientAzure WHERE name = :newname AND used_for_smtp = :newuseforsmtp AND id != :id");
|
|
$oSet = new DBObjectSet($oSearch, array(), ['id' => $this->GetKey(), 'newname' => $sNewName, 'newuseforsmtp' => $sNewUseForSMTP]);
|
|
if ($oSet->Count() > 0)
|
|
{
|
|
$this->m_aCheckIssues[] = Dict::Format('OAuthClient:Name/UseForSMTPMustBeUnique', $sNewName, $sNewUseForSMTP);
|
|
}
|
|
}
|
|
}
|
|
} ]]></code>
|
|
</method>
|
|
<method id="ComputeValues">
|
|
<static>false</static>
|
|
<access>public</access>
|
|
<type>Overload-DBObject</type>
|
|
<code><![CDATA[
|
|
public function ComputeValues()
|
|
{
|
|
parent::ComputeValues();
|
|
if (empty($this->Get('provider'))) {
|
|
$this->Set('provider', 'Google');
|
|
}
|
|
if (empty($this->Get('redirect_url'))) {
|
|
$this->Set('redirect_url', Combodo\iTop\Core\Authentication\Client\OAuth\OAuthClientProviderFactory::GetRedirectUri());
|
|
}
|
|
if (empty($this->Get('advanced_scope'))) {
|
|
$this->Set('used_scope', 'simple');
|
|
if (count($this->Get('scope')->GetValues()) == 0) {
|
|
$this->Set('scope', 'SMTP, IMAP');
|
|
}
|
|
} else {
|
|
$this->Set('used_scope', 'advanced');
|
|
$this->Set('scope', '');
|
|
}
|
|
}
|
|
]]></code>
|
|
</method>
|
|
<method id="GetAttributeFlags">
|
|
<static>false</static>
|
|
<access>public</access>
|
|
<type>Overload-DBObject</type>
|
|
<code><![CDATA[
|
|
public function GetAttributeFlags($sAttCode, &$aReasons = array(), $sTargetState = '')
|
|
{
|
|
switch ($sAttCode) {
|
|
case 'provider':
|
|
case 'redirect_url':
|
|
case 'used_scope':
|
|
return OPT_ATT_READONLY;
|
|
}
|
|
|
|
return parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState);
|
|
}
|
|
]]></code>
|
|
</method>
|
|
<method id="GetInitialStateAttributeFlags">
|
|
<static>false</static>
|
|
<access>public</access>
|
|
<type>Overload-DBObject</type>
|
|
<code><![CDATA[
|
|
public function GetInitialStateAttributeFlags($sAttCode, &$aReasons = array())
|
|
{
|
|
switch ($sAttCode) {
|
|
case 'provider':
|
|
case 'redirect_url':
|
|
case 'used_scope':
|
|
return OPT_ATT_READONLY;
|
|
}
|
|
|
|
return parent::GetInitialStateAttributeFlags($sAttCode, $aReasons);
|
|
}
|
|
]]></code>
|
|
</method>
|
|
<method id="GetDefaultMailServer">
|
|
<static>false</static>
|
|
<access>public</access>
|
|
<code><![CDATA[
|
|
public function GetDefaultMailServer()
|
|
{
|
|
return 'imap.gmail.com';
|
|
}
|
|
]]></code>
|
|
</method>
|
|
<method id="GetScope">
|
|
<static>false</static>
|
|
<access>public</access>
|
|
<code><![CDATA[
|
|
public function GetScope()
|
|
{
|
|
if (!empty($this->Get('advanced_scope'))) {
|
|
return $this->Get('advanced_scope');
|
|
}
|
|
$aScopes = $this->Get('scope')->GetValues();
|
|
$aRawScopes = [];
|
|
foreach ($aScopes as $sScope) {
|
|
switch ($sScope) {
|
|
case 'SMTP':
|
|
$aRawScopes['https://mail.google.com/'] = 'https://mail.google.com/';
|
|
break;
|
|
|
|
case 'IMAP':
|
|
$aRawScopes['https://mail.google.com/'] = 'https://mail.google.com/';
|
|
break;
|
|
}
|
|
}
|
|
return implode(' ', $aRawScopes);
|
|
}
|
|
]]></code>
|
|
</method>
|
|
</methods>
|
|
</class>
|
|
</classes>
|
|
<menus>
|
|
<menu id="OAuthClient" xsi:type="OQLMenuNode" _delta="define">
|
|
<rank>100</rank>
|
|
<parent>ConfigurationTools</parent>
|
|
<oql><![CDATA[SELECT OAuthClient]]></oql>
|
|
<do_search>1</do_search>
|
|
<enable_admin_only>0</enable_admin_only>
|
|
<enable_class>OAuthClient</enable_class>
|
|
<enable_action>UR_ACTION_MODIFY</enable_action>
|
|
</menu>
|
|
</menus>
|
|
<user_rights>
|
|
<groups>
|
|
<group id="OauthConnection" _delta="define">
|
|
<classes>
|
|
<class id="OAuthClient"/>
|
|
</classes>
|
|
</group>
|
|
</groups>
|
|
</user_rights>
|
|
</itop_design>
|