From fd2aacad8ef2f4f3a017f656de2b08ca7ff7377b Mon Sep 17 00:00:00 2001 From: Jonathan Champ Date: Thu, 27 Feb 2025 12:04:55 -0500 Subject: [PATCH] scopes: handle scope type in check_scopes --- classes/task/delete_meeting_recordings.php | 6 ++---- classes/task/get_meeting_recordings.php | 6 ++---- classes/task/update_meetings.php | 6 ++---- classes/task/update_tracking_fields.php | 6 ++---- classes/webservice.php | 9 +++++---- 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/classes/task/delete_meeting_recordings.php b/classes/task/delete_meeting_recordings.php index 8d0687f6..340ecafd 100644 --- a/classes/task/delete_meeting_recordings.php +++ b/classes/task/delete_meeting_recordings.php @@ -71,11 +71,9 @@ public function execute() { ], ]; - $this->scopetype = $this->get_scope_type($this->scopes); - // Checking for missing scopes. - $missingscopes = $service->check_zoom_scopes($requiredscopes[$this->scopetype]); - if ($missingscopes != []) { + $missingscopes = $service->check_scopes($requiredscopes); + if (!empty($missingscopes)) { foreach ($missingscopes as $missingscope) { mtrace('Missing scope: ' . $missingscope); } diff --git a/classes/task/get_meeting_recordings.php b/classes/task/get_meeting_recordings.php index d5d07210..933143e3 100644 --- a/classes/task/get_meeting_recordings.php +++ b/classes/task/get_meeting_recordings.php @@ -78,11 +78,9 @@ public function execute() { ], ]; - $this->scopetype = $this->get_scope_type($this->scopes); - // Checking for missing scopes. - $missingscopes = $service->check_zoom_scopes($requiredscopes[$this->scopetype]); - if ($missingscopes != []) { + $missingscopes = $service->check_scopes($requiredscopes); + if (!empty($missingscopes)) { foreach ($missingscopes as $missingscope) { mtrace('Missing scope: ' . $missingscope); } diff --git a/classes/task/update_meetings.php b/classes/task/update_meetings.php index 0261d772..42358c51 100644 --- a/classes/task/update_meetings.php +++ b/classes/task/update_meetings.php @@ -76,11 +76,9 @@ public function execute() { ], ]; - $this->scopetype = $this->get_scope_type($this->scopes); - // Checking for missing scopes. - $missingscopes = $service->check_zoom_scopes($requiredscopes[$this->scopetype]); - if ($missingscopes != []) { + $missingscopes = $service->check_scopes($requiredscopes); + if (!empty($missingscopes)) { foreach ($missingscopes as $missingscope) { mtrace('Missing scope: ' . $missingscope); } diff --git a/classes/task/update_tracking_fields.php b/classes/task/update_tracking_fields.php index 445762cb..49ad248d 100644 --- a/classes/task/update_tracking_fields.php +++ b/classes/task/update_tracking_fields.php @@ -68,11 +68,9 @@ public function execute() { ], ]; - $this->scopetype = $this->get_scope_type($this->scopes); - // Checking for missing scopes. - $missingscopes = $service->check_zoom_scopes($requiredscopes[$this->scopetype]); - if ($missingscopes != []) { + $missingscopes = $service->check_scopes($requiredscopes); + if (!empty($missingscopes)) { foreach ($missingscopes as $missingscope) { mtrace('Missing scope: ' . $missingscope); } diff --git a/classes/webservice.php b/classes/webservice.php index 5db45539..36731e9f 100644 --- a/classes/webservice.php +++ b/classes/webservice.php @@ -1072,7 +1072,7 @@ public function list_tracking_fields() { $response = null; try { // Classic: tracking_fields:read:admin. - // Granular: Not yet implemented by Zoom. + // Granular: tracking_field:read:list_tracking_fields:admin $response = $this->make_call('tracking_fields'); } catch (moodle_exception $error) { debugging($error->getMessage()); @@ -1247,12 +1247,14 @@ public function has_scope($scopes) { * @throws moodle_exception * @return array missingscopes */ - public function check_zoom_scopes($requiredscopes) { + public function check_scopes($requiredscopes) { if (!isset($this->scopes)) { $this->get_access_token(); } - $missingscopes = array_diff($requiredscopes, $this->scopes); + $scopetype = $this->get_scope_type($this->scopes); + + $missingscopes = array_diff($requiredscopes[$scopetype], $this->scopes); return $missingscopes; } @@ -1260,7 +1262,6 @@ public function check_zoom_scopes($requiredscopes) { * Checks for the type of scope (classic or granular) of the user. * * @param array $scopes - * @throws moodle_exception * @return string scope type */ private function get_scope_type($scopes) {