Commit 779815f9 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge "Bug 1828753: Moving usr_roles table to usr_access_roles table"

parents a9d65a97 a1bce068
...@@ -570,7 +570,7 @@ class ArtefactTypePeerassessment extends ArtefactType { ...@@ -570,7 +570,7 @@ class ArtefactTypePeerassessment extends ArtefactType {
return false; return false;
} }
$verifiable = get_field_sql("SELECT va.usr FROM {view_access} va $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 = ? WHERE ur.see_block_content = ?
AND va.view = ? AND va.usr = ? AND va.view = ? AND va.usr = ?
LIMIT 1", array(1, $view->get('id'), $USER->get('id'))); LIMIT 1", array(1, $view->get('id'), $USER->get('id')));
......
...@@ -1440,7 +1440,7 @@ ...@@ -1440,7 +1440,7 @@
<KEY NAME="editedbyfk" TYPE="foreign" FIELDS="editedby" REFTABLE="usr" REFFIELDS="id" /> <KEY NAME="editedbyfk" TYPE="foreign" FIELDS="editedby" REFTABLE="usr" REFFIELDS="id" />
</KEYS> </KEYS>
</TABLE> </TABLE>
<TABLE NAME="usr_roles"> <TABLE NAME="usr_access_roles">
<FIELDS> <FIELDS>
<FIELD NAME="role" TYPE="char" LENGTH="255" NOTNULL="true" /> <FIELD NAME="role" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="see_block_content" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" /> <FIELD NAME="see_block_content" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
......
...@@ -1323,5 +1323,29 @@ function xmldb_core_upgrade($oldversion=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; return $status;
} }
...@@ -862,15 +862,15 @@ function core_install_lastcoredata_defaults() { ...@@ -862,15 +862,15 @@ function core_install_lastcoredata_defaults() {
// the order of installation stuff. // the order of installation stuff.
install_blocktype_extras(); install_blocktype_extras();
// Setting user roles for content block access // Setting user access roles for content block access
$table = new XMLDBTable('usr_roles'); $table = new XMLDBTable('usr_access_roles');
$roles = array('peer' => 0, 'manager' => 1, 'peermanager' => 1); $roles = array('peer' => 0, 'manager' => 1, 'peermanager' => 1);
foreach ($roles as $role => $state) { foreach ($roles as $role => $state) {
$obj = new stdClass(); $obj = new stdClass();
$obj->role = $role; $obj->role = $role;
$obj->see_block_content = $state; $obj->see_block_content = $state;
insert_record('usr_roles', $obj); insert_record('usr_access_roles', $obj);
} }
} }
......
...@@ -16,7 +16,7 @@ $config = new stdClass(); ...@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy // 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. // 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->series = '19.10';
$config->release = '19.10dev'; $config->release = '19.10dev';
$config->minupgradefrom = 2017031605; $config->minupgradefrom = 2017031605;
......
...@@ -1527,7 +1527,7 @@ class View { ...@@ -1527,7 +1527,7 @@ class View {
case 'user': case 'user':
$accessrecord->usr = $item['id']; $accessrecord->usr = $item['id'];
if (isset($item['role']) && strlen($item['role'])) { 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) { foreach ($roleinfo as $key => $role) {
if ($role == $item['role']) { if ($role == $item['role']) {
$accessrecord->role = $item['role']; $accessrecord->role = $item['role'];
...@@ -1790,7 +1790,7 @@ class View { ...@@ -1790,7 +1790,7 @@ class View {
} }
public static function get_user_access_roles() { public static function get_user_access_roles() {
$roles = get_records_array('usr_roles'); $roles = get_records_array('usr_access_roles');
$data = array(); $data = array();
foreach ($roles as $r) { foreach ($roles as $r) {
$data[] = array('name' => $r->role, 'display' => get_string($r->role, 'view')); $data[] = array('name' => $r->role, 'display' => get_string($r->role, 'view'));
......
...@@ -1912,7 +1912,7 @@ EOD; ...@@ -1912,7 +1912,7 @@ EOD;
} }
$id = $ids[0]->id; $id = $ids[0]->id;
$type = 'user'; $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; $role = $userrole;
} }
break; break;
......
...@@ -32,7 +32,7 @@ switch ($type) { ...@@ -32,7 +32,7 @@ switch ($type) {
break; break;
case 'user': case 'user':
$data = search_user($query, $limit, $offset, array('exclude' => $USER->get('id'))); $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(); $data['roles'] = array();
foreach ($roles as $r) { foreach ($roles as $r) {
$data['roles'][] = array('name' => $r->role, 'display' => get_string($r->role, 'view')); $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