Commit 8ea9523b authored by frankiejol's avatar frankiejol
Browse files

refactor(networking): show correct allowed domain

parent 1f4ef498
......@@ -727,7 +727,9 @@ sub list_bases_network($self, $id_network) {
$sth->execute;
my $default = $sth->fetchrow_hashref();
$sth->finish;
lock_hash(%$default);
warn "Warning: all_domains and no_domains both true for default network ".Dumper($default)
if $default->{all_domains} && $default->{no_domains};
my $sth_nd = $CONNECTOR->dbh->prepare("SELECT id,allowed,anonymous FROM domains_network"
." WHERE id_domain=? AND id_network=? "
......@@ -738,15 +740,17 @@ sub list_bases_network($self, $id_network) {
$sth->execute();
my @bases;
while (my $row = $sth->fetchrow_hashref) {
$row->{anonymous} = ( $default->{anonymous} or 0);
$sth_nd->execute($row->{id}, $id_network);
my ($id,$allowed, $anonymous) = $sth_nd->fetchrow;
$row->{anonymous} = $anonymous if defined $anonymous;
$row->{anonymous} = ( $anonymous or 0);
if (defined $allowed) {
$row->{allowed} = $allowed;
} else {
$row->{allowed} = 1;
$row->{allowed} = $default->{all_domains};
$row->{allowed} = 0 if $default->{no_domains};
}
lock_hash(%$row);
......
......@@ -247,6 +247,25 @@ sub _id_network {
return $id;
}
sub test_conflict_allowed {
my $sth = connector->dbh->prepare(
"INSERT INTO networks (name, address, all_domains, no_domains) "
." VALUES ( ? , ?, ?, ? )"
);
my $name = 'all';
$sth->execute($name, '91.2.3.4/24', 1 , 1);
$sth = connector->dbh->prepare(
"SELECT all_domains, no_domains FROM networks WHERE name=?"
);
$sth->execute($name);
my ($all,$no) = $sth->fetchrow;
TODO: {
local $TODO = "Requires trigger to avoid all_domains=1 and no_domains=1";
isnt($all,$no);
};
}
########################################################################3
#
#
......@@ -260,6 +279,8 @@ my $domain = $vm->create_domain( name => $domain_name
$domain->prepare_base(user_admin);
$domain->is_public(1);
test_conflict_allowed();
my $net = Ravada::Network->new(address => '127.0.0.1/32');
ok($net->allowed($domain->id));
......
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