Skip to content

Commit

Permalink
Updated webservice and task to check for scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
cbounphengsy committed Jan 9, 2025
1 parent eafd124 commit b267c48
Show file tree
Hide file tree
Showing 5 changed files with 111 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 @@ -59,6 +59,27 @@ public function execute() {
mtrace('Skipping task - ', $exception->getMessage());
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');
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
21 changes: 21 additions & 0 deletions classes/task/update_meetings.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ public function execute() {
mtrace('Skipping task - ', $exception->getMessage());
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 @@ -1190,6 +1190,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

1 comment on commit b267c48

@jrchamp
Copy link
Collaborator

@jrchamp jrchamp commented on b267c48 Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move the get_scope_type into the check_zoom_scopes function and remove the implied zoom word from the method. That will reduce the task code to:

        $missingscopes = zoom_webservice()->check_scopes($requiredscopes);
        if(!empty($missingscopes)) {
            mtrace('Missing required scopes: ' . implode(', ', $missingscopes));
            return;
        }

We can also use the get_scope_type method to do the in_array check that is in the oauth() method:

if (in_array('meeting:read:admin', $scopes, true)) {

Please sign in to comment.