diff --git a/apps/maarch_entreprise/Views/status-list-administration.component.html b/apps/maarch_entreprise/Views/status-list-administration.component.html index f378ac7534427c386bcce23ddd58caa99c3e40f3..c8c84cdf43373d306ce67daaa8d69bb91fb6a3ad 100644 --- a/apps/maarch_entreprise/Views/status-list-administration.component.html +++ b/apps/maarch_entreprise/Views/status-list-administration.component.html @@ -5,7 +5,7 @@ <h1 style="margin-top: 0"><i class="fa fa-check-circle fa-2x"></i> {{lang.statusListTitle}} : {{nbStatus}} {{lang.status}}(s)</h1> <div style="margin-top:15px"> - <table id="statusTable"> + <table id="statusTable" class="display"> <thead> <tr> <th><span>{{lang.identifier}}</span></th> diff --git a/apps/maarch_entreprise/Views/user-administration.component.html b/apps/maarch_entreprise/Views/user-administration.component.html index 3024961cb000e360ca99a4f148e6f3415e2652e0..1b58199ea2193019589230c46799c6bb3709f500 100644 --- a/apps/maarch_entreprise/Views/user-administration.component.html +++ b/apps/maarch_entreprise/Views/user-administration.component.html @@ -5,7 +5,14 @@ <i class="fa fa-spinner fa-spin fa-5x" style="margin-left: 50%;margin-top: 16%;font-size: 8em"></i> </div> <div *ngIf="!loading" class="container-fluid"> - <h1 style="margin-top: 0"><i class="fa fa-user fa-2x"></i> {{user.lang.userModification}}: {{userId}}</h1> + <h1 style="margin-top: 0"> + <i class="fa fa-user fa-2x"></i> {{user.lang.userModification}}: {{userId}} + <sup> + <span *ngIf="user.status == 'OK' && user.enabled == 'Y'" class="label label-primary" title="Actif" >Actif</span> + <span *ngIf="user.status == 'ABS'" class="label label-warning" title="Absent" >Absent</span> + <span *ngIf="user.enabled == 'N'" class="label label-danger" title="Inactif" >Inactif</span> + </sup> + </h1> <nav class="navbar navbar-default"> <div class="container-fluid"> <div class="navbar-header"> @@ -87,42 +94,38 @@ </form> </div> <div class="col-md-3 col-md-offset-1" style="border-left:solid 1px white;border-right:solid 1px white;background-color: #CEE9F1;border-top: solid 2px #FDD16C;border-bottom: solid 2px #FDD16C;padding:10px;"> - <h2>{{user.lang.myGroups}}</h2> + <h2>{{user.lang.myGroups}} <i class="fa fa-plus pull-right" style="cursor:pointer;" aria-hidden="true" title="Ajouter un groupe"></i></h2> <div *ngFor="let group of user.groups" class="col-sm-12 form-group"> <div class="input-group"> - <span *ngIf="group.primary_group == 'Y'" class="input-group-addon label-primary" id="group_desc" style="color:white;">{{group.group_desc}}</span> - <span *ngIf="group.primary_group == 'N'" class="input-group-addon label-default" id="group_desc" style="background-color:#eee;">{{group.group_desc}}</span> - <input type="text" class="form-control" id="basic-url" aria-describedby="group_desc" placeholder="rôle" value="{{group.role}}"> <div class="input-group-btn"> - <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-bars" aria-hidden="true"></i> -<span class="caret"></span></button> - <ul class="dropdown-menu dropdown-menu-right"> - <li *ngIf="group.primary_group == 'N'"><a href="#">Passer en groupe primaire</a></li> - <li><a href="#">Enregistrer les modifications</a></li> - <li role="separator" class="divider"></li> - <li><a href="#">Supprimer</a></li> + <button *ngIf="group.primary_group == 'Y'" type="button" style="color:white;" class="btn btn-default dropdown-toggle label-primary" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{group.group_desc}} <span class="caret"></span></button> + <button *ngIf="group.primary_group == 'N'" type="button" style="background-color:#eee;" class="btn btn-default dropdown-toggle label-default" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{group.group_desc}} <span class="caret"></span></button> + <ul class="dropdown-menu"> + <li *ngIf="group.primary_group == 'N'"><a href="#">Passer en groupe primaire</a></li> + <li><a href="#">Enregistrer les modifications</a></li> + <li role="separator" class="divider"></li> + <li><a href="#">Supprimer</a></li> </ul> </div> + <input type="text" class="form-control" id="basic-url" aria-describedby="group_desc" placeholder="rôle" value="{{group.role}}"> </div> </div> </div> <div class="col-md-3 col-md-offset-1" style="border-left:solid 1px white;border-right:solid 1px white;background-color: #CEE9F1;border-top: solid 2px #FDD16C;border-bottom: solid 2px #FDD16C;padding:10px;"> - <h2>{{user.lang.myEntities}}</h2> + <h2>{{user.lang.myEntities}} <i class="fa fa-plus pull-right" style="cursor:pointer;" aria-hidden="true" title="Ajouter une entité" ></i></h2> <div *ngFor="let entity of user.entities" class="col-sm-12 form-group"> <div class="input-group"> - <span *ngIf="entity.primary_entity == 'Y'" class="input-group-addon label-primary" id="group_desc" style="color:white;">{{entity.entity_label}}</span> - <span *ngIf="entity.primary_entity == 'N'" class="input-group-addon label-default" id="group_desc" style="background-color:#eee;">{{entity.entity_label}}</span> - <input type="text" class="form-control" id="basic-url" aria-describedby="group_desc" placeholder="rôle" value="{{entity.entity_role}}"> <div class="input-group-btn"> - <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-bars" aria-hidden="true"></i> -<span class="caret"></span></button> - <ul class="dropdown-menu dropdown-menu-right"> - <li *ngIf="entity.primary_entity == 'N'"><a href="#">Passer en entité primaire</a></li> - <li><a href="#">Enregistrer les modifications</a></li> - <li role="separator" class="divider"></li> - <li><a href="#">Supprimer</a></li> + <button *ngIf="entity.primary_entity == 'Y'" type="button" style="color:white;" class="btn btn-default dropdown-toggle label-primary" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{entity.entity_label}} <span class="caret"></span></button> + <button *ngIf="entity.primary_entity == 'N'" type="button" style="background-color:#eee;" class="btn btn-default dropdown-toggle label-default" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{entity.entity_label}} <span class="caret"></span></button> + <ul class="dropdown-menu"> + <li *ngIf="entity.primary_entity == 'N'"><a href="#">Passer en entité primaire</a></li> + <li><a href="#">Enregistrer les modifications</a></li> + <li role="separator" class="divider"></li> + <li><a href="#">Supprimer</a></li> </ul> </div> + <input type="text" class="form-control" id="basic-url" aria-describedby="group_desc" placeholder="rôle" value="{{entity.entity_role}}"> </div> </div> </div> diff --git a/apps/maarch_entreprise/Views/users-administration.component.html b/apps/maarch_entreprise/Views/users-administration.component.html index bf8ce6722e73fdd467339ae8eb1b7b3ddd511cff..6cb67314451b7251dc4e231b2f4f2d4dce623661 100644 --- a/apps/maarch_entreprise/Views/users-administration.component.html +++ b/apps/maarch_entreprise/Views/users-administration.component.html @@ -35,7 +35,7 @@ </tr> </thead> <tbody> - <tr *ngFor="let user of users"> + <tr *ngFor="let user of users" id="{{user.user_id}}"> <td>{{user.user_id}}</td> <td>{{user.lastname}}</td> <td>{{user.firstname}}</td> @@ -47,16 +47,16 @@ <td>{{user.mail}}</td> <td style="text-align:right;"> <div class="btn-group" role="group" aria-label="..."> - <button type="button" class="btn btn-default" title="{{lang.edit}}"> - <a><i routerLink="/administration" style="cursor:pointer" class="fa fa-edit"></i></a> + <button routerLink="/administration/user/{{user.user_id}}" type="button" class="btn btn-default" title="{{lang.edit}}"> + <a><i style="cursor:pointer" class="fa fa-edit"></i></a> </button> - <button type="button" class="btn btn-default" title="{{lang.suspend}}" *ngIf="user.enabled == 'Y'"> + <button type="button" class="btn btn-default" title="{{lang.suspend}}" *ngIf="user.enabled == 'Y'" (click)="suspendUser(user)"> <a><i style="cursor:pointer;color: #f0ad4e"class="fa fa-pause"></i></a> </button> - <button type="button" class="btn btn-default" title="{{lang.reactivate}}" *ngIf="user.enabled == 'N'"> + <button type="button" class="btn btn-default" title="{{lang.reactivate}}" *ngIf="user.enabled == 'N'" (click)="activateUser(user)"> <a><i style="cursor:pointer;color: #5cb85c" class="fa fa-check"></i></a> </button> - <button type="button" class="btn btn-default" title="{{lang.delete}}"> + <button type="button" class="btn btn-default" title="{{lang.delete}}" (click)="deleteUser(user.user_id)"> <a><i style="cursor:pointer;color: #D9534F" class="fa fa-trash"></i></a> </button> </div> diff --git a/apps/maarch_entreprise/actions/docLocker.php b/apps/maarch_entreprise/actions/docLocker.php index 6fafb45e315384c8263709d06042f9cef2e7dec6..3cc69419f396152231d527fa4e582874d0812093 100644 --- a/apps/maarch_entreprise/actions/docLocker.php +++ b/apps/maarch_entreprise/actions/docLocker.php @@ -70,7 +70,7 @@ class docLocker $query .= $this->table . " "; $query .= "SET "; $query .= "locker_user_id = ?, "; - $query .= "locker_time = current_timestamp + interval '1 MINUTE' "; + $query .= "locker_time = current_timestamp + interval '1' MINUTE "; $query .= "WHERE "; $query .= "res_id = ?"; diff --git a/apps/maarch_entreprise/css/styles.css b/apps/maarch_entreprise/css/styles.css index 77e9cdf9f6ca7a4b122674e766c733282407c054..179b7eaffa7da29beae92c4968a9b5f94eccc351 100644 --- a/apps/maarch_entreprise/css/styles.css +++ b/apps/maarch_entreprise/css/styles.css @@ -3681,9 +3681,12 @@ a.next{ .dataTables_info{ float: none !important; - font-weight: bold !important; color:#666 !important; } .dataTables_filter input{ font-size: inherit; +} + +.dataTables_length{ + float:none !important; } \ No newline at end of file diff --git a/apps/maarch_entreprise/css/users-administration.component.css b/apps/maarch_entreprise/css/users-administration.component.css index d7c025b7568b17ddc0ad4d4d3c51bb5dd2e058db..1e9030fb12316e3059d9dc5d09249d78bd2d5c48 100644 --- a/apps/maarch_entreprise/css/users-administration.component.css +++ b/apps/maarch_entreprise/css/users-administration.component.css @@ -1,3 +1,18 @@ +/* Alert info*/ +#resultInfo{ + top :10px; + text-align: center; + position: fixed; + width: 30%; + right: 10px; + z-index: 1051; + height: 40px; + -moz-box-shadow: 0px 0px 5px 0px #656565; + -webkit-box-shadow: 0px 0px 5px 0px #656565; + -o-box-shadow: 0px 0px 5px 0px #656565; + box-shadow: 0px 0px 5px 0px #656565; + filter:progid:DXImageTransform.Microsoft.Shadow(color=#656565, Direction=NaN, Strength=5); +} nav{ margin-top:10px !important; margin-bottom: 0px !important; diff --git a/apps/maarch_entreprise/js/angular/app/user-administration.component.js b/apps/maarch_entreprise/js/angular/app/user-administration.component.js index 2094399a64cc182156d99568219ad8cbc53c8130..0e381ae385cdb5f6c30bafcb5c59839ef268f4c8 100644 --- a/apps/maarch_entreprise/js/angular/app/user-administration.component.js +++ b/apps/maarch_entreprise/js/angular/app/user-administration.component.js @@ -23,7 +23,7 @@ var UserAdministrationComponent = (function () { } UserAdministrationComponent.prototype.updateBreadcrumb = function (applicationName) { if ($j('#ariane')[0]) { - $j('#ariane')[0].innerHTML = "<a href='index.php?reinit=true'>" + applicationName + "</a> > <a onclick='location.hash = \"/administration\"' style='cursor: pointer'>Administration</a> > <a onclick='location.hash = \"/administration/users\"' style='cursor: pointer'>Liste utilisateurs</a> > Modification"; + $j('#ariane')[0].innerHTML = "<a href='index.php?reinit=true'>" + applicationName + "</a> > <a onclick='location.hash = \"/administration\"' style='cursor: pointer'>Administration</a> > <a onclick='location.hash = \"/administration/users\"' style='cursor: pointer'>Utilisateurs</a> > Modification"; } }; UserAdministrationComponent.prototype.ngOnInit = function () { diff --git a/apps/maarch_entreprise/js/angular/app/user-administration.component.ts b/apps/maarch_entreprise/js/angular/app/user-administration.component.ts index 1807ed5eaac3b35238491f385cee4d190914379d..cb169346a20e171e10ba975b5cc6da93105b904d 100644 --- a/apps/maarch_entreprise/js/angular/app/user-administration.component.ts +++ b/apps/maarch_entreprise/js/angular/app/user-administration.component.ts @@ -28,7 +28,7 @@ export class UserAdministrationComponent implements OnInit { updateBreadcrumb(applicationName: string) { if ($j('#ariane')[0]) { - $j('#ariane')[0].innerHTML = "<a href='index.php?reinit=true'>" + applicationName + "</a> > <a onclick='location.hash = \"/administration\"' style='cursor: pointer'>Administration</a> > <a onclick='location.hash = \"/administration/users\"' style='cursor: pointer'>Liste utilisateurs</a> > Modification"; + $j('#ariane')[0].innerHTML = "<a href='index.php?reinit=true'>" + applicationName + "</a> > <a onclick='location.hash = \"/administration\"' style='cursor: pointer'>Administration</a> > <a onclick='location.hash = \"/administration/users\"' style='cursor: pointer'>Utilisateurs</a> > Modification"; } } diff --git a/apps/maarch_entreprise/js/angular/app/users-administration.component.js b/apps/maarch_entreprise/js/angular/app/users-administration.component.js index 80ea165a6124d629ed1969180971a6e25d75ea11..aa4aeb79303cbe0651d8d976f273a689573182cc 100644 --- a/apps/maarch_entreprise/js/angular/app/users-administration.component.js +++ b/apps/maarch_entreprise/js/angular/app/users-administration.component.js @@ -36,10 +36,11 @@ var UsersAdministrationComponent = (function () { _this.users = data.users; _this.lang = data.lang; setTimeout(function () { - $j('#usersTable').DataTable({ - "dom": '<"datatablesLeft"p><"datatablesRight"f>rt<"datatablesCenter"i><"clear">', + _this.table = $j('#usersTable').DataTable({ + "dom": '<"datatablesLeft"p><"datatablesRight"f><"datatablesCenter"l>rt<"datatablesCenter"i><"clear">', + "lengthMenu": [10, 25, 50, 75, 100], "oLanguage": { - "sLengthMenu": "Display _MENU_ records per page", + "sLengthMenu": "<i class='fa fa-bars'></i> _MENU_", "sZeroRecords": _this.lang.noResult, "sInfo": "_START_ - _END_ / _TOTAL_ " + _this.lang.record, "sSearch": "", @@ -64,6 +65,86 @@ var UsersAdministrationComponent = (function () { location.href = "index.php"; }); }; + UsersAdministrationComponent.prototype.suspendUser = function (user) { + var _this = this; + var r = confirm(this.lang.suspendMsg + ' ?'); + if (r) { + user.enabled = 'N'; + this.http.put(this.coreUrl + 'rest/user/' + user.user_id, user) + .map(function (res) { return res.json(); }) + .subscribe(function (data) { + if (data.errors) { + _this.resultInfo = data.errors; + $j('#resultInfo').removeClass().addClass('alert alert-danger alert-dismissible'); + $j("#resultInfo").fadeTo(3000, 500).slideUp(500, function () { + $j("#resultInfo").slideUp(500); + }); + } + else { + _this.resultInfo = data.success; + $j('#resultInfo').removeClass().addClass('alert alert-success alert-dismissible'); + $j("#resultInfo").fadeTo(3000, 500).slideUp(500, function () { + $j("#resultInfo").slideUp(500); + }); + } + }); + } + }; + UsersAdministrationComponent.prototype.activateUser = function (user) { + var _this = this; + var r = confirm(this.lang.authorizeMsg + ' ?'); + if (r) { + user.enabled = 'Y'; + this.http.put(this.coreUrl + 'rest/user/' + user.user_id, user) + .map(function (res) { return res.json(); }) + .subscribe(function (data) { + if (data.errors) { + _this.resultInfo = data.errors; + $j('#resultInfo').removeClass().addClass('alert alert-danger alert-dismissible'); + $j("#resultInfo").fadeTo(3000, 500).slideUp(500, function () { + $j("#resultInfo").slideUp(500); + }); + } + else { + _this.resultInfo = data.success; + $j('#resultInfo').removeClass().addClass('alert alert-success alert-dismissible'); + $j("#resultInfo").fadeTo(3000, 500).slideUp(500, function () { + $j("#resultInfo").slideUp(500); + }); + } + }); + } + }; + UsersAdministrationComponent.prototype.deleteUser = function (id) { + var _this = this; + var r = confirm(this.lang.deleteMsg + ' ?'); + if (r) { + this.http.delete(this.coreUrl + 'rest/user/' + id) + .map(function (res) { return res.json(); }) + .subscribe(function (data) { + if (data.errors) { + _this.resultInfo = data.errors; + $j('#resultInfo').removeClass().addClass('alert alert-danger alert-dismissible'); + $j("#resultInfo").fadeTo(3000, 500).slideUp(500, function () { + $j("#resultInfo").slideUp(500); + }); + } + else { + for (var i = 0; i < _this.users.length; i++) { + if (_this.users[i].user_id == id) { + _this.users.splice(i, 1); + } + } + _this.table.row($j("#" + id)).remove().draw(); + _this.resultInfo = data.success; + $j('#resultInfo').removeClass().addClass('alert alert-success alert-dismissible'); + $j("#resultInfo").fadeTo(3000, 500).slideUp(500, function () { + $j("#resultInfo").slideUp(500); + }); + } + }); + } + }; return UsersAdministrationComponent; }()); UsersAdministrationComponent = __decorate([ diff --git a/apps/maarch_entreprise/js/angular/app/users-administration.component.ts b/apps/maarch_entreprise/js/angular/app/users-administration.component.ts index 6fd81feacac0aaa7e8f1ffa2e5298e0f244dbb9d..dba6242704732f7f250b3af4ef2d3ba2c646507d 100644 --- a/apps/maarch_entreprise/js/angular/app/users-administration.component.ts +++ b/apps/maarch_entreprise/js/angular/app/users-administration.component.ts @@ -17,7 +17,7 @@ export class UsersAdministrationComponent implements OnInit { users : any[] = []; lang : any = {}; - + table : any resultInfo : string = ""; loading : boolean = false; @@ -45,10 +45,11 @@ export class UsersAdministrationComponent implements OnInit { this.lang = data.lang; setTimeout(() => { - $j('#usersTable').DataTable({ - "dom": '<"datatablesLeft"p><"datatablesRight"f>rt<"datatablesCenter"i><"clear">', + this.table = $j('#usersTable').DataTable({ + "dom": '<"datatablesLeft"p><"datatablesRight"f><"datatablesCenter"l>rt<"datatablesCenter"i><"clear">', + "lengthMenu": [ 10, 25, 50, 75, 100 ], "oLanguage": { - "sLengthMenu": "Display _MENU_ records per page", + "sLengthMenu": "<i class='fa fa-bars'></i> _MENU_", "sZeroRecords": this.lang.noResult, "sInfo": "_START_ - _END_ / _TOTAL_ "+this.lang.record, "sSearch": "", @@ -74,4 +75,84 @@ export class UsersAdministrationComponent implements OnInit { location.href = "index.php"; }); } + + suspendUser(user: any) { + let r = confirm(this.lang.suspendMsg+' ?'); + + if (r) { + user.enabled = 'N'; + this.http.put(this.coreUrl + 'rest/user/' + user.user_id, user) + .map(res => res.json()) + .subscribe((data) => { + if (data.errors) { + this.resultInfo = data.errors; + $j('#resultInfo').removeClass().addClass('alert alert-danger alert-dismissible'); + $j("#resultInfo").fadeTo(3000, 500).slideUp(500, function(){ + $j("#resultInfo").slideUp(500); + }); + } else { + this.resultInfo = data.success; + $j('#resultInfo').removeClass().addClass('alert alert-success alert-dismissible'); + $j("#resultInfo").fadeTo(3000, 500).slideUp(500, function(){ + $j("#resultInfo").slideUp(500); + }); + } + }); + } + } + + activateUser(user: any) { + let r = confirm(this.lang.authorizeMsg+' ?'); + + if (r) { + user.enabled = 'Y'; + this.http.put(this.coreUrl + 'rest/user/' + user.user_id, user) + .map(res => res.json()) + .subscribe((data) => { + if (data.errors) { + this.resultInfo = data.errors; + $j('#resultInfo').removeClass().addClass('alert alert-danger alert-dismissible'); + $j("#resultInfo").fadeTo(3000, 500).slideUp(500, function(){ + $j("#resultInfo").slideUp(500); + }); + } else { + this.resultInfo = data.success; + $j('#resultInfo').removeClass().addClass('alert alert-success alert-dismissible'); + $j("#resultInfo").fadeTo(3000, 500).slideUp(500, function(){ + $j("#resultInfo").slideUp(500); + }); + } + }); + } + } + + deleteUser(id: string) { + let r = confirm(this.lang.deleteMsg+' ?'); + + if (r) { + this.http.delete(this.coreUrl + 'rest/user/' + id) + .map(res => res.json()) + .subscribe((data) => { + if (data.errors) { + this.resultInfo = data.errors; + $j('#resultInfo').removeClass().addClass('alert alert-danger alert-dismissible'); + $j("#resultInfo").fadeTo(3000, 500).slideUp(500, function(){ + $j("#resultInfo").slideUp(500); + }); + } else { + for(var i = 0;i<this.users.length;i++){ + if(this.users[i].user_id == id){ + this.users.splice(i,1); + } + } + this.table.row($j("#"+id)).remove().draw(); + this.resultInfo = data.success; + $j('#resultInfo').removeClass().addClass('alert alert-success alert-dismissible'); + $j("#resultInfo").fadeTo(3000, 500).slideUp(500, function(){ + $j("#resultInfo").slideUp(500); + }); + } + }); + } + } } diff --git a/apps/maarch_entreprise/js/functions.js b/apps/maarch_entreprise/js/functions.js index 605d99d0bbcad6d1c1c0eccd75d11a40b4c10c88..52c3e403d59d6cb613e1d5890822c590c89d1da9 100755 --- a/apps/maarch_entreprise/js/functions.js +++ b/apps/maarch_entreprise/js/functions.js @@ -3672,3 +3672,26 @@ function change3(id){ ouvre3(id); } } +var isBootstrapEvent = false; +if (window.jQuery) { + var all = jQuery('*'); + jQuery.each(['hide.bs.dropdown', + 'hide.bs.collapse', + 'hide.bs.modal', + 'hide.bs.tooltip', + 'hide.bs.popover'], function(index, eventName) { + all.on(eventName, function( event ) { + isBootstrapEvent = true; + }); + }); +} +var originalHide = Element.hide; +Element.addMethods({ + hide: function(element) { + if(isBootstrapEvent) { + isBootstrapEvent = false; + return element; + } + return originalHide(element); + } +}); \ No newline at end of file diff --git a/core/Controllers/UserController.php b/core/Controllers/UserController.php index 7d8103c141e784d50f662c5a71e22d0b5741ba5c..21e8f729713c75c83af1d47fa6a9ba5fd699f819 100644 --- a/core/Controllers/UserController.php +++ b/core/Controllers/UserController.php @@ -403,8 +403,8 @@ class UserController if ($_SESSION['user']['UserId'] == 'superadmin') { $users = UserModel::get([ 'select' => ['user_id', 'firstname', 'lastname', 'status', 'enabled', 'mail'], - 'where' => ['user_id != ?'], - 'data' => ['superadmin'] + 'where' => ['user_id != ?', 'status != ?'], + 'data' => ['superadmin', 'DEL'] ]); } else { $entities = EntitiesModel::getAllEntitiesByUserId(['userId' => $_SESSION['user']['UserId']]); @@ -439,7 +439,7 @@ class UserController return $response->withStatus(403)->withJson(['errors' => 'UserId out of perimeter']); } } - $user = UserModel::getById(['userId' => $aArgs['userId'], 'select' => ['user_id', 'firstname', 'lastname', 'phone', 'mail', 'initials', 'thumbprint']]); + $user = UserModel::getById(['userId' => $aArgs['userId'], 'select' => ['user_id', 'firstname', 'lastname', 'status', 'enabled', 'phone', 'mail', 'initials', 'thumbprint']]); $user['signatures'] = UserModel::getSignaturesById(['userId' => $aArgs['userId']]); $user['emailSignatures'] = UserModel::getEmailSignaturesById(['userId' => $aArgs['userId']]); $user['groups'] = UserModel::getGroupsById(['userId' => $aArgs['userId']]); @@ -473,6 +473,25 @@ class UserController return $response->withJson(['success' => _ADDED_GROUP]); } + public function deleteUser(RequestInterface $request, ResponseInterface $response, $aArgs) + { + $error = $this->hasUsersRights(['userId' => $aArgs['userId']]); + if (!empty($error['error'])) { + return $response->withStatus($error['status'])->withJson(['errors' => $error['error']]); + } + if (empty(UserModel::getById(['userId' => $aArgs['userId']]))) { + return $response->withStatus(400)->withJson(['errors' => 'User not found']); + } + + $r = UserModel::delete(['userId' => $aArgs['userId']]); + + if (!$r) { + return $response->withStatus(500)->withJson(['errors' => 'User Delete Error']); + } + + return $response->withJson(['success' => _DELETED_USER]); + } + public function deleteGroup(RequestInterface $request, ResponseInterface $response, $aArgs) { $error = $this->hasUsersRights(['userId' => $aArgs['userId']]); @@ -483,7 +502,7 @@ class UserController return $response->withStatus(400)->withJson(['errors' => 'Group not found']); } - $r = UserModel::addGroup(['userId' => $aArgs['userId'], 'groupId' => $aArgs['groupId']]); + $r = UserModel::deleteGroup(['userId' => $aArgs['userId'], 'groupId' => $aArgs['groupId']]); if (!$r) { return $response->withStatus(500)->withJson(['errors' => 'User Update Error']); diff --git a/core/Models/LangModelAbstract.php b/core/Models/LangModelAbstract.php index e3de87ad7b8758b0ac1daf73d48858034bd9690c..ebcd847b6e9e8607df405044da9e4aa6cbc7f3e6 100644 --- a/core/Models/LangModelAbstract.php +++ b/core/Models/LangModelAbstract.php @@ -166,7 +166,7 @@ class LangModelAbstract 'noRecords' => _NO_RECORDS, 'available' => _AVAILABLE, 'filteredFrom' => _FILTERED_FROM, - 'records' => _RECORDS, + 'records' => _RECORDS ]; return $aLang; } @@ -195,7 +195,10 @@ class LangModelAbstract 'previous' => _PREVIOUS_PAGE, 'next' => _NEXT_PAGE, 'record' => _RECORD, - 'search' => _SEARCH + 'search' => _SEARCH, + 'deleteMsg' => _REALLY_DELETE, + 'suspendMsg' => _REALLY_SUSPEND, + 'authorizeMsg' => _REALLY_AUTHORIZE ]; return $aLang; diff --git a/core/Models/UserModelAbstract.php b/core/Models/UserModelAbstract.php index 2c5bdc5ab4b405f038c8bc8594a526af9be2cbfc..0e1baff715051aa4096dd36ae642416c4efc5972 100644 --- a/core/Models/UserModelAbstract.php +++ b/core/Models/UserModelAbstract.php @@ -88,7 +88,7 @@ class UserModelAbstract extends \Apps_Table_Service { static::checkRequired($aArgs, ['user', 'userId']); static::checkRequired($aArgs['user'], ['firstname', 'lastname']); - static::checkString($aArgs['user'], ['firstname', 'lastname', 'mail', 'initials', 'thumbprint', 'phone']); + static::checkString($aArgs['user'], ['firstname', 'lastname', 'mail', 'initials', 'thumbprint', 'phone', 'status', 'enabled']); $isUpdated = parent::update([ 'table' => 'users', @@ -98,6 +98,8 @@ class UserModelAbstract extends \Apps_Table_Service 'mail' => $aArgs['user']['mail'], 'phone' => $aArgs['user']['phone'], 'initials' => $aArgs['user']['initials'], + 'status' => $aArgs['user']['status'], + 'enabled' => $aArgs['user']['enabled'], 'thumbprint' => $aArgs['user']['thumbprint'] ], 'where' => ['user_id = ?'], @@ -107,6 +109,23 @@ class UserModelAbstract extends \Apps_Table_Service return $isUpdated; } + public static function delete(array $aArgs = []) + { + static::checkRequired($aArgs, ['userId']); + static::checkString($aArgs, ['userId']); + + $isUpdated = parent::update([ + 'table' => 'users', + 'set' => [ + 'status' => 'DEL', + ], + 'where' => ['user_id = ?'], + 'data' => [$aArgs['userId']] + ]); + + return $isUpdated; + } + public static function updatePassword(array $aArgs = []) { static::checkRequired($aArgs, ['userId', 'password']); diff --git a/rest/index.php b/rest/index.php index a0071c41fd4db1822579c038cf5adc8f10254413..89c555b177a9782447f2985b134c61b18feabfc0 100644 --- a/rest/index.php +++ b/rest/index.php @@ -145,6 +145,7 @@ $app->post('/resExt', \Core\Controllers\ResExtController::class . ':create'); $app->get('/user/profile', \Core\Controllers\UserController::class . ':getCurrentUserInfos'); $app->put('/user/profile', \Core\Controllers\UserController::class . ':updateProfile'); $app->put('/user/{userId}', \Core\Controllers\UserController::class . ':update'); +$app->delete('/user/{userId}', \Core\Controllers\UserController::class . ':deleteUser'); $app->post('/user/{userId}/groups/{groupId}', \Core\Controllers\UserController::class . ':addGroup'); $app->delete('/user/{userId}/groups/{groupId}', \Core\Controllers\UserController::class . ':deleteGroup'); $app->put('/currentUser/password', \Core\Controllers\UserController::class . ':updateCurrentUserPassword');