Abilities
view release on metacpan or search on metacpan
that can be used by applications, or just taken as an example of an
ability-based authorization system. Entities::User and Entities::Role
are the user and role classes that consume the Abilities role in the
Entities distribution.
CONSTRAINTS
Generally, an ability is a yes/no option. Either the user can or can't
perform a specific action. At times, this might not be flexible enough,
and the user's ability to perform a certain action should be
constrained. For example, a user might be granted the ability to edit
posts in a blog, but this ability should be constrained to the user's
posts only. The user is not to be allowed to edit posts created by other
users. "Abilities" supports constraints by allowing to set a name-based
constraint when granting a user/role a certain ability. Then, checking
the user's ability to perform an action can include the constraint, for
example:
if ($post->{user_id} eq $user->id && $user->can_perform('edit_posts', 'only_his')) {
# allow
} else {
# do not allow
UPGRADING FROM v0.2
Up to version 0.2, "Abilities" required the "roles" and "actions"
attributes to return objects. While this made it easier to calculate
abilities, it made this system a bit less flexible.
In version 0.3, "Abilities" changed the requirement such that both these
attributes need to return strings (the names of the roles/actions). If
your implementation has granted roles and actions stored in a database
by names, this made life a bit easier for you. On other implementations,
however, this has the potential of requiring you to write a bit more
code. If that is the case, I apologize, but keep in mind that you can
still store granted roles and actions any way you want in a database
(either by names or by references), just as long as you correctly
provide "roles" and "actions".
Unfortunately, in both versions 0.3 and 0.4, I made a bit of a mess that
rendered both versions unusable. While I documented the "roles"
attribute as requiring role names instead of role objects, the actual
implementation still required role objects. This has now been fixed, but
it also meant I had to add a new requirement: consuming classes now have
to provide a method called "get_role()" that takes the name of a role
and returns its object. This will probably means loading the role from a
database and blessing it into your role class that also consumes this
module.
I apologize for any inconvenience this might have caused.
AUTHOR
Ido Perlmuter, "<ido at ido50 dot net>"
BUGS
Please report any bugs or feature requests to "bug-abilities at
rt.cpan.org", or through the web interface at
<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Abilities>. I will be
notified, and then you'll automatically be notified of progress on your
bug as I make changes.
lib/Abilities.pm view on Meta::CPAN
More specifically, a user class and a role class must be implemented, consuming this role. L<Entities> is a reference implementation that can be used by applications, or
just taken as an example of an ability-based authorization system. L<Entities::User>
and L<Entities::Role> are the user and role classes that consume the Abilities
role in the Entities distribution.
=head2 CONSTRAINTS
Generally, an ability is a yes/no option. Either the user can or can't perform
a specific action. At times, this might not be flexible enough, and the user's
ability to perform a certain action should be constrained. For example, a user
might be granted the ability to edit posts in a blog, but this ability should
be constrained to the user's posts only. The user is not to be allowed to edit
posts created by other users. C<Abilities> supports constraints by allowing to
set a name-based constraint when granting a user/role a certain ability. Then,
checking the user's ability to perform an action can include the constraint,
for example:
if ($post->{user_id} eq $user->id && $user->can_perform('edit_posts', 'only_his')) {
# allow
} else {
# do not allow
lib/Abilities.pm view on Meta::CPAN
=head1 UPGRADING FROM v0.2
Up to version 0.2, C<Abilities> required the C<roles> and C<actions>
attributes to return objects. While this made it easier to calculate
abilities, it made this system a bit less flexible.
In version 0.3, C<Abilities> changed the requirement such that both these
attributes need to return strings (the names of the roles/actions). If your implementation
has granted roles and actions stored in a database by names, this made life a bit easier
for you. On other implementations, however, this has the potential of
requiring you to write a bit more code. If that is the case, I apologize,
but keep in mind that you can still store granted roles and actions
any way you want in a database (either by names or by references), just
as long as you correctly provide C<roles> and C<actions>.
Unfortunately, in both versions 0.3 and 0.4, I made a bit of a mess
that rendered both versions unusable. While I documented the C<roles>
attribute as requiring role names instead of role objects, the actual
implementation still required role objects. This has now been fixed,
but it also meant I had to add a new requirement: consuming classes
now have to provide a method called C<get_role()> that takes the name
of a role and returns its object. This will probably means loading the
role from a database and blessing it into your role class that also consumes
this module.
I apologize for any inconvenience this might have caused.
=head1 AUTHOR
Ido Perlmuter, C<< <ido at ido50 dot net> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-abilities at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Abilities>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
lib/Abilities/Features.pm view on Meta::CPAN
=head1 UPGRADING FROM v0.2
Up to version 0.2, C<Abilities::Features> required the C<plans> and C<features>
attributes to return objects. While this made it easier to calculate
available features, it made this system a bit less flexible.
In version 0.3, C<Abilities::Features> changed the requirement such that both these
attributes need to return strings (the names of the plans/features). If your implementation
has granted plans and features stored in a database by names, this made life a bit easier
for you. On other implementations, however, this has the potential of
requiring you to write a bit more code. If that is the case, I apologize,
but keep in mind that you can still store granted plans and features
any way you want in a database (either by names or by references), just
as long as you correctly provide C<plans> and C<features>.
Unfortunately, in both versions 0.3 and 0.4, I made a bit of a mess
that rendered both versions unusable. While I documented the C<plans>
attribute as requiring plan names instead of plan objects, the actual
implementation still required plan objects. This has now been fixed,
but it also meant I had to add a new requirement: consuming classes
now have to provide a method called C<get_plan()> that takes the name
of a plan and returns its object. This will probably means loading the
plan from a database and blessing it into your plan class that also consumes
this module.
I apologize for any inconvenience this might have caused.
=head1 AUTHOR
Ido Perlmuter, C<< <ido at ido50 dot net> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-abilities at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Abilities>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
( run in 1.366 second using v1.01-cache-2.11-cpan-49f99fa48dc )