info/expand print better(?) permission codes

see doc/report-output.mkd for details
This commit is contained in:
Sitaram Chamarty 2010-08-24 13:34:27 +05:30
parent d6704d052a
commit 2b066fc9f0
3 changed files with 25 additions and 12 deletions

View file

@ -518,6 +518,19 @@ sub report_version {
system("cat", ($GL_PACKAGE_CONF || "$GL_ADMINDIR/conf") . "/VERSION"); system("cat", ($GL_PACKAGE_CONF || "$GL_ADMINDIR/conf") . "/VERSION");
} }
sub perm_code {
# print the permission code
my($all, $super, $user, $x) = @_;
return " " unless $all or $super or $user;
return " $x " unless $all or $super; # only $user (explicit access) was given
my $ret;
$ret = " \@$x" if $all; # prefix @ if repo allows access for @all users
$ret = " \#$x" if $super; # prefix # if user has access to @all repos (sort of like a super user)
$ret = " \&$x" if $all and $super; # prefix & if both the above
$ret .= ($user ? " " : "_" ); # suffix _ if no explicit access else <space>
return $ret;
}
# basic means wildcards will be shown as wildcards; this is pretty much what # basic means wildcards will be shown as wildcards; this is pretty much what
# got parsed by the compile script # got parsed by the compile script
sub report_basic sub report_basic
@ -551,8 +564,8 @@ sub report_basic
# #R => you're a super user and can see @all repos # #R => you're a super user and can see @all repos
# R => normal access # R => normal access
my $perm .= ( $repos{$r}{C}{'@all'} ? ' @C' : ( $repos{$r}{C}{$user} ? ' C' : ' ' ) ); my $perm .= ( $repos{$r}{C}{'@all'} ? ' @C' : ( $repos{$r}{C}{$user} ? ' C' : ' ' ) );
$perm .= ( $repos{$r}{R}{'@all'} ? ' @R' : ( $repos{'@all'}{R}{$user} ? ' #R' : ( $repos{$r}{R}{$user} ? ' R' : ' ' ))); $perm .= &perm_code( $repos{$r}{R}{'@all'}, $repos{'@all'}{R}{$user}, $repos{$r}{R}{$user}, 'R');
$perm .= ( $repos{$r}{W}{'@all'} ? ' @W' : ( $repos{'@all'}{W}{$user} ? ' #W' : ( $repos{$r}{W}{$user} ? ' W' : ' ' ))); $perm .= &perm_code( $repos{$r}{W}{'@all'}, $repos{'@all'}{W}{$user}, $repos{$r}{W}{$user}, 'W');
print "$perm\t$r\r\n" if $perm =~ /\S/; print "$perm\t$r\r\n" if $perm =~ /\S/;
} }
print "only 20 out of $count candidate repos examined\r\nplease use a partial reponame or regex pattern to limit output\r\n" if $GL_BIG_CONFIG and $count > 20; print "only 20 out of $count candidate repos examined\r\nplease use a partial reponame or regex pattern to limit output\r\n" if $GL_BIG_CONFIG and $count > 20;
@ -648,8 +661,8 @@ sub expand_wild
delete $repos{$repo} if $perm !~ /C/ and $wild; delete $repos{$repo} if $perm !~ /C/ and $wild;
$creator = "<notfound>"; $creator = "<notfound>";
} }
$perm .= ( $repos{$repo}{R}{'@all'} ? ' @R' : ( $repos{'@all'}{R}{$ENV{GL_USER}} ? ' #R' : ( $repos{$repo}{R}{$ENV{GL_USER}} ? ' R' : ' ' ))); $perm .= &perm_code( $repos{$repo}{R}{'@all'}, $repos{'@all'}{R}{$ENV{GL_USER}}, $repos{$repo}{R}{$ENV{GL_USER}}, 'R' );
$perm .= ( $repos{$repo}{W}{'@all'} ? ' @W' : ( $repos{'@all'}{W}{$ENV{GL_USER}} ? ' #W' : ( $repos{$repo}{W}{$ENV{GL_USER}} ? ' W' : ' ' ))); $perm .= &perm_code( $repos{$repo}{W}{'@all'}, $repos{'@all'}{W}{$ENV{GL_USER}}, $repos{$repo}{W}{$ENV{GL_USER}}, 'W' );
# set up for caching %repos # set up for caching %repos
$last_repo = $repo; $last_repo = $repo;

View file

@ -33,7 +33,7 @@ do
expect "RW u2" expect "RW u2"
name "expand" name "expand"
runlocal ssh u2 expand runlocal ssh u2 expand
expect "R W.(u1).foo/u1/bar" expect "R W .(u1).foo/u1/bar"
name "push" name "push"
cd ~/td cd ~/td
@ -80,7 +80,7 @@ do
expect "RW u2" expect "RW u2"
name "expand" name "expand"
runlocal ssh u2 expand runlocal ssh u2 expand
expect "R W.(u1).foo/u1/bar" expect " R W .(u1).foo/u1/bar"
name "push" name "push"
cd ~/td cd ~/td

View file

@ -36,17 +36,17 @@ do
name "u1 info" name "u1 info"
runlocal ssh u1 info runlocal ssh u1 info
expect "hello u1, the gitolite version here is" expect "hello u1, the gitolite version here is"
expect "@R.*@W.*testing" expect " @R_ @W_.testing"
[ "$wr" = "1" ] && [ "$bc" = "0" ] && expect "C.*R.*W.*foo/u1/\\.\\+" [ "$wr" = "1" ] && [ "$bc" = "0" ] && expect " C R W .foo/u1/\\.\\+"
[ "$wr" = "1" ] && [ "$bc" = "1" ] && notexpect "C.*R.*W.*foo/u1/\\.\\+" [ "$wr" = "1" ] && [ "$bc" = "1" ] && notexpect " C R W .foo/u1/\\.\\+"
[ "$wr" = "1" ] && [ "$bc" = "1" ] && expect "C.*@gfoo" [ "$wr" = "1" ] && [ "$bc" = "1" ] && expect " C .@gfoo"
name "u1 expand" name "u1 expand"
runlocal ssh u1 expand runlocal ssh u1 expand
[ "$wr" = "0" ] && expect "wildrepos disabled, sorry" [ "$wr" = "0" ] && expect "wildrepos disabled, sorry"
[ "$wr" = "1" ] && expect "hello u1, the gitolite version here is" [ "$wr" = "1" ] && expect "hello u1, the gitolite version here is"
[ "$wr" = "1" ] && expect "R.*W.*(u1).*foo/u1/bar" [ "$wr" = "1" ] && expect " R W .(u1).foo/u1/bar"
[ "$wr" = "1" ] && expect "@R.*@W.*testing" [ "$wr" = "1" ] && expect "@R_ @W_..gitolite..testing"
name INTERNAL name INTERNAL
done done