Skip to content

Commit

Permalink
filter: webservice needs context
Browse files Browse the repository at this point in the history
  • Loading branch information
jrchamp committed Sep 5, 2024
1 parent cf07e5b commit bdcfec0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
4 changes: 3 additions & 1 deletion backup/moodle2/restore_zoom_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ protected function process_zoom($data) {

// Either create a new meeting or set meeting as expired.
try {
$updateddata = zoom_webservice()->create_meeting($data);
// FIXME: Do we provide course context? That won't have the right activity names etc.
$cmid = null;
$updateddata = zoom_webservice()->create_meeting($data, $cmid);
$data = populate_zoom_from_response($data, $updateddata);
$data->exists_on_zoom = ZOOM_MEETING_EXISTS;
} catch (moodle_exception $e) {
Expand Down
27 changes: 13 additions & 14 deletions classes/webservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,23 +585,20 @@ public function get_schedule_for_users($identifier) {
* database fields to the appropriate API request fields.
*
* @param stdClass $zoom The zoom meeting to format.
* @param ?int $cmid The cmid if available.
* @return array The formatted meetings for the meeting.
*/
private function database_to_api($zoom) {
private function database_to_api($zoom, $cmid) {
global $CFG;

if (isset($zoom->coursemodule)) {
$cmid = $zoom->coursemodule;
} else {
[$course, $cm] = get_course_and_cm_from_instance($zoom, 'zoom');
$cmid = $cm->id;
$options = [];
if (!empty($cmid)) {
$options['context'] = \context_module::instance($cmid);
}

$context = \context_module::instance($cmid);

$data = [
// Process the meeting topic with proper filter.
'topic' => substr(format_string($zoom->name, true, ['context' => $context, 'escape' => false]), 0, 200),
'topic' => substr(format_string($zoom->name, true, $options + ['escape' => false]), 0, 200),
'settings' => [
'host_video' => (bool) ($zoom->option_host_video),
'audio' => $zoom->option_audio,
Expand All @@ -612,7 +609,7 @@ private function database_to_api($zoom) {
$data['agenda'] = substr(content_to_text(format_text(
$zoom->intro,
FORMAT_MOODLE,
['context' => $context]
$options
), false), 0, 2000);
}

Expand Down Expand Up @@ -780,9 +777,10 @@ public function provide_license($zoomuserid) {
* Take a $zoom object as returned from the Moodle form and respond with an object that can be saved to the database.
*
* @param stdClass $zoom The meeting to create.
* @param ?int $cmid The cmid if available.
* @return stdClass The call response.
*/
public function create_meeting($zoom) {
public function create_meeting($zoom, $cmid) {
// Provide license if needed.
$this->provide_license($zoom->host_id);

Expand All @@ -791,22 +789,23 @@ public function create_meeting($zoom) {
// Classic: webinar:write:admin.
// Granular: webinar:write:webinar:admin.
$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, $cmid), 'post');
}

/**
* Update a meeting/webinar on Zoom.
*
* @param stdClass $zoom The meeting to update.
* @param ?int $cmid The cmid if available.
* @return void
*/
public function update_meeting($zoom) {
public function update_meeting($zoom, $cmid) {
// Classic: meeting:write:admin.
// Granular: meeting:update:meeting:admin.
// Classic: webinar:write:admin.
// Granular: webinar:update:webinar:admin.
$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, $cmid), 'patch');
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function zoom_add_instance(stdClass $zoom, ?mod_zoom_mod_form $mform = null) {
$zoom->breakoutrooms = $breakoutrooms['zoom'];
}

$response = zoom_webservice()->create_meeting($zoom);
$response = zoom_webservice()->create_meeting($zoom, $mform->_cm->id);
$zoom = populate_zoom_from_response($zoom, $response);
$zoom->timemodified = time();
if (!empty($zoom->schedule_for)) {
Expand Down Expand Up @@ -187,7 +187,7 @@ function zoom_update_instance(stdClass $zoom, ?mod_zoom_mod_form $mform = null)

// Update meeting on Zoom.
try {
zoom_webservice()->update_meeting($zoom);
zoom_webservice()->update_meeting($zoom, $mform->_cm->id);
if (!empty($zoom->schedule_for)) {
// Only update this if we actually get a valid user.
if ($correcthostzoomuser = zoom_get_user($zoom->schedule_for)) {
Expand Down Expand Up @@ -424,7 +424,7 @@ function zoom_refresh_events($courseid, $zoom, $cm) {
// Only if the name has changed, update meeting on Zoom.
if ($zoom->name !== $fullzoom->name) {
$fullzoom->name = $zoom->name;
zoom_webservice()->update_meeting($zoom);
zoom_webservice()->update_meeting($zoom, $cm->id);
}

zoom_calendar_item_update($fullzoom);
Expand Down
2 changes: 1 addition & 1 deletion recreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
}

// Set the current zoom table entry to use the new meeting (meeting_id/etc).
$response = zoom_webservice()->create_meeting($zoom);
$response = zoom_webservice()->create_meeting($zoom, $cm->id);
$zoom = populate_zoom_from_response($zoom, $response);
$zoom->exists_on_zoom = ZOOM_MEETING_EXISTS;
$zoom->timemodified = time();
Expand Down

0 comments on commit bdcfec0

Please sign in to comment.