mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-18 23:08:46 +02:00
N°5102 - Allow to send emails using GSuite SMTP and OAuth - Rework
This commit is contained in:
@@ -1,137 +1,5 @@
|
||||
<?php
|
||||
//
|
||||
// File generated by ... on the 2022-06-21T13:02:44+0000
|
||||
// File generated
|
||||
// Please do not edit manually
|
||||
//
|
||||
|
||||
/**
|
||||
* Classes and menus for itop-remote-authent-oauth (version 1.0.0)
|
||||
*
|
||||
* @author iTop compiler
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
|
||||
abstract class RemoteAuthentOAuth extends cmdbAbstractObject
|
||||
{
|
||||
public static function Init()
|
||||
{
|
||||
$aParams = array( 'category' => 'cloud,searchable',
|
||||
'key_type' => 'autoincrement',
|
||||
'name_attcode' => array('provider', 'name'),
|
||||
'state_attcode' => '',
|
||||
'reconc_keys' => array('provider', 'name'),
|
||||
'db_table' => 'priv_remote_authent_oauth',
|
||||
'db_key_field' => 'id',
|
||||
'db_finalclass_field' => '',
|
||||
'uniqueness_rules' => array (
|
||||
'Username' =>
|
||||
array (
|
||||
'attributes' =>
|
||||
array (
|
||||
0 => 'name',
|
||||
),
|
||||
'filter' => NULL,
|
||||
'disabled' => false,
|
||||
'is_blocking' => true,
|
||||
),
|
||||
'OAuth Server' =>
|
||||
array (
|
||||
'attributes' =>
|
||||
array (
|
||||
0 => 'provider',
|
||||
1 => 'scope',
|
||||
2 => 'client_id',
|
||||
3 => 'client_secret',
|
||||
),
|
||||
'filter' => NULL,
|
||||
'disabled' => false,
|
||||
'is_blocking' => true,
|
||||
),
|
||||
),);
|
||||
MetaModel::Init_Params($aParams);
|
||||
MetaModel::Init_InheritAttributes();
|
||||
MetaModel::Init_AddAttribute(new AttributeString("provider", array("allowed_values"=>null, "sql"=>'provider', "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array(), "always_load_in_tables"=>false)));
|
||||
MetaModel::Init_AddAttribute(new AttributeString("name", array("allowed_values"=>null, "sql"=>'name', "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array(), "always_load_in_tables"=>false)));
|
||||
MetaModel::Init_AddAttribute(new AttributeString("scope", array("allowed_values"=>null, "sql"=>'scope', "default_value"=>'', "is_null_allowed"=>true, "depends_on"=>array(), "always_load_in_tables"=>false)));
|
||||
MetaModel::Init_AddAttribute(new AttributeText("description", array("allowed_values"=>null, "sql"=>'description', "default_value"=>'', "is_null_allowed"=>true, "depends_on"=>array(), "always_load_in_tables"=>false)));
|
||||
MetaModel::Init_AddAttribute(new AttributeText("client_id", array("allowed_values"=>null, "sql"=>'client_id', "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array(), "always_load_in_tables"=>false)));
|
||||
MetaModel::Init_AddAttribute(new AttributeText("client_secret", array("allowed_values"=>null, "sql"=>'client_secret', "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array(), "always_load_in_tables"=>false)));
|
||||
MetaModel::Init_AddAttribute(new AttributeText("refresh_token", array("allowed_values"=>null, "sql"=>'refresh_token', "default_value"=>'', "is_null_allowed"=>true, "depends_on"=>array(), "always_load_in_tables"=>false, "tracking_level"=>ATTRIBUTE_TRACKING_NONE)));
|
||||
MetaModel::Init_AddAttribute(new AttributeDateTime("refresh_token_expiration", array("allowed_values"=>null, "sql"=>'refresh_token_expiration', "default_value"=>'', "is_null_allowed"=>true, "depends_on"=>array(), "always_load_in_tables"=>false, "tracking_level"=>ATTRIBUTE_TRACKING_NONE)));
|
||||
MetaModel::Init_AddAttribute(new AttributeText("token", array("allowed_values"=>null, "sql"=>'token', "default_value"=>'', "is_null_allowed"=>true, "depends_on"=>array(), "always_load_in_tables"=>false, "tracking_level"=>ATTRIBUTE_TRACKING_NONE)));
|
||||
MetaModel::Init_AddAttribute(new AttributeDateTime("token_expiration", array("allowed_values"=>null, "sql"=>'token_expiration', "default_value"=>'', "is_null_allowed"=>true, "depends_on"=>array(), "always_load_in_tables"=>false, "tracking_level"=>ATTRIBUTE_TRACKING_NONE)));
|
||||
MetaModel::Init_AddAttribute(new AttributeURL("redirect_url", array("target"=>'_blank', "allowed_values"=>null, "sql"=>'redirect_url', "default_value"=>'', "is_null_allowed"=>true, "depends_on"=>array(), "always_load_in_tables"=>false)));
|
||||
MetaModel::Init_AddAttribute(new AttributeLinkedSet("mailbox_list", array("linked_class"=>'MailInboxOAuth', "ext_key_to_me"=>'remote_authent_oauth_id', "count_min"=>0, "count_max"=>0, "allowed_values"=>null, "depends_on"=>array(), "always_load_in_tables"=>false)));
|
||||
|
||||
|
||||
|
||||
MetaModel::Init_SetZListItems('details', array (
|
||||
0 => 'name',
|
||||
1 => 'description',
|
||||
2 => 'provider',
|
||||
3 => 'scope',
|
||||
4 => 'redirect_url',
|
||||
5 => 'client_id',
|
||||
6 => 'client_secret',
|
||||
7 => 'mailbox_list',
|
||||
));
|
||||
MetaModel::Init_SetZListItems('standard_search', array (
|
||||
0 => 'name',
|
||||
1 => 'provider',
|
||||
));
|
||||
MetaModel::Init_SetZListItems('default_search', array (
|
||||
0 => 'name',
|
||||
1 => 'provider',
|
||||
));
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function DisplayBareHeader(WebPage $oPage, $bEditMode = false)
|
||||
{
|
||||
parent::DisplayBareHeader($oPage, $bEditMode);
|
||||
if (!$bEditMode) {
|
||||
$oConfig = utils::GetConfig();
|
||||
if ($oConfig->Get('email_transport_smtp.username') == $this->Get('name')) {
|
||||
$sLabel = Dict::S('itop-remote-authent-oauth:UsedForSMTP');
|
||||
$sTestLabel = Dict::S('itop-remote-authent-oauth:TestSMTP');
|
||||
$sTestURL = utils::GetAbsoluteUrlAppRoot().'setup/email.test.php';
|
||||
$oPage->p("<b>$sLabel</b> <a href='$sTestURL' target='_blank'>$sTestLabel</a>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function GetDefaultMailServer()
|
||||
{
|
||||
return 'imap.'.$this->Get('provider').'.com';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function GetDefaultMailServerPort()
|
||||
{
|
||||
return 993;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//
|
||||
// Menus
|
||||
//
|
||||
class MenuCreation_itop_remote_authent_oauth extends ModuleHandlerAPI
|
||||
{
|
||||
public static function OnMenuCreation()
|
||||
{
|
||||
global $__comp_menus__; // ensure that the global variable is indeed global !
|
||||
$__comp_menus__['ConfigurationTools'] = new MenuGroup('ConfigurationTools', 90 , null, UR_ACTION_MODIFY, UR_ALLOWED_YES, null);
|
||||
$__comp_menus__['RemoteOAuth'] = new SearchMenuNode('RemoteOAuth', 'RemoteAuthentOAuth', $__comp_menus__['ConfigurationTools']->GetIndex(), 100, null , null, UR_ACTION_MODIFY, UR_ALLOWED_YES, null);
|
||||
}
|
||||
} // class MenuCreation_itop_remote_authent_oauth
|
||||
|
||||
@@ -14,12 +14,12 @@ class RemoteAuthentOAuthAzure extends RemoteAuthentOAuth
|
||||
(
|
||||
'category' => 'cloud',
|
||||
'key_type' => 'autoincrement',
|
||||
'name_attcode' => ['provider','name'],
|
||||
'name_attcode' => ['provider', 'name'],
|
||||
'state_attcode' => '',
|
||||
'reconc_keys' => ['provider','name'],
|
||||
'reconc_keys' => ['provider', 'name'],
|
||||
'db_table' => 'priv_remote_authent_oauth_azure',
|
||||
'db_key_field' => 'id',
|
||||
'icon' => utils::GetAbsoluteUrlModulesRoot().'itop-remote-authent-oauth/assets/img/icons8-azure.svg',
|
||||
'icon' => utils::GetAbsoluteUrlModulesRoot().'itop-remote-authent-oauth/assets/img/icons8-azure.svg',
|
||||
'db_finalclass_field' => '',
|
||||
);
|
||||
MetaModel::Init_Params($aParams);
|
||||
@@ -56,4 +56,13 @@ class RemoteAuthentOAuthAzure extends RemoteAuthentOAuth
|
||||
{
|
||||
return 'imap.office365.com';
|
||||
}
|
||||
|
||||
public function GetAttributeFlags($sAttCode, &$aReasons = array(), $sTargetState = '')
|
||||
{
|
||||
if ($sAttCode == 'provider' || $sAttCode == 'redirect_url') {
|
||||
return OPT_ATT_READONLY;
|
||||
}
|
||||
|
||||
return parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState);
|
||||
}
|
||||
}
|
||||
@@ -57,4 +57,12 @@ class RemoteAuthentOAuthGoogle extends RemoteAuthentOAuth
|
||||
return 'imap.gmail.com';
|
||||
}
|
||||
|
||||
public function GetAttributeFlags($sAttCode, &$aReasons = array(), $sTargetState = '')
|
||||
{
|
||||
if ($sAttCode == 'provider' || $sAttCode == 'scope' || $sAttCode == 'redirect_url') {
|
||||
return OPT_ATT_READONLY;
|
||||
}
|
||||
|
||||
return parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user