Commit fa63d1b8 authored by Edward Murrell's avatar Edward Murrell
Browse files

Add moderating roles to GroupType for comment delete. bug809625



This change was added to limit deleting of comments in standard groups
views to admins only, and admins and tutors in course groups. This commit
adds the functions
    User::can_moderate_view()
and
    GroupType::get_view_moderating_roles()
to implement this functionality.

Change-Id: Ifb8f4fc55d31fd7c5928c73c3d81710934bfdad8
Signed-off-by: default avatarEdward Murrell <edwardm@catalyst.net.nz>
parent 63d8877b
......@@ -276,7 +276,7 @@ class ArtefactTypeComment extends ArtefactType {
$artefactid = $artefact->get('id');
}
else {
$canedit = $USER->can_edit_view($view);
$canedit = $USER->can_moderate_view($view);
$owner = $view->get('owner');
$isowner = $userid && $userid == $owner;
$artefactid = null;
......
......@@ -942,6 +942,27 @@ class User {
return false;
}
/**
* Function to check if user can moderate (ie; delete) comments in a view
*/
public function can_moderate_view($v) {
$owner = $v->get('owner');
if ($owner > 0 && $owner == $this->get('id')) {
return true;
}
$institution = $v->get('institution');
if ($institution && $this->can_edit_institution($institution)) {
return true;
}
$group = $v->get('group');
if ($group) {
$moderatingroles = $v->get('moderatingroles');
$this->reset_grouproles();
return isset($this->grouproles[$group]) && in_array($this->grouproles[$group], $moderatingroles);
}
return false;
}
/**
* Function to check current user can edit collection
*
......
......@@ -66,6 +66,10 @@ class GroupTypeCourse extends GroupType {
return array('tutor', 'admin');
}
public static function get_view_moderating_roles() {
return array('tutor', 'admin');
}
public static function get_view_assessing_roles() {
return array('tutor', 'admin');
}
......
......@@ -99,6 +99,8 @@ abstract class GroupType {
public static abstract function get_view_editing_roles();
public static abstract function get_view_moderating_roles();
public static abstract function get_view_assessing_roles();
public static function get_group_artefact_plugins() {
......
......@@ -64,6 +64,10 @@ class GroupTypeStandard extends GroupType {
return array('member', 'admin');
}
public static function get_view_moderating_roles() {
return array('admin');
}
public static function get_view_assessing_roles() {
return array();
}
......
......@@ -60,6 +60,7 @@ class View {
private $tags;
private $categorydata;
private $editingroles;
private $moderatingroles;
private $template;
private $retainview;
private $copynewuser = 0;
......@@ -152,6 +153,7 @@ class View {
}
safe_require('grouptype', $group->grouptype);
$this->editingroles = call_static_method('GroupType' . ucfirst($group->grouptype), 'get_view_editing_roles');
$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