Re-factor grant parsing, and fix bug that prevent grants from being displayed when DBI returns an array

This commit is contained in:
Jamie Cameron
2013-12-30 11:13:25 -08:00
parent 4d2e876a68
commit 554164d052
4 changed files with 28 additions and 13 deletions

View File

@ -15,9 +15,8 @@ else {
foreach $g (@{$s->{'data'}}) {
if ($g->[0] eq $in{'table'} &&
$g->[2] eq $in{'ns'}) {
$g->[1] =~ s/^\{//; $g->[1] =~ s/\}$//;
@grant = map { /^"(.*)=(.*)"$/ || /^(.*)=(.*)$/; [ $1, $2 ] }
split(/,/, $g->[1]);
@grant = &extract_grants($g->[1]);
last;
}
}
@ -59,7 +58,7 @@ foreach $g (@grant, [ undef, undef ]) {
[ 'public', $text{'grant_public'} ],
(map { [ "group $_", &text('grant_group', $_) ] }
@groups),
(@users) ]));
(@users) ], 1, 0, 1));
# Permissions
($acl = $g->[1]) =~ s/\/.*//g;

View File

@ -75,20 +75,19 @@ elsif (@tables) {
"'>".&html_escape($tname)."</a>");
push(@cols, $text{"grant_$type"});
push(@cols, &html_escape($d));
$g->[1] =~ s/^\{//; $g->[1] =~ s/\}$//;
@gr = grep { /=\S/ } map { /^"(.*)"$/ ? $1 : $_ } split(/,/, $g->[1]);
my @gr = &extract_grants($g->[1]);
local $gstr;
foreach $gr (@gr) {
$gstr .= "&nbsp;|&nbsp;" if ($gr ne $gr[0]);
if ($gr =~ /^=(\S+)/) {
if ($gr->[0] eq "") {
$gstr .= $text{'grant_public'};
}
elsif ($gr =~ /^group\s+(\S+)=(\S+)/) {
elsif ($gr->[0] =~ /^group\s+(\S+)/) {
$gstr .= &text('grant_group',
"<tt>".&html_escape($1)."</tt>");
}
elsif ($gr =~ /^(\S+)=(\S+)$/) {
$gstr .= "<tt>".&html_escape($1)."</tt>";
else {
$gstr .= "<tt>".&html_escape($gr->[0])."</tt>";
}
}
push(@cols, $gstr);

View File

@ -1231,5 +1231,23 @@ else {
return $cmd;
}
# extract_grants(field)
# Given a field from pg_class that contains grants either as a comma-separated
# list or an array, return a list of tuples in user,grant format
sub extract_grants
{
my ($f) = @_;
my @rv;
if (ref($f)) {
@rv = map { [ split(/=/, $_, 2) ] } @$f;
}
else {
$f =~ s/^\{//;
$f =~ s/\}$//;
@rv = map { [ split(/=/, $_, 2) ] } map { s/\\"/"/g; s/"//g; $_ } grep { /=\S/ } split(/,/, $f);
}
return @rv;
}
1;

View File

@ -18,9 +18,8 @@ else {
foreach $g (@{$s->{'data'}}) {
if ($g->[0] eq $in{'table'} &&
$g->[2] eq $in{'ns'}) {
$g->[1] =~ s/^\{//; $g->[1] =~ s/\}$//;
@grant = map { /^"(.*)=(.*)"$/ || /^(.*)=(.*)$/; [ $1, $2 ] }
split(/,/, $g->[1]);
@grant = &extract_grants($g->[1]);
last;
}
}
$qt = $ss ? &quote_table($in{'ns'}.".".$in{'table'})