Skip to content

Commit

Permalink
[#231] insert only when no defined grant value
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejol committed May 31, 2017
1 parent abf0056 commit 6e3e5bc
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/Ravada/Auth/SQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -561,18 +561,21 @@ sub grant($self,$user,$permission,$value=1) {
}

return 0 if !$value && !$user->can_do($permission);
return $value if defined $user->can_do($permission) && $user->can_do($permission) eq $value;

my $value_sql = $user->can_do($permission);
return $value if defined $value_sql && $value_sql eq $value;

my $id_grant = _search_id_grant($permission);
my $sth = $$CON->dbh->prepare(
if (! defined $value_sql ) {
my $sth = $$CON->dbh->prepare(
"INSERT INTO grants_user "
." (id_grant, id_user, allowed)"
." VALUES(?,?,?) "
);
eval { $sth->execute($id_grant, $user->id, $value) };
$sth->finish;
if ($@ && $@ =~ /UNIQUE|duplicate/i) {
$sth = $$CON->dbh->prepare(
);
$sth->execute($id_grant, $user->id, $value);
$sth->finish;
} else {
my $sth = $$CON->dbh->prepare(
"UPDATE grants_user "
." set allowed=?"
." WHERE id_grant = ? AND id_user=?"
Expand Down

0 comments on commit 6e3e5bc

Please sign in to comment.