Commit b078b3a8 authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1789297: module/lti: LTI assignment submission fix



Make sure launch_presentation_return_url exists before trying to parse
it into URL parts

Make sure LTI module is active before trying to include it in
searches

Also fix confusion with 'lock' config setting

behatnotneeded

Change-Id: Ia96a316bfcfed8a81a3523261b77365e2a7f4a5e
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 832defd7
......@@ -2201,6 +2201,9 @@ function group_get_associated_groups($userid, $filter='all', $limit=20, $offset=
}
// TODO: make it work on other databases?
$ltijoin = is_plugin_active('lti', 'module') ? ' LEFT JOIN {lti_assessment} a ON g.id = a.group ' : '';
$ltiwhere = is_plugin_active('lti', 'module') ? ' AND a.id IS NULL ' : '';
// Different filters join on the different kinds of association
if ($filter == 'admin') {
$sql = "
......@@ -2276,9 +2279,9 @@ function group_get_associated_groups($userid, $filter='all', $limit=20, $offset=
}
}
$sql .= ' LEFT JOIN {lti_assessment} a ON g.id = a.group ';
$sql .= $ltijoin;
$count = count_records_sql('SELECT COUNT(*) FROM {group} g ' . $sql . ' WHERE g.deleted = ? AND a.id IS NULL '.$catsql, $values);
$count = count_records_sql('SELECT COUNT(*) FROM {group} g ' . $sql . ' WHERE g.deleted = ? ' . $ltiwhere . $catsql, $values);
// almost the same as query used in find - common parts should probably be pulled out
// gets the groups filtered by above
......@@ -2294,8 +2297,8 @@ function group_get_associated_groups($userid, $filter='all', $limit=20, $offset=
FROM {group} g
LEFT JOIN {group_member} gm ON (gm.group = g.id)' .
$sql . '
WHERE g.deleted = ? AND a.id IS NULL ' .
$catsql . '
WHERE g.deleted = ? ' .
$ltiwhere . $catsql . '
GROUP BY g.id, g.name, g.description, g.public, g.jointype, g.request, g.grouptype, g.submittableto,
g.hidemembers, g.hidemembersfrommembers, g.groupparticipationreports, g.urlid, t.membershiptype, t.reason, t.role, g.editwindowstart, g.editwindowend
) g1
......@@ -2346,17 +2349,17 @@ function group_get_user_groups($userid=null, $roles=null, $sort=null, $limit=nul
}
if (!$fromcache || !isset($usergroups[$userid])) {
$ltijoin = is_plugin_active('lti', 'module') ? ' LEFT JOIN {lti_assessment} a ON g.id = a.group ' : '';
$ltiwhere = is_plugin_active('lti', 'module') ? ' AND a.id IS NULL ' : '';
$groups = get_records_sql_array("
SELECT g.id, g.name, gm.role, g.jointype, g.request, g.grouptype, gtr.see_submitted_views, g.category,
g.hidemembers, g.invitefriends, g.urlid, gm.ctime, gm1.role AS loggedinrole
FROM {group} g
JOIN {group_member} gm ON gm.group = g.id
JOIN {grouptype_roles} gtr ON g.grouptype = gtr.grouptype AND gm.role = gtr.role
LEFT OUTER JOIN {group_member} gm1 ON gm1.group = gm.group AND gm1.member = ?
LEFT JOIN {lti_assessment} a ON a.group = g.id
LEFT OUTER JOIN {group_member} gm1 ON gm1.group = gm.group AND gm1.member = ?" . $ltijoin . "
WHERE gm.member = ?
AND g.deleted = 0 AND a.id IS NULL
AND g.deleted = 0" . $ltiwhere . "
ORDER BY g.name, gm.role = 'admin' DESC, gm.role, g.id",
array($loggedinid, $userid)
);
......
......@@ -3963,6 +3963,7 @@ class View {
public static function get_myviews_data($limit=12, $offset=0, $query=null, $tag=null, $groupid=null, $institution=null, $orderby=null, $searchin=null, $alltags=false) {
global $USER;
$userid = (!$groupid && !$institution) ? $USER->get('id') : null;
$haslti = is_plugin_active('lti', 'module') ? true : false;
$select = '
SELECT v.id, v.id AS vid, v.title, v.title AS vtitle, v.description, v.type, v.ctime as vctime, v.mtime as vmtime, v.atime as vatime,
......@@ -4138,18 +4139,20 @@ class View {
if ($userid) {
$select .= ',v.submittedtime, v.submittedstatus,
g.id AS submitgroupid, g.name AS submitgroupname, g.urlid AS submitgroupurlid,
h.wwwroot AS submithostwwwroot, h.name AS submithostname, a.id AS ltiassessment';
h.wwwroot AS submithostwwwroot, h.name AS submithostname' . ($haslti ? ', a.id AS ltiassessment' : '');
$collselect .= ', c.submittedtime, c.submittedstatus,
g.id AS submitgroupid, g.name AS submitgroupname, g.urlid AS submitgroupurlid,
h.wwwroot AS submithostwwwroot, h.name AS submithostname, a.id AS ltiassessment';
h.wwwroot AS submithostwwwroot, h.name AS submithostname' . ($haslti ? ', a.id AS ltiassessment' : '');
$emptycollselect .= ', c.submittedtime, c.submittedstatus,
NULL AS submitgroupid, NULL AS submitgroupname, NULL AS submitgroupurlid,
NULL AS submithostwwwroot, NULL AS submithostname, NULL AS ltiassessment';
NULL AS submithostwwwroot, NULL AS submithostname' . ($haslti ? ', NULL AS ltiassessment' : '');
$fromstr = '
LEFT OUTER JOIN {group} g ON (v.submittedgroup = g.id AND g.deleted = 0)
LEFT OUTER JOIN {host} h ON (v.submittedhost = h.wwwroot)
LEFT JOIN {lti_assessment} a ON g.id = a.group ';
LEFT OUTER JOIN {host} h ON (v.submittedhost = h.wwwroot)';
if ($haslti) {
$fromstr .= ' LEFT JOIN {lti_assessment} a ON g.id = a.group ';
}
$from .= $fromstr;
$collfrom .= $fromstr;
......@@ -4218,7 +4221,7 @@ class View {
if (!empty($data['submittedstatus'])) {
$status = $data['submittedstatus'];
if (!empty($data['submitgroupid'])) {
if ($data['ltiassessment']) {
if ($haslti && $data['ltiassessment']) {
$url = '#';
}
else {
......
......@@ -985,7 +985,7 @@ class Framework {
$isadminofowner = true;
}
}
else if (!empty($USER->get('id')) && group_user_can_assess_submitted_views($view->get('submittedgroup'), $USER->get('id'))) {
else if (!empty($USER->get('id')) && !empty($view->get('submittedgroup')) && group_user_can_assess_submitted_views($view->get('submittedgroup'), $USER->get('id'))) {
if ($USER->get('id') != $owner->get('id')) {
$isadminofowner = true;
}
......
......@@ -33,7 +33,7 @@ $string['gradesubmissions'] = 'Submissions for grading';
$string['gradesubmitted'] = 'Grade successfully submitted';
$string['groupname'] = 'Assessment submissions for "%s" - "%s"';
$string['institutiondenied'] = 'Access to "%s" is denied. Please contact your institution administrator.';
$string['lock'] = 'Unlock portfolio after grading';
$string['lock'] = 'Keep portfolio locked after grading';
$string['lockdescription'] = 'Users make changes to their portfolio after it has been graded.';
$string['ltiserviceexists'] = 'The LTI service group is registered.';
$string['nocollections'] = 'You do not have any portfolios that can be submitted for assessment.';
......@@ -56,7 +56,7 @@ $string['timesubmitted'] = 'Time submitted';
$string['usernameexists1'] = 'Username "%s" already exists.';
$string['viewsubmittedmessage1'] = '%s has submitted "%s" to %s
Please grade this submission via "%s"';
Please grade this submission by clicking on the activity "%s" in your LMS';
$string['viewsubmittedsubject1'] = 'Assessment submission to %s';
$string['webserviceauthdisabled'] = 'Web service authentication is not enabled for this institution';
$string['webserviceproviderenabled'] = 'Incoming web service requests allowed';
......@@ -285,7 +285,7 @@ class PluginModuleLti extends PluginModule {
'submit' => array(
'type' => 'button',
'usebuttontag' => true,
'class' => 'btn-primary input-group-btn ',
'class' => 'btn-primary input-group-btn',
'value' => get_string('submit')
),
),
......@@ -417,11 +417,10 @@ class PluginModuleLti extends PluginModule {
'type' => 'fieldset',
'class' => 'input-group',
'elements' => array(
'submit' => array(
'type' => 'button',
'usebuttontag' => true,
'class' => 'btn-primary input-group-btn ',
'class' => 'btn-primary input-group-btn',
'value' => get_string('submit')
),
),
......@@ -485,12 +484,6 @@ class PluginModuleLti extends PluginModule {
return new ModuleLtiSubmission($SESSION->get('lti.assessment'), $USER->get('id'));
}
public static function update_submission_group() {
global $SESSION, $USER;
}
public static function get_all_submissions() {
global $SESSION;
......@@ -654,6 +647,7 @@ class PluginModuleLti extends PluginModule {
),
'submit' => array(
'type' => 'submit',
'class' => 'btn btn-primary',
'value' => empty($data->timeconfigured) ? get_string('saveandrelease', 'module.lti') : get_string('save')
)
),
......
......@@ -10,7 +10,7 @@
*/
define('INTERNAL', 1);
define('MENUITEM', 'configextensions/frameworks');
define('MENUITEM', 'create/views');
define('SECTION_PLUGINTYPE', 'module');
define('SECTION_PLUGINNAME', 'lti');
define('SECTION_PAGE', 'submission');
......
......@@ -242,13 +242,13 @@ class module_lti_launch extends external_api {
$SESSION->set('lti.presentation_target', $params['launch_presentation_document_target']);
$SESSION->set('lti.launch_presentation_return_url', $params['launch_presentation_return_url']);
$parts = parse_url($params['launch_presentation_return_url']);
$cspurl = $parts['scheme'] . '://' . $parts['host'];
$SESSION->set('csp-ancestor-exemption', $cspurl);
// If the consumer supports grading send the user to select a portfolio
if (!empty($params['lis_outcome_service_url'])) {
$parts = parse_url($params['launch_presentation_return_url']);
$cspurl = $parts['scheme'] . '://' . $parts['host'];
$SESSION->set('csp-ancestor-exemption', $cspurl);
db_begin();
if ($assessment = get_record('lti_assessment', 'oauthserver', $WEBSERVICE_OAUTH_SERVERID, 'resourcelinkid', $params['resource_link_id'])) {
......@@ -304,6 +304,7 @@ class module_lti_launch extends external_api {
$assessment->contexttitle = $params['context_title'];
$assessment->resourcelinktitle = $params['resource_link_title'];
$assessment->group = $groupid;
$assessment->lock = 0; // Have the config for lock set to false by default so portfolios get unlocked after grading
$assessment->id = insert_record('lti_assessment', $assessment, 'id', true);
}
......
......@@ -850,16 +850,16 @@ class PluginSearchInternal extends PluginSearch {
public static function search_group($query_string, $limit, $offset=0, $type='member', $category='', $institution='all') {
global $USER;
$data = array();
$ltijoin = is_plugin_active('lti', 'module') ? ' LEFT JOIN {lti_assessment} a ON g.id = a.group ' : '';
$ltiwhere = is_plugin_active('lti', 'module') ? ' AND a.id IS NULL ' : '';
$sql = "
FROM
{group} g
LEFT JOIN {lti_assessment} a ON g.id = a.group
{group} g " . $ltijoin . "
WHERE (
name " . db_ilike() . " '%' || ? || '%'
OR description " . db_ilike() . " '%' || ? || '%'
OR shortname " . db_ilike() . " '%' || ? || '%'
) AND deleted = 0 AND a.id IS NULL ";
) AND deleted = 0" . $ltiwhere;
$values = array($query_string, $query_string, $query_string);
if (!$grouproles = join(',', array_keys($USER->get('grouproles')))) {
......
......@@ -132,11 +132,13 @@ if ($USER->is_logged_in() && $submittedgroup && group_user_can_assess_submitted_
$submittedgroup = get_group_by_id($submittedgroup, true);
// Form for LTI grading
if ($collection) {
$ltigradeform = PluginModuleLti::get_grade_dialogue($collection->get('id'), null);
}
else {
$ltigradeform = PluginModuleLti::get_grade_dialogue(null, $view->get('id'));
if (is_plugin_active('lti', 'module')) {
if ($collection) {
$ltigradeform = PluginModuleLti::get_grade_dialogue($collection->get('id'), null);
}
else {
$ltigradeform = PluginModuleLti::get_grade_dialogue(null, $view->get('id'));
}
}
// If the view is part of a submitted collection, the whole
......@@ -301,8 +303,7 @@ if ($owner && $owner == $USER->get('id')) {
$viewgroupform = view_group_submission_form($view, $tutorgroupdata, 'view');
}
}
if (PluginModuleLti::can_submit_for_grading()) {
if (is_plugin_active('lti', 'module') && PluginModuleLti::can_submit_for_grading()) {
$ltisubmissionform = PluginModuleLti::submit_from_view_or_collection_form($view);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment