Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add username setting to use with panopto #209

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SSO.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

// Verify passed in parameters are properly signed.
if (panopto_validate_auth_code($requestauthpayload, $requestauthcode)) {
$userkey = panopto_decorate_username($USER->username);
$userkey = panopto_decorate_username(panopto_convert_user_to_send($USER));


$selectedssotype = get_config('block_panopto', 'sso_sync_type');
Expand Down
2 changes: 2 additions & 0 deletions lang/en/block_panopto.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@
$string['unprovisioncourseselect_help'] = 'Multiple selections are possible by Ctrl-clicking (Windows) or Cmd-clicking (Mac).';
$string['unprovisioned'] = 'This course has not yet been provisioned.';
$string['upgrade_panopto_required_version'] = 'A Panopto server you are using does not meet the minimum required version to support this version of the Moodle Panopto Block. The upgrade will be blocked from succeeding until all Panopto servers in use meet minimum version requirements.';
$string['username_field_to_send'] = 'User name field to send to Panopto';
$string['username_field_to_send_desc'] = 'Choose user/userprofile field name to send to Panopto for creating its account.';
$string['users_have_been_synced'] = 'The below users have been synced and should be ready to use Panopto.';
$string['users_will_be_synced_custom'] = 'Future users will automatically be synced according to your custom Panopto settings.';
$string['verifying_permission'] = 'Verifying permission';
Expand Down
22 changes: 22 additions & 0 deletions lib/block_panopto_lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,26 @@ function panopto_update_system_publishers() {
$systemcontext->mark_dirty();
}
}

/**
* Convert the username to be sent to panopto.
*
* @param object $user the moodle username for the account which is sent to panopto.
* @return string
*/
function panopto_convert_user_to_send($user): string {
global $CFG, $DB;
$userfieldtosend = get_config('block_panopto', 'userfield_to_send');
if (!empty($userfieldtosend)) {
$fieldname = 'profile_field_' . $userfieldtosend;
if (!isset($user->$fieldname)) {
require_once($CFG->dirroot . '/user/profile/lib.php');
profile_load_data($user);
}
if (!empty($user->$fieldname)) {
return $user->$fieldname;
}
}
return $user->username;
}
/* End of file block_panopto_lib.php */
2 changes: 1 addition & 1 deletion lib/panopto_category_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function __construct($moodlecategoryid, $selectedserver, $selectedkey) {
$this->instancename = get_config('block_panopto', 'instance_name');

if (isset($USER->username)) {
$username = $USER->username;
$username = panopto_convert_user_to_send($USER);
} else {
$username = 'guest';
}
Expand Down
8 changes: 4 additions & 4 deletions lib/panopto_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function __construct($moodlecourseid) {
}

if (isset($USER->username)) {
$username = $USER->username;
$username = panopto_convert_user_to_send($USER);
} else {
$username = 'guest';
}
Expand Down Expand Up @@ -1097,7 +1097,7 @@ public function get_user_by_key($userkey) {
global $USER;

if (!empty($this->servername) && !empty($this->applicationkey)) {
$this->ensure_user_manager($USER->username);
$this->ensure_user_manager(panopto_convert_user_to_send($USER));
}

$panoptouser = $this->usermanager->get_user_by_key($userkey);
Expand All @@ -1114,7 +1114,7 @@ public function delete_users_from_panopto($userids) {
global $USER;

if (!empty($this->servername) && !empty($this->applicationkey)) {
$this->ensure_user_manager($USER->username);
$this->ensure_user_manager(panopto_convert_user_to_send($USER));
}

$result = $this->usermanager->delete_users($userids);
Expand All @@ -1135,7 +1135,7 @@ public function update_contact_info($userid, $firstname, $lastname, $email, $sen
global $USER;

if (!empty($this->servername) && !empty($this->applicationkey)) {
$this->ensure_user_manager($USER->username);
$this->ensure_user_manager(panopto_convert_user_to_send($USER));
}

$result = $this->usermanager->update_contact_info(
Expand Down
15 changes: 15 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,21 @@
)
);

$userfields = ['' => get_string('username')];
$userprofilefields = $DB->get_records('user_info_field', ['datatype' => 'text'], 'sortorder');
foreach ($userprofilefields as $userprofilefield) {
$userfields[$userprofilefield->shortname] = $userprofilefield->name;
}
$settings->add(
new admin_setting_configselect(
'block_panopto/userfield_to_send',
get_string('username_field_to_send', 'block_panopto'),
get_string('username_field_to_send_desc', 'block_panopto'),
'',
$userfields
)
);

$settings->add(new admin_setting_heading('block_panopto/panopto_folder_and_category_options',
get_string('block_global_panopto_folder_and_category_options', 'block_panopto'),
''));
Expand Down