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

Protect group from license borrowing #630

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
50 changes: 45 additions & 5 deletions classes/webservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ class webservice {
*/
protected $instanceusers;

/**
* Zoom group to protect from licenses redefining
* @var array
*/
protected $protectedgroups;

/**
* Maximum limit of paid users
* @var int
Expand Down Expand Up @@ -151,6 +157,7 @@ public function __construct() {
if (!empty($config->utmost)) {
$this->recyclelicenses = $config->utmost;
$this->instanceusers = !empty($config->instanceusers);
$this->protectedgroups = !empty($config->protectedgroups) ? explode(',', $config->protectedgroups) : [];
}

if ($this->recyclelicenses) {
Expand Down Expand Up @@ -461,12 +468,23 @@ private function get_least_recently_active_paid_user_id() {
$userslist = $this->list_users();

foreach ($userslist as $user) {
if ($user->type != ZOOM_USER_TYPE_BASIC && isset($user->last_login_time)) {
// Count the user if we're including all users or if the user is on this instance.
if (!$this->instanceusers || core_user::get_user_by_email($user->email)) {
$usertimes[$user->id] = strtotime($user->last_login_time);
}
// Skip Basic user accounts.
if ($user->type == ZOOM_USER_TYPE_BASIC) {
continue;
}
// Skip the protected group.
if (!empty($this->protectedgroups) && array_intersect($this->protectedgroups, $user->group_ids ?? [])) {
continue;
}
// We need the login time.
if (!isset($user->last_login_time)) {
continue;
}
// Count the user only if we're including all users or if the user is on this instance.
jrchamp marked this conversation as resolved.
Show resolved Hide resolved
if (!$this->instanceusers || core_user::get_user_by_email($user->email)) {
continue;
}
$usertimes[$user->id] = strtotime($user->last_login_time);
izendegi marked this conversation as resolved.
Show resolved Hide resolved
}

if (!empty($usertimes)) {
Expand All @@ -476,6 +494,28 @@ private function get_least_recently_active_paid_user_id() {
return false;
}

/**
* Get a list of Zoom groups
*
* @return stdClass The call's result in JSON format.
*/
public function get_groups() {
// Classic: group:read:admin.
// Granular: group:read:list_groups:admin.
// Not essential scope, execute only if scope has been granted.
if ($this->has_scope(['group:read:list_groups:admin']) || $this->has_scope(['group:read:admin'])) {
try {
$response = $this->make_call('/groups');
} catch (moodle_exception $error) {
$response = '';
}
} else {
$response = '';
}

return $response;
izendegi marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Gets a user's settings.
*
Expand Down
2 changes: 2 additions & 0 deletions lang/en/zoom.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@
$string['privacy:metadata:zoom_meeting_participants:user_email'] = 'The email of the participant';
$string['privacy:metadata:zoom_meeting_view'] = 'The database table to track users that view the meeting recordings';
$string['privacy:metadata:zoom_meeting_view:userid'] = 'The id of the user that viewed the recording';
$string['protectedgroups'] = 'Protect groups';
$string['protectedgroups_desc'] = 'Select Zoom groups to protect member users from license redefining';
$string['recording'] = 'Recording';
$string['recordingadd'] = 'Add Recording';
$string['recordingdate'] = 'Recording Date';
Expand Down
19 changes: 19 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,25 @@
);
$settings->add($recycleonjoin);

// Only call to the web services and load the setting if the connection is OK.
if (isset($status) && $status === 'connectionok') {
$zoomgrps = [];
$groupobj = zoom_webservice()->get_groups();
if ($groupobj) {
foreach ($groupobj->groups as $group) {
$zoomgrps[$group->id] = $group->name;
}
}
jrchamp marked this conversation as resolved.
Show resolved Hide resolved

$protectedgroups = new admin_setting_configmultiselect(
'zoom/protectedgroups',
get_string('protectedgroups', 'mod_zoom'),
get_string('protectedgroups_desc', 'mod_zoom'),
[],
$zoomgrps);
jrchamp marked this conversation as resolved.
Show resolved Hide resolved
$settings->add($protectedgroups);
}

// Global settings.
$settings->add(new admin_setting_heading(
'zoom/globalsettings',
Expand Down
Loading