[Catalyst] check_user_roles [ $user ], @roles ?

Eden Cardim edencardim at gmail.com
Wed Feb 4 13:21:23 GMT 2009


On Wed, Feb 4, 2009 at 10:03 AM, Jens Schwarz <blacky6767 at gmx.de> wrote:
> Hi *,
>
> in my Catalyst app I use $c->check_user_roles(qw/Admin/) to determine, if the currently logged in user is part of the Admin role. Works fine.
>
> Now I want to check if _another_ (currently _not_ logged in user) is part of the Admin role. I read the documentation of Catalyst::Plugin::Authorization::Roles and found that check_user_roles can optionally take $user as additional parameter. But it does not work as I suspected: With ...
>
> $c->log->info(">> " . $c->check_user_roles( "some_other_user" , qw/Admin/ ));
>
> ... Catalyst debug just gives me ...
>
> [debug] Role denied: some_other_user, Admin
> [info] >>
>
> ... where I expected something like ...
>
> [info] >> 1
>
> "some_other_user" is a username string, in the column "username" of my user table. myapp/myapp.conf ist setup accordingly (i.e.: user_class myapp::user and id_field username).
>
> What am I doing wrong?

$c->check_user_roles expects a user object not a username string (how
would it distinguish a user name from a role name?). You can get a
user object via $c->find_user.

-- 
   Eden Cardim       Need help with your Catalyst or DBIx::Class project?
  Code Monkey                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://edenc.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the Catalyst mailing list