Error using has_capability function

Error using has_capability function

by james mergenthaler -
Number of replies: 6

I am using moodle 2.2.

I have a custom block called instructors located beneath the blocks folder blocks\instructors

I have experimented with the has_capability() function, but keep getting the message "Capability "blocks/instructors:manager_view" was not found". 

I have a db folder beneath the instructors folder that contains a access.php file that includes this

    'block/instructors:manager_view' => array(
        'captype' => 'read',
        'contextlevel' => CONTEXT_BLOCK,
        'legacy' => array(
            'manager' => CAP_ALLOW
        )
    ),

I have incremented the version.php # located in the instructors folder, visited notifications but still get the message..

Capability "blocks/instructors:manager_view" was not found! This has to be fixed in code.

  • line 370 of \lib\accesslib.php: call to debugging()
  • line 43 of \blocks\instructors\index.php: call to has_capability()

Please help, frustrated.

Average of ratings: -
In reply to james mergenthaler

Re: Error using has_capability function

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

after adding version.php, did you go to .../admin/index.php to let moodle update itself?

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Error using has_capability function

by james mergenthaler -

Tim, I incremented the version.php file again, saved, Saw the plugins check form, saw my block indicating that it was going to update, clicked Update, which returned me to the admin root saying successful.

Entered my block and still see the same message.

Capability "blocks/instructors:manager_view" was not found! This has to be fixed in code.

  • line 370 of \lib\accesslib.php: call to debugging()
  • line 43 of \blocks\instructors\index.php: call to has_capability()

Clicked the Notifications link, just for good measure - but did not do anything since update was already done.

In reply to james mergenthaler

Re: Error using has_capability function

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

OK, so it sounds like you are doing everything correctly.

You should probably have a quick look in the mdl_capabilities table, to see if your capability is there, but it probably isn't.

Also, I wonder if _ is allowed in capability names. It might not be. Try renaming your capability to blocks/instructors:managerview

In reply to james mergenthaler

Re: Error using has_capability function

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
You meant "block/instructors:manager_view", right? Also the "_" in capability name is a bit unusual.
In reply to Petr Skoda

Re: Error using has_capability function

by james mergenthaler -

ahhh, that was it the 's' at the end of blocks...I guess I included the 's' since the directory structure is blocks.  thanks for that catch.

It did not mind the _ underscore in the name

The rule was in the DB table.

@Tim, thanks for your help too.

In reply to james mergenthaler

Re: Error using has_capability function

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

The fact that the folder is called blocks, not block, is the problem. For all other plugins, the containing folder is singular (mod, report, question/type, ...) It has been like that for so long that it is basically impossible to change blocks -> block now. You just have to live with it.