فهرست منبع

Fix issue where customers can see unverified tests

Alan Lam 2 سال پیش
والد
کامیت
47a8ff01fd
3فایلهای تغییر یافته به همراه21 افزوده شده و 6 حذف شده
  1. 8 3
      controllers/customer_ajax.php
  2. 4 2
      controllers/locations.php
  3. 9 1
      engine/searches/location_search.php

+ 8 - 3
controllers/customer_ajax.php

@@ -11,14 +11,19 @@ use Searches\LocationSearch;
 JSON::header();
 JSON::header();
 
 
 $customer = Customer::get($id);
 $customer = Customer::get($id);
-if(!$customer) JSON::fail("Customer not found.");
+if(!$customer) {
+	JSON::fail("Customer not found.");
+}
 
 
-if(!Core::$user->hasPermission($customer)) throw new Exception(__("No permission."));
+$user = Core::$user;
+if(!$user->hasPermission($customer)) {
+	throw new RuntimeException(__("No permission."));
+}
 
 
 switch($action) {
 switch($action) {
 	case "get-locations":
 	case "get-locations":
 
 
-		$search = new LocationSearch($customer);
+		$search = new LocationSearch($customer, $user);
 
 
 		$id = http::value("id", "int");
 		$id = http::value("id", "int");
 		$internal_id = http::value("internal_id", "trim");
 		$internal_id = http::value("internal_id", "trim");

+ 4 - 2
controllers/locations.php

@@ -11,9 +11,11 @@ Core::addBreadcrumb("/account/locations", "Locations");
 
 
 $customer = Customer::getForAdmin();
 $customer = Customer::getForAdmin();
 if(!$customer) {
 if(!$customer) {
-	throw new Exception("You do not have permission to access this page.");
+	throw new RuntimeException("You do not have permission to access this page.");
 }
 }
 
 
+$user = Core::$user;
+
 $customer_slug = Util::slug($customer->name);
 $customer_slug = Util::slug($customer->name);
 
 
 $sorts = [
 $sorts = [
@@ -42,7 +44,7 @@ $nvp = [
 	"closed" => 0,
 	"closed" => 0,
 ];
 ];
 
 
-$search = new LocationSearch($customer);
+$search = new LocationSearch($customer, $user);
 
 
 $id = http::value("id", "int");
 $id = http::value("id", "int");
 $search->setId($id);
 $search->setId($id);

+ 9 - 1
engine/searches/location_search.php

@@ -7,10 +7,13 @@ use Customer;
 use DB;
 use DB;
 use Location;
 use Location;
 use Test;
 use Test;
+use User;
 
 
 class LocationSearch {
 class LocationSearch {
 
 
 	private Customer $customer;
 	private Customer $customer;
+	private ?User $user = null;
+
 	private ?int $id = null;
 	private ?int $id = null;
 	private ?array $ids = null;
 	private ?array $ids = null;
 	private ?string $internalId = null;
 	private ?string $internalId = null;
@@ -28,8 +31,9 @@ class LocationSearch {
 	/** @var Test[] */
 	/** @var Test[] */
 	private array $allTests = [];
 	private array $allTests = [];
 
 
-	public function __construct(Customer $customer) {
+	public function __construct(Customer $customer, ?User $user) {
 		$this->customer = $customer;
 		$this->customer = $customer;
+		$this->user = $user;
 	}
 	}
 
 
 	public function getId(): ?int {
 	public function getId(): ?int {
@@ -138,6 +142,10 @@ class LocationSearch {
 			"location_id" => array_column($locations, "id")
 			"location_id" => array_column($locations, "id")
 		];
 		];
 
 
+		if($this->user && $this->user->level <= User::LEVEL_CUSTOMER) {
+			$base_test_nvp["status"] = Test::STATUS_COMPLETED;
+		}
+
 		$this->populateAllTests($base_test_nvp);
 		$this->populateAllTests($base_test_nvp);
 		$this->populateLiveTests($base_test_nvp);
 		$this->populateLiveTests($base_test_nvp);