capabilities help

capabilities help

by A Guy -
Number of replies: 0

I have built a custom block.

Right now the admin can add the block to the course, which is what I want. However, I also want a person with a custom role that I created to be able to see/add the block too.

However, right now only the admin user can see/add it. In my block I have created the following capabilities:

 

$capabilities = array( 'block/mytestbk:view' => array( 'captype' => 'read', 'contextlevel' => CONTEXT_BLOCK, 'archetypes' => array( 'admin' => CAP_ALLOW, 'mytestbkadmin' => CAP_ALLOW ), 'clonepermissionsfrom' => 'moodle/my:manageblocks' ), 'block/mytestbk:myaddinstance' => array( 'captype' => 'write', 'contextlevel' => CONTEXT_BLOCK, 'archetypes' => array( 'mytestbkadmin' => CAP_ALLOW, ), 'clonepermissionsfrom' => 'moodle/my:manageblocks' ), 'block/mytestbk:addinstance' => array( 'captype' => 'write', 'contextlevel' => CONTEXT_BLOCK, 'archetypes' => array( 'admin' => CAP_ALLOW, 'mytestbkadmin' => CAP_ALLOW ), 'clonepermissionsfrom' => 'moodle/site:manageblocks' ), );

 

In the block code I also create the content to show based upon the user's capabilities by do the following: $context = get_context_instance(CONTEXT_SYSTEM); if(has_capability("block/mytestbk:view", $context)) {

 

I created role mytestbkadmin and clicked allow view,myaddinstance, addinstance. I added a person. She shows TRUE for the capability test above but so does every other user.That is problem number one. Problem number two is that even though they test TRUE for the capability the block does not show up. And it does not sh ow up in the add a block drop down.

I should further point out that after I created my new role mytestbkadmin I tried two things: 1) I tried clicking the add role to this block (or whatever it says) button on the block and added a user. She tested true but so did someone I didn't add. and 2) I tried adding a user to the role with system context. Again the user tested true but so did someone I didn't add that way. And neither one could see the block.

Average of ratings: -