Jump to content

addRole("rolename") is removed in 2.1


Recommended Posts

Posted

That function is commented in 2.1 source. I think that would be great shortcut to have in P21 also. Docs still have it.

Also roles don't have title, so if you use page fields that allow choosing roles, they default to id number. I think it would be good to have optional titles for roles too, like permissions do have.

Posted
That function is commented in 2.1 source. I think that would be great shortcut to have in P21 also. Docs still have it.

This is for the User class right? I only ask because I see a commented addRole() in the Page class, but not in the User class. Though the context here seems to be Users, since roles are on templates not pages. So I'm thinking we're talking about the User class, but let me know if I'm wrong. There are some updates that I need to make to the API docs throughout (though additions, not removals). I'm not remembering why I removed the addRole/removeRole from the User class, but I will add them back. It's not commented in my source. Can you paste in the commented function you are talking about? I'm just confused about why you've got it and I don't, so I want to make sure I'm not missing anything important. :)

Btw, here's how to accomplish the same thing, though not as pretty as $user->addRole('rolename');

$user->roles->add($roles->get("rolename")); 

Also roles don't have title, so if you use page fields that allow choosing roles, they default to id number. I think it would be good to have optional titles for roles too, like permissions do have.

Titles are optional for roles already (you have the option to add it to the role template). But once you add a title field to the template, it's no longer optional. I figure that separate name and title are redundant until you have complex needs, which is why it's not there already. So I left it as something that you can add to your role template if you want it.

When creating any kind of page reference, it lets you choose what you want to be the 'label' field. It will show you all the fields in the system, with 'title' being the first (default) as it's the obvious choice in most cases. But with a Role, unless you add a title field, you'd want to change it to use 'name' as the label field. Role and user are the only templates in PW that have no title by default.

Posted

This is for the User class right? I only ask because I see a commented addRole() in the Page class, but not in the User class. Though the context here seems to be Users, since roles are on templates not pages. So I'm thinking we're talking about the User class, but let me know if I'm wrong. There are some updates that I need to make to the API docs throughout (though additions, not removals). I'm not remembering why I removed the addRole/removeRole from the User class, but I will add them back. It's not commented in my source. Can you paste in the commented function you are talking about? I'm just confused about why you've got it and I don't, so I want to make sure I'm not missing anything important. :)

Btw, here's how to accomplish the same thing, though not as pretty as $user->addRole('rolename');

Only commented line is this in Page.php:

/** REMOVED
public function roles() {}
public function addRole($role) {}
public function addsRole($role) {}
public function hasRole($role) {}
public function removeRole($role) {}
public function removesRole($role) {}
 */

My co-worker was testing the API and $user->addRole($role) didn't work and that was what he found - so it cannot be working since the whole function is missing.

This is what docs currently have:

$u = new User(); 
$u->name = "gonzo"; 
$u->pass = "BamBam!";
$u->addRole("guest"); 
$u->save();

So this fails also at the moment (not tested though). Also removeRole shortcut that docs mention is missing. These aren't critical issues (all the functionality is there, but docs and code is not in sync at the moment)

When creating any kind of page reference, it lets you choose what you want to be the 'label' field. It will show you all the fields in the system, with 'title' being the first (default) as it's the obvious choice in most cases. But with a Role, unless you add a title field, you'd want to change it to use 'name' as the label field. Role and user are the only templates in PW that have no title by default.

.

We were quickly testing this in bootstrapped API so that is why our output was ID. Using page field it is easy and trivial to set label to be name field. I agree that probably no reason to add title on role and user templates by default.

Posted

I've added $user->addRole() and $user->removeRole() methods and confirmed everything is consistent with the docs page. Thanks for finding this. I also added $role->addPermission() and $role->removePermission() just to enable consistent syntax between User and Role types.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...