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

fix(install): upgrade start_many

parent e4bdb5aa
......@@ -166,9 +166,6 @@ sub add_user {
sub _search_id_grant($self, $type) {
return $self->{_grant_id}->{$type}
if exists $self->{_grant_id}->{$type};
$self->_load_grants();
my @names = $self->_grant_alternate_name($type);
......@@ -181,8 +178,6 @@ sub _search_id_grant($self, $type) {
confess "Unknown grant $type\n".Dumper($self->{_grant_alias}, $self->{_grant}) if !$id;
$self->{_grant_id}->{$type} = $id;
return $id;
}
......@@ -860,14 +855,13 @@ sub grant($self,$user,$permission,$value=1) {
.Dumper(\@perms);
}
return 0 if !$value && !$user->can_do($permission);
my $value_sql = $user->can_do($permission);
return 0 if !$value && !$value_sql;
return $value if defined $value_sql && $value_sql eq $value;
$permission = $self->_grant_alias($permission);
my $id_grant = $self->_search_id_grant($permission);
if (! defined $user->can_do($permission)) {
if (! defined $value_sql) {
my $sth = $$CON->dbh->prepare(
"INSERT INTO grants_user "
." (id_grant, id_user, allowed)"
......
......@@ -873,6 +873,7 @@ sub remove_old_disks {
sub create_user {
my ($name, $pass, $is_admin) = @_;
$is_admin = 1 if $is_admin;
my $login;
eval { $login = Ravada::Auth::SQL->new(name => $name, password => $pass ) };
......
......@@ -68,14 +68,14 @@ sub test_defaults {
}
sub test_admin {
my $user = create_user("foo$$","bar",1);
my $user = create_user(new_domain_name()." foo$$","bar",1);
ok($user->is_admin);
for my $perm ($user->list_all_permissions) {
if ($perm->{name} eq 'start_limit') {
is($user->can_do($perm->{name}),undef,$perm->{name});
next;
}
is($user->can_do($perm->{name}),1,$perm->{name});
is($user->can_do($perm->{name}),1,$user->name." ".$perm->{name}) or exit;
}
$user->remove();
}
......@@ -778,11 +778,38 @@ sub test_start_limit_upgrade{
$usera->remove();
}
sub test_start_many_upgrade{
my $user = create_user("oper_startm","bar");
my $usera = create_user("admin_startm","bar",1);
my $sth = connector->dbh->prepare("SELECT id FROM grant_types WHERE name='start_many'");
$sth->execute();
my ($id) = $sth->fetchrow;
$sth = connector->dbh->prepare("DELETE FROM grants_user WHERE id_grant=?");
$sth->execute($id);
$sth = connector->dbh->prepare("DELETE FROM grant_types WHERE id=?");
$sth->execute($id);
rvd_back->{_null_grants}=0;
rvd_back->_install();
$user->_reload_grants();
$usera->_reload_grants();
is($user->can_start_many,0);
is($usera->can_start_many,1);
$user->remove();
$usera->remove();
}
##########################################################
test_start_many();
test_start_limit_upgrade();
test_start_many_upgrade();
test_defaults();
test_admin();
......
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