Commit 0b3edde7 authored by Laura Figuerola's avatar Laura Figuerola
Browse files

make_admin and remove_admin added in Users List

parent d67daf12
......@@ -178,6 +178,24 @@ sub make_admin {
}
=head2 remove_admin
Remove user admin privileges. Returns nothing.
Ravada::Auth::SQL::remove_admin($id);
=cut
sub remove_admin {
my $id = shift;
my $sth = $$CON->dbh->prepare(
"UPDATE users SET is_admin=NULL WHERE id=?");
$sth->execute($id);
$sth->finish;
}
=head2 is_admin
Returns true if the user is admin.
......
......@@ -130,9 +130,27 @@
$scope.make_admin = function(id) {
$http.get('/users/make_admin/' + id + '.json')
location.reload();
};
$scope.remove_admin = function(id) {
$http.get('/users/remove_admin/' + id + '.json')
location.reload();
};
$scope.checkbox = [];
//if it is checked make the user admin, otherwise remove admin
$scope.stateChanged = function(id,userid) {
if($scope.checkbox[id]) { //if it is checked
$http.get('/users/make_admin/' + userid + '.json')
location.reload();
}
else {
$http.get('/users/remove_admin/' + userid + '.json')
location.reload();
}
};
};
......
......@@ -5,21 +5,19 @@
<thead>
<tr>
<th>Name</th>
<th>ID</th>
<th>Admins</th>
<th>Actions</th>
<th>Admin</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in list_users">
<td>{{user.name}}</td>
<td>{{user.id}}</td>
<td><i ng-show="{{user.is_admin}}" class="fa fa-check" aria-hidden="true"</i><i ng-show= "{{user.is_admin!=1}}" class="fa fa-times" aria-hidden="true"</i></td>
<td><button class= "btn btn-success btn-sm" ng-click="make_admin(user.id)"> Make Admin</button></td><tr>
<!-- <td><i ng-show= "{{user.is_admin!=1}}" class="btn btn-danger">Make Admin</i><i ng-show= "{{user.is_admin}}" class="btn btn-success">Remove Admin</i></td>-->
</tr>
<td><a ng-show="{{user.is_admin}}" ng-click="remove_admin(user.id)" class="fa fa-check" aria-hidden="true"</a>
<a ng-show="{{user.is_admin!=1}}" ng-click="make_admin(user.id)" class="fa fa-times" aria-hiden="true"</a></td>
</tr>
</tbody>
</table>
</table>
</div>
</div>
......@@ -173,6 +173,13 @@ get '/users/make_admin/*.json' => sub {
return make_admin($c);
};
##remove admin
get '/users/remove_admin/*.json' => sub {
my $c = shift;
return remove_admin($c);
};
##############################################
#
......@@ -560,11 +567,22 @@ sub make_admin {
warn "id usuari $id";
#my $user= Ravada::Auth::SQL->search_by_id($id);
Ravada::Auth::SQL::make_admin($id);
}
sub remove_admin {
my $c = shift;
return login($c) if !_logged_in($c);
my ($id) = $c->req->url->to_abs->path =~ m{/(\d+).json};
warn "id usuari $id";
Ravada::Auth::SQL::remove_admin($id);
}
sub manage_machine {
my $c = shift;
return login($c) if !_logged_in($c);
......
......@@ -12,8 +12,7 @@
<div class="panel panel-default">
<div class="panel-heading">
<h2>Users List
<button id="newMButton" style="float: right; margin: 0 10px;" class="btn btn-info" ng-click="location.reload('forceGet')"><i class="fa fa-refresh" aria-hidden="true"></i></button>
<button id="newMButton" style="float: right; margin: 0 10px;" class="btn btn-info" onclick="location.reload('forceGet')"><i class="fa fa-refresh" aria-hidden="true"></i></button>
</h2>
</div>
......
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