title: MOODLE ROLES AND CAPABILITIES
body: <p>I had developed a block in 2.5. I installed the block successfully..and gave permissions settings on front end to view this block only for one role users say 'Manager'. So, Manager/Admin can only view this block and no one else.</p>
  
  <p>But this block is still visible for all. Could you please judge me.. where I went wrong.. Here is my leisure block code</p>
  
  <p>Blocks/block_leisure/block_leisure.php</p>
  
  <pre><code>&lt;?php
  
  class block_leisure extends block_base
  {
      public function init()
      {
          global $CFG;
          $this-&gt;title = get_string('leisure', 'block_leisure');
      }
  
      public function get_content()
      {
          global $COURSE, $DB, $PAGE, $CFG, $USER, $CFG, $SESSION, $OUTPUT;
          if ($this-&gt;content !== null) 
          {
               return $this-&gt;content;
          }
          $this-&gt;content = new stdClass;
          $context = $PAGE-&gt;context;
          $this-&gt;content-&gt;text = 'This is a leisure block content';           
          $this-&gt;content-&gt;footer = 'Footer here...';           
          return $this-&gt;content;
      } // Function - get_content().
      public function getmodules() 
      {
          return true;
      }
  }
  </code></pre>
  
  <p>Blocks/block_leisure/db/access.php</p>
  
  <pre><code>&lt;?php
  
   defined('MOODLE_INTERNAL') || die;
  
      $capabilities = array(
      'block/leisure:myaddinstance' =&gt; array(
          'captype' =&gt; 'write',
          'contextlevel' =&gt; CONTEXT_SYSTEM,
          'archetypes' =&gt; array(
              'user' =&gt; CAP_ALLOW
          ),
          'clonepermissionsfrom' =&gt; 'moodle/my:manageblocks'
      ),
      'block/leisure:addinstance' =&gt; array(
          'riskbitmask' =&gt; RISK_SPAM | RISK_XSS,
          'captype' =&gt; 'write',
          'contextlevel' =&gt; CONTEXT_BLOCK,
          'archetypes' =&gt; array(
              'editingteacher' =&gt; CAP_ALLOW,
              'manager' =&gt; CAP_ALLOW
          ),
          'clonepermissionsfrom' =&gt; 'moodle/site:manageblocks'
      ),
      'block/leisure:viewpages' =&gt; array(
          'captype' =&gt; 'read',
          'contextlevel' =&gt; CONTEXT_COURSE,
          'legacy' =&gt; array(
              'guest' =&gt; CAP_PREVENT,
              'student' =&gt; CAP_ALLOW,
              'teacher' =&gt; CAP_ALLOW,
              'editingteacher' =&gt; CAP_ALLOW,
              'coursecreator' =&gt; CAP_ALLOW,
              'manager' =&gt; CAP_ALLOW
          )
      ),
      'block/leisure:managepages' =&gt; array(
          'captype' =&gt; 'read',
          'contextlevel' =&gt; CONTEXT_COURSE,
          'legacy' =&gt; array(
              'guest' =&gt; CAP_PREVENT,
              'student' =&gt; CAP_PREVENT,
              'teacher' =&gt; CAP_PREVENT,
              'editingteacher' =&gt; CAP_ALLOW,
              'coursecreator' =&gt; CAP_ALLOW,
              'manager' =&gt; CAP_ALLOW
          )
      )
  );
  </code></pre>
  
  <p>and as usual I have lang folder, version.php and read me file.</p>