Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

You can now make a class viewable using the PrivilegeControlled role.

  • Loading branch information...
commit e33c3d15b6622906a9cecacea75b6675a52122f9 1 parent 1c4b9e5
@rizen rizen authored
Showing with 15 additions and 0 deletions.
  1. +3 −0  CHANGES.txt
  2. +12 −0 lib/Wing/Role/Result/PrivilegeControlled.pm
View
3  CHANGES.txt
@@ -4,6 +4,9 @@ This file tracks the changes to Wing over time. Especially
with respect to new features and compatibility changes.
==========================================================
+2014-02-27
+ * You can now make a class viewable using the PrivilegeControlled role.
+
2013-10-30
* Changed session to compare the password hash stored in the session with the one stored in the database. This way all existing sessions will get logged out if the user changes their password.
View
12 lib/Wing/Role/Result/PrivilegeControlled.pm
@@ -13,6 +13,7 @@ Wing::Role::Result::PrivilegeControlled - Make your Wing objects controllable by
with 'Wing::Role::Result::PrivilegeControlled';
__PACKAGE__->wing_controlled_by_privilege('pizza_manager');
+ __PACKAGE__->wing_viewed_by_privilege('pizza_employee');
=head1 DESCRIPTION
@@ -31,4 +32,15 @@ sub wing_controlled_by_privilege {
});
}
+sub wing_viewed_by_privilege {
+ my ($class, $privilege_name) = @_;
+ my $is_method_name = 'is_'.$privilege_name;
+
+ $class->meta->add_around_method_modifier( can_view => sub {
+ my ($orig, $self, $user) = @_;
+ return 1 if (defined $user && $user->$is_method_name);
+ return $orig->($self, $user);
+ });
+}
+
1;
Please sign in to comment.
Something went wrong with that request. Please try again.