diff --git a/datamodels/2.x/itop-oauth-client/datamodel.itop-oauth-client.xml b/datamodels/2.x/itop-oauth-client/datamodel.itop-oauth-client.xml index d950e034c..c1ed17ac4 100644 --- a/datamodels/2.x/itop-oauth-client/datamodel.itop-oauth-client.xml +++ b/datamodels/2.x/itop-oauth-client/datamodel.itop-oauth-client.xml @@ -110,10 +110,9 @@ parent::DisplayBareHeader($oPage, $bEditMode); if (!$bEditMode) { $oConfig = utils::GetConfig(); - $aScopes = $this->Get('scope')->GetValues(); if ($this->Get('status') == 'inactive') { $oPage->p(''.Dict::S('itop-oauth-client:Message:MissingToken').''); - } elseif (in_array('SMTP', $aScopes) && $oConfig->Get('email_transport_smtp.username') == $this->Get('name')) { + } 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'; @@ -290,12 +289,6 @@ - - - - - true - @@ -336,6 +329,16 @@ + + true + + yes + no + + used_for_smtp + no + true +
@@ -389,6 +392,9 @@ 30 + + 40 + @@ -435,6 +441,30 @@ } ]]> + + false + public + Overload-DBObject + 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); + } + } + } + } ]]> + false public @@ -559,12 +589,6 @@ - - - - - true - @@ -605,6 +629,16 @@ + + true + + yes + no + + used_for_smtp + no + true +
@@ -658,6 +692,9 @@ 30 + + 40 + @@ -704,6 +741,30 @@ } ]]> + + false + public + Overload-DBObject + 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); + } + } + } + } ]]> + false public diff --git a/datamodels/2.x/itop-oauth-client/en.dict.itop-oauth-client.php b/datamodels/2.x/itop-oauth-client/en.dict.itop-oauth-client.php index 510e01cbe..c93f56053 100644 --- a/datamodels/2.x/itop-oauth-client/en.dict.itop-oauth-client.php +++ b/datamodels/2.x/itop-oauth-client/en.dict.itop-oauth-client.php @@ -22,6 +22,8 @@ Dict::Add('EN US', 'English', 'English', [ 'itop-oauth-client:Message:TokenCreated' => 'Access token created', 'itop-oauth-client:Message:TokenRecreated' => 'Access token regenerated', + 'OAuthClient:Name/UseForSMTPMustBeUnique' => 'The combination Login (%1$s) and Use for SMTP (%2$s) has already be used for OAuth Client', + 'OAuthClient:baseinfo' => 'Base Information', 'OAuthClient:scope' => 'Scope', ]); @@ -81,6 +83,10 @@ Dict::Add('EN US', 'English', 'English', array( 'Class:OAuthClientAzure/Attribute:used_scope/Value:simple+' => '', 'Class:OAuthClientAzure/Attribute:used_scope/Value:advanced' => 'Advanced', 'Class:OAuthClientAzure/Attribute:used_scope/Value:advanced+' => '', + 'Class:OAuthClientAzure/Attribute:used_for_smtp' => 'Used for SMTP', + 'Class:OAuthClientAzure/Attribute:used_for_smtp+' => '', + 'Class:OAuthClientAzure/Attribute:used_for_smtp/Value:yes' => 'Yes', + 'Class:OAuthClientAzure/Attribute:used_for_smtp/Value:no' => 'No', )); // @@ -104,4 +110,8 @@ Dict::Add('EN US', 'English', 'English', array( 'Class:OAuthClientGoogle/Attribute:used_scope/Value:simple+' => '', 'Class:OAuthClientGoogle/Attribute:used_scope/Value:advanced' => 'Advanced', 'Class:OAuthClientGoogle/Attribute:used_scope/Value:advanced+' => '', + 'Class:OAuthClientGoogle/Attribute:used_for_smtp' => 'Used for SMTP', + 'Class:OAuthClientGoogle/Attribute:used_for_smtp+' => '', + 'Class:OAuthClientGoogle/Attribute:used_for_smtp/Value:yes' => 'Yes', + 'Class:OAuthClientGoogle/Attribute:used_for_smtp/Value:no' => 'No', )); diff --git a/datamodels/2.x/itop-oauth-client/fr.dict.itop-oauth-client.php b/datamodels/2.x/itop-oauth-client/fr.dict.itop-oauth-client.php index 82837874b..c023795f1 100644 --- a/datamodels/2.x/itop-oauth-client/fr.dict.itop-oauth-client.php +++ b/datamodels/2.x/itop-oauth-client/fr.dict.itop-oauth-client.php @@ -5,6 +5,7 @@ * @copyright Copyright (C) 2013 XXXXX * @license http://opensource.org/licenses/AGPL-3.0 */ + Dict::Add('FR FR', 'French', 'Français', [ 'Menu:CreateMailbox' => 'Créer une boite mail...', 'Menu:OAuthClient' => 'Client OAuth', @@ -21,6 +22,8 @@ Dict::Add('FR FR', 'French', 'Français', [ 'itop-oauth-client:Message:TokenCreated' => 'Le jeton d\'accès à été créé', 'itop-oauth-client:Message:TokenRecreated' => 'Le jeton d\'accès à été renouvelé', + 'OAuthClient:Name/UseForSMTPMustBeUnique' => 'La combinaison Login (%1$s) and Utilisé pour SMTP (%2$s) a déjà été utilisée pour OAuth Client', + 'OAuthClient:baseinfo' => 'Information', 'OAuthClient:scope' => 'Scope', ]); @@ -80,6 +83,10 @@ Dict::Add('FR FR', 'French', 'Français', array( 'Class:OAuthClientAzure/Attribute:used_scope/Value:simple+' => '', 'Class:OAuthClientAzure/Attribute:used_scope/Value:advanced' => 'Avancé', 'Class:OAuthClientAzure/Attribute:used_scope/Value:advanced+' => '', + 'Class:OAuthClientAzure/Attribute:used_for_smtp' => 'Utilisé pour SMTP', + 'Class:OAuthClientAzure/Attribute:used_for_smtp+' => '', + 'Class:OAuthClientAzure/Attribute:used_for_smtp/Value:yes' => 'Oui', + 'Class:OAuthClientAzure/Attribute:used_for_smtp/Value:no' => 'Non', )); // @@ -102,4 +109,8 @@ Dict::Add('FR FR', 'French', 'Français', array( 'Class:OAuthClientGoogle/Attribute:used_scope/Value:simple' => 'Simple', 'Class:OAuthClientGoogle/Attribute:used_scope/Value:advanced' => 'Avancé', 'Class:OAuthClientGoogle/Attribute:used_scope/Value:advanced+' => '', + 'Class:OAuthClientGoogle/Attribute:used_for_smtp' => 'Utilisé pour SMTP', + 'Class:OAuthClientGoogle/Attribute:used_for_smtp+' => '', + 'Class:OAuthClientGoogle/Attribute:used_for_smtp/Value:yes' => 'Oui', + 'Class:OAuthClientGoogle/Attribute:used_for_smtp/Value:no' => 'Non', )); diff --git a/datamodels/2.x/itop-oauth-client/src/Service/ApplicationUIExtension.php b/datamodels/2.x/itop-oauth-client/src/Service/ApplicationUIExtension.php index 4ab73d852..7fb0b8a53 100644 --- a/datamodels/2.x/itop-oauth-client/src/Service/ApplicationUIExtension.php +++ b/datamodels/2.x/itop-oauth-client/src/Service/ApplicationUIExtension.php @@ -19,10 +19,9 @@ class ApplicationUIExtension extends AbstractApplicationUIExtension // Possible return values are: // HILIGHT_CLASS_CRITICAL, HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE $oConfig = utils::GetConfig(); - $aScopes = $oObject->Get('scope')->GetValues(); if ($oObject->Get('status') == 'inactive') { return HILIGHT_CLASS_WARNING; - } elseif (in_array('SMTP', $aScopes) && $oConfig->Get('email_transport_smtp.username') == $oObject->Get('name')) { + } elseif ($oObject->Get('used_for_smtp') == 'yes' && $oConfig->Get('email_transport_smtp.username') == $oObject->Get('name')) { return HILIGHT_CLASS_OK; } } diff --git a/sources/Core/Authentication/Client/OAuth/OAuthClientProviderFactory.php b/sources/Core/Authentication/Client/OAuth/OAuthClientProviderFactory.php index 7d5f3b721..66230eb3e 100644 --- a/sources/Core/Authentication/Client/OAuth/OAuthClientProviderFactory.php +++ b/sources/Core/Authentication/Client/OAuth/OAuthClientProviderFactory.php @@ -43,8 +43,7 @@ class OAuthClientProviderFactory throw new CoreException(Dict::Format('itop-oauth-client:MissingOAuthClient', $sUsername)); } while ($oOAuthClient = $oSet->Fetch()) { - $aScopes = $oOAuthClient->Get('scope')->GetValues(); - if (in_array('SMTP', $aScopes)) { + if ($oOAuthClient->Get('used_for_smtp') == 'yes') { return $oOAuthClient; } }