Commit f6d95ace authored by Cyril Vazquez's avatar Cyril Vazquez
Browse files

Merge branch 'fix/15334_scheduler_crash_with_multiple_service-accounts' into 'release/2.6.8'

fix/15334 : fix mmemory issues on scheduling interface when great number of…

See merge request !603
parents b2d505a2 0ebe576a
Pipeline #10320 failed with stages
in 59 seconds
......@@ -243,7 +243,7 @@ class serviceAccount
}
if (!$serviceAccount->ownerOrgId && !empty($orgId)) {
if(!empty($serviceAccount->ownerOrgId) && $serviceAccount->ownerOrgId != $organization->ownerOrgId) {
if (!empty($serviceAccount->ownerOrgId) && $serviceAccount->ownerOrgId != $organization->ownerOrgId) {
throw new \core\Exception\NotFoundException("Organization identified by " . $serviceAccount->ownerOrgId . " is not the owner organization of the organization identified by " . $orgId);
}
$serviceAccount->ownerOrgId = $organization->ownerOrgId;
......@@ -503,6 +503,56 @@ class serviceAccount
return $this->sdoFactory->find("auth/servicePrivilege", "accountId='".$serviceAccountId."'");
}
/**
* Search accounts for a privilege
*
* @param string $serviceUri Privilege service uri
*
* @return array $accounts Array of service accounts with same privilege
*/
public function getAccountsByPrivilege($serviceUri)
{
$queryAssert = null;
if ($this->hasSecurityLevel) {
$accountId = \laabs::getToken("AUTH")->accountId;
$account = $this->sdoFactory->read("auth/account", array("accountId" => $accountId));
switch ($account->getSecurityLevel()) {
case $account::SECLEVEL_GENADMIN:
$queryAssert = " AND (isAdmin='TRUE' AND ownerOrgId!=null)";
break;
case $account::SECLEVEL_FUNCADMIN:
$organization = $this->sdoFactory->read('organization/organization', $account->ownerOrgId);
$organizations = $this->organizationController->readDescendantOrg($organization->orgId);
$organizations[] = $organization;
$organizationsIds = [];
foreach ($organizations as $key => $organization) {
$organizationsIds[] = (string) $organization->orgId;
}
$queryAssert = " AND ((ownerOrgId= ['" .
implode("', '", $organizationsIds) .
"']) OR (isAdmin!=TRUE AND ownerOrgId=null))
";
break;
case $account::SECLEVEL_USER:
$queryAssert = " AND ((isAdmin!='TRUE' AND ownerOrgId='". $account->ownerOrgId."')";
break;
}
}
$accounts = $this->sdoFactory->index(
"auth/account",
["accountId", "accountName", "displayName"],
"accountId = [READ auth/servicePrivilege [accountId] (serviceURI='".$serviceUri."' OR serviceURI = :aster)] . $queryAssert",
['aster' => "*"]
);
return $accounts;
}
/**
* create the service privileges
* @param array $servicesURI The service privilege
......
......@@ -146,4 +146,12 @@ interface serviceAccountInterface
* @return boolean Import with reset of table data or not
*/
public function createImport($data, $isReset);
/**
* @param string $serviceUri Uri to check privileges
*
* @action auth/serviceAccount/getAccountsByPrivilege
*
*/
public function readByRoute($serviceUri);
}
......@@ -68,17 +68,17 @@ interface schedulingInterface
* @action batchProcessing/scheduling/execute
*/
public function readExecute_schedulingId_();
/**
* Process scedulings
*
* @action batchProcessing/scheduling/process
*/
public function updateProcess();
/**
* Update status of scheduling
*
*
* @action batchProcessing/scheduling/changeStatus
*/
public function updateChangestatus($schedulingId, $status);
......
......@@ -233,4 +233,19 @@ class scheduling
return $this->json->save();
}
/**
* List of service accounts available to select for user
*
* @param array $serviceAccounts array of serviceAccounts
*
* @return object JSON object
*/
public function listServiceAccounts($serviceAccounts)
{
$this->json->status = true;
$this->json->serviceAccounts = $serviceAccounts;
return $this->json->save();
}
}
......@@ -20,15 +20,13 @@
</select>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Executed by<span style="color:red">&nbsp;*</span></label>
<div class="col-lg-7">
<?merge isUser.bool().not().then('disabled') @disabled ?>
<select class="form-control" id="serviceAccountId" name="serviceAccountId" title="Executed by">
<option value="" disabled selected>Select a service account</option>
<?merge serviceAccount ?>
<option value="[?merge .accountId ?]" data-privilege="[?merge .privileges ?]"><?merge .displayName ?></option>
</select>
</div>
</div>
......@@ -374,7 +372,8 @@
$('#taskId').on('change', function () {
$('#serviceAccountId').val('');
TaskSchedulingForm.checkServiceAccount();
var route = $('#taskId').find('option:selected').data('route');
TaskSchedulingForm.loadServiceAccounts(route);
});
// Week day selection color
......@@ -461,17 +460,15 @@
this.clear();
this.form.removeClass('hide');
this.changeFormPosition();
$('#modifyTask').removeClass('hide');
$('#addTask').addClass('hide');
this.form.find('[name="schedulingId"]').val(scheduling.schedulingId);
this.form.find('[name="taskId"]').val(scheduling.taskId);
this.form.find('[name="name"]').val(scheduling.name);
this.loadServiceAccounts($('#taskId').find('option:selected').data('route'));
this.form.find('[name="serviceAccountId"]').val(scheduling.executedBy);
TaskSchedulingForm.checkServiceAccount();
// Freqency selector
if (scheduling.monthDays.length) {
this.form.find("[name='frequencyType'][value='monthly']").parent().click();
......@@ -608,30 +605,10 @@
return valid;
},
checkServiceAccount: function() {
var route = $('#taskId').find('option:selected').data('route').toLowerCase();
$('#serviceAccountId option').each(function() {
var privileges = $(this).data('privilege');
if (privileges) {
for (var i = 0; i < privileges.length; i++) {
privileges[i] = privileges[i].toLowerCase();
}
}
if (!privileges || ($.inArray(route, privileges) === -1 && $.inArray("*", privileges) === -1)) {
$(this).addClass('hide');
} else {
$(this).removeClass('hide');
}
});
},
addParameters: function() {
let parameterInput = this.form.find('[name="parameters"]');
let parameters = parameterInput.val();
if( parameters == "") {
return;
}
......@@ -731,6 +708,7 @@
clear: function() {
this.form.addClass('hide');
this.form.find('[name="serviceAccountId"]').attr('disabled', 'disabled');
this.form.find('[name="frequencyType"][value="daily"]').parent().click().addClass('btn-info').addClass('btn-default');
this.form.find('[name="taskId"], [name="serviceAccountId"], [name="name"]').val('');
this.form.find('[name="startHours"], [name="startMinutes"]').val('00');
......@@ -774,6 +752,35 @@
TaskList.unselect();
},
loadServiceAccounts: function(route) {
var serviceAccountSelect = $('#serviceAccountId');
serviceAccountSelect.empty();
if ($('#taskId').length == 0 || $('#taskId') == '') {
serviceAccountSelect.attr('disabled', 'disabled');
return;
}
serviceAccountSelect.removeAttr('disabled');
$.ajax({
type : "GET",
url : "/serviceaccountsbyroute",
data : {'serviceUri' : route},
dataType : 'json',
contentType : 'application/json',
success : function (response) {
$.each(response.serviceAccounts, function() {
serviceAccountSelect.append($('<option/>', {
value : this.accountId,
text : this.displayName
}));
})
},
error : function(response) {
gritter.show(response.responseJSON.message, response.responseJSON.status, response.responseJSON.errors);
}
});
}
}
</script>
\ No newline at end of file
</script>
......@@ -80,6 +80,16 @@ interface batchSchedulingInterface
*/
public function updateBatchprocessingChangestatus($schedulingId, $status);
/**
* List service accounts available by scheduling
*
* @param string $serviceUri url route to check right for
*
* @uses auth/serviceAccount/readByRoute
* @return batchProcessing/scheduling/listServiceAccounts
*/
public function readServiceaccountsbyroute($serviceUri);
/*******************LOG**********************/
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment