Commit 048aa788 authored by Cyril Vazquez's avatar Cyril Vazquez
Browse files

Merge branch '15333services_account' into 'release/2.6.8'

15333services account

See merge request !600
parents 0e05ca18 5a44de0c
Pipeline #10254 canceled with stages
......@@ -76,9 +76,19 @@ 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;
}
public function getSearchQuery($accountName = null)
{
$accountId = \laabs::getToken("AUTH")->accountId;
$account = $this->sdoFactory->read("auth/account", array("accountId" => $accountId));
......@@ -88,6 +98,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,9 +129,14 @@ class serviceAccount
}
}
$serviceAccounts = $this->sdoFactory->find('auth/account', \laabs\implode(" AND ", $queryAssert));
return \laabs\implode(" AND ", $queryAssert);
}
return $serviceAccounts;
public function searchCount($accountName = null)
{
$count = $this->sdoFactory->count('auth/account', $this->getSearchQuery($accountName));
return $count;
}
/**
......
......@@ -36,10 +36,22 @@ 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);
/**
* List the service account detail
*
* @param string $accountName Name of account
*
* @action auth/serviceAccount/searchCount
*/
public function readSearchCount($accountName = null);
/**
* Prepare an empty service Account object
......
......@@ -55,16 +55,37 @@ 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("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");
......
......@@ -497,6 +497,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"
......@@ -730,6 +733,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"
......@@ -760,6 +769,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"
......@@ -887,3 +899,4 @@ msgctxt "userStory"
msgid "importDescriptionField"
msgstr "Champs de description"
msgctxt "userStory"
<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,24 @@ 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
*
......
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