Allow globs to be used in user() pagespecs.

master
Joey Hess 2010-02-11 20:39:10 -05:00
parent 7af18f2a1e
commit c923e0ba33
4 changed files with 14 additions and 3 deletions

View File

@ -2266,11 +2266,13 @@ sub match_user ($$;@) {
my $user=shift;
my %params=@_;
my $regexp=IkiWiki::glob2re($user);
if (! exists $params{user}) {
return IkiWiki::ErrorReason->new("no user specified");
}
if (defined $params{user} && lc $params{user} eq lc $user) {
if (defined $params{user} && $params{user}=~/^$regexp$/i) {
return IkiWiki::SuccessReason->new("user is $user");
}
elsif (! defined $params{user}) {

1
debian/changelog vendored
View File

@ -21,6 +21,7 @@ ikiwiki (3.20100123) UNRELEASED; urgency=low
a button on the login form to use it.
* httpauth: Add httpauth_pagespec setting that can be used to limit
pages to only being edited via users authed with httpauth.
* Allow globs to be used in user() pagespecs.
-- Joey Hess <joeyh@debian.org> Tue, 26 Jan 2010 22:25:33 -0500

View File

@ -44,7 +44,8 @@ Some more elaborate limits can be added to what matches using these functions:
metadata, matching the specified glob.
* "`user(username)`" - tests whether a modification is being made by a
user with the specified username. If openid is enabled, an openid can also
be put here.
be put here. Glob patterns can be used in the username. For example,
to match all openid users, use `user(*://.*)`
* "`admin()`" - tests whether a modification is being made by one of the
wiki admins.
* "`ip(address)`" - tests whether a modification is being made from the

View File

@ -1,7 +1,7 @@
#!/usr/bin/perl
use warnings;
use strict;
use Test::More tests => 64;
use Test::More tests => 70;
BEGIN { use_ok("IkiWiki"); }
@ -40,6 +40,13 @@ ok(! pagespec_match("foo", "foo and bar"), "foo and bar");
ok(pagespec_match("{f}oo", "{*}*"), "curly match");
ok(! pagespec_match("foo", "{*}*"), "curly !match");
ok(pagespec_match("somepage", "user(frodo)", user => "frodo"));
ok(pagespec_match("somepage", "user(frodo)", user => "Frodo"));
ok(! pagespec_match("somepage", "user(frodo)", user => "Sam"));
ok(pagespec_match("somepage", "user(*o)", user => "Bilbo"));
ok(pagespec_match("somepage", "user(*o)", user => "frodo"));
ok(! pagespec_match("somepage", "user(*o)", user => "Sam"));
# The link and backlink stuff needs this.
$config{userdir}="";
$links{foo}=[qw{bar baz}];