Skip to content

Commit

Permalink
scopes: handle scope type in check_scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
jrchamp committed Feb 27, 2025
1 parent 7c2b7b2 commit fd2aaca
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 20 deletions.
6 changes: 2 additions & 4 deletions classes/task/delete_meeting_recordings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 2 additions & 4 deletions classes/task/get_meeting_recordings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 2 additions & 4 deletions classes/task/update_meetings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 2 additions & 4 deletions classes/task/update_tracking_fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 5 additions & 4 deletions classes/webservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -1247,20 +1247,21 @@ 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;
}

/**
* 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) {
Expand Down

0 comments on commit fd2aaca

Please sign in to comment.