MDL-6568 shortname added to roles
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
<input type="hidden" name="sesskey" value="<?php print (sesskey()); ?>">
|
||||
<input type="hidden" name="action" value="<?php echo $action; ?>">
|
||||
<br/>Role Name: <input type="text" name="name" value="<?php echo $role->name; ?>">
|
||||
|
||||
Role short name (ASCII): <input type="text" name="shortname" value="<?php echo $role->shortname; ?>" />
|
||||
<br/>Role Description:
|
||||
|
||||
<?php print_textarea($CFG->htmleditor, 10, 50, 50, 10, 'description', "$role->description"); ?>
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
|
||||
admin_externalpage_setup('defineroles', $adminroot);
|
||||
|
||||
$roleid = optional_param('roleid', 0, PARAM_INT); // if set, we are editing a role
|
||||
$roleid = optional_param('roleid', 0, PARAM_INT); // if set, we are editing a role
|
||||
$name = optional_param('name', '', PARAM_MULTILANG); // new role name
|
||||
$shortname = optional_param('shortname', '', PARAM_SAFEDIR); // new role shortname
|
||||
$description = optional_param('description', '', PARAM_MULTILANG); // new role desc
|
||||
$action = optional_param('action', '', PARAM_ALPHA);
|
||||
$name = optional_param('name', '', PARAM_ALPHA); // new role name
|
||||
$description = optional_param('description', '', PARAM_NOTAGS); // new role desc
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
||||
@@ -37,7 +38,7 @@
|
||||
switch ($action) {
|
||||
case 'add':
|
||||
|
||||
$newrole = create_role($name, $description);
|
||||
$newrole = create_role($name, $shortname, $description);
|
||||
|
||||
$ignore = array('roleid', 'sesskey', 'action', 'name', 'description', 'contextid');
|
||||
|
||||
@@ -142,6 +143,7 @@
|
||||
} else {
|
||||
$action='add';
|
||||
$role->name='';
|
||||
$role->shortname='';
|
||||
$role->description='';
|
||||
}
|
||||
|
||||
|
||||
+15
-9
@@ -887,15 +887,15 @@ function moodle_install_roles() {
|
||||
|
||||
// Create default/legacy roles and capabilities.
|
||||
// (1 legacy capability per legacy role at system level).
|
||||
$adminrole = create_role(get_string('administrator'), get_string('administratordescription'), 'moodle/legacy:admin');
|
||||
$adminrole = create_role(get_string('administrator'), 'admin', get_string('administratordescription'), 'moodle/legacy:admin');
|
||||
if (!assign_capability('moodle/site:doanything', CAP_ALLOW, $adminrole, $systemcontext->id)) {
|
||||
error('Could not assign moodle/site:doanything to the admin role');
|
||||
}
|
||||
$coursecreatorrole = create_role(get_string('coursecreators'), get_string('coursecreatorsdescription'), 'moodle/legacy:coursecreator');
|
||||
$noneditteacherrole = create_role(get_string('noneditingteacher'), get_string('noneditingteacherdescription'), 'moodle/legacy:teacher');
|
||||
$editteacherrole = create_role(get_string('defaultcourseteacher'), get_string('defaultcourseteacherdescription'), 'moodle/legacy:editingteacher');
|
||||
$studentrole = create_role(get_string('defaultcoursestudent'), get_string('defaultcoursestudentdescription'), 'moodle/legacy:student');
|
||||
$guestrole = create_role(get_string('guest'), get_string('guestdescription'), 'moodle/legacy:guest');
|
||||
$coursecreatorrole = create_role(get_string('coursecreators'), 'coursecreator', get_string('coursecreatorsdescription'), 'moodle/legacy:coursecreator');
|
||||
$editteacherrole = create_role(get_string('defaultcourseteacher'), 'editingteacher', get_string('defaultcourseteacherdescription'), 'moodle/legacy:editingteacher');
|
||||
$noneditteacherrole = create_role(get_string('noneditingteacher'), 'teacher', get_string('noneditingteacherdescription'), 'moodle/legacy:teacher');
|
||||
$studentrole = create_role(get_string('defaultcoursestudent'), 'student', get_string('defaultcoursestudentdescription'), 'moodle/legacy:student');
|
||||
$guestrole = create_role(get_string('guest'), 'guest', get_string('guestdescription'), 'moodle/legacy:guest');
|
||||
|
||||
|
||||
// Look inside user_admin, user_creator, user_teachers, user_students and
|
||||
@@ -1168,11 +1168,12 @@ function get_local_override($roleid, $contextid, $capability) {
|
||||
/**
|
||||
* function that creates a role
|
||||
* @param name - role name
|
||||
* @param shortname - role short name
|
||||
* @param description - role description
|
||||
* @param legacy - optional legacy capability
|
||||
* @return id or false
|
||||
*/
|
||||
function create_role($name, $description, $legacy='') {
|
||||
function create_role($name, $shortname, $description, $legacy='') {
|
||||
|
||||
// check for duplicate role name
|
||||
|
||||
@@ -1180,7 +1181,12 @@ function create_role($name, $description, $legacy='') {
|
||||
error('there is already a role with this name!');
|
||||
}
|
||||
|
||||
if ($role = get_record('role','shortname', $shortname)) {
|
||||
error('there is already a role with this shortname!');
|
||||
}
|
||||
|
||||
$role->name = $name;
|
||||
$role->shortname = $shortname;
|
||||
$role->description = $description;
|
||||
|
||||
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
||||
@@ -2207,7 +2213,7 @@ function get_roles_used_in_context($context) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
return get_records_sql('SELECT distinct r.id, r.name
|
||||
return get_records_sql('SELECT distinct r.id, r.name, r.shortname
|
||||
FROM '.$CFG->prefix.'role_assignments ra,
|
||||
'.$CFG->prefix.'role r
|
||||
WHERE r.id = ra.roleid
|
||||
@@ -2313,7 +2319,7 @@ function get_user_roles($context, $userid=0, $checkparentcontexts=true) {
|
||||
$contexts = ' ra.contextid = \''.$context->id.'\'';
|
||||
}
|
||||
|
||||
return get_records_sql('SELECT ra.*, r.name
|
||||
return get_records_sql('SELECT ra.*, r.name, r.shortname
|
||||
FROM '.$CFG->prefix.'role_assignments ra,
|
||||
'.$CFG->prefix.'role r,
|
||||
'.$CFG->prefix.'context c
|
||||
|
||||
+4
-3
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="lib/db" VERSION="20060917" COMMENT="XMLDB file for core Moodle tables"
|
||||
<XMLDB PATH="lib/db" VERSION="20060918" COMMENT="XMLDB file for core Moodle tables"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
@@ -915,8 +915,9 @@
|
||||
<TABLE NAME="role" COMMENT="moodle roles" PREVIOUS="blog_tag_instance" NEXT="context">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="name"/>
|
||||
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="description"/>
|
||||
<FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="name" NEXT="sortorder"/>
|
||||
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="shortname"/>
|
||||
<FIELD NAME="shortname" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="name" NEXT="description"/>
|
||||
<FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="shortname" NEXT="sortorder"/>
|
||||
<FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="description"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
|
||||
@@ -2224,6 +2224,30 @@ function main_upgrade($oldversion=0) {
|
||||
delete_records('config', 'name', 'requestedstudentsname');
|
||||
}
|
||||
|
||||
if ($oldversion < 2006091804) {
|
||||
$roles = get_records('role');
|
||||
$first = array_shift($roles);
|
||||
if (!empty($first->shortname)) {
|
||||
// shortnames already exist
|
||||
} else {
|
||||
table_column('role', '', 'shortname', 'varchar', '100', '', '', 'not null', 'name');
|
||||
$legacy_names = array('admin', 'coursecreator', 'editingteacher', 'teacher', 'student', 'guest');
|
||||
foreach ($legacy_names as $name) {
|
||||
if ($roles = get_roles_with_capability('moodle/legacy:'.$name, CAP_ALLOW)) {
|
||||
$i = '';
|
||||
foreach ($roles as $role) {
|
||||
if (empty($role->shortname)) {
|
||||
$updated = new object();
|
||||
$updated->id = $role->id;
|
||||
$updated->shortname = $name.$i;
|
||||
update_record('role', $updated);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
@@ -910,6 +910,7 @@ CREATE TABLE prefix_blog_tag_instance (
|
||||
CREATE TABLE prefix_role (
|
||||
`id` int(10) unsigned NOT NULL auto_increment,
|
||||
`name` varchar(255) NOT NULL default '',
|
||||
`shortname` varchar(100) NOT NULL default '',
|
||||
`description` text NOT NULL default '',
|
||||
`sortorder` int(10) unsigned NOT NULL default '0',
|
||||
KEY `sortorder` (`sortorder`),
|
||||
|
||||
@@ -681,6 +681,7 @@ CREATE INDEX prefix_bti_tagid_idx ON prefix_blog_tag_instance (tagid);
|
||||
CREATE TABLE prefix_role (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name varchar(255) NOT NULL default '',
|
||||
shortname varchar(100) NOT NULL default '',
|
||||
description text NOT NULL default '',
|
||||
sortorder integer NOT NULL default '0'
|
||||
);
|
||||
|
||||
@@ -137,6 +137,11 @@ define('PARAM_FORMAT', 0x0004);
|
||||
*/
|
||||
define('PARAM_NOTAGS', 0x0008);
|
||||
|
||||
/**
|
||||
* PARAM_MULTILANG - general plain text compatible with multilang filter, no other html tags.
|
||||
*/
|
||||
define('PARAM_MULTILANG', 0x0009);
|
||||
|
||||
/**
|
||||
* PARAM_FILE - safe file name, all dangerous chars are stripped, protects against XSS, SQL injections and directory traversals
|
||||
*/
|
||||
@@ -368,6 +373,9 @@ function clean_param($param, $type) {
|
||||
case PARAM_NOTAGS: // Strip all tags
|
||||
return strip_tags($param);
|
||||
|
||||
case PARAM_MULTILANG: // leave only tags needed for multilang
|
||||
return clean_param(strip_tags($param, '<lang><span>'), PARAM_CLEAN);
|
||||
|
||||
case PARAM_SAFEDIR: // Remove everything not a-zA-Z0-9_-
|
||||
return eregi_replace('[^a-zA-Z0-9_-]', '', $param);
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
// This is compared against the values stored in the database to determine
|
||||
// whether upgrades should be performed (see lib/db/*.php)
|
||||
|
||||
$version = 2006091800; // YYYYMMDD = date
|
||||
$version = 2006091804; // YYYYMMDD = date
|
||||
// XY = increments within a single day
|
||||
|
||||
$release = '1.7 dev'; // Human-friendly version name
|
||||
|
||||
Reference in New Issue
Block a user