Skip to content

Commit

Permalink
Protect group from license borrowing
Browse files Browse the repository at this point in the history
  • Loading branch information
izendegi committed Nov 28, 2024
1 parent 52ae1a7 commit a09283b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
19 changes: 18 additions & 1 deletion 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 $protectedgroup;

/**
* 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->protectedgroup = $config->protectedgrp;
}

if ($this->recyclelicenses) {
Expand Down Expand Up @@ -461,7 +468,8 @@ 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)) {
if ($user->type != ZOOM_USER_TYPE_BASIC && isset($user->last_login_time)
&& !in_array($this->protectedgroup,$user->group_ids ?? array(),true)) { // needle: 'PROTECTED' zoom group
// 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);
Expand All @@ -476,6 +484,15 @@ 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() {
return $this->make_call('/groups');
}

/**
* 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['protectedgrp'] = 'Protect group';
$string['protectedgrp_desc'] = 'Select a Zoom group to protect member users from license redefining';
$string['recording'] = 'Recording';
$string['recordingadd'] = 'Add Recording';
$string['recordingdate'] = 'Recording Date';
Expand Down
14 changes: 14 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

require_once($CFG->dirroot . '/mod/zoom/locallib.php');
require_once($CFG->libdir . '/environmentlib.php');
require_once($CFG->dirroot . '/mod/zoom/classes/webservice.php');

if ($ADMIN->fulltree) {
require_once($CFG->dirroot . '/mod/zoom/classes/invitation.php');
Expand Down Expand Up @@ -171,6 +172,19 @@
1
);
$settings->add($recycleonjoin);

// Only call to the web services and load the setting if the connection is OK
if ($status == 'connectionok') {
$zoomgrps[] = null;
$groupobj = zoom_webservice()->get_groups();
foreach ($groupobj->groups as $group) {
$zoomgrps[$group->id] = $group->name;
}
$protectedgrp = new admin_setting_configselect('zoom/protectedgrp',
get_string('protectedgrp','mod_zoom'),
get_string('protectedgrp_desc','mod_zoom'),0,$zoomgrps);
$settings->add($protectedgrp);
}

// Global settings.
$settings->add(new admin_setting_heading(
Expand Down

0 comments on commit a09283b

Please sign in to comment.