Differences Between: [Versions 402 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 namespace core\moodlenet; 18 19 use core\oauth2\issuer; 20 21 /** 22 * Class containing static utilities (such as various checks) required by the MoodleNet API. 23 * 24 * @package core 25 * @copyright 2023 Michael Hawkins <michaelh@moodle.com> 26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 27 */ 28 class utilities { 29 /** 30 * Check whether the specified issuer is configured as a MoodleNet instance that can be shared to. 31 * 32 * @param issuer $issuer The OAuth 2 issuer being validated. 33 * @return bool true if the issuer is enabled and available to share to. 34 */ 35 public static function is_valid_instance(issuer $issuer): bool { 36 global $CFG; 37 38 $issuerid = $issuer->get('id'); 39 $allowedissuer = get_config('moodlenet', 'oauthservice'); 40 41 return ($CFG->enablesharingtomoodlenet && $issuerid == $allowedissuer && $issuer->get('enabled') && 42 $issuer->get('servicetype') == 'moodlenet'); 43 } 44 45 /** 46 * Check whether a user has the capabilities required to share activities from a given course to MoodleNet. 47 * 48 * @param \core\context\course $coursecontext Course context where the activity would be shared from. 49 * @param int $userid The user ID being checked. 50 * @return boolean 51 */ 52 public static function can_user_share(\core\context\course $coursecontext, int $userid): bool { 53 return (has_capability('moodle/moodlenet:shareactivity', $coursecontext, $userid) && 54 has_capability('moodle/backup:backupactivity', $coursecontext, $userid)); 55 } 56 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body