Skip to content

Commit

Permalink
Updated webservice and tasks to check for required scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
cbounphengsy committed Jan 9, 2025
1 parent d6a515d commit 394ddec
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 0 deletions.
21 changes: 21 additions & 0 deletions classes/task/delete_meeting_recordings.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,27 @@ public function execute() {
return;
}

// Required scopes for deleting meeting recordings.
$requiredscopes = [
'classic' => [
'recording:write:admin',
],
'granular' => [
'cloud_recording:delete:meeting_recording:admin'
],
];

$this->scopetype = $this->get_scope_type($this->scopes);

// Checking for missing scopes.
$missingscopes = $this->check_zoom_scopes($requiredscopes[$this->scopetype]);
if($missingscopes != []){
foreach($missingscopes as $missingscope){
mtrace('Missing scope: '.$missingscope);
}
return;
}

// See if we cannot make anymore API calls.
$retryafter = get_config('zoom', 'retry-after');
if (!empty($retryafter) && time() < $retryafter) {
Expand Down
21 changes: 21 additions & 0 deletions classes/task/get_meeting_recordings.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,27 @@ public function execute() {
return;
}

// Required scopes for meeting recordings.
$requiredscopes = [
'classic' => [
'recording:read:admin',
],
'granular' => [
'cloud_recording:read:list_recording_files:admin'
],
];

$this->scopetype = $this->get_scope_type($this->scopes);

// Checking for missing scopes.
$missingscopes = $this->check_zoom_scopes($requiredscopes[$this->scopetype]);
if($missingscopes != []){
foreach($missingscopes as $missingscope){
mtrace('Missing scope: '.$missingscope);
}
return;
}

// See if we cannot make anymore API calls.
$retryafter = get_config('zoom', 'retry-after');
if (!empty($retryafter) && time() < $retryafter) {
Expand Down
20 changes: 20 additions & 0 deletions classes/task/get_meeting_reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,27 @@ public function execute($paramstart = null, $paramend = null, $hostuuids = null)
mtrace('Skipping task - ', $exception->getMessage());
return;
}
// Required scopes for reports.
$requiredscopes = [
'classic' => [
'report:read:admin'
],
'granular' => [
'report:read:user:admin'
],
];

$this->scopetype = $this->get_scope_type($this->scopes);

// Checking for missing scopes.
$missingscopes = $this->check_zoom_scopes($requiredscopes[$this->scopetype]);
if($missingscopes != []){
foreach($missingscopes as $missingscope){
mtrace('Missing scope: '.$missingscope);
}
return;
}

// See if we cannot make anymore API calls.
$retryafter = get_config('zoom', 'retry-after');
if (!empty($retryafter) && time() < $retryafter) {
Expand Down
21 changes: 21 additions & 0 deletions classes/task/update_meetings.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,27 @@ public function execute() {
return;
}

// Required scopes for updating meetings.
$requiredscopes = [
'classic' => [
'tracking_fields:write:admin',
],
'granular' => [
'tracking_field:update:tracking_field:admin'
],
];

$this->scopetype = $this->get_scope_type($this->scopes);

// Checking for missing scopes.
$missingscopes = $this->check_zoom_scopes($requiredscopes[$this->scopetype]);
if($missingscopes != []){
foreach($missingscopes as $missingscope){
mtrace('Missing scope: '.$missingscope);
}
return;
}

// Show trace message.
mtrace('Starting to process existing Zoom meeting activities ...');

Expand Down
21 changes: 21 additions & 0 deletions classes/task/update_tracking_fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@ public function execute() {
return;
}

// Required scopes for tracking fields.
$requiredscopes = [
'classic' => [
'tracking_fields:write:admin',
],
'granular' => [
'tracking_field:update:tracking_field:admin'
],
];

$this->scopetype = $this->get_scope_type($this->scopes);

// Checking for missing scopes.
$missingscopes = $this->check_zoom_scopes($requiredscopes[$this->scopetype]);
if($missingscopes != []){
foreach($missingscopes as $missingscope){
mtrace('Missing scope: '.$missingscope);
}
return;
}

// Show trace message.
mtrace('Starting to process existing Zoom tracking fields ...');

Expand Down
27 changes: 27 additions & 0 deletions classes/webservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,33 @@ public function has_scope($scopes) {
return !empty($matchingscopes);
}

/**
* Check for Zoom scopes
*
* @param string $requiredscopes Required Zoom scopes.
* @throws moodle_exception
* @return array missingscopes
*/
public function check_zoom_scopes($requiredscopes) {
if (!isset($this->scopes)) {
$this->get_access_token();
}

$missingscopes = array_diff($requiredscopes, $this->scopes);
return $missingscopes;
}

/**
* 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) {
return in_array('meeting:read:admin', $scopes, true) ? 'classic' : 'granular';
}

/**
* Stores token and expiration in cache, returns token from OAuth call.
*
Expand Down

0 comments on commit 394ddec

Please sign in to comment.