Skip to content

Commit

Permalink
MDL-78597 mod_lti: deprecate mod/lti:addmanualinstance and lock config
Browse files Browse the repository at this point in the history
This change:
- removes all uses of mod/lti:addmanualinstance and deprecates it.
- updates the activity instance edit form, specifically the way it deals
with existing manually-configured instances, removing the ability to
edit tool configuration and adding a notice to the user.
  • Loading branch information
snake committed Aug 29, 2023
1 parent d8e2067 commit 93707d8
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 154 deletions.
18 changes: 7 additions & 11 deletions mod/lti/db/access.php
Expand Up @@ -102,17 +102,6 @@
'clonepermissionsfrom' => 'mod/lti:addinstance',
),

// The ability to add a manual instance (i.e. not from a preconfigured tool) to the course.
'mod/lti:addmanualinstance' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'mod/lti:addinstance',
),

// The ability to request the administrator to configure a particular
// External tool globally.
'mod/lti:requesttooladd' => array(
Expand All @@ -124,3 +113,10 @@
)
)
);
$deprecatedcapabilities = [
// The ability to add a manual instance (i.e. not from a preconfigured tool) to the course.
'mod/lti:addmanualinstance' => [
'message' => 'Manual instance configuration is deprecated. Please create a course tool (mod/lti:addcoursetool) and ensure '.
'users are able to add an instance of the course tool via the activity chooser (mod/lti:addpreconfiguredinstance).'
],
];
1 change: 1 addition & 0 deletions mod/lti/lang/en/deprecated.txt
@@ -0,0 +1 @@
lti:addmanualinstance,mod_lti
9 changes: 8 additions & 1 deletion mod/lti/lang/en/lti.php
Expand Up @@ -191,6 +191,11 @@
$string['dynreg_update_btn_new'] = 'Register as a new external tool';
$string['duplicateregurl'] = 'This registration URL is already in use';
$string['editdescription'] = 'Click here to give this tool a description';
$string['editmanualinstancedeprecationwarning'] = 'Manually configured External tool activities are no longer supported. Don\'t worry, this activity will still work as it is, but you can\'t make changes to the tool configuration here anymore.
<br><br>
To make any changes to the tool, or to create new activities with it, the tool needs to be added to your course in Course > More > LTI External tools. Then, you will be able to create new activities, selecting the tool directly in the Activity chooser.
<br><br>
You can read more about adding LTI External tools in the documentation <a href="{$a}" target="_blank">External tool</a>.';
$string['edittype'] = 'Edit preconfigured tool';
$string['embed'] = 'Embed';
$string['embed_no_blocks'] = 'Embed, without blocks';
Expand Down Expand Up @@ -288,7 +293,6 @@
$string['launchoptions'] = 'Launch options';
$string['lti'] = 'LTI';
$string['lti:addcoursetool'] = 'Add course-specific tool configurations';
$string['lti:addmanualinstance'] = 'Add a manually-configured tool';
$string['lti:addmanualinstanceprohibitederror'] = 'The manual creation of tools without a course tool definition is no longer supported. Please create a course tool first and then use that to create activity instances.';
$string['lti:addinstance'] = 'Add a new external tool';
$string['lti:addpreconfiguredinstance'] = 'Add a preconfigured tool';
Expand Down Expand Up @@ -621,3 +625,6 @@
$string['using_tool_configuration'] = 'Using tool configuration: ';
$string['validurl'] = 'A valid URL must start with http(s)://';
$string['viewsubmissions'] = 'View submissions and grading screen';

// Deprecated since Moodle 4.3.
$string['lti:addmanualinstance'] = 'Add a manually-configured tool';
45 changes: 5 additions & 40 deletions mod/lti/locallib.php
Expand Up @@ -2320,41 +2320,8 @@ function lti_get_lti_types_by_course($courseid, $coursevisible = null) {
debugging(__FUNCTION__ . '() is deprecated. Please use \mod_lti\local\types_helper::get_lti_types_by_course() instead.',
DEBUG_DEVELOPER);

global $DB, $SITE;

if ($coursevisible === null) {
$coursevisible = [LTI_COURSEVISIBLE_PRECONFIGURED, LTI_COURSEVISIBLE_ACTIVITYCHOOSER];
}

list($coursevisiblesql, $coursevisparams) = $DB->get_in_or_equal($coursevisible, SQL_PARAMS_NAMED, 'coursevisible');
$courseconds = [];
if (has_capability('mod/lti:addmanualinstance', context_course::instance($courseid))) {
$courseconds[] = "t.course = :courseid";
}
if (has_capability('mod/lti:addpreconfiguredinstance', context_course::instance($courseid))) {
$courseconds[] = "t.course = :siteid";
}
if (!$courseconds) {
return [];
}
$coursecond = implode(" OR ", $courseconds);
$coursecategory = $DB->get_field('course', 'category', ['id' => $courseid]);
$query = "SELECT t.*
FROM {lti_types} t
LEFT JOIN {lti_types_categories} tc on t.id = tc.typeid
WHERE t.coursevisible $coursevisiblesql
AND ($coursecond)
AND t.state = :active
AND (tc.id IS NULL OR tc.categoryid = :categoryid)
ORDER BY t.name ASC";

return $DB->get_records_sql($query,
[
'siteid' => $SITE->id,
'courseid' => $courseid,
'active' => LTI_TOOL_STATE_CONFIGURED,
'categoryid' => $coursecategory
] + $coursevisparams);
global $USER;
return \mod_lti\local\types_helper::get_lti_types_by_course($courseid, $USER->id, $coursevisible ?? []);
}

/**
Expand All @@ -2364,13 +2331,11 @@ function lti_get_lti_types_by_course($courseid, $coursevisible = null) {
*/
function lti_get_types_for_add_instance() {
global $COURSE, $USER;
$preconfiguredtypes = \mod_lti\local\types_helper::get_lti_types_by_course($COURSE->id, $USER->id);

$types = [];
if (has_capability('mod/lti:addmanualinstance', context_course::instance($COURSE->id))) {
$types[0] = (object)array('name' => get_string('automatic', 'lti'), 'course' => 0, 'toolproxyid' => null);
}
// Always return the 'manual' type option, despite manual config being deprecated, so that we have it for legacy instances.
$types = [(object) ['name' => get_string('automatic', 'lti'), 'course' => 0, 'toolproxyid' => null]];

$preconfiguredtypes = \mod_lti\local\types_helper::get_lti_types_by_course($COURSE->id, $USER->id);
foreach ($preconfiguredtypes as $type) {
$types[$type->id] = $type;
}
Expand Down

0 comments on commit 93707d8

Please sign in to comment.