Commit 76533228 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

Merge branch 'users'

parents c0b25234 0b3edde7
......@@ -160,6 +160,42 @@ sub login {
return;
}
=head2 make_admin
Makes the user admin. Returns nothing.
Ravada::Auth::SQL::make_admin($id);
=cut
sub make_admin {
my $id = shift;
my $sth = $$CON->dbh->prepare(
"UPDATE users SET is_admin=1 WHERE id=?");
$sth->execute($id);
$sth->finish;
}
=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.
......
......@@ -16,8 +16,8 @@
.controller("SupportForm", suppFormCtrl)
.controller("machines", machinesCrtl)
.controller("messages", messagesCrtl)
.controller("users", usersCrtl)
.controller("users", usersCrtl)
......@@ -171,9 +171,29 @@
$scope.list_users= response.data;
});
request.get(function( res ) {
$scope.res = res;
});
$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();
}
};
};
......@@ -195,7 +215,6 @@
};
// list messages
function messagesCrtl($scope, $http, request) {
......
......@@ -5,16 +5,19 @@
<thead>
<tr>
<th>Name</th>
<th>ID</th>
<th>Admin</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in list_users">
<td>{{user.name}}</td>
<td>{{user.id}}</td>
<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>
</tbody>
</table>
</div>
</div>
......@@ -167,7 +167,6 @@ get '/list_users.json' => sub {
$c->render(json => $RAVADA->list_users);
};
get '/list_lxc_templates.json' => sub {
my $c = shift;
$c->render(json => $RAVADA->list_lxc_templates);
......@@ -248,6 +247,20 @@ get '/machine/start/*.json' => sub {
my $c = shift;
return start_machine($c);
};
##make admin
get '/users/make_admin/*.json' => sub {
my $c = shift;
return make_admin($c);
};
##remove admin
get '/users/remove_admin/*.json' => sub {
my $c = shift;
return remove_admin($c);
};
##############################################
#
......@@ -673,6 +686,30 @@ sub _search_requested_machine {
return $domain;
}
sub make_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::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);
......@@ -866,6 +903,8 @@ sub resume_machine {
return $c->render(json => { req => $req->id });
}
sub list_requests {
my $c = shift;
......
......@@ -13,7 +13,6 @@
<div class="panel-heading">
<h2>Users List
<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