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

[#222] fix daemon user

parent dbb2e89f
......@@ -104,9 +104,9 @@ sub BUILD {
}
Ravada::Auth::init($CONFIG);
$self->_init_user_daemon();
$self->_create_tables();
$self->_upgrade_tables();
$self->_init_user_daemon();
$self->_update_data();
}
......@@ -126,12 +126,15 @@ sub _init_user_daemon {
}
sub _update_user_grants {
my $self = shift;
$self->_init_user_daemon();
my $sth = $CONNECTOR->dbh->prepare("SELECT id FROM users");
my $id;
$sth->bind_columns(\$id);
$sth->execute;
$sth->bind_columns(\$id);
while ($sth->fetch) {
my $user = Ravada::Auth::SQL->search_by_id($id);
next if $user->name() eq $USER_DAEMON_NAME;
$USER_DAEMON->grant_user_permissions($user);
$USER_DAEMON->grant_admin_permissions($user) if $user->is_admin;
}
......
......@@ -450,8 +450,11 @@ sub grant_admin_permissions($self,$user) {
}
sub grant($self,$user,$permission) {
die "ERROR: ".$self->name." can't grant permissions for ".$user->name."\n"
if !$self->can_grant();
if ( !$self->can_grant() && $self->name ne $Ravada::USER_DAEMON_NAME ) {
my @perms = $self->list_permissions();
confess "ERROR: ".$self->name." can't grant permissions for ".$user->name."\n"
.Dumper(\@perms);
}
return if $user->can_do($permission);
my $id_grant = _search_id_grant($permission);
......@@ -466,7 +469,7 @@ sub grant($self,$user,$permission) {
}
sub list_permissions($self) {
sub list_all_permissions($self) {
return if !$self->is_admin;
my $sth = $$CON->dbh->prepare(
......@@ -480,6 +483,15 @@ sub list_permissions($self) {
return @list;
}
sub list_permissions($self) {
my @list;
for my $grant (sort keys %{$self->{_grant}}) {
push @list , ( [$grant => $self->{_grant}->{$grant} ] )
if $self->{_grant}->{$grant};
}
return @list;
}
sub AUTOLOAD {
my $self = shift;
......
......@@ -64,7 +64,7 @@ sub test_defaults {
sub test_admin {
my $user = create_user("foo$$","bar",1);
ok($user->is_admin);
for my $perm ($user->list_permissions) {
for my $perm ($user->list_all_permissions) {
is($user->can_do($perm),1);
}
}
......
Markdown is supported
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