Commit 3a7e31ae authored by Mathieu Pionnier's avatar Mathieu Pionnier
Browse files

fix/15333 : limit number of service account display

parent a9be7231
Pipeline #10229 failed with stages
in 56 seconds
......@@ -73,9 +73,18 @@ class serviceAccount
/**
* List all service to display
*
* @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($maxResults = null)
{
$serviceAccounts = $this->sdoFactory->find('auth/account', $this->getSearchQuery(), null, false, false, $maxResults);
return $serviceAccounts;
}
public function getSearchQuery()
{
$accountId = \laabs::getToken("AUTH")->accountId;
$account = $this->sdoFactory->read("auth/account", array("accountId" => $accountId));
......@@ -112,9 +121,14 @@ class serviceAccount
}
}
$serviceAccounts = $this->sdoFactory->find('auth/account', \laabs\implode(" AND ", $queryAssert));
return \laabs\implode(" AND ", $queryAssert);
}
return $serviceAccounts;
public function searchCount()
{
$count = $this->sdoFactory->count('auth/account', $this->getSearchQuery());
return $count;
}
/** Get a service account object
......@@ -123,7 +137,7 @@ class serviceAccount
*
* @return auth/account The service account object
*/
public function searchServiceAccountsByName($serviceAccountName)
public function searchServiceAccountsByQuery($serviceAccountName)
{
$maxResults = 200;
return $this->sdoFactory->find("auth/account", "accountType = 'service'", $maxResults);
......
......@@ -37,9 +37,20 @@ interface serviceAccountInterface
/**
* List the service account detail
*
* @param integer $maxResults
*
* @action auth/serviceAccount/search
*/
public function readSearch();
public function readSearch($maxResults = null);
/**
* List the service account detail
*
* @param integer $maxResults
*
* @action auth/serviceAccount/searchCount
*/
public function readSearchCount($maxResults = null);
/**
* Prepare an empty service Account object
......
......@@ -55,15 +55,36 @@ class serviceAccount
/**
* List all service account
* @param array $serviceAccounts Array of service account object
*
* @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("accountsLimit", 200);
$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;
$account = \laabs::callService("auth/userAccount/read_userAccountId_", $accountId);
......@@ -75,6 +96,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");
......
<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 class="input-group"> -->
<input type="text" class="searchBar" id="serviceAccount_search" name="serviceAccount" placeholder="Service account search"/>
<button type="button" class="btn btn-primary" id="searchServiceAccount" title="Search"><i class="fa fa-search">&nbsp;</i>Search</button>
<!-- </div> -->
<?merge accountsLimit.ifgt(199) ?>
<p>toto</p>
</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>
</div>
</div>
</div>
</div>
<div id="listServiceAccounts"></div>
</div>
<script type="application/javascript">
//index service account
$.ajax({
url : "/serviceaccountslist?maxResults="+$("#maxResults").val(),
type : "GET",
success : function(response){
$("#listServiceAccounts").html(response);
},
error : function(response) {
console.log("error");
}
});
//add
$("#addServiceAccount").on("click", function(){
load("/serviceAccount");
});
//search
$('#searchServiceAccount').on('click', function () {
$('#searchServiceAccount').prop('disabled', true);
$.ajax({
type : 'GET',
url : '/serviceAccount/searchServiceAccountsByName',
data : $('#serviceAccount_search').val(),
dataType : 'html',
// success : function (response) {
// $('#archive_searchResult').empty().html(response);
// $('#archive_search').prop('disabled', false);
// },
// error : function(response) {
// response = JSON.parse(response.responseText);
// gritter.show(response.message);
// $('#archive_search').prop('disabled', false);
// }
});
});
//edit
$("#list-serviceAccount").on('click', '.edit', function() {
......
<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">
<?merge hasReachMaxResults ?>
<h4><span>Your query returns too much results, only first results are displayed.</span></h4>
<div class="pull-left">
<?merge hasReachMaxResults.not() ?>
<h4><?merge serviceAccounts.count() ?> Service account(s)</h4>
<?merge hasReachMaxResults ?>
<h4><?merge serviceAccounts.count() ?> Service account(s) on <?merge totalResultsWithoutLimit ?> result(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>
</div>
</div>
</div>
</div>
......@@ -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 integer $maxResult
*
* @uses auth/serviceAccount/readSearch
* @uses auth/serviceAccount/readSearchCount
*
* @return auth/serviceAccount/accountList
*/
public function readServiceaccountslist($maxResults = null);
/**
* Get a service account
*
......@@ -99,14 +111,4 @@ interface adminServiceaccountInterface
*/
public function updateServiceaccount_serviceAccountId_Disable();
/**
* Search for service account by name
*
* @param string $accountName
*
* @action auth/serviceAccount/searchServiceAccountsByName
* @return auth/serviceAccount/index
*/
public function searchServiceAccountsByName($accountName);
}
\ 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