Переглянути джерело

Limit pros in list/search according to authedPro->[can_see_any_client_via_search, can_see_all_clients_in_list]

Vijayakrishnan 4 роки тому
батько
коміт
5c3ccb0d3f
2 змінених файлів з 6 додано та 6 видалено
  1. 2 2
      app/Http/Controllers/HomeController.php
  2. 4 4
      app/Models/Pro.php

+ 2 - 2
app/Http/Controllers/HomeController.php

@@ -596,9 +596,9 @@ WHERE measurement.label NOT IN ('SBP', 'DBP')
                     ->orWhere('cell_number', 'ILIKE', '%' . $term . '%');
             });
 
-        if($pro->pro_type != 'ADMIN') {
+        if(!($pro->pro_type === 'ADMIN' && $pro->can_see_any_client_via_search)) {
             $clientQuery->where(function ($q) use ($pro) {
-                $q->whereIn('id', $pro->getMyClientIds())
+                $q->whereIn('id', $pro->getMyClientIds(true))
                     ->orWhereNull('mcp_pro_id');
             });
         }

+ 4 - 4
app/Models/Pro.php

@@ -260,8 +260,8 @@ class Pro extends Model
 
     }
 
-    public function getMyClientIds() {
-        $clients = $this->getAccessibleClientsQuery()->get();
+    public function getMyClientIds($_search = false) {
+        $clients = $this->getAccessibleClientsQuery($_search)->get();
         $clientIds = [];
         foreach($clients as $client){
             $clientIds[] = $client->id;
@@ -278,10 +278,10 @@ class Pro extends Model
             ->get();
     }
 
-    public function getAccessibleClientsQuery() {
+    public function getAccessibleClientsQuery($_search = false) {
         $proID = $this->id;
         $query = Client::whereNull('shadow_pro_id');
-        if ($this->pro_type === 'ADMIN') {
+        if ($this->pro_type === 'ADMIN' && ($_search ? $this->can_see_any_client_via_search : $this->can_see_all_clients_in_list)) {
             $query = $query->where('id', '>', 0);
         } else {
             $query = $query->where(function ($q) use ($proID) {