Commit c79a8e0e authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Get moderating roles from group function instead of the view



When deciding who can moderate comments on a group view, the
'moderating' roles are stored in the view object, but they don't
need to be, because they only depend on the group settings.  So
we can remove moderating roles from the View object, and get them
directly using the group id when required.

Change-Id: I69f5cd467e474a1fd9c0c589322c6a3935aa3482
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 9b48e8c4
......@@ -1002,9 +1002,15 @@ class User {
}
$group = $v->get('group');
if ($group) {
$moderatingroles = $v->get('moderatingroles');
$this->reset_grouproles();
return isset($this->grouproles[$group]) && in_array($this->grouproles[$group], $moderatingroles);
if (!isset($this->grouproles[$group])) {
return false;
}
if (($v->get('type') == 'grouphomepage' || $v->get('locked')) && $this->grouproles[$group] != 'admin') {
return false;
}
require_once('group.php');
return group_role_can_moderate_views($group, $this->grouproles[$group]);
}
return false;
}
......
......@@ -182,6 +182,26 @@ function group_role_can_edit_views($group, $role) {
return $editroles != 'admin';
}
function group_role_can_moderate_views($group, $role) {
static $moderatingroles = array();
if (empty($role)) {
return false;
}
if ($role == 'admin') {
return true;
}
if (!isset($moderatingroles[$group])) {
$grouptype = get_field('group', 'grouptype', 'id', $group);
safe_require('grouptype', $grouptype);
$moderatingroles[$group] = call_static_method('GroupType' . ucfirst($grouptype), 'get_view_moderating_roles');
}
return in_array($role, $moderatingroles[$group]);
}
/**
* Returns whether a user is allowed to assess views that have been submitted
* to the given group.
......
......@@ -59,7 +59,6 @@ class View {
private $dirtycolumns; // for when we change stuff
private $tags;
private $categorydata;
private $moderatingroles;
private $template;
private $retainview;
private $copynewuser = 0;
......@@ -151,8 +150,6 @@ class View {
if ($group->deleted) {
throw new ViewNotFoundException(get_string('viewnotfound', 'error', $id));
}
safe_require('grouptype', $group->grouptype);
$this->moderatingroles = call_static_method('GroupType' . ucfirst($group->grouptype), 'get_view_moderating_roles');
}
}
......
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