Monday, April 2, 2012

How to limit role access to custom blocks

When I migrated my custom blocks from moodle 2.0 to moodle 2.2, I experienced a brain fart.

These are the steps I performed for each of the 3 custom blocks I copied over to my moodle 2.2.
1 - copied the folder from the moodle\blocks folder in moodle 2.0
2 - pasted the folder in the moodle\blocks folder in moodle 2.2
3 - Logged in as Admin, refreshed the page, whatever page you are sitting on should work
4 - Clicked the Update button on the Plugins check Screen that prompted me each time

Now that I had copied them and moodle indexed them, I was ready to turn them one.

I turned on Editing and clicked on the Add a block menu...

I turned on each of my three custom blocks that appeared in the menu, one at a time.

Everything seemed in order, I could see my blocks now appearing as they did in my moodle 2.0 instance. When I clicked on each of them, I got the expected behavior.

This is where my brain farted...

When I logged in as a student, I could still see the block. I did not expect to see the block because I did not on the moodle 2.0 server. I had solved this along time ago. How do I limit access to a block to a specific role.

I logged back in as Admin and turned on editing. As I hover over the block, I can see the familiar icons allowing me to configure the block, move the block, make the block invisible, delete the block and Assign roles.

Here it is:



Twice I went into the configuration setting trying to specify how to limit access to the block...twice I did not find the answer. After posting a question like "how do I control access to a custom block" in a couple moodle forums, I found what I was looking for.

See the link that says Permissions? - that's the ticket.



The Permissions had defaulted back to allowing all the roles access to the block. Once I saw the interface showing all the default roles active, I remembered turning them off for each of the blocks. I had to explicitly say ONLY this role can see this block. I removed all other roles from viewing and all roles from editing the block. I only left the manager block or the instructor or advisor roles with permission to view the block.



When I completed updating the permissions, I logged in as different roles to check things out.

Moral of the story?

Moodle uses roles, permissions, context to control who sees what and when.

No comments:

Post a Comment