Commit a1bce068 authored by Robert Lyon's avatar Robert Lyon

Bug 1828753: Moving usr_roles table to usr_access_roles table

As this better refects what the table is for

behatnotneeded

Change-Id: Ia6f8746804b50c2e9946d09e0315f5c7cee80ab2
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 9d3620f3
......@@ -570,7 +570,7 @@ class ArtefactTypePeerassessment extends ArtefactType {
return false;
}
$verifiable = get_field_sql("SELECT va.usr FROM {view_access} va
JOIN {usr_roles} ur ON ur.role = va.role
JOIN {usr_access_roles} ur ON ur.role = va.role
WHERE ur.see_block_content = ?
AND va.view = ? AND va.usr = ?
LIMIT 1", array(1, $view->get('id'), $USER->get('id')));
......
......@@ -1440,7 +1440,7 @@
<KEY NAME="editedbyfk" TYPE="foreign" FIELDS="editedby" REFTABLE="usr" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="usr_roles">
<TABLE NAME="usr_access_roles">
<FIELDS>
<FIELD NAME="role" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="see_block_content" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
......
......@@ -1323,5 +1323,29 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2019051300) {
log_debug('Moving peer, manager and peer&manager roles to new table');
$oldtable = new XMLDBTable('usr_roles');
$newtable = new XMLDBTable('usr_access_roles');
if (!table_exists($newtable)) {
$newtable->addFieldInfo('role', XMLDB_TYPE_CHAR, 255, null, XMLDB_NOTNULL);
$newtable->addFieldInfo('see_block_content', XMLDB_TYPE_INTEGER, 1, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0);
$newtable->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('role'));
create_table($newtable);
$roles = array('peer' => 0, 'manager' => 1, 'peermanager' => 1);
foreach ($roles as $role => $state) {
$obj = new stdClass();
$obj->role = $role;
$obj->see_block_content = $state;
insert_record('usr_access_roles', $obj);
}
}
if (table_exists($oldtable)) {
drop_table($oldtable);
}
}
return $status;
}
......@@ -862,15 +862,15 @@ function core_install_lastcoredata_defaults() {
// the order of installation stuff.
install_blocktype_extras();
// Setting user roles for content block access
$table = new XMLDBTable('usr_roles');
// Setting user access roles for content block access
$table = new XMLDBTable('usr_access_roles');
$roles = array('peer' => 0, 'manager' => 1, 'peermanager' => 1);
foreach ($roles as $role => $state) {
$obj = new stdClass();
$obj->role = $role;
$obj->see_block_content = $state;
insert_record('usr_roles', $obj);
insert_record('usr_access_roles', $obj);
}
}
......
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2019043000;
$config->version = 2019051300;
$config->series = '19.10';
$config->release = '19.10dev';
$config->minupgradefrom = 2017031605;
......
......@@ -1527,7 +1527,7 @@ class View {
case 'user':
$accessrecord->usr = $item['id'];
if (isset($item['role']) && strlen($item['role'])) {
$roleinfo = get_column('usr_roles', 'role');
$roleinfo = get_column('usr_access_roles', 'role');
foreach ($roleinfo as $key => $role) {
if ($role == $item['role']) {
$accessrecord->role = $item['role'];
......@@ -1790,7 +1790,7 @@ class View {
}
public static function get_user_access_roles() {
$roles = get_records_array('usr_roles');
$roles = get_records_array('usr_access_roles');
$data = array();
foreach ($roles as $r) {
$data[] = array('name' => $r->role, 'display' => get_string($r->role, 'view'));
......
......@@ -1912,7 +1912,7 @@ EOD;
}
$id = $ids[0]->id;
$type = 'user';
if (!empty($record['role']) && $userrole = get_field('usr_roles', 'role', 'role', $record['role'])) {
if (!empty($record['role']) && $userrole = get_field('usr_access_roles', 'role', 'role', $record['role'])) {
$role = $userrole;
}
break;
......
......@@ -32,7 +32,7 @@ switch ($type) {
break;
case 'user':
$data = search_user($query, $limit, $offset, array('exclude' => $USER->get('id')));
$roles = get_records_array('usr_roles');
$roles = get_records_array('usr_access_roles');
$data['roles'] = array();
foreach ($roles as $r) {
$data['roles'][] = array('name' => $r->role, 'display' => get_string($r->role, '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