Skip to content

Commit

Permalink
2018070900 release code. (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalmsten-panopto authored Jul 9, 2018
1 parent b4a4074 commit a34e1f5
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 13 deletions.
13 changes: 13 additions & 0 deletions block_panopto.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ public function instance_config_save($data, $nolongerused = false) {
$publisherroles = (isset($data->publisher)) ? $data->publisher : array();
$creatorroles = (isset($data->creator)) ? $data->creator : array();

// Get the current role mappings set for the current course from the db.
$mappings = panopto_data::get_course_role_mappings($this->page->course->id);

$oldcreators = array_diff($mappings['creator'], $creatorroles);
$oldpublishers = array_diff($mappings['publisher'], $publisherroles);

// Make sure the old unassigned roles get unset.
panopto_data::unset_course_role_permissions(
$this->page->course->id,
$oldpublishers,
$oldcreators
);

panopto_data::set_course_role_permissions(
$this->page->course->id,
$publisherroles,
Expand Down
21 changes: 21 additions & 0 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
// …

namespace block_panopto\privacy;
use core_privacy\local\metadata\collection;

class provider implements
// This plugin does store personal user data.
\core_privacy\local\metadata\provider {

public static function get_metadata(collection $collection) : collection {
$collection->add_external_location_link('block_panopto', [
'username' => 'privacy:metadata:block_panopto:username',
'firstname' => 'privacy:metadata:block_panopto:firstname',
'lastname' => 'privacy:metadata:block_panopto:lastname',
'email' => 'privacy:metadata:block_panopto:email',
], 'privacy:metadata:bloack_panopto');

return $collection;
}
}
4 changes: 4 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ function xmldb_block_panopto_upgrade($oldversion = 0) {
$oldfoldermaptable->addKey($mappingkey);
$dbman->create_table($oldfoldermaptable);
}

// Delete any existing tasks since those would be from the old plug-in generation.
$DB->delete_records_select('task_adhoc', $DB->sql_like('classname', '?'), array('%block_panopto%task%'));

// Panopto savepoint reached.
upgrade_block_savepoint(true, 2017110600, 'panopto');
}
Expand Down
8 changes: 7 additions & 1 deletion lang/en/block_panopto.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@
$string['podcast_audio'] = 'Audio Podcast';
$string['podcast_feeds'] = 'Podcast Feeds';
$string['podcast_video'] = 'Video Podcast';
$string['privacy:metadata:block_panopto'] = 'In order to integrate with a Panopto service, user data needs to be exchanged with that service.';
$string['privacy:metadata:block_panopto:firstname'] = 'Your first name is sent to Panopto to allow showing user\'s real name in Panopto\'s user experience.';
$string['privacy:metadata:block_panopto:lastname'] = 'Your last name is sent to Panopto to allow showing user\'s real name in Panopto\'s user experience.';
$string['privacy:metadata:block_panopto:email'] = 'Your email is sent to Panopto to allow use of Panopto\'s email features.';
$string['privacy:metadata:block_panopto:username'] = 'Your username is sent to Panopto to allow it to create a Panopto account using the Moodle username as the Panopto username.';
$string['provision'] = 'Provision';
$string['provision_course_link_text'] = 'Provision Course';
$string['provision_access_error'] = 'Course already provisioned to a Panopto folder and the current user does not have access to perform operations on that folder (User needs at least viewer access to target Panopto folder).';
Expand All @@ -150,8 +155,9 @@
$string['publishers'] = 'Publishers';
$string['reinitialize_import_started'] = 'Beginning to reininitialize import.';
$string['reinitialize_import_finished'] = 'finished reininitialize import.';
$string['removing_corrupt_folder_row'] = 'Foldermap entry appears corrupted, moving entry to old_foldermap for user reference. Corrupted row used for course with Moodle Id: ';
$string['removing_corrupt_folder_row'] = 'Foldermap entry appears corrupted, moving entry to old_foldermap for user reference. Corrupted row used for course with Moodle Id: {$a}';
$string['result'] = 'Result';
$string['removed_panopto_adhoc_tasks'] = 'All existing Panopto adhoc tasks were deleted';
$string['require_panopto_version_title'] = 'Minimum Panopto version required for this version of the Moodle Panopto block';
$string['missing_moodle_required_version'] = 'Panopto block requires a Moodle version newer than {$a->requiredversion}, your current Moodle version is: {$a->currentversion}';
$string['role_map_header'] = 'Change Panopto Role Mappings';
Expand Down
50 changes: 50 additions & 0 deletions lib/cli/remove_all_panopto_adhoc_tasks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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/>.

/**
* This logic will get a list of all current Panopto folders on a Moodle server then it will go through each folder
* and reprovision them and reinitialize the imports to that folders if the user has access to the folder.
* This is needed for the Panopto Generation 1 to Generation 2 migration.
*
* @package block_panopto
* @copyright Panopto 2009 - 2017 with contributions from Hittesh Ahuja
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

define('CLI_SCRIPT', 1);
require_once(dirname(__FILE__) . '/../../../../config.php');

global $CFG;
require_once("$CFG->libdir/clilib.php");
require_once("$CFG->libdir/formslib.php");
require_once(dirname(__FILE__) . '/../panopto_data.php');

$admin = get_admin();
if (!$admin) {
mtrace("Error: No admin account was found");
die;
}
\core\session\manager::set_user(get_admin());
cli_heading('Removing all queued Panopto adhoc tasks');

function remove_panopto_adhoc_tasks() {
panopto_data::remove_all_panopto_adhoc_tasks();

cli_writeln(get_string('removed_panopto_adhoc_tasks', 'block_panopto'));
}


remove_panopto_adhoc_tasks();
4 changes: 2 additions & 2 deletions lib/cli/upgrade_all_folders.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function upgrade_all_panopto_folders() {
}
} else {
// Shouldn't hit this case, but in the case a row in the DB has invalid data move it to the old_foldermap.
cli_writeln(get_string('removing_corrupt_folder_row', 'block_panopto') . $oldcourse->moodleid);
cli_writeln(get_string('removing_corrupt_folder_row', 'block_panopto', $oldcourse->moodleid));
panopto_data::delete_panopto_relation($oldcourse->moodleid, true);
// Continue to the next entry assuming this one was cleanup.
continue;
Expand Down Expand Up @@ -150,7 +150,7 @@ function upgrade_all_panopto_folders() {
// We can still continue on with the upgrade, assume this was an old entry that was deleted from Panopto side.
}
} else {
cli_writeln(get_string('removing_corrupt_folder_row', 'block_panopto') . $courseimport);
cli_writeln(get_string('removing_corrupt_folder_row', 'block_panopto', $courseimport));
panopto_data::delete_panopto_relation($courseimport, true);
// Continue to the next entry assuming this one was cleanup.
continue;
Expand Down
35 changes: 28 additions & 7 deletions lib/panopto_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ public static function getpossiblefoldernamestyles() {
);
}


public static function remove_all_panopto_adhoc_tasks() {
global $DB;

return $DB->delete_records_select('task_adhoc', $DB->sql_like('classname', '?'), array('%block_panopto%task%'));
}

/**
* main constructor
*
Expand Down Expand Up @@ -621,7 +628,6 @@ public function sync_external_user($userid) {
}
}


// Only try to sync the users if he Panopto server is up.
if (self::is_server_alive('https://' . $this->servername . '/Panopto')) {

Expand Down Expand Up @@ -1179,8 +1185,8 @@ public static function build_and_assign_context_capability_to_roles($context, $r
}
}

// Remove existing capabilities that are no longer needed.
$assignnew = array_diff($existing, $assigned);
// Remove existing capabilities that are no longer needed. This needs to be assoc to take into account the keys
$assignnew = array_diff_assoc($existing, $assigned);
if (!empty($assignnew)) {
foreach ($assignnew as $roleid => $cap) {
unassign_capability($capability, $roleid, $context);
Expand All @@ -1189,7 +1195,8 @@ public static function build_and_assign_context_capability_to_roles($context, $r
}

// Add new capabilities that don't exist yet.
$existingnew = array_diff($assigned, $existing);
$existingnew = array_diff_assoc($assigned, $existing);

if (!empty($existingnew)) {
foreach ($existingnew as $roleid => $cap) {
if (isset($roleid) && trim($roleid) !== '') {
Expand Down Expand Up @@ -1218,9 +1225,6 @@ public static function build_and_assign_context_capability_to_roles($context, $r
public static function set_course_role_permissions($courseid, $publisherroles, $creatorroles) {
$coursecontext = context_course::instance($courseid);

// Get the current role mappings set for the current course from the db.
$mappings = self::get_course_role_mappings($courseid);

// Build and process new/old changes to capabilities to be applied to roles and capabilities.
$capability = 'block/panopto:provision_aspublisher';
$publisherprocessed = self::build_and_assign_context_capability_to_roles($coursecontext, $publisherroles, $capability);
Expand Down Expand Up @@ -1249,6 +1253,23 @@ public static function set_course_role_permissions($courseid, $publisherroles, $
self::set_course_role_mappings($courseid, $publisherroles, $creatorroles);
}

// If a role was unset from a capability we need to reflect that change on Moodle.
public static function unset_course_role_permissions($courseid, $oldpublisherroles, $oldcreatorroles) {
$coursecontext = context_course::instance($courseid);

foreach ($oldpublisherroles as $publisherrole) {
unassign_capability('block/panopto:provision_aspublisher', $publisherrole, $coursecontext);
}

foreach ($oldcreatorroles as $creatorrole) {
unassign_capability('block/panopto:provision_asteacher', $creatorrole, $coursecontext);
}

if (!empty($oldpublisherroles) || !empty($oldcreatorroles)) {
$coursecontext->mark_dirty();
}
}

public static function is_server_alive($url = null) {
// Only proceed with the cURL check if this toggle is true. This code is dependent on platform/OS specific calls.
if (!get_config('block_panopto', 'check_server_status')) {
Expand Down
4 changes: 2 additions & 2 deletions upgrade_all_folders.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function upgrade_all_panopto_folders() {
}
} else {
// Shouldn't hit this case, but in the case a row in the DB has invalid data move it to the old_foldermap.
panopto_data::print_log(get_string('removing_corrupt_folder_row', 'block_panopto') . $oldcourse->moodleid);
panopto_data::print_log(get_string('removing_corrupt_folder_row', 'block_panopto', $oldcourse->moodleid));
panopto_data::delete_panopto_relation($oldcourse->moodleid, true);
// Continue to the next entry assuming this one was cleanup.
continue;
Expand Down Expand Up @@ -195,7 +195,7 @@ function upgrade_all_panopto_folders() {
// We can still continue on with the upgrade, assume this was an old entry that was deleted from Panopto side.
}
} else {
panopto_data::print_log(get_string('removing_corrupt_folder_row', 'block_panopto') . $courseimport);
panopto_data::print_log(get_string('removing_corrupt_folder_row', 'block_panopto', $courseimport));
panopto_data::delete_panopto_relation($courseimport, true);
// Continue to the next entry assuming this one was cleanup.
continue;
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

// Plugin version should normally be the same as the internal version.
// If an admin wants to install with an older version number, however, set that here.
$plugin->version = 2018050700;
$plugin->version = 2018070900;

// Requires this Moodle version - 2.7.
$plugin->requires = 2014051200;
Expand Down

0 comments on commit a34e1f5

Please sign in to comment.