Skip to content

Commit ebac202

Browse files
authored
Merge pull request #3350 from AngelFQC/BT17512
DRH can access to document when drh_can_access_all_session_content is enabled
2 parents aa98936 + a2edc49 commit ebac202

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

main/inc/lib/document.lib.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,7 @@ public static function is_visible(
16051605
$docTable = Database::get_course_table(TABLE_DOCUMENT);
16061606
$propTable = Database::get_course_table(TABLE_ITEM_PROPERTY);
16071607

1608+
$userId = api_get_user_id();
16081609
$course_id = $course['real_id'];
16091610
// note the extra / at the end of doc_path to match every path in
16101611
// the document table that is part of the document path
@@ -1633,7 +1634,7 @@ public static function is_visible(
16331634
*/
16341635

16351636
if (strpos($doc_path, 'HotPotatoes_files') && preg_match("/\.t\.html$/", $doc_path)) {
1636-
$doc_path = substr($doc_path, 0, strlen($doc_path) - 7 - strlen(api_get_user_id()));
1637+
$doc_path = substr($doc_path, 0, strlen($doc_path) - 7 - strlen($userId));
16371638
}
16381639

16391640
if (!in_array($file_type, ['file', 'folder'])) {
@@ -1658,7 +1659,11 @@ public static function is_visible(
16581659
if (Database::num_rows($result) > 0) {
16591660
$row = Database::fetch_array($result, 'ASSOC');
16601661
if ($row['visibility'] == 1) {
1661-
$is_visible = api_is_allowed_in_course() || api_is_platform_admin();
1662+
$drhAccessContent = api_drh_can_access_all_session_content()
1663+
&& $session_id
1664+
&& SessionManager::isSessionFollowedByDrh($session_id, $userId);
1665+
1666+
$is_visible = api_is_allowed_in_course() || api_is_platform_admin() || $drhAccessContent;
16621667
}
16631668
}
16641669

main/inc/lib/sessionmanager.lib.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9622,4 +9622,45 @@ private static function compareByCourse($listA, $listB)
96229622
return -1;
96239623
}
96249624
}
9625+
9626+
/**
9627+
* Check if a session is followed by human resources manager.
9628+
*
9629+
* @param int $sessionId
9630+
* @param int $userId
9631+
*
9632+
* @return bool
9633+
*/
9634+
public static function isSessionFollowedByDrh($sessionId, $userId)
9635+
{
9636+
$userId = (int) $userId;
9637+
$sessionId = (int) $sessionId;
9638+
9639+
$tblSession = Database::get_main_table(TABLE_MAIN_SESSION);
9640+
$tblSessionRelUser = Database::get_main_table(TABLE_MAIN_SESSION_USER);
9641+
9642+
if (api_is_multiple_url_enabled()) {
9643+
$tblSessionRelAccessUrl = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
9644+
9645+
$sql = "SELECT s.id FROM $tblSession s
9646+
INNER JOIN $tblSessionRelUser sru ON (sru.session_id = s.id)
9647+
LEFT JOIN $tblSessionRelAccessUrl a ON (s.id = a.session_id)
9648+
WHERE
9649+
sru.user_id = '$userId' AND
9650+
sru.session_id = '$sessionId' AND
9651+
sru.relation_type = '".SESSION_RELATION_TYPE_RRHH."' AND
9652+
access_url_id = ".api_get_current_access_url_id();
9653+
} else {
9654+
$sql = "SELECT s.id FROM $tblSession s
9655+
INNER JOIN $tblSessionRelUser sru ON sru.session_id = s.id
9656+
WHERE
9657+
sru.user_id = '$userId' AND
9658+
sru.session_id = '$sessionId' AND
9659+
sru.relation_type = '".SESSION_RELATION_TYPE_RRHH."'";
9660+
}
9661+
9662+
$result = Database::query($sql);
9663+
9664+
return Database::num_rows($result) > 0;
9665+
}
96259666
}

0 commit comments

Comments
 (0)