Use function "api_protect_course_group"

- Format code
- Fix phpdoc
- Use function "api_protect_course_group" instead of
GroupManager::user_has_access
- Add optional course id
pull/2487/head
jmontoyaa 8 years ago
parent 0cb4d56942
commit 3f6dbcf6d7
  1. 3
      main/calendar/agenda_js.php
  2. 9
      main/forum/viewforum.php
  3. 5
      main/inc/lib/api.lib.php
  4. 20
      main/work/student_work.php

@ -57,7 +57,8 @@ if (!empty($group_id)) {
$group_properties = GroupManager::get_group_properties($group_id); $group_properties = GroupManager::get_group_properties($group_id);
$is_group_tutor = GroupManager::is_tutor_of_group( $is_group_tutor = GroupManager::is_tutor_of_group(
api_get_user_id(), api_get_user_id(),
$group_properties $group_properties,
$courseId
); );
$interbreadcrumb[] = array( $interbreadcrumb[] = array(
"url" => api_get_path(WEB_CODE_PATH)."group/group.php?".api_get_cidreq(), "url" => api_get_path(WEB_CODE_PATH)."group/group.php?".api_get_cidreq(),

@ -29,6 +29,7 @@ $current_course_tool = TOOL_FORUM;
// Notification for unauthorized people. // Notification for unauthorized people.
api_protect_course_script(true); api_protect_course_script(true);
api_protect_course_group(GroupManager::GROUP_TOOL_FORUM);
// The section (tabs). // The section (tabs).
$this_section = SECTION_COURSES; $this_section = SECTION_COURSES;
@ -74,12 +75,6 @@ $is_group_tutor = false;
if (!empty($groupId)) { if (!empty($groupId)) {
//Group info & group category info //Group info & group category info
$group_properties = GroupManager::get_group_properties($groupId); $group_properties = GroupManager::get_group_properties($groupId);
//User has access in the group?
$user_has_access_in_group = GroupManager::user_has_access(
$userId,
$group_properties['iid'],
GroupManager::GROUP_TOOL_FORUM
);
$is_group_tutor = GroupManager::is_tutor_of_group( $is_group_tutor = GroupManager::is_tutor_of_group(
api_get_user_id(), api_get_user_id(),
$group_properties $group_properties
@ -88,7 +83,7 @@ if (!empty($groupId)) {
// Course // Course
if (!api_is_allowed_to_edit(false, true) && //is a student if (!api_is_allowed_to_edit(false, true) && //is a student
(($current_forum_category && $current_forum_category['visibility'] == 0) || (($current_forum_category && $current_forum_category['visibility'] == 0) ||
$current_forum['visibility'] == 0 || !$user_has_access_in_group) $current_forum['visibility'] == 0)
) { ) {
api_not_allowed(true); api_not_allowed(true);
} }

@ -8274,9 +8274,8 @@ function api_mail_html(
} }
/** /**
* @param string $tool Possible values: * @param string $tool Possible values: GroupManager::GROUP_TOOL_*
* GroupManager::GROUP_TOOL_* * @param bool $showHeader
*
*/ */
function api_protect_course_group($tool, $showHeader = true) function api_protect_course_group($tool, $showHeader = true)
{ {

@ -7,6 +7,7 @@ require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_STUDENTPUBLICATION; $current_course_tool = TOOL_STUDENTPUBLICATION;
api_protect_course_script(true); api_protect_course_script(true);
api_protect_course_group(GroupManager::GROUP_TOOL_WORK);
require_once 'work.lib.php'; require_once 'work.lib.php';
$this_section = SECTION_COURSES; $this_section = SECTION_COURSES;
@ -29,24 +30,7 @@ if (empty($userInfo) || empty($courseInfo)) {
// Only a teachers page. // Only a teachers page.
if (!empty($group_id)) { if (!empty($group_id)) {
$group_properties = GroupManager :: get_group_properties($group_id); $group_properties = GroupManager::get_group_properties($group_id);
$show_work = false;
if (api_is_allowed_to_edit(false, true)) {
$show_work = true;
} else {
// you are not a teacher
$show_work = GroupManager::user_has_access(
api_get_user_id(),
$group_properties['iid'],
GroupManager::GROUP_TOOL_WORK
);
}
if (!$show_work) {
api_not_allowed();
}
$interbreadcrumb[] = array( $interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(), 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
'name' => get_lang('Groups') 'name' => get_lang('Groups')

Loading…
Cancel
Save