Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check a task's necessary scopes prior to API calls #621

Open
jrchamp opened this issue Sep 27, 2024 · 2 comments
Open

Check a task's necessary scopes prior to API calls #621

jrchamp opened this issue Sep 27, 2024 · 2 comments
Assignees
Labels
bug Fixes problems or reduces technical debt

Comments

@jrchamp
Copy link
Collaborator

jrchamp commented Sep 27, 2024

From #614, we should check the necessary scopes for a task before we make API calls that will fail (especially if it's going to fail silently). This will allow us to use mtrace() or similar to provide information to the Moodle server administrators if they are trying to figure out why a task is not working as expected. Because recording/reports/etc scopes are technically optional, this will allow us to let them know if a task is running that has not been granted the scopes for that task to function/provide value.

@github-project-automation github-project-automation bot moved this to Needs triage in mod_zoom Workflow Sep 27, 2024
@jrchamp jrchamp changed the title Check a tasknecessary scopes prior to API Check a task's necessary scopes prior to API calls Sep 27, 2024
@jrchamp jrchamp added the bug Fixes problems or reduces technical debt label Sep 27, 2024
@smbader smbader moved this from Needs triage to To Do in mod_zoom Workflow Oct 3, 2024
@smbader
Copy link
Contributor

smbader commented Oct 3, 2024

Investigate:

  • Make sure we have the correct list of scopes for the task. For example:

    $dashboardscopes = [
    'dashboard_meetings:read:admin',
    'dashboard_meetings:read:list_meetings:admin',
    'dashboard_meetings:read:list_webinars:admin',
    ];
    $reportscopes = [
    'report:read:admin',
    'report:read:list_users:admin',
    ];

  • It would be nice to know which scopes are optional vs required and relay that information accordingly.

  • Should has_scopes report which scopes are missing via mtrace?

    public function has_scope($scopes) {
    if (!isset($this->scopes)) {
    $this->get_access_token();
    }
    mtrace('checking has_scope(' . implode(' || ', $scopes) . ')');
    $matchingscopes = \array_intersect($scopes, $this->scopes);
    return !empty($matchingscopes);
    }

@jrchamp
Copy link
Collaborator Author

jrchamp commented Oct 31, 2024

Ideas:

        $reportscopes = [
            'classic' => [
                'report:read:admin',
            ],
            'granular' => [
                'report:read:list_' . $meetingtypesingular . '_participants:admin',
            ],
        ];

private function get_scope_type($scopes) {
    return in_array('meeting:read:admin', $scopes, true) ? 'classic' : 'granular';
}

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

        $missingscopes = array_diff($requiredscopes[$this->scopetype], $scopes);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes problems or reduces technical debt
Projects
Status: To Do
Development

No branches or pull requests

3 participants