Commit bd320942 authored by Ruslan Kabalin's avatar Ruslan Kabalin
Browse files

groupviews: Prevent view submission to oneself (bug #632308)



If there are no other people with view assessment permission in the group,
the view can't be submitted.
Signed-off-by: default avatarRuslan Kabalin <ruslan.kabalin@luns.net.uk>
parent 744d9398
...@@ -108,7 +108,9 @@ class PluginBlocktypeGroupViews extends SystemBlocktype { ...@@ -108,7 +108,9 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
} }
} }
if (group_allows_submission($group->grouptype) && ($userviewdata = View::get_user_views())) { if (group_allows_submission($group->grouptype) &&
count(group_get_members_can_see_submitted_views($group->id)) &&
$userviewdata = View::get_user_views()) {
// A user can submit more than one view to the same group, but no view can be // A user can submit more than one view to the same group, but no view can be
// submitted to more than one group. // submitted to more than one group.
......
...@@ -1391,6 +1391,31 @@ function group_get_user_course_groups($userid=null) { ...@@ -1391,6 +1391,31 @@ function group_get_user_course_groups($userid=null) {
return array(); return array();
} }
/**
* Returns a list of users that are allowed to see submitted view for the given group.
* $USER is excluded from results.
*
* @param int $groupid ID of group
* @return array
*/
function group_get_members_can_see_submitted_views($groupid) {
global $USER;
$groupid = group_param_groupid($groupid);
if ($groups = get_column_sql(
"SELECT u.member
FROM {group_member} u
INNER JOIN {group} g ON (u.group = g.id AND g.deleted = 0)
INNER JOIN {grouptype} t ON t.name = g.grouptype
INNER JOIN {grouptype_roles} r ON (g.grouptype = r.grouptype AND r.role = u.role)
WHERE g.id = ?
AND t.submittableto = 1 AND r.see_submitted_views = 1 AND u.member != ?
", array($groupid, $USER->get('id')))) {
return $groups;
}
return array();
}
function group_allows_submission($grouptype) { function group_allows_submission($grouptype) {
static $grouptypes = null; static $grouptypes = null;
if (is_null($grouptypes)) { if (is_null($grouptypes)) {
......
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