On Dec 18, 2007, at 2:04 AM, Michael Higgins wrote:

On Mon, 17 Dec 2007 21:03:52 -0800
Michael Higgins <[EMAIL PROTECTED]> wrote:

On Mon, 17 Dec 2007 20:09:23 -0800
Michael Higgins <[EMAIL PROTECTED]> wrote:

On Mon, 17 Dec 2007 20:47:20 -0700
Jay K <[EMAIL PROTECTED]> wrote:

Hi Michael,

Unfortunately the Tutorial is a bit out of date.

[8<]

Do I go about redefining my 'roles' as '1', '2', '3'?? Or do I have to
change my database configuration?

. . . [reply to self again]

Okay, it appears as if the join table is no longer needed? (I don't
know why it was needed before, but it's part of the tutorial, IIRC.)

So, I have a table "users" and "user_roles". First table is user
information with a user_id. Second table is user_id and role_name. My
role_id column and 'roles' table are probably both superfluous now?

__PACKAGE__->belongs_to(user => 'MyAppDB::Users', 'user_id');

__PACKAGE__->has_many(map_user_roles => 'MyAppDB::UserRoles',
'user_id');

Is that _really_ all that's required?

T
he way you had it will still work too, as long as you also have a many_to_many relationship that maps across the join table...

package MyAppDB::Role;
__PACKAGE__->columns(qw( id name ));

package MyAppDB::UserRole;
__PACKAGE__->belongs_to( 'user', 'MyAppDB::User', 'user_id' );
__PACKAGE__->belongs_to( 'role', 'MyAppDB::Role', 'role_id' );

package MyAppDB::User;
__PACKAGE__->has_many( 'map_user_roles', 'MyAppDB::UserRole', 'user_id' );
__PACKAGE__->many_to_many( 'user_roles', 'map_user_roles', 'role' );

And then in your configuration...
authentication:
  realms:
    default:
      store:
        role_relation: user_roles
        role_field: name

As you can see, role_relation needs to be a relationship that returns MyAppDB::Role objects, if you tell it to use map_user_roles, it is going to get MyAppDB::UserRole objects instead, and role_field is the name of the field in MyAppDB::Role that contains the name of the role.

So when you say __PACKAGE__->assert_user_role(qw( admin ));

What's happening behind the scenes is something like this:

# These actually come from the configuration...
my $role_relation = 'user_roles';
my $role_field = 'name';
for my $role ( $c->user->$role_relation() ) {
    if ( $role->$role_field() eq 'admin' ) { return 1 }
}


--
Jason Kohles, RHCA RHCDS RHCE
[EMAIL PROTECTED] - http://www.jasonkohles.com/
"A witty saying proves nothing."  -- Voltaire



_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to