Merge branch '20.0' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2024-10-29 15:55:42 +01:00
commit d9a5636b77
8 changed files with 69 additions and 18 deletions

View File

@ -413,7 +413,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
} else {
$keyforprovider = '';
}
$keyforsupportedoauth2array = preg_replace('/-.*$/', '', $keyforsupportedoauth2array);
$keyforsupportedoauth2array = preg_replace('/-.*$/', '', strtoupper($keyforsupportedoauth2array));
$keyforsupportedoauth2array = 'OAUTH_'.$keyforsupportedoauth2array.'_NAME';
if (!empty($supportedoauth2array)) {

View File

@ -125,8 +125,20 @@ if ($action == 'refreshtoken' && $user->admin) {
$tokenobj = null;
// Load OAUth libraries
require_once DOL_DOCUMENT_ROOT.'/includes/OAuth/bootstrap.php';
$keyforsupportedoauth2array = $OAUTH_SERVICENAME;
if (preg_match('/^.*-/', $keyforsupportedoauth2array)) {
$keyforprovider = preg_replace('/^.*-/', '', $keyforsupportedoauth2array);
} else {
$keyforprovider = '';
}
$keyforsupportedoauth2array = preg_replace('/-.*$/', '', strtoupper($keyforsupportedoauth2array));
$keyforsupportedoauth2array = 'OAUTH_'.$keyforsupportedoauth2array.'_NAME';
$keyforparamtenant = 'OAUTH_'.strtoupper(empty($supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']) ? 'Unknown' : $supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']).($keyforprovider ? '-'.$keyforprovider : '').'_TENANT';
// Dolibarr storage
$storage = new DoliStorage($db, $conf, $keyforprovider);
$storage = new DoliStorage($db, $conf, $keyforprovider, getDolGlobalString($keyforparamtenant));
try {
// $OAUTH_SERVICENAME is for example 'Google-keyforprovider'
print '<!-- '.$OAUTH_SERVICENAME.' -->'."\n";
@ -161,8 +173,15 @@ if ($action == 'refreshtoken' && $user->admin) {
//$httpClient->setCurlParameters($params);
$serviceFactory->setHttpClient($httpClient);
$scopes = array();
if (preg_match('/^Microsoft/', $OAUTH_SERVICENAME)) {
//$extraparams = $tokenobj->getExtraParams();
$tmp = explode('-', $OAUTH_SERVICENAME);
$scopes = explode(',', getDolGlobalString('OAUTH_'.strtoupper($tmp[0]).(empty($tmp[1]) ? '' : '-'.$tmp[1]).'_SCOPE'));
}
// ex service is Google-Emails we need only the first part Google
$apiService = $serviceFactory->createService($oauthname[0], $credentials, $storage, array());
$apiService = $serviceFactory->createService($oauthname[0], $credentials, $storage, $scopes);
if ($apiService instanceof OAuth\OAuth2\Service\AbstractService || $apiService instanceof OAuth\OAuth1\Service\AbstractService) {
// ServiceInterface does not provide refreshAccessToekn, AbstractService does
@ -254,7 +273,7 @@ if ($mode == 'setup' && $user->admin) {
$keybeforeprovider = $keyforsupportedoauth2array;
$keyforprovider = '';
}
$keyforsupportedoauth2array = preg_replace('/-.*$/', '', $keyforsupportedoauth2array);
$keyforsupportedoauth2array = preg_replace('/-.*$/', '', strtoupper($keyforsupportedoauth2array));
$keyforsupportedoauth2array = 'OAUTH_'.$keyforsupportedoauth2array.'_NAME';
$nameofservice = ucfirst(strtolower(empty($supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']) ? 'Unknown' : $supportedoauth2array[$keyforsupportedoauth2array]['callbackfile']));

View File

@ -44,8 +44,6 @@ class modSalaries extends DolibarrModules
*/
public function __construct($db)
{
global $conf;
$this->db = $db;
$this->numero = 510; // Perms from 501..519
@ -151,17 +149,18 @@ class modSalaries extends DolibarrModules
$r++;
$this->export_code[$r] = $this->rights_class.'_'.$r;
$this->export_label[$r] = 'SalariesAndPayments';
$this->export_icon[$r] = 'salary';
$this->export_permission[$r] = array(array("salaries", "export"));
$this->export_fields_array[$r] = array('u.firstname'=>"Firstname", 'u.lastname'=>"Lastname", 'u.login'=>"Login", 'u.salary'=>'CurrentSalary', 'p.datep'=>'DatePayment', 'p.datesp'=>'DateStartPeriod', 'p.dateep'=>'DateEndPeriod', 'p.amount'=>'AmountPayment', 'p.num_payment'=>'Numero', 'p.label'=>'Label', 'p.note'=>'Note');
$this->export_TypeFields_array[$r] = array('u.firstname'=>"Text", 'u.lastname'=>"Text", 'u.login'=>'Text', 'u.salary'=>"Numeric", 'p.datep'=>'Date', 'p.datesp'=>'Date', 'p.dateep'=>'Date', 'p.amount'=>'Numeric', 'p.num_payment'=>'Numeric', 'p.label'=>'Text');
$this->export_fields_array[$r] = array('s.rowid' => 'SalaryID', 's.label'=>'Label', 's.datesp'=>'DateStartPeriod', 's.dateep'=>'DateEndPeriod', 's.amount' => 'SalaryAmount', 's.paye' => 'Status', 'u.firstname'=>"Firstname", 'u.lastname'=>"Lastname", 'u.login'=>"Login", 'u.salary'=>'CurrentSalary', 'p.datep'=>'DatePayment', 'p.amount'=>'AmountPayment', 'p.num_payment'=>'Numero', 'p.note'=>'Note');
$this->export_TypeFields_array[$r] = array('s.rowid' => 'Numeric', 's.label'=>'Text', 's.amount' => 'Numeric', 's.paye' => 'Numeric', 'u.firstname'=>"Text", 'u.lastname'=>"Text", 'u.login'=>'Text', 'u.salary'=>"Numeric", 'p.datep'=>'Date', 's.datesp'=>'Date', 's.dateep'=>'Date', 'p.amount'=>'Numeric', 'p.num_payment'=>'Numeric');
$this->export_entities_array[$r] = array('u.firstname'=>'user', 'u.lastname'=>'user', 'u.login'=>'user', 'u.salary'=>'user', 'p.datep'=>'payment', 'p.datesp'=>'payment', 'p.dateep'=>'payment', 'p.amount'=>'payment', 'p.label'=>'payment', 'p.note'=>'payment', 'p.num_payment'=>'payment');
$this->export_sql_start[$r] = 'SELECT DISTINCT ';
$this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'user as u';
$this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'salary as s ON s.fk_user = u.rowid';
$this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'salary as s';
$this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON s.fk_user = u.rowid';
$this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'payment_salary as p ON p.fk_salary = s.rowid';
$this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_typepayment = cp.id';
$this->export_sql_end[$r] .= ' AND u.entity IN ('.getEntity('user').')';
$this->export_sql_end[$r] .= ' AND s.entity IN ('.getEntity('salary').')';
}

View File

@ -1203,7 +1203,7 @@ class EmailCollector extends CommonObject
} else {
$keyforprovider = '';
}
$keyforsupportedoauth2array = preg_replace('/-.*$/', '', $keyforsupportedoauth2array);
$keyforsupportedoauth2array = preg_replace('/-.*$/', '', strtoupper($keyforsupportedoauth2array));
$keyforsupportedoauth2array = 'OAUTH_'.$keyforsupportedoauth2array.'_NAME';
if (!empty($supportedoauth2array)) {
@ -1244,11 +1244,22 @@ class EmailCollector extends CommonObject
$serviceFactory = new \OAuth\ServiceFactory();
$oauthname = explode('-', $OAUTH_SERVICENAME);
// ex service is Google-Emails we need only the first part Google
$apiService = $serviceFactory->createService($oauthname[0], $credentials, $storage, array());
$scopes = array();
if (preg_match('/^Microsoft/', $OAUTH_SERVICENAME)) {
//$extraparams = $tokenobj->getExtraParams();
$tmp = explode('-', $OAUTH_SERVICENAME);
$scopes = explode(',', getDolGlobalString('OAUTH_'.strtoupper($tmp[0]).(empty($tmp[1]) ? '' : '-'.$tmp[1]).'_SCOPE'));
}
$apiService = $serviceFactory->createService($oauthname[0], $credentials, $storage, $scopes);
'@phan-var-force OAuth\OAuth2\Service\AbstractService|OAuth\OAuth1\Service\AbstractService $apiService'; // createService is only ServiceInterface
// We have to save the token because Google give it only once
$refreshtoken = $tokenobj->getRefreshToken();
$tokenobj = $apiService->refreshAccessToken($tokenobj);
// We have to save the token because answer give it only once
$tokenobj->setRefreshToken($refreshtoken);
$storage->storeAccessToken($OAUTH_SERVICENAME, $tokenobj);
}

View File

@ -2937,7 +2937,7 @@ if ($action != 'presend') {
}
// Presend form
$modelmail = 'expensereport';
$modelmail = 'expensereport_send';
$defaulttopic = 'SendExpenseReportRef';
$diroutput = $conf->expensereport->dir_output;
$trackid = 'exp'.$object->id;

View File

@ -218,12 +218,31 @@ abstract class AbstractService extends BaseAbstractService implements ServiceInt
'refresh_token' => $refreshToken,
);
// @CHANGE LDR
//global $conf; $conf->global->OAUTH_ADD_SCOPE_AND_TENANT_IN_REFRESH_MESSAGE = 1;
if (getDolGlobalString('OAUTH_ADD_SCOPE_AND_TENANT_IN_REFRESH_MESSAGE')) {
if (!empty($this->scopes)) {
$parameters['scope'] = implode($this->getScopesDelimiter(), $this->scopes);
}
if ($this->storage->getTenant()) {
$parameters['tenant'] = $this->storage->getTenant();
}
}
//var_dump($parameters);
$responseBody = $this->httpClient->retrieveResponse(
$this->getAccessTokenEndpoint(),
$parameters,
$this->getExtraOAuthHeaders()
);
//print $responseBody;exit; // We must have a result "{"token_type":"Bearer","scope...
// @CHANGE LDR
$data = json_decode((string) $responseBody, true);
if (is_array($data) && !empty($data['error_description'])) {
print 'Oauth2 AbstractService error received: '.$data['error_description'];
}
//print $responseBody;exit; // We must have a result string "{"token_type":"Bearer","error_description":...,"scope...
$token = $this->parseAccessTokenResponse($responseBody);
$this->storage->storeAccessToken($this->service(), $token);

View File

@ -9,6 +9,8 @@ NewSalary=New salary
AddSalary=Add salary
NewSalaryPayment=New salary card
AddSalaryPayment=Add salary payment
SalaryID=Salary ID
SalaryAmount=Salary amount
SalaryPayment=Salary payment
SalariesPayments=Salaries payments
SalariesPaymentsOf=Salaries payments of %s

View File

@ -72,10 +72,10 @@ if (GETPOST('btn_view_ticket_list')) {
unset($_SESSION['track_id_customer']);
unset($_SESSION['email_customer']);
}
if (isset($_SESSION['track_id_customer'])) {
if (empty($track_id) && isset($_SESSION['track_id_customer'])) {
$track_id = $_SESSION['track_id_customer'];
}
if (isset($_SESSION['email_customer'])) {
if (empty($email) && isset($_SESSION['email_customer'])) {
$email = strtolower($_SESSION['email_customer']);
}
@ -215,6 +215,7 @@ if ($action == "view_ticketlist") {
// Store current page url
$url_page_current = dol_buildpath('/public/ticket/list.php', 1);
$contextpage = $url_page_current;
// Do we click on purge search criteria ?
if (GETPOST("button_removefilter_x")) {