Skip to content

Commit

Permalink
Merge pull request #311 from jrchamp/release/v4.1.2
Browse files Browse the repository at this point in the history
Release/v4.1.2
  • Loading branch information
jrchamp authored Oct 1, 2021
2 parents 45300e1 + bd17903 commit 967fc3b
Show file tree
Hide file tree
Showing 9 changed files with 748 additions and 273 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ server is properly synchronized with the time servers.

## Changelog

v4.1.2

- Make loadmeeting consistent via web and mobile (event, completion, grade, etc) #307 (thanks @nstefanski)

v4.1.1

- Fix invitation class not found exception #296 (thanks @byvamo for reporting)
Expand Down
14 changes: 7 additions & 7 deletions backup/moodle2/backup_zoom_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class backup_zoom_activity_structure_step extends backup_activity_structure_step
protected function define_structure() {
// Define the root element describing the zoom instance.
$zoom = new backup_nested_element('zoom', array('id'), array(
'intro', 'introformat', 'grade', 'meeting_id', 'start_url', 'join_url', 'created_at', 'host_id', 'name',
'start_time', 'timemodified', 'recurring', 'recurrence_type', 'repeat_interval', 'weekly_days', 'monthly_day',
'monthly_week', 'monthly_week_day', 'monthly_repeat_option', 'end_times', 'end_date_time', 'end_date_option',
'webinar', 'duration', 'timezone', 'password', 'option_jbh', 'option_start_type', 'option_host_video',
'option_participants_video', 'option_audio', 'option_mute_upon_entry', 'option_waiting_room', 'option_authenticated_users',
'option_encryption_type', 'exists_on_zoom', 'alternative_hosts')
);
'intro', 'introformat', 'grade', 'meeting_id', 'start_url', 'join_url', 'created_at', 'host_id', 'name',
'start_time', 'timemodified', 'recurring', 'recurrence_type', 'repeat_interval', 'weekly_days', 'monthly_day',
'monthly_week', 'monthly_week_day', 'monthly_repeat_option', 'end_times', 'end_date_time', 'end_date_option',
'webinar', 'duration', 'timezone', 'password', 'option_jbh', 'option_start_type', 'option_host_video',
'option_participants_video', 'option_audio', 'option_mute_upon_entry', 'option_waiting_room',
'option_authenticated_users', 'option_encryption_type', 'exists_on_zoom', 'alternative_hosts',
));

// If we had more elements, we would build the tree here.

Expand Down
78 changes: 38 additions & 40 deletions classes/webservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class mod_zoom_webservice {
protected static $userslist;

/**
* Number of retries we've made for _make_call
* Number of retries we've made for make_call
* @var int
*/
protected $makecallretries = 0;
Expand Down Expand Up @@ -153,15 +153,15 @@ public function __construct() {

/**
* Makes the call to curl using the specified method, url, and parameter data.
* This has been moved out of _make_call to make unit testing possible.
* This has been moved out of make_call to make unit testing possible.
*
* @param \curl $curl The curl object used to make the request.
* @param string $method The HTTP method to use.
* @param string $url The URL to append to the API URL
* @param array|string $data The data to attach to the call.
* @return stdClass The call's result.
*/
protected function _make_curl_call(&$curl, $method, $url, $data) {
protected function make_curl_call(&$curl, $method, $url, $data) {
return $curl->$method($url, $data);
}

Expand All @@ -170,7 +170,7 @@ protected function _make_curl_call(&$curl, $method, $url, $data) {
* to enable unit testing for the webservice class.
* @return curl The curl object used to make the API calls
*/
protected function _get_curl_object() {
protected function get_curl_object() {
return new curl();
}

Expand All @@ -183,7 +183,7 @@ protected function _get_curl_object() {
* @return stdClass The call's result in JSON format.
* @throws moodle_exception Moodle exception is thrown for curl errors.
*/
protected function _make_call($path, $data = array(), $method = 'get') {
private function make_call($path, $data = array(), $method = 'get') {
global $CFG;
$url = $this->apiurl . $path;
$method = strtolower($method);
Expand All @@ -204,7 +204,7 @@ protected function _make_call($path, $data = array(), $method = 'get') {
$CFG->proxyuser = '';
$CFG->proxypassword = '';
}
$curl = $this->_get_curl_object(); // Create $curl, which implicitly uses the proxy settings from $CFG.
$curl = $this->get_curl_object(); // Create $curl, which implicitly uses the proxy settings from $CFG.
if (!empty($proxyhost)) {
// Restore the stored global proxy settings from above.
$CFG->proxyhost = $cfg->proxyhost;
Expand All @@ -224,7 +224,7 @@ protected function _make_call($path, $data = array(), $method = 'get') {
$curl->setHeader('Content-Type: application/json');
$data = is_array($data) ? json_encode($data) : $data;
}
$response = $this->_make_curl_call($curl, $method, $url, $data);
$response = $this->make_curl_call($curl, $method, $url, $data);

if ($curl->get_errno()) {
throw new moodle_exception('errorwebservice', 'mod_zoom', '', $curl->error);
Expand Down Expand Up @@ -275,7 +275,7 @@ protected function _make_call($path, $data = array(), $method = 'get') {
if ($timediff > 0 && !(defined('PHPUNIT_TEST') && PHPUNIT_TEST)) {
sleep($timediff);
}
return $this->_make_call($path, $data, $method);
return $this->make_call($path, $data, $method);
default:
if ($response) {
$exception = new moodle_exception('errorwebservice', 'mod_zoom', '', $response->message);
Expand All @@ -294,22 +294,22 @@ protected function _make_call($path, $data = array(), $method = 'get') {

/**
* Makes a paginated REST call.
* Makes a call like _make_call() but specifically for GETs with paginated results.
* Makes a call like make_call() but specifically for GETs with paginated results.
*
* @param string $url The URL to append to the API URL
* @param array|string $data The data to attach to the call.
* @param string $datatoget The name of the array of the data to get.
* @return array The retrieved data.
* @see _make_call()
* @see make_call()
* @link https://zoom.github.io/api/#list-users
*/
protected function _make_paginated_call($url, $data = array(), $datatoget) {
private function make_paginated_call($url, $data = array(), $datatoget) {
$aggregatedata = array();
$data['page_size'] = ZOOM_MAX_RECORDS_PER_CALL;
do {
$callresult = null;
$moredata = false;
$callresult = $this->_make_call($url, $data);
$callresult = $this->make_call($url, $data);

if ($callresult) {
$aggregatedata = array_merge($aggregatedata, $callresult->$datatoget);
Expand Down Expand Up @@ -345,7 +345,7 @@ public function autocreate_user($user) {
);

try {
$this->_make_call($url, $data, 'post');
$this->make_call($url, $data, 'post');
} catch (moodle_exception $error) {
// If the user already exists, the error will contain 'User already in the account'.
if (strpos($error->getMessage(), 'User already in the account') === true) {
Expand All @@ -366,7 +366,7 @@ public function autocreate_user($user) {
*/
public function list_users() {
if (empty(self::$userslist)) {
self::$userslist = $this->_make_paginated_call('users', null, 'users');
self::$userslist = $this->make_paginated_call('users', null, 'users');
}
return self::$userslist;
}
Expand All @@ -378,7 +378,7 @@ public function list_users() {
* @see $numlicenses
* @return bool Whether the paid user license limit has been reached.
*/
protected function _paid_user_limit_reached() {
private function paid_user_limit_reached() {
$userslist = $this->list_users();
$numusers = 0;
foreach ($userslist as $user) {
Expand All @@ -394,7 +394,7 @@ protected function _paid_user_limit_reached() {
*
* @return string|false If user is found, returns the User ID. Otherwise, returns false.
*/
protected function _get_least_recently_active_paid_user_id() {
private function get_least_recently_active_paid_user_id() {
$usertimes = array();
$userslist = $this->list_users();
foreach ($userslist as $user) {
Expand All @@ -417,8 +417,8 @@ protected function _get_least_recently_active_paid_user_id() {
* @return stdClass The call's result in JSON format.
* @link https://zoom.github.io/api/#retrieve-a-users-settings
*/
public function _get_user_settings($userid) {
return $this->_make_call('users/' . $userid . '/settings');
public function get_user_settings($userid) {
return $this->make_call('users/' . $userid . '/settings');
}

/**
Expand All @@ -431,7 +431,7 @@ public function get_account_meeting_security_settings() {
$url = 'accounts/me/settings?option=meeting_security';
$response = null;
try {
$response = $this->_make_call($url);
$response = $this->make_call($url);
// Set a default meeting password requirment if it is not present.
if (!isset($response->meeting_security->meeting_password_requirement)) {
$response->meeting_security->meeting_password_requirement = (object) DEFAULT_MEETING_PASSWORD_REQUIREMENT;
Expand All @@ -455,7 +455,7 @@ public function get_user($identifier) {
$url = 'users/' . $identifier;

try {
$founduser = $this->_make_call($url);
$founduser = $this->make_call($url);
} catch (moodle_exception $error) {
if (zoom_is_user_not_found_error($error)) {
return false;
Expand All @@ -480,7 +480,7 @@ public function get_schedule_for_users($identifier) {
$schedulerswithoutkey = [];
$schedulers = [];
try {
$response = $this->_make_call($url);
$response = $this->make_call($url);
if (is_array($response->schedulers)) {
$schedulerswithoutkey = $response->schedulers;
}
Expand All @@ -502,10 +502,8 @@ public function get_schedule_for_users($identifier) {
*
* @param stdClass $zoom The zoom meeting to format.
* @return array The formatted meetings for the meeting.
* @todo Add functionality for 'alternative_hosts' => $zoom->option_alternative_hosts in $data['settings']
* @todo Make UCLA data fields and API data fields match?
*/
protected function _database_to_api($zoom) {
private function database_to_api($zoom) {
global $CFG;

$data = array(
Expand Down Expand Up @@ -611,14 +609,14 @@ protected function _database_to_api($zoom) {
*/
public function provide_license($zoomuserid) {
// Checks whether we need to recycle licenses and acts accordingly.
if ($this->recyclelicenses && $this->_make_call("users/$zoomuserid")->type == ZOOM_USER_TYPE_BASIC) {
if ($this->_paid_user_limit_reached()) {
$leastrecentlyactivepaiduserid = $this->_get_least_recently_active_paid_user_id();
if ($this->recyclelicenses && $this->make_call("users/$zoomuserid")->type == ZOOM_USER_TYPE_BASIC) {
if ($this->paid_user_limit_reached()) {
$leastrecentlyactivepaiduserid = $this->get_least_recently_active_paid_user_id();
// Changes least_recently_active_user to a basic user so we can use their license.
$this->_make_call("users/$leastrecentlyactivepaiduserid", array('type' => ZOOM_USER_TYPE_BASIC), 'patch');
$this->make_call("users/$leastrecentlyactivepaiduserid", array('type' => ZOOM_USER_TYPE_BASIC), 'patch');
}
// Changes current user to pro so they can make a meeting.
$this->_make_call("users/$zoomuserid", array('type' => ZOOM_USER_TYPE_PRO), 'patch');
$this->make_call("users/$zoomuserid", array('type' => ZOOM_USER_TYPE_PRO), 'patch');
}
}

Expand All @@ -633,7 +631,7 @@ public function create_meeting($zoom) {
// Provide license if needed.
$this->provide_license($zoom->host_id);
$url = "users/$zoom->host_id/" . (!empty($zoom->webinar) ? 'webinars' : 'meetings');
return $this->_make_call($url, $this->_database_to_api($zoom), 'post');
return $this->make_call($url, $this->database_to_api($zoom), 'post');
}

/**
Expand All @@ -644,7 +642,7 @@ public function create_meeting($zoom) {
*/
public function update_meeting($zoom) {
$url = ($zoom->webinar ? 'webinars/' : 'meetings/') . $zoom->meeting_id;
$this->_make_call($url, $this->_database_to_api($zoom), 'patch');
$this->make_call($url, $this->database_to_api($zoom), 'patch');
}

/**
Expand All @@ -656,7 +654,7 @@ public function update_meeting($zoom) {
*/
public function delete_meeting($id, $webinar) {
$url = ($webinar ? 'webinars/' : 'meetings/') . $id . '?schedule_for_reminder=false';
$this->_make_call($url, null, 'delete');
$this->make_call($url, null, 'delete');
}

/**
Expand All @@ -670,7 +668,7 @@ public function get_meeting_webinar_info($id, $webinar) {
$url = ($webinar ? 'webinars/' : 'meetings/') . $id;
$response = null;
try {
$response = $this->_make_call($url);
$response = $this->make_call($url);
} catch (moodle_exception $error) {
throw $error;
}
Expand All @@ -694,7 +692,7 @@ public function get_meeting_invitation($zoom) {
}
$url = 'meetings/' . $zoom->meeting_id . '/invitation';
try {
$response = $this->_make_call($url);
$response = $this->make_call($url);
} catch (moodle_exception $error) {
debugging($error->getMessage());
return new \mod_zoom\invitation(null);
Expand All @@ -714,7 +712,7 @@ public function get_meeting_invitation($zoom) {
public function get_user_report($userid, $from, $to) {
$url = 'report/users/' . $userid . '/meetings';
$data = array('from' => $from, 'to' => $to, 'page_size' => ZOOM_MAX_RECORDS_PER_CALL);
return $this->_make_paginated_call($url, $data, 'meetings');
return $this->make_paginated_call($url, $data, 'meetings');
}

/**
Expand All @@ -728,7 +726,7 @@ public function get_user_report($userid, $from, $to) {
*/
public function list_meetings($userid, $webinar) {
$url = 'users/' . $userid . ($webinar ? '/webinars' : '/meetings');
$instances = $this->_make_paginated_call($url, null, ($webinar ? 'webinars' : 'meetings'));
$instances = $this->make_paginated_call($url, null, ($webinar ? 'webinars' : 'meetings'));
return $instances;
}

Expand All @@ -740,7 +738,7 @@ public function list_meetings($userid, $webinar) {
*/
public function get_meeting_participants($meetinguuid, $webinar) {
$meetinguuid = $this->encode_uuid($meetinguuid);
return $this->_make_paginated_call('report/' . ($webinar ? 'webinars' : 'meetings') . '/'
return $this->make_paginated_call('report/' . ($webinar ? 'webinars' : 'meetings') . '/'
. $meetinguuid . '/participants', null, 'participants');
}

Expand All @@ -752,7 +750,7 @@ public function get_meeting_participants($meetinguuid, $webinar) {
* @return array An array of UUIDs.
*/
public function get_active_hosts_uuids($from, $to) {
$users = $this->_make_paginated_call('report/users', array('type' => 'active', 'from' => $from, 'to' => $to), 'users');
$users = $this->make_paginated_call('report/users', array('type' => 'active', 'from' => $from, 'to' => $to), 'users');
$uuids = array();
foreach ($users as $user) {
$uuids[] = $user->id;
Expand All @@ -775,7 +773,7 @@ public function get_active_hosts_uuids($from, $to) {
* @return array An array of meeting objects.
*/
public function get_meetings($from, $to) {
return $this->_make_paginated_call('metrics/meetings',
return $this->make_paginated_call('metrics/meetings',
['type' => 'past', 'from' => $from, 'to' => $to], 'meetings');
}

Expand All @@ -794,7 +792,7 @@ public function get_meetings($from, $to) {
* @return array An array of meeting objects.
*/
public function get_webinars($from, $to) {
return $this->_make_paginated_call('metrics/webinars',
return $this->make_paginated_call('metrics/webinars',
['type' => 'past', 'from' => $from, 'to' => $to], 'webinars');
}

Expand Down
3 changes: 2 additions & 1 deletion loadmeeting.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

// phpcs:ignore moodle.Files.RequireLogin.Missing
require_once(dirname(dirname(__DIR__)) . '/config.php');
require_once(__DIR__ . '/locallib.php');

Expand All @@ -31,7 +32,7 @@
$context = context_module::instance($id);
$PAGE->set_context($context);

// Call load meeting function.
// Call load meeting function (note: this is where require_login() happens).
$meetinginfo = zoom_load_meeting($id, $context);

// Redirect if available, otherwise deny access.
Expand Down
2 changes: 1 addition & 1 deletion locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ function zoom_get_meeting_capacity(string $zoomhostid, bool $iswebinar = false)
$service = new mod_zoom_webservice();

// Get the 'feature' section of the user's Zoom settings.
$userfeatures = $service->_get_user_settings($zoomhostid)->feature;
$userfeatures = $service->get_user_settings($zoomhostid)->feature;

// If this is a webinar.
if ($iswebinar == true) {
Expand Down
Loading

0 comments on commit 967fc3b

Please sign in to comment.