Moodle
  1. Moodle
  2. MDL-13891

admin tree block disply in myMoodle controlled by capabilities

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.9
    • Fix Version/s: DEV backlog
    • Component/s: Blocks
    • Labels:
      None
    • Affected Branches:
      MOODLE_19_STABLE
    • Rank:
      584

      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); }

      }

        Activity

        Hide
        Petr Škoda added a comment -

        this would not have a good performance at all we should not do such expensive operations on other than mymoodle pages

        my +1 to wait for rewrite/refactoring of general page/theme structures which is planned for 2.0

        Show
        Petr Škoda added a comment - this would not have a good performance at all we should not do such expensive operations on other than mymoodle pages my +1 to wait for rewrite/refactoring of general page/theme structures which is planned for 2.0
        Hide
        Petr Škoda added a comment -

        Or am I wrong with the performance issue? going to study the code more today...
        anyway thanks for working on this

        Show
        Petr Škoda added a comment - Or am I wrong with the performance issue? going to study the code more today... anyway thanks for working on this
        Hide
        Jenny Gray added a comment -

        If there's something better coming in the pipeline then it might be as well to wait. I wasn't aware about that.

        I did wonder whether its necessary to check all the category contexts. But the current code has a comment to that effect in there, so I did what it said.

        I'm pretty sure the code only triggers once you've got editing turned on. It would be trivial to code a bit more round it to check whether the page being edited is /my/index.php or not.

        Show
        Jenny Gray added a comment - If there's something better coming in the pipeline then it might be as well to wait. I wasn't aware about that. I did wonder whether its necessary to check all the category contexts. But the current code has a comment to that effect in there, so I did what it said. I'm pretty sure the code only triggers once you've got editing turned on. It would be trivial to code a bit more round it to check whether the page being edited is /my/index.php or not.

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: