MDL-20534 lti: Updating privacy settings dynamically based on matched Launch URL.
authorChris Scribner <scriby@gmail.com>
Wed, 16 Nov 2011 20:49:57 +0000 (15:49 -0500)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 21 Nov 2011 15:42:12 +0000 (16:42 +0100)
mod/lti/ajax.php
mod/lti/lang/en/lti.php
mod/lti/locallib.php
mod/lti/mod_form.js
mod/lti/mod_form.php

index efa6c80..8bcc089 100644 (file)
@@ -46,6 +46,22 @@ switch ($action) {
             $response->toolid = $tool->id;
             $response->toolname = htmlspecialchars($tool->name);
             $response->tooldomain = htmlspecialchars($tool->tooldomain);
+            
+            //Look up privacy settings
+            $query = 
+            '
+                SELECT name, value
+                FROM {lti_types_config}
+                WHERE
+                    typeid = :typeid
+                AND name IN (\'sendname\', \'sendemailaddr\', \'acceptgrades\', \'allowroster\')
+            ';
+                        
+            $privacyconfigs = $DB->get_records_sql($query, array('typeid' => $tool->id));
+            foreach($privacyconfigs as $config){
+                $configname = $config->name;
+                $response->$configname = $config->value;
+            }
         }
         break;
 }
index d3942a7..d7e166e 100644 (file)
@@ -181,6 +181,7 @@ $string['fixexistingconf'] = 'Use an existing configuration for the misconfigure
 $string['fixnew'] = 'New Configuration';
 $string['fixnewconf'] = 'Define a new configuration for the misconfigured instance';
 $string['fixold'] = 'Use Existing';
+$string['forced_help'] = 'This setting has been forced in a course or site level tool configuration. You may not change it from this interface.';
 $string['force_ssl'] = 'Force SSL';
 $string['force_ssl_help'] = 'Selecting this option forces all launches to this tool provider to use SSL.
 
index 525a2fa..53425a3 100644 (file)
@@ -646,7 +646,7 @@ function lti_get_best_tool_by_url($url, $tools, $courseid = null) {
 
         //Prefer course tools over site tools
         if (!empty($courseid)) {
-            //Minus 25 points for not matching the course id (global tools)
+            //Minus 10 points for not matching the course id (global tools)
             if ($tool->course != $courseid) {
                 $tool->_matchscore -= 10;
             }
index cfaf7e9..0167ead 100644 (file)
 
     M.mod_lti = M.mod_lti || {};
 
+    M.mod_lti.LTI_SETTING_NEVER = 0;
+    M.mod_lti.LTI_SETTING_ALWAYS = 1;
+    M.mod_lti.LTI_SETTING_DELEGATE = 2;
+
     M.mod_lti.editor = {
         init: function(yui3, settings){
             if(yui3){
             var selectedOption = typeSelector.one('option[value="' + selectedToolType + '"]');
 
             //A specific tool type is selected (not "auto")
+            //We still need to check with the server to get privacy settings
             if(selectedToolType > 0){
                 //If the entered domain matches the domain of the tool configuration...
                 var domainRegex = /(?:https?:\/\/)?(?:www\.)?([^\/]+)(?:\/|$)/i;
                     //The entered URL does not match the domain of the tool configuration
                     automatchToolDisplay.set('innerHTML', '<img style="vertical-align:text-bottom" src="' + self.settings.warning_icon_url + '" />' + M.str.lti.domain_mismatch);
                 }
-
-                return;
             }
 
             var key = Y.one('#id_resourcekey');
             var secret = Y.one('#id_password');
 
-            //We don't care what tool type this tool is associated with if it's manually configured'
+            //Indicate the tool is manually configured
+            //We still check the Launch URL with the server as course/site tools may override privacy settings
             if(key.get('value') !== '' && secret.get('value') !== ''){
                 automatchToolDisplay.set('innerHTML',  '<img style="vertical-align:text-bottom" src="' + self.settings.green_check_icon_url + '" />' + M.str.lti.custom_config);
-            } else {
-                var continuation = function(toolInfo){
-                    if(toolInfo.toolname){
-                        automatchToolDisplay.set('innerHTML',  '<img style="vertical-align:text-bottom" src="' + self.settings.green_check_icon_url + '" />' + M.str.lti.using_tool_configuration + toolInfo.toolname);
-                    } else {
-                        //Inform them custom configuration is in use
-                        if(key.get('value') === '' || secret.get('value') === ''){
-                            automatchToolDisplay.set('innerHTML', '<img style="vertical-align:text-bottom" src="' + self.settings.warning_icon_url + '" />' + M.str.lti.tool_config_not_found);
-                        }
-                    }
-                };
+            } 
+            
+            var continuation = function(toolInfo){
+                self.updatePrivacySettings(toolInfo);
 
-                //Cache urls which have already been checked to increaes performance
-                if(self.urlCache[url]){
-                    continuation(self.urlCache[url]);
+                if(toolInfo.toolname){
+                    automatchToolDisplay.set('innerHTML',  '<img style="vertical-align:text-bottom" src="' + self.settings.green_check_icon_url + '" />' + M.str.lti.using_tool_configuration + toolInfo.toolname);
                 } else {
-                    self.findToolByUrl(url, function(toolInfo){
+                    //Inform them custom configuration is in use
+                    if(key.get('value') === '' || secret.get('value') === ''){
+                        automatchToolDisplay.set('innerHTML', '<img style="vertical-align:text-bottom" src="' + self.settings.warning_icon_url + '" />' + M.str.lti.tool_config_not_found);
+                    }
+                }
+            };
+
+            //Cache urls which have already been checked to increase performance
+            if(self.urlCache[url]){
+                continuation(self.urlCache[url]);
+            } else {
+                self.findToolByUrl(url, function(toolInfo){
+                    if(toolInfo){
                         self.urlCache[url] = toolInfo;
 
                         continuation(toolInfo);
-                    });
+                    }
+                });
+            }
+        },
+
+        /**
+         * Updates display of privacy settings to show course / site tool configuration settings.
+         */
+        updatePrivacySettings: function(toolInfo){
+            if(!toolInfo || !toolInfo.toolname){
+                toolInfo = {
+                    sendname: M.mod_lti.LTI_SETTING_DELEGATE,
+                    sendemailaddr: M.mod_lti.LTI_SETTING_DELEGATE,
+                    acceptgrades: M.mod_lti.LTI_SETTING_DELEGATE,
+                    allowroster: M.mod_lti.LTI_SETTING_DELEGATE
+                }
+            }
+            
+            var setting, control;
+            
+            //Can't look these up by ID as they seem to get random IDs. 
+            //Setting an id manually from mod_form made them turn into text boxes.
+            var privacyControls = {
+                sendname: Y.one('input[name=instructorchoicesendname]'),
+                sendemailaddr: Y.one('input[name=instructorchoicesendemailaddr]'),
+                acceptgrades: Y.one('input[name=instructorchoiceacceptgrades]'),
+                allowroster: Y.one('input[name=instructorchoiceallowroster]')
+            };
+            
+            //Store a copy of user entered privacy settings as we may overwrite them
+            if(!this.userPrivacySettings){
+                this.userPrivacySettings = {};
+            }
+
+            for(setting in privacyControls){
+                if(privacyControls.hasOwnProperty(setting)){
+                    control = privacyControls[setting];
+
+                    //Only store the value if it hasn't been forced by the editor
+                    if(!control.get('disabled')){
+                        this.userPrivacySettings[setting] = control.get('checked');
+                    }
+                }
+            }
+            
+            //Update UI based on course / site tool configuration
+            for(setting in privacyControls){
+                if(privacyControls.hasOwnProperty(setting)){
+                    var settingValue = toolInfo[setting];
+                    control = privacyControls[setting];
+                    
+                    if(settingValue == M.mod_lti.LTI_SETTING_NEVER){
+                        control.set('disabled', true);
+                        control.set('checked', false);
+                        control.set('title', M.str.lti.forced_help);
+                    } else if(settingValue == M.mod_lti.LTI_SETTING_ALWAYS){
+                        control.set('disabled', true);
+                        control.set('checked', true);
+                        control.set('title', M.str.lti.forced_help);
+                    } else if(settingValue == M.mod_lti.LTI_SETTING_DELEGATE){
+                        control.set('disabled', false);
+                        
+                        //Get the value out of the stored copy
+                        control.set('checked', this.userPrivacySettings[setting]); 
+                        control.set('title', '');
+                    }
                 }
             }
         },
 
         findToolByUrl: function(url, callback){
             var self = this;
+            
+            if(!url || url === ''){
+                return callback();
+            }
 
             Y.io(self.settings.ajax_url, {
                 data: {action: 'find_tool_config',
index 1369980..1d4d8ba 100644 (file)
@@ -224,7 +224,8 @@ class mod_lti_mod_form extends moodleform_mod {
                 array('using_tool_configuration', 'lti'),
                 array('domain_mismatch', 'lti'),
                 array('custom_config', 'lti'),
-                array('tool_config_not_found', 'lti')
+                array('tool_config_not_found', 'lti'),
+                array('forced_help', 'lti')
             ),
         );