| 1 | package WWW::MenuGrinder::Plugin::RequirePrivilege; | ||
| 2 | our $VERSION = '0.01_01'; | ||
| 3 | |||
| 4 | |||
| 5 | # ABSTRACT: WWW::MenuGrinder plugin that does privilege checks on items. | ||
| 6 | |||
| 7 | use Moose; | ||
| 8 | use List::Util; | ||
| 9 | |||
| 10 | with 'WWW::MenuGrinder::Role::ItemMogrifier'; | ||
| 11 | |||
| 12 | sub plugin_depends { qw(Visitor) } | ||
| 13 | |||
| 14 | sub plugin_required_grinder_methods { qw(has_priv) } | ||
| 15 | |||
| 16 | |||
| 17 | sub item_mogrify { | ||
| 18 | my ( $self, $item ) = @_; | ||
| 19 | |||
| 20 | if (exists $item->{need_priv}) { | ||
| 21 | my @privs = ref($item->{need_priv}) ? | ||
| 22 | @{ $item->{need_priv} } : $item->{need_priv}; | ||
| 23 | |||
| 24 | for my $priv (@privs) { | ||
| 25 | if (! $self->grinder->has_priv($priv) ) { | ||
| 26 | return (); | ||
| 27 | } | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | return $item; | ||
| 32 | } | ||
| 33 | |||
| 34 | no Moose; | ||
| 35 | 1; | ||
| 36 | |||
| 37 | |||
| 38 | __END__ | ||
| 39 | =head1 NAME | ||
| 40 | |||
| 41 | WWW::MenuGrinder::Plugin::RequirePrivilege - WWW::MenuGrinder plugin that does privilege checks on items. | ||
| 42 | |||
| 43 | =head1 VERSION | ||
| 44 | |||
| 45 | version 0.01_01 | ||
| 46 | |||
| 47 | =head1 DESCRIPTION | ||
| 48 | |||
| 49 | C<WWW::MenuGrinder::Plugin::RequirePrivilege> is a plugin for | ||
| 50 | C<WWW::MenuGrinder>. You should not use it directly, but include it in the | ||
| 51 | C<plugins> section of a C<WWW::MenuGrinder> config. | ||
| 52 | |||
| 53 | When loaded, this plugin will remove any menu item containing a C<need_priv> key | ||
| 54 | identifying a privilege that's not available to the current request's user, and | ||
| 55 | all of that item's children. | ||
| 56 | |||
| 57 | =head2 Configuration | ||
| 58 | |||
| 59 | None. | ||
| 60 | |||
| 61 | =head2 Required Methods | ||
| 62 | |||
| 63 | In order to load this plugin your C<WWW::MenuGrinder> subclass must implement | ||
| 64 | the method C<has_priv>, which receives a privilege name as a string and returns | ||
| 65 | true or false indicating whether the privilege check was successful. | ||
| 66 | |||
| 67 | =head2 Dependencies | ||
| 68 | |||
| 69 | C<WWW::MenuGrinder::Plugin::Visitor>. | ||
| 70 | |||
| 71 | =head1 AUTHOR | ||
| 72 | |||
| 73 | Andrew Rodland <andrew@hbslabs.com> | ||
| 74 | |||
| 75 | =head1 COPYRIGHT AND LICENSE | ||
| 76 | |||
| 77 | This software is copyright (c) 2009 by HBS Labs, LLC.. | ||
| 78 | |||
| 79 | This is free software; you can redistribute it and/or modify it under | ||
| 80 | the same terms as perl itself. | ||
| 81 |