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

admin tree block disply in myMoodle controlled by capabilities

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Inactive
    • Affects Version/s: 1.9
    • Fix Version/s: DEV backlog
    • Component/s: Blocks
    • Labels:
      None
    • Affected Branches:
      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); }

      }

        Gliffy Diagrams

          Activity

          Hide
          skodak Petr Skoda 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
          skodak Petr Skoda 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
          skodak Petr Skoda 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
          skodak Petr Skoda 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 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 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.
          Hide
          marina Marina Glancy added a comment -

          We have detected that this issue has been inactive for over two years and also did not collect many votes. It is possible that it has been already implemented in a more recent version of Moodle, or it is not highly demanded. There are unlimited number of ways Moodle functinality can be expanded and improved but we would like to concentrate on the features that will benefit majority of users, and which can not be implemented as plugins. If you have a suggestion for improving Moodle core, and there is no open issue for it in the tracker, please start a new forum discussion to see how many other users agree with you, and then create a new issue providing as many details as possible.

          ==BLK2YIMP20141121==

          Show
          marina Marina Glancy added a comment - We have detected that this issue has been inactive for over two years and also did not collect many votes. It is possible that it has been already implemented in a more recent version of Moodle, or it is not highly demanded. There are unlimited number of ways Moodle functinality can be expanded and improved but we would like to concentrate on the features that will benefit majority of users, and which can not be implemented as plugins. If you have a suggestion for improving Moodle core, and there is no open issue for it in the tracker, please start a new forum discussion to see how many other users agree with you, and then create a new issue providing as many details as possible. ==BLK2YIMP20141121==

            People

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

              Dates

              • Created:
                Updated:
                Resolved: