Skip to content

Commit

Permalink
Merge pull request #79 from Panopto/december-release-branch
Browse files Browse the repository at this point in the history
December Release Merge
  • Loading branch information
jmalmsten-panopto authored Dec 10, 2016
2 parents 7bef430 + efb522c commit 77c8cab
Show file tree
Hide file tree
Showing 21 changed files with 712 additions and 106 deletions.
2 changes: 2 additions & 0 deletions SSO.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

// This can't be defined moodle internal because it is called from panopto to authorize login.

global $CFG, $USER;

if (empty($CFG)) {
Expand Down
15 changes: 10 additions & 5 deletions block_panopto.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,20 @@ public function instance_allow_config() {
public function instance_config_save($data, $nolongerused = false) {

if (!empty($data->course)) {

panopto_data::set_panopto_course_id($this->page->course->id, $data->course);
// Add roles mapping.
$publisherroles = (isset($data->publisher)) ? $data->publisher : array();
$creatorroles = (isset($data->creator)) ? $data->creator : array();
self::set_course_role_permissions(

panopto_data::set_course_role_permissions(
$this->page->course->id,
$publisherroles,
$creatorroles
);

$panoptodata = new panopto_data($this->page->course->id);
$panoptodata->provision_course($panoptodata->get_provisioning_info());
}
}

Expand Down Expand Up @@ -155,16 +160,16 @@ public function get_content() {
get_string('fetching_content', 'block_panopto') . '</font>', $params);

$this->content->text .= '<script type="text/javascript">' .
'// Function to pop up Panopto live note taker.' .
// Function to pop up Panopto live note taker.
'function panopto_launchNotes(url) {' .
'// Open empty notes window, then POST SSO form to it.' .
// Open empty notes window, then POST SSO form to it.
'var notesWindow = window.open("", "PanoptoNotes", ' .
'"width=500,height=800,resizable=1,scrollbars=0,status=0,location=0");' .
'document.SSO.action = url;' .
'document.SSO.target = "PanoptoNotes";' .
'document.SSO.submit();' .

'// Ensure the new window is brought to the front of the z-order.' .
// Ensure the new window is brought to the front of the z-order.
'notesWindow.focus();' .
'}' .

Expand All @@ -173,7 +178,7 @@ public function get_content() {
'document.SSO.target = "_blank";' .
'document.SSO.submit();' .

'// Cancel default link navigation.' .
// Cancel default link navigation.
'return false;' .
'}' .

Expand Down
77 changes: 77 additions & 0 deletions classes/admin/trim_configtext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* a new admin setting that trims any input, supports maxlength
*
* @package block_panopto
* @copyright Panopto 2009 - 2016 /With contributions from Spenser Jones ([email protected]),
* Skylar Kelty <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

/**
* Text input that trims any extra whitespace. Also supports maxlength
* @copyright Panopto 2016
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_configtext_trimmed extends admin_setting_configtext_with_maxlength {

/**
* @var int maximum number of chars allowed.
*/
protected $maxlength;

/**
* Config text constructor
*
* @param string $name unique ascii name, either 'mysetting' for settings that in config,
* or 'myplugin/mysetting' for ones in config_plugins.
* @param string $visiblename localised
* @param string $description long localised info
* @param string $defaultsetting
* @param mixed $paramtype int means PARAM_XXX type, string is a allowed format in regex
* @param int $size default field size
* @param mixed $maxlength int maxlength allowed, 0 for infinite.
*/
public function __construct($name, $visiblename, $description, $defaultsetting, $paramtype=PARAM_RAW,
$size=null, $maxlength = 0) {
$this->maxlength = $maxlength;
parent::__construct($name, $visiblename, $description, $defaultsetting, $paramtype, $size, $maxlength);
}

/**
* write data to storage
*
* @param string $data the data being written.
*/
public function write_setting($data) {
if ($this->paramtype === PARAM_INT and $data === '') {
// Do not complain if '' used instead of 0.
$data = 0;
}

// ...$data is a string.
$trimmeddata = trim($data);
$validated = $this->validate($trimmeddata);
if ($validated !== true) {
return $validated;
}
return ($this->config_write($this->name, $trimmeddata) ? '' : get_string('errorsetting', 'admin'));
}
}
67 changes: 66 additions & 1 deletion classes/rollingsync.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
* @copyright Panopto 2009 - 2016
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* Upon course creation: coursecreated is triggered
* Upon enroll of user: enrollmentcreated AND roleadded is triggered
* Upon unassigning role: roledeleted is triggered
* Upon reassigning role: roleadded is triggered
* Upon setting enrollment status to suspended: enrolmentupdated is triggered
* Upon setting enrollment status to reactivated: enrolmentupdated is triggered
* Upon unenroll of user: roledeleted AND enrollmentdeleted is triggered
*/
class block_panopto_rollingsync {

Expand Down Expand Up @@ -98,6 +105,47 @@ public static function enrollmentdeleted(\core\event\user_enrolment_deleted $eve
}
}

/**
* Called when an enrolment has been suspended or reactivated
* but not when new enrollments are added or when enrollments are removed.
*
* @param \core\event\user_enrolment_updated $event
*/
public static function enrolmentupdated(\core\event\user_enrolment_updated $event) {
global $CFG;

if (\panopto_data::get_panopto_course_id($event->courseid) === false
|| $CFG->version < self::$requiredversion) {
return;
}

$task = new \block_panopto\task\update_user();
$context = context_course::instance($event->courseid);
if (is_enrolled($context, $event->relateduserid, '', true)) {
// User is enrolled. Make sure they are added in Panopto.
$task->set_custom_data(array(
'courseid' => $event->courseid,
'relateduserid' => $event->relateduserid,
'contextid' => $event->contextid,
'eventtype' => "enroll_add"
));
} else {
// User is unenrolled or suspended. Make sure they are removed from Panopto.
$task->set_custom_data(array(
'courseid' => $event->courseid,
'relateduserid' => $event->relateduserid,
'contextid' => $event->contextid,
'eventtype' => "enroll_remove"
));
}

if (get_config('block_panopto', 'async_tasks')) {
\core\task\manager::queue_adhoc_task($task);
} else {
$task->execute();
}
}

/**
* Called when an role has been added.
*
Expand Down Expand Up @@ -164,7 +212,6 @@ public static function roledeleted(\core\event\role_unassigned $event) {
public static function coursecreated(\core\event\course_created $event) {
$allowautoprovision = get_config('block_panopto', 'auto_provision_new_courses');


if ($allowautoprovision) {
$selectedserver = get_config('block_panopto', 'server_name1');
$selectedkey = get_config('block_panopto', 'application_key1');
Expand All @@ -181,4 +228,22 @@ public static function coursecreated(\core\event\course_created $event) {
$task->execute();
}
}

/**
* Called when a course has been restored (imported/backed up).
*
* @param \core\event\course_restored $event
*/
public static function courserestored(\core\event\course_restored $event) {
global $DB;

$originalcourseenabled = $event->other['samesite'] && isset($event->other['originalcourseid']);
if (get_config('block_panopto', 'auto_sync_imports') && $originalcourseenabled) {
$newcourseid = intval($event->courseid);
$originalcourseid = intval($event->other['originalcourseid']);

$panoptodata = new panopto_data($newcourseid);
$panoptodata->init_and_sync_import($newcourseid, $originalcourseid);
}
}
}
28 changes: 23 additions & 5 deletions classes/task/update_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,42 @@ public function get_component() {
* the main execution function of the class
*/
public function execute() {
global $DB;

$eventdata = (array) $this->get_custom_data();

$panopto = new \panopto_data($eventdata['courseid']);
$courseid = $eventdata['courseid'];
$eventtype = $eventdata['eventtype'];

$panopto = new \panopto_data($courseid);
$enrollmentinfo = $this->get_info_for_enrollment_change($panopto, $eventdata['relateduserid'], $eventdata['contextid']);
$targetrole = $enrollmentinfo['role'];
$targetuserkey = $enrollmentinfo['userkey'];

switch ($eventdata['eventtype']) {
switch ($eventtype) {
case 'enroll_add':
$panopto->add_course_user($enrollmentinfo['role'], $enrollmentinfo['userkey']);
$panopto->add_course_user($targetrole, $targetuserkey);
break;

case 'enroll_remove':
$panopto->remove_course_user($enrollmentinfo['role'], $enrollmentinfo['userkey']);
$panopto->remove_course_user($targetrole, $targetuserkey);
break;

case 'role':
$panopto->change_user_role($enrollmentinfo['role'], $enrollmentinfo['userkey']);
$panopto->change_user_role($targetrole, $targetuserkey);
break;
}
// Need to reprovision the course and it's imports for enrollment/role changes to take effect on panopto's side.
$courseimports = \panopto_data::get_import_list($courseid);
foreach ($courseimports as $importedcourse) {
$importedpanopto = new \panopto_data($importedcourse);

$importprovisioninginfo = $importedpanopto->get_provisioning_info();
$importedpanopto->provision_course($importprovisioninginfo);
}

$provisioninginfo = $panopto->get_provisioning_info();
$provisioneddata = $panopto->provision_course($provisioninginfo);
}

/**
Expand Down
10 changes: 10 additions & 0 deletions db/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
'eventname' => '\core\event\user_enrolment_deleted',
'callback' => 'block_panopto_rollingsync::enrollmentdeleted',
),
// Event when user has role updated.
array(
'eventname' => '\core\event\user_enrolment_updated',
'callback' => 'block_panopto_rollingsync::enrolmentupdated',
),
// Event when user has role added to enrollment.
array(
'eventname' => '\core\event\role_assigned',
Expand All @@ -48,5 +53,10 @@
array(
'eventname' => '\core\event\course_created',
'callback' => 'block_panopto_rollingsync::coursecreated',
),
// Event when a course is imported or backed up.
array(
'eventname' => '\core\event\course_restored',
'callback' => 'block_panopto_rollingsync::courserestored',
)
);
10 changes: 10 additions & 0 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,15 @@
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for test"/>
</KEYS>
</TABLE>
<TABLE NAME="block_panopto_importmap" COMMENT="Map Moodle courses to imported courses">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" COMMENT="id of the current import"/>
<FIELD NAME="target_moodle_id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="ID of the recipient Moodle course for the import."/>
<FIELD NAME="import_moodle_id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="ID of the imported Moodle course."/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for import map table"/>
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
26 changes: 26 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,31 @@ function xmldb_block_panopto_upgrade($oldversion = 0) {
upgrade_block_savepoint(true, 2016101227, 'panopto');
}

if ($oldversion < 2016102709) {
// Define table importmap where we will place all of our imports.
$table = new xmldb_table('block_panopto_importmap');

if (!$dbman->table_exists($table)) {
$importfields = array();
$importfields[] = new xmldb_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true);
$importfields[] = new xmldb_field('target_moodle_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL);
$importfields[] = new xmldb_field('import_moodle_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL);

$importkey = new xmldb_key('primary', XMLDB_KEY_PRIMARY, array('id'), null, null);

foreach ($importfields as $importfield) {
// Conditionally launch add field import_moodle_id.
$table->addField($importfield);
}

$table->addKey($importkey);

$dbman->create_table($table);
}

// Panopto savepoint reached.
upgrade_block_savepoint(true, 2016102709, 'panopto');
}

return true;
}
5 changes: 4 additions & 1 deletion edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected function specific_definition($mform) {

if (!empty($panoptodata->servername) && !empty($panoptodata->instancename) && !empty($panoptodata->applicationkey)) {
$mform->addElement('header', 'configheader', get_string('block_edit_header', 'block_panopto'));
$mform->addHelpButton('configheader', 'block_edit_header', 'block_panopto');

$params = new stdClass;
$params->course_id = $COURSE->id;
Expand Down Expand Up @@ -82,10 +83,11 @@ protected function specific_definition($mform) {
}

$mform->addElement('header', 'rolemapheader', get_string('role_map_header', 'block_panopto'));
$mform->addElement('html', get_string('role_map_info_text', 'block_panopto'));
$mform->addHelpButton('rolemapheader', 'role_map_header', 'block_panopto');

$createselect = $mform->addElement('select', 'config_creator', get_string('creator', 'block_panopto'),
$rolearray, null);
$mform->addHelpButton('config_creator', 'creator', 'block_panopto');
$createselect->setMultiple(true);

// Set default selected to previous setting.
Expand All @@ -95,6 +97,7 @@ protected function specific_definition($mform) {

$pubselect = $mform->addElement('select', 'config_publisher', get_string('publisher', 'block_panopto'),
$rolearray, null);
$mform->addHelpButton('config_publisher', 'publisher', 'block_panopto');
$pubselect->setMultiple(true);

// Set default selected to previous setting.
Expand Down
Binary file modified images/feed_icon.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 77c8cab

Please sign in to comment.