Unverified Commit 30f9104a authored by Jerome Boucher's avatar Jerome Boucher
Browse files

fix/15334 : add limit to number of serviceAccounts retuned

parent 328e48e6
Pipeline #10336 failed with stages
in 52 seconds
......@@ -76,9 +76,26 @@ class serviceAccount
/**
* List all service to display
*
* @param string $accountName Name of account
* @param integer $maxResults Max result number to return
*
* @return array The array of stdClass with dislpay name and service identifier
*/
public function search()
public function search($accountName = null, $maxResults = null)
{
$serviceAccounts = $this->sdoFactory->find('auth/account', $this->getSearchQuery($accountName), null, false, false, $maxResults);
return $serviceAccounts;
}
/**
* Query builder for search and count function
*
* @param string $accountName Account Name
*
* @return string PDO query
*/
public function getSearchQuery($accountName = null)
{
$accountId = \laabs::getToken("AUTH")->accountId;
$account = $this->sdoFactory->read("auth/account", array("accountId" => $accountId));
......@@ -88,6 +105,10 @@ class serviceAccount
$queryAssert = [];
$queryAssert[] = "accountType='service'";
if (!is_null($accountName) && $accountName != "null") {
$queryAssert[] = "accountName~'*$accountName*'";
}
if ($this->hasSecurityLevel) {
switch ($account->getSecurityLevel()) {
case $account::SECLEVEL_GENADMIN:
......@@ -115,11 +136,22 @@ class serviceAccount
}
}
$serviceAccounts = $this->sdoFactory->find('auth/account', \laabs\implode(" AND ", $queryAssert));
return $serviceAccounts;
return \laabs\implode(" AND ", $queryAssert);
}
/**
* Count service Accounts
*
* @param string $accountName
*
* @return integer $count Number of service accounts
*/
public function searchCount($accountName = null)
{
$count = $this->sdoFactory->count('auth/account', $this->getSearchQuery($accountName));
return $count;
}
/**
* Prepare an empty service object
*
......
......@@ -37,9 +37,21 @@ interface serviceAccountInterface
/**
* List the service account detail
*
* @param string $accountName Name of account
* @param integer $maxResults Limit of result display
*
* @action auth/serviceAccount/search
*/
public function readSearch();
public function readSearch($accountName = null, $maxResults = null);
/**
* Count service account
*
* @param string $accountName Name of account
*
* @action auth/serviceAccount/searchCount
*/
public function readSearchCount($accountName = null);
/**
* Prepare an empty service Account object
......
......@@ -59,10 +59,33 @@ class serviceAccount
*
* @return string
*/
public function indexHtml(array $serviceAccounts)
public function indexHtml()
{
$maxResults = null;
if (isset(\laabs::configuration('presentation.maarchRM')['maxResults'])) {
$maxResults = \laabs::configuration('presentation.maarchRM')['maxResults'];
}
$this->view->addContentFile("auth/serviceAccount/index.html");
$this->view->setSource("maxResults", $maxResults);
$this->view->translate();
$this->view->merge();
return $this->view->saveHtml();
}
/**
* @param array $serviceAccounts Array of service accounts
* @param integer $count Count of service accounts without limits
*
*/
public function accountList(array $serviceAccounts, $count)
{
$this->view->setSource("serviceAccounts", $serviceAccounts);
$this->view->setSource("totalResultsWithoutLimit", $count);
$this->view->addContentFile("auth/serviceAccount/serviceAccountsList.html");
$hasSecurityLevel = isset(\laabs::configuration('auth')['useSecurityLevel']) ? (bool) \laabs::configuration('auth')['useSecurityLevel'] : false;
$accountId = \laabs::getToken("AUTH")->accountId;
......@@ -75,6 +98,13 @@ class serviceAccount
$manageUserRights = false;
}
$hasReachMaxResults = false;
if (isset(\laabs::configuration('presentation.maarchRM')['maxResults'])
&& count($serviceAccounts) >= \laabs::configuration('presentation.maarchRM')['maxResults']) {
$hasReachMaxResults = true;
}
$this->view->setSource('hasReachMaxResults', $hasReachMaxResults);
$this->view->setSource('manageUserRights', $manageUserRights);
$table = $this->view->getElementById("list-serviceAccount");
......
......@@ -509,6 +509,9 @@ msgstr "Ajouter un utilisateur"
msgid "User modification"
msgstr "Modification"
msgid "Service account search"
msgstr "Rechercher un compte de service"
msgid "User name"
msgstr "Identifiant"
......@@ -742,6 +745,12 @@ msgstr "Jeton généré"
msgid "Service account(s)"
msgstr "Compte(s) de service"
msgid "result(s) displayed on"
msgstr "résulat(s) affiché(s) sur"
msgid "total"
msgstr "au total"
msgid "Manage service account"
msgstr "Comptes de service"
......@@ -772,6 +781,9 @@ msgstr "Compte de service activé"
msgid "Service account updated"
msgstr "Compte de service modifié"
msgid "Your query returns too much results, only first results are displayed."
msgstr "Le nombre de résultats retournés est trop important. Veuillez affiner votre recherche."
msgid "The fields contain white spaces."
msgstr "Le champ contient des espaces"
......
<div id="contain" >
<div id="contain">
<input type="hidden" id="maxResults" name="maxResults" value="[?merge maxResults ?]">
<div class="container-fluid" data-translate-catalog="auth/messages">
<div class="page-header">
<h1>
<i class="fa fa-laptop"></i>
Manage service account
</h1>
</div>
</div>
<div class="container-fluid" data-translate-catalog="auth/messages">
<div class="row">
<div class="col-xs-12">
<div class="panel panel-primary">
<div class="panel-heading clearfix">
<div class="pull-left">
<h4><?merge serviceAccounts.count() ?> Service account(s)</h4>
</div>
<div class="pull-right">
<?merge manageUserRights.bool().not().then('disabled') @disabled ?>
<button type="button" class="btn btn-default btn-sm" id="addServiceAccount" title="Add"><i class="fa fa-plus">&nbsp;</i>Add</button>
</div>
</div>
<div class="panel-body" style="padding: 0;">
<table class="table table-condensed dataTable" style="margin: 0;" id="list-serviceAccount">
<thead>
<tr>
<th>Service name</th>
<th>Enabled</th>
<th>Token date</th>
<th style="min-width:160px"></th>
</tr>
</thead>
<tbody>
<?merge serviceAccounts ?>
<tr id ="[?merge .accountId ?]">
<td><?merge .accountName ?></td>
<td>
<?merge .enabled.not() ?><i class="fa fa-ban"></i>
<?merge .enabled.ifne(false) ?><i class="fa fa-check"></i>
</td>
<td><?merge .tokenDate ?></td>
<td>
<div class="btn-group pull-right">
<?merge manageUserRights.bool().not().then('disabled') @disabled ?>
<button type="button" class="btn btn-info edit" title="Edit">
<span class="fa fa-fw fa-edit"></span>
</button>
<?merge .enabled.not() ?>
<?merge manageUserRights.bool().not().then('disabled') @disabled ?>
<button type="button" class="btn btn-danger enable" title="Enable">
<span class="fa fa-fw fa-check"></span>
</button>
<?merge .enabled.ifne(false) ?>
<?merge manageUserRights.bool().not().then('disabled') @disabled ?>
<button type="button" class="btn btn-danger disable" title="Disable">
<span class="fa fa-fw fa-times"></span>
</button>
</div>
</td>
</tr>
</tbody>
</table>
<div class="form-group">
<div class="col-sm-6" style="padding-left: 0px; padding-top:30px;margin-bottom:10px;">
<div class="col-md-9" style="padding-left: 0px;">
<input type="text" class="form-control" id="serviceAccountSearch" name="serviceAccountSearch" placeholder="Service account search"/>
</div>
<button type="button" class="btn btn-primary" id="searchServiceAccount" title="Search"><i class="fa fa-search">&nbsp;</i>Search</button>
</div>
</div>
</div>
</div>
<div id="listServiceAccounts"></div>
</div>
<script type="application/javascript">
//add
$("#addServiceAccount").on("click", function(){
load("/serviceAccount");
});
//edit
$("#list-serviceAccount").on('click', '.edit', function() {
var serviceAccountId = $(this).closest('tr').attr('id');
load("/serviceAccount/"+serviceAccountId);
});
//enable
$("#list-serviceAccount").on('click', '.enable', function() {
$.ajax({
url : "/serviceAccount/" + $(this).closest('tr').attr("id")+ '/enable',
type : "PUT",
dataType : "json",
success : function(response){
gritter.show(response.message, response.status, response.errors);
load("/serviceAccounts");
},
error : function(response) {
gritter.show(response.responseJSON.message, response.responseJSON.status, response.responseJSON.errors);
}
});
//search
var serviceAccounts = {
"search" : function(accountName = null) {
var params;
var accountName = "accountName=" + accountName;
var maxResults = "maxResults=" + $("#maxResults").val();
params = "?" + accountName + "&" + maxResults;
$.ajax({
url : "/serviceaccountslist" + params,
type : "GET",
success : function(response){
$("#listServiceAccounts").empty().html(response);
},
error : function(response) {
console.log("error");
}
})
}
}
$("#serviceAccountSearch").val('');
$('#serviceAccountSearch').keyup(function(e){
if(e.keyCode == 13)
{
serviceAccounts.search(this.value);
}
});
//disable
$("#list-serviceAccount").on('click', '.disable', function() {
$.ajax({
url : "/serviceAccount/" + $(this).closest('tr').attr('id')+ "/disable",
type : "PUT",
dataType : "json",
success : function(response){
gritter.show(response.message, response.status, response.errors);
load("/serviceAccounts");
},
error : function(response) {
gritter.show(response.responseJSON.message, response.responseJSON.status, response.responseJSON.errors);
}
});
serviceAccounts.search();
$("#searchServiceAccount").on("click", function() {
serviceAccounts.search($("#serviceAccountSearch").val());
});
</script>
<div class="container-fluid" data-translate-catalog="auth/messages">
<?merge hasReachMaxResults ?>
<p><span class="alert-danger">Your query returns too much results, only first results are displayed.</span></p>
<div class="row">
<div class="col-xs-12">
<div class="panel panel-primary">
<div class="panel-heading clearfix">
<div class="pull-left">
<?merge hasReachMaxResults.not() ?>
<h4><?merge serviceAccounts.count() ?> Service account(s)</h4>
<?merge hasReachMaxResults ?>
<h4><?merge serviceAccounts.count() ?> result(s) displayed on <?merge totalResultsWithoutLimit ?> total</h4>
</div>
<div class="pull-right">
<?merge manageUserRights.bool().not().then('disabled') @disabled ?>
<button type="button" class="btn btn-default btn-sm" id="addServiceAccount" title="Add"><i class="fa fa-plus">&nbsp;</i>Add</button>
</div>
</div>
<div class="panel-body" style="padding: 0;">
<table class="table table-condensed dataTable" style="margin: 0;" id="list-serviceAccount">
<thead>
<tr>
<th>Service name</th>
<th>Enabled</th>
<th>Token date</th>
<th style="min-width:160px"></th>
</tr>
</thead>
<tbody>
<?merge serviceAccounts ?>
<tr id ="[?merge .accountId ?]">
<td><?merge .accountName ?></td>
<td>
<?merge .enabled.not() ?><i class="fa fa-ban"></i>
<?merge .enabled.ifne(false) ?><i class="fa fa-check"></i>
</td>
<td><?merge .tokenDate ?></td>
<td>
<div class="btn-group pull-right">
<?merge manageUserRights.bool().not().then('disabled') @disabled ?>
<button type="button" class="btn btn-info edit" title="Edit">
<span class="fa fa-fw fa-edit"></span>
</button>
<?merge .enabled.not() ?>
<?merge manageUserRights.bool().not().then('disabled') @disabled ?>
<button type="button" class="btn btn-danger enable" title="Enable">
<span class="fa fa-fw fa-check"></span>
</button>
<?merge .enabled.ifne(false) ?>
<?merge manageUserRights.bool().not().then('disabled') @disabled ?>
<button type="button" class="btn btn-danger disable" title="Disable">
<span class="fa fa-fw fa-times"></span>
</button>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<script type="application/javascript">
//add
$("#addServiceAccount").on("click", function(){
load("/serviceAccount");
});
//edit
$("#list-serviceAccount").on('click', '.edit', function() {
var serviceAccountId = $(this).closest('tr').attr('id');
load("/serviceAccount/"+serviceAccountId);
});
//enable
$("#list-serviceAccount").on('click', '.enable', function() {
$.ajax({
url : "/serviceAccount/" + $(this).closest('tr').attr("id")+ '/enable',
type : "PUT",
dataType : "json",
success : function(response){
gritter.show(response.message, response.status, response.errors);
load("/serviceAccounts");
},
error : function(response) {
gritter.show(response.responseJSON.message, response.responseJSON.status, response.responseJSON.errors);
}
});
});
//disable
$("#list-serviceAccount").on('click', '.disable', function() {
$.ajax({
url : "/serviceAccount/" + $(this).closest('tr').attr('id')+ "/disable",
type : "PUT",
dataType : "json",
success : function(response){
gritter.show(response.message, response.status, response.errors);
load("/serviceAccounts");
},
error : function(response) {
gritter.show(response.responseJSON.message, response.responseJSON.status, response.responseJSON.errors);
}
});
});
</script>
......@@ -31,11 +31,23 @@ interface adminServiceaccountInterface
/**
* List all service account
*
* @uses auth/serviceAccount/readSearch
* @return auth/serviceAccount/indexHtml
*/
public function readServiceaccounts();
/**
* List service accounts list with max results
*
* @param string $accountName Name of account
* @param integer $maxResult Limit of result display
*
* @uses auth/serviceAccount/readSearch
* @uses auth/serviceAccount/readSearchCount
*
* @return auth/serviceAccount/accountList
*/
public function readServiceaccountslist($accountName = null, $maxResults = null);
/**
* Get a service account
*
......@@ -68,7 +80,7 @@ interface adminServiceaccountInterface
* @param string $serviceName The service name
*
* @uses auth/serviceAccount/updateServicetoken_serviceAccountId_
*
*
* @return auth/serviceAccount/serviceToken
*/
public function updateServiceaccount_serviceAccountId_Token();
......@@ -90,7 +102,7 @@ interface adminServiceaccountInterface
* @return auth/serviceAccount/enable
*/
public function updateServiceaccount_serviceAccountId_Enable();
/**
* Disable service account
*
......@@ -99,4 +111,4 @@ interface adminServiceaccountInterface
*/
public function updateServiceaccount_serviceAccountId_Disable();
}
\ No newline at end of file
}
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