make can_write() in Easy.pm more flexible
This commit is contained in:
parent
198dcfd4c8
commit
d74f596e23
|
@ -112,14 +112,18 @@ sub can_read {
|
||||||
}
|
}
|
||||||
|
|
||||||
# can_write()
|
# can_write()
|
||||||
# return true if $ENV{GL_USER} is set and can write to the given repo
|
# return true if $ENV{GL_USER} is set and can write to the given repo.
|
||||||
|
# Optional second argument can be '+' to check that instead of 'W'. Optional
|
||||||
|
# third argument can be a full ref name instead of 'any'.
|
||||||
|
|
||||||
# shell equivalent
|
# shell equivalent
|
||||||
# if gitolite access -q $REPONAME $GL_USER W; then ...
|
# if gitolite access -q $REPONAME $GL_USER W; then ...
|
||||||
sub can_write {
|
sub can_write {
|
||||||
valid_user();
|
valid_user();
|
||||||
my $r = shift;
|
my ($r, $aa, $ref) = @_;
|
||||||
return not( access( $r, $user, 'W', 'any' ) =~ /DENIED/ );
|
$aa ||= 'W';
|
||||||
|
$ref ||= 'any';
|
||||||
|
return not( access( $r, $user, $aa, $ref ) =~ /DENIED/ );
|
||||||
}
|
}
|
||||||
|
|
||||||
# config()
|
# config()
|
||||||
|
|
12
t/easy.t
12
t/easy.t
|
@ -18,7 +18,7 @@ sub ok { (+shift) ? print "ok\n" : print "not ok\n"; }
|
||||||
sub nok { (+shift) ? print "not ok\n" : print "ok\n"; }
|
sub nok { (+shift) ? print "not ok\n" : print "ok\n"; }
|
||||||
sub msg { return unless $ENV{D}; print STDERR "#" . +shift . "\n"; }
|
sub msg { return unless $ENV{D}; print STDERR "#" . +shift . "\n"; }
|
||||||
|
|
||||||
try "plan 90";
|
try "plan 98";
|
||||||
|
|
||||||
try "
|
try "
|
||||||
cat $ENV{HOME}/.gitolite.rc
|
cat $ENV{HOME}/.gitolite.rc
|
||||||
|
@ -117,6 +117,11 @@ $ENV{GL_USER} = "u2"; ok(can_write("aa"));
|
||||||
$ENV{GL_USER} = "u3"; nok(can_write("aa"));
|
$ENV{GL_USER} = "u3"; nok(can_write("aa"));
|
||||||
$ENV{GL_USER} = "u4"; nok(can_write("aa"));
|
$ENV{GL_USER} = "u4"; nok(can_write("aa"));
|
||||||
|
|
||||||
|
$ENV{GL_USER} = "u1"; ok(can_write("aa", "+"));
|
||||||
|
$ENV{GL_USER} = "u2"; nok(can_write("aa", "+"));
|
||||||
|
$ENV{GL_USER} = "u3"; nok(can_write("aa", "+"));
|
||||||
|
$ENV{GL_USER} = "u4"; nok(can_write("aa", "+"));
|
||||||
|
|
||||||
$ENV{GL_USER} = "u1"; nok(can_write("bb"));
|
$ENV{GL_USER} = "u1"; nok(can_write("bb"));
|
||||||
$ENV{GL_USER} = "u2"; nok(can_write("bb"));
|
$ENV{GL_USER} = "u2"; nok(can_write("bb"));
|
||||||
$ENV{GL_USER} = "u3"; nok(can_write("bb"));
|
$ENV{GL_USER} = "u3"; nok(can_write("bb"));
|
||||||
|
@ -132,6 +137,11 @@ $ENV{GL_USER} = "u4"; ok(can_write("cc/u4"));
|
||||||
$ENV{GL_USER} = "u5"; ok(can_write("cc/u4"));
|
$ENV{GL_USER} = "u5"; ok(can_write("cc/u4"));
|
||||||
$ENV{GL_USER} = "u6"; nok(can_write("cc/u4"));
|
$ENV{GL_USER} = "u6"; nok(can_write("cc/u4"));
|
||||||
|
|
||||||
|
$ENV{GL_USER} = "u3"; nok(can_write("cc/u4", "+"));
|
||||||
|
$ENV{GL_USER} = "u4"; ok(can_write("cc/u4", "+"));
|
||||||
|
$ENV{GL_USER} = "u5"; ok(can_write("cc/u4", "+"));
|
||||||
|
$ENV{GL_USER} = "u6"; nok(can_write("cc/u4", "+"));
|
||||||
|
|
||||||
# config
|
# config
|
||||||
try("glt ls-remote u4 cc/sub/one; /Initialized empty.*cc/sub/one/");
|
try("glt ls-remote u4 cc/sub/one; /Initialized empty.*cc/sub/one/");
|
||||||
try("glt ls-remote u4 cc/two; /Initialized empty.*cc/two/");
|
try("glt ls-remote u4 cc/two; /Initialized empty.*cc/two/");
|
||||||
|
|
Loading…
Reference in a new issue