Commit 05378095 authored by Francois Marier's avatar Francois Marier Committed by Gerrit Code Review
Browse files

Merge "Add moderating roles to GroupType for comment delete. bug809625"

parents 328b3f93 fa63d1b8
......@@ -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