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

New setting for identification use #95

Open
wants to merge 8 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
4 changes: 2 additions & 2 deletions common/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ function equella_getssotoken($course = null) {
// see if the user has a role that is linked to an equella role
$shareid = $CFG->{"equella_{$role->shortname}_shareid"};
if (!empty($shareid)) {
return equella_getssotoken_raw($USER->username, $shareid, $CFG->{"equella_{$role->shortname}_sharedsecret"});
return equella_getssotoken_raw($USER->equellauser, $shareid, $CFG->{"equella_{$role->shortname}_sharedsecret"});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do $CFG -> equellauser ? I just compared this one with other settings and they are all access from $CFG.

}
}
}

// no roles found, use the default shareid and secret
$shareid = $CFG->equella_shareid;
if (!empty($shareid)) {
return equella_getssotoken_raw($USER->username, $shareid, $CFG->equella_sharedsecret);
return equella_getssotoken_raw($USER->equellauser, $shareid, $CFG->equella_sharedsecret);
}
}

Expand Down
4 changes: 4 additions & 0 deletions lang/en/equella.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
1. Use "selectOrAdd" for EQUELLA 6.0 and older, for EQUELLA 6.1 onward please use "structured"
2. There should not be a ? or a & at the start or end of the string.';

$string['config.userfield.title'] = 'User field to use';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$string['config.userfield.title'] = 'User field to use';
$string['config.userfield.title'] = 'User field for SSO identification';

$string['config.userfield.desc'] = 'Choose the user field to be used instead of username';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$string['config.userfield.desc'] = 'Choose the user field to be used instead of username';
$string['config.userfield.desc'] = 'Choose which User field to be used for SSO identification';

$string['config.userfield.username'] = 'Username';

$string['config.restriction.title'] = 'Restrict selections';
$string['config.restriction.desc'] = 'Choose whether course editors should only be able to select items, attachments, packages or anything. Please note that the restrictions only working for EQUELLA 6.0 and higher.';
$string['config.restriction.none'] = 'No restrictions';
Expand Down
14 changes: 14 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -635,3 +635,17 @@ function equella_grade_item_delete($eq) {
return grade_update(EQUELLA_SOURCE, $eq->courseid, EQUELLA_ITEM_TYPE, EQUELLA_ITEM_MODULE, $eq->id, 0, NULL, array('deleted'=>1));
}

/**
* Select the corresponding field to allocate the username to $USER
*/
function mod_equella_after_config(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if you need this callback. The configured SSO identification field is available in $CFG->equella_userfield.

global $USER, $CFG;
if(!isset($USER->equellauser) && isset($USER->username)) {
$userfield = $CFG->equella_userfield;
if ($userfield != 'default' && isset($USER->profile[$userfield])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I ask where is $USER->profile[$userfield] set ?

$USER->equellauser = $USER->profile[$userfield];
} else {
$USER->equellauser = $USER->username;
}
}
}
4 changes: 2 additions & 2 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ function equella_lti_params($equella, $course, $extra = array()) {
$requestparams['lis_person_name_family'] = $USER->lastname;
$requestparams['lis_person_name_full'] = fullname($USER);
$requestparams['lis_person_contact_email_primary'] = $USER->email;
$requestparams['lis_person_sourcedid'] = $USER->username;
$requestparams['lis_person_sourcedid'] = $USER->equellauser;
$requestparams["ext_lms"] = "moodle-2";
$requestparams['tool_consumer_info_product_family_code'] = 'moodle';
$requestparams['tool_consumer_info_version'] = strval($CFG->version);
Expand Down Expand Up @@ -351,7 +351,7 @@ function equella_add_lmsinfo_parameters(&$params, $course, $contributiontype) {
$params['course/fullname'] = $course->fullname;
$params['course/shortname'] = $course->shortname;
$params['course/code'] = $course->idnumber;
$params['user/username'] = $USER->username;
$params['user/username'] = $USER->equellauser;
$params['user/firstname'] = $USER->firstname;
$params['user/lastname'] = $USER->lastname;
//$params['moodle/section'] = get_section_name($course, $sectionid));
Expand Down
2 changes: 1 addition & 1 deletion ltilaunch.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function get_item_xml($course, $sectionid) {

// User
$integuserxml = $integxml->addChild('user');
$integuserxml->addChild('username', $USER->username);
$integuserxml->addChild('username', $USER->equellauser);
$integuserxml->addChild('firstname', $USER->firstname);
$integuserxml->addChild('lastname', $USER->lastname);

Expand Down
7 changes: 7 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ function ecs($configoption, $params = null) {
$settings->add(new admin_setting_configtext('equella_url', ecs('url.title'), ecs('url.desc'), ''));
$settings->add(new admin_setting_configtext('equella_action', ecs('action.title'), ecs('action.desc'), ''));

$userfieldoptions = array();
$userfieldoptions = array('default' => ecs('userfield.username'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of default, why not use Username as the default option ?


define('EQUELLA_SSO_IDENTIFICATION_FIELD', 'Username');

foreach($DB->get_records('user_info_field') as $params){
$userfieldoptions[$params->shortname] = $params->name;
}
$settings->add(new admin_setting_configselect('equella_userfield', ecs('userfield.title'), ecs('userfield.desc'), 'default', $userfieldoptions));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, why not use Username as the default option ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this setting should be under General settings which is more focused on oEQ.

I think it's good to have a separate section named SSO identification at the bottom of this page.


$restrictionOptions = array(EQUELLA_CONFIG_SELECT_RESTRICT_NONE => trim(ecs('restriction.none')),EQUELLA_CONFIG_SELECT_RESTRICT_ITEMS_ONLY => trim(ecs('restriction.itemsonly')),EQUELLA_CONFIG_SELECT_RESTRICT_ATTACHMENTS_ONLY => trim(ecs('restriction.attachmentsonly')),
EQUELLA_CONFIG_SELECT_RESTRICT_PACKAGES_ONLY => trim(ecs('restriction.packagesonly')));

Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') || die();

$plugin->version = 2023070300;
$plugin->version = 2023070300.3;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We typically do not have decimal in the version. It can be the date when you made the commit.

$plugin->requires = 2014041101; // Requires this Moodle version
$plugin->component = 'mod_equella'; // Full name of the plugin (used for diagnostics)
$plugin->release = '1.3.1';