1 [[!template id=plugin name=groupfile core=0 author="[[Jogo]]"]]
3 This plugin add a `group(groupname)` function to [[ikiwiki/PageSpec]], which is true
4 only if the actual user is member of the group named `groupname`.
6 Groups membership are read from a file. The syntax of this file is very close to
7 usual `/etc/passwd` Unix file : the group's name, followed by a colon, followed by
8 a coma separated list of user's names. For exemple :
17 # by Joseph Boudou <jogo at matabio dot net>
19 package IkiWiki::Plugin::groupfile;
26 hook(type => 'getsetup', id => 'groups', call => \&get_setup);
37 example => '/etc/ikiwiki/group',
38 description => 'group file location',
50 if (not defined $config{group_file}) {
51 return 'group_file option not set';
54 open my $file, '<', $config{group_file}
55 or return 'Unable to open group_file';
60 next READ if (/^\s*$/);
62 if (/^(\w+):([\w,]+)/) {
63 %{ $users_of->{$1} } = map { $_ => 1 } split /,/, $2;
66 $users_of = "Error at group_file:$.";
77 package IkiWiki::PageSpec;
79 sub match_group ($$;@) {
84 if (not exists $params{user}) {
85 return IkiWiki::ErrorReason->new('no user specified');
87 if (not defined $params{user}) {
88 return IkiWiki::FailReason->new('not logged in');
91 my $users_of = IkiWiki::Plugin::groupfile::get_groups();
92 if (not ref $users_of) {
93 return IkiWiki::ErrorReason->new($users_of);
96 if (exists $users_of->{$group}{ $params{user} }) {
97 return IkiWiki::SuccessReason->new("user is member of $group");
100 return IkiWiki::FailReason->new(
101 "user $params{user} isn't member of $group");