Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-13891

admin tree block disply in myMoodle controlled by capabilities

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Inactive
    • 1.9
    • None
    • Blocks
    • None
    • MOODLE_19_STABLE

    Description

      I noticed in the code for the admin tree block a //todo about how the block decides whether a user can add it in their myMoodle. I've been having to go through changing the code for a few blocks, so I thought I'd try to do a proper job! MDL-13888 is a similar effort on the RSS client block.

      anyway, in line with the comment, the function below loops through the key capabilities tested when generating the tree and checks if the user has them in the site or any course category context.

      Could you review please and let me know if you're happy for me to commit it?

      function applicable_formats() {
      global $USER;
      $contexts = array();
      $contexts[0] = get_context_instance(CONTEXT_SYSTEM);
      $categs = get_records('course_categories');
      foreach ($categs as $category)

      { array_push($contexts,get_context_instance(CONTEXT_COURSECAT,$category->id)); }

      $hascap = false;
      $capabilities = array('moodle/site:uploadusers','moodle/user:create','moodle/user:update','moodle/user:delete',
      'moodle/site:config','moodle/grade:manage','moodle/grade:manageletters','moodle/role:assign',
      'moodle/course:update','moodle/site:restore','moodle/site:backup','moodle/course:managefiles',
      'moodle/category:update','moodle/site:doanything','moodle/site:langeditmaster','moodle/site:langeditlocal',
      'moodle/question:add','moodle/question:editmine','moodle/question:editall','moodle/question:viewmine',
      'moodle/question:viewall','moodle/question:movemine','moodle/question:moveall');
      foreach($contexts as $context) {
      foreach($capabilities as $cap) {
      if (has_capability($cap,$context))

      { $hascap = true; break; // break as soon as we find at least one capability match for efficiency }

      }
      }

      if ($hascap)

      { return array('site' => true, 'admin' => true, 'my' => true); }

      else

      { return array('site' => true, 'admin' => true, 'my' => false); }

      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            jenny-gray Jenny Gray
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Sujith Haridasan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: