Commit 397290a3 authored by Roberto P. Rubio's avatar Roberto P. Rubio
Browse files

List machines includes also not public machines

parent 02638600
......@@ -128,21 +128,21 @@ Returns: listref of machines
=cut
sub list_machines_user($self, $user, $access_data={}) {
sub _list_machines_user($self, $user, $access_data, $typeof) {
my $base = $typeof ? 1 : 0;
my $sth = $CONNECTOR->dbh->prepare(
"SELECT id,name,is_public, description, screenshot"
"SELECT id,name,is_public, description, screenshot, id_owner"
." FROM domains "
." WHERE is_base=1"
." WHERE is_base=$base"
." ORDER BY name "
);
my ($id, $name, $is_public, $description, $screenshot);
my ($id, $name, $is_public, $description, $screenshot, $id_owner);
$sth->execute;
$sth->bind_columns(\($id, $name, $is_public, $description, $screenshot));
$sth->bind_columns(\($id, $name, $is_public, $description, $screenshot, $id_owner));
my @list;
while ( $sth->fetch ) {
next if !$is_public && !$user->is_admin;
next if !$is_public && !$user->is_admin && (($typeof) || ($user->id != $id_owner));
next if !$user->allowed_access($id);
my $is_active = 0;
my $clone = $self->search_clone(
......@@ -190,6 +190,14 @@ sub list_machines_user($self, $user, $access_data={}) {
return \@list;
}
sub list_machines_user($self, $user, $access_data={}) {
return _list_machines_user($self, $user, $access_data, 1);
}
sub list_private_machines_user($self, $user, $access_data={}) {
return _list_machines_user($self, $user, $access_data, 0);
}
sub _access_allowed($self, $id_base, $id_clone, $access_data) {
if ($id_clone) {
my $clone = Ravada::Front::Domain->open($id_clone);
......
......@@ -25,18 +25,19 @@ has ravada => (
);
my %SUB = (
list_alerts => \&_list_alerts
,list_bases => \&_list_bases
,list_isos => \&_list_isos
,list_nodes => \&_list_nodes
,list_machines => \&_list_machines
,list_machines_tree => \&_list_machines_tree
,list_machines_user => \&_list_machines_user
,list_bases_anonymous => \&_list_bases_anonymous
,list_requests => \&_list_requests
,machine_info => \&_get_machine_info
,ping_backend => \&_ping_backend
,request => \&_request
list_alerts => \&_list_alerts
,list_bases => \&_list_bases
,list_isos => \&_list_isos
,list_nodes => \&_list_nodes
,list_machines => \&_list_machines
,list_machines_tree => \&_list_machines_tree
,list_machines_user => \&_list_machines_user
,list_machines_user_including_privates => \&_list_machines_user_including_privates
,list_bases_anonymous => \&_list_bases_anonymous
,list_requests => \&_list_requests
,machine_info => \&_get_machine_info
,ping_backend => \&_ping_backend
,request => \&_request
);
our %TABLE_CHANNEL = (
......@@ -171,6 +172,20 @@ sub _list_machines_user($rvd, $args) {
return $ret;
}
sub _list_machines_user_including_privates($rvd, $args) {
my $login = $args->{login} or die "Error: no login arg ".Dumper($args);
my $user = Ravada::Auth::SQL->new(name => $login)
or die "Error: uknown user $login";
my $client = $args->{client};
my $ret = $rvd->list_machines_user($user, {client => $client});
my $priv_machines = $rvd->list_private_machines_user($user, {client => $client});
push(@$ret, $_) foreach (@$priv_machines);
return $ret;
}
sub _list_bases_anonymous($rvd, $args) {
my $remote_ip = $args->{remote_ip} or die "Error: no remote_ip arg ".Dumper($args);
return $rvd->list_bases_anonymous($remote_ip);
......
......@@ -121,7 +121,7 @@
$scope.subscribe_list_machines_user = function(url) {
$scope.machines = [];
var channel = 'list_machines_user';
var channel = 'list_machines_user_including_privates';
if ($scope.anonymous) {
channel = 'list_bases_anonymous';
}
......
......@@ -14,7 +14,7 @@
<div class="card-body">
<div ng-repeat="machine in machines | orderBy: 'id_clone'"
class="col-sm-4 d-inline-block mb-2"
ng-show="machine.is_public || (!machine.is_public && !only_public)">
ng-show="machine.is_public || (!only_public)">
<div class="card card-success">
<div class="card-header" id="step1" >
<h3 class="card-title">
......
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