瀏覽代碼

Update permissions

jmontoyaa 7 年之前
父節點
當前提交
5fa816b1ad
共有 1 個文件被更改,包括 37 次插入28 次删除
  1. 37 28
      plugin/studentfollowup/StudentFollowUpPlugin.php

+ 37 - 28
plugin/studentfollowup/StudentFollowUpPlugin.php

@@ -106,6 +106,12 @@ class StudentFollowUpPlugin extends Plugin
         } else {
             $isDrh = api_is_drh();
             $isCareTaker = false;
+            $isDrhRelatedViaPost = false;
+            $isCourseCoach = false;
+            $isDrhRelatedToSession = false;
+
+            // Only admins and DRH that follow the user
+            $isAdmin = api_is_platform_admin();
 
             // Check if user is care taker
             if ($isDrh) {
@@ -113,42 +119,45 @@ class StudentFollowUpPlugin extends Plugin
                     'user' => $studentId,
                     'insertUser' => $currentUserId
                 ];
-
-                $post = Database::getManager()->getRepository('ChamiloPluginBundle:StudentFollowUp\CarePost')->findOneBy($criteria);
+                $repo = Database::getManager()->getRepository('ChamiloPluginBundle:StudentFollowUp\CarePost');
+                $post = $repo->findOneBy($criteria);
                 if ($post) {
-                    $isCareTaker = true;
+                    $isDrhRelatedViaPost = true;
                 }
-            }
-
-            // Only admins and DRH that follow the user
-            $isAdmin = api_is_platform_admin();
 
-            // Check if course session coach
-            $sessions = SessionManager::get_sessions_by_user($studentId);
-
-            $isCourseCoach = false;
-            $isDrhSession = false;
-            if (!empty($sessions)) {
-                foreach ($sessions as $session) {
-                    $sessionId = $session['session_id'];
-                    $sessionDrhInfo = SessionManager::getSessionFollowedByDrh($currentUserId, $sessionId);
-                    if (!empty($sessionDrhInfo)) {
-                        $isDrhSession = true;
-                        break;
-                    }
-                    foreach ($session['courses'] as $course) {
-                        //$isCourseCoach = api_is_coach($sessionId, $course['real_id']);
-                        $coachList = SessionManager::getCoachesByCourseSession($sessionId, $course['real_id']);
-                        if (!empty($coachList) && in_array($currentUserId, $coachList)) {
-                            $isCourseCoach = true;
-                            break(2);
+                // Check if course session coach
+                $sessions = SessionManager::get_sessions_by_user($studentId);
+
+                if (!empty($sessions)) {
+                    foreach ($sessions as $session) {
+                        $sessionId = $session['session_id'];
+                        $sessionDrhInfo = SessionManager::getSessionFollowedByDrh(
+                            $currentUserId,
+                            $sessionId
+                        );
+                        if (!empty($sessionDrhInfo)) {
+                            $isDrhRelatedToSession = true;
+                            break;
+                        }
+                        foreach ($session['courses'] as $course) {
+                            //$isCourseCoach = api_is_coach($sessionId, $course['real_id']);
+                            $coachList = SessionManager::getCoachesByCourseSession(
+                                $sessionId,
+                                $course['real_id']
+                            );
+                            if (!empty($coachList) && in_array($currentUserId, $coachList)) {
+                                $isCourseCoach = true;
+                                break(2);
+                            }
                         }
                     }
                 }
+
+                $isCareTaker = $isDrhRelatedViaPost && $isDrhRelatedToSession;
             }
 
-            $isAllow = $isAdmin || $isDrhSession || $isCourseCoach;
-            $showPrivate = $isAdmin || ($isDrhSession && $isCareTaker);
+            $isAllow = $isAdmin || $isCareTaker || $isDrhRelatedToSession || $isCourseCoach;
+            $showPrivate = $isAdmin || $isCareTaker;
         }
 
         return [