Explorar o código

Merge branch 'hotfix/customer-locations' into develop

Alan Lam %!s(int64=2) %!d(string=hai) anos
pai
achega
6254a919e4

+ 9 - 4
controllers/customer_ajax.php

@@ -11,14 +11,19 @@ use Searches\LocationSearch;
 JSON::header();
 
 $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) {
 	case "get-locations":
 
-		$search = new LocationSearch($customer);
+		$search = new LocationSearch($customer, $user);
 
 		$id = http::value("id", "int");
 		$internal_id = http::value("internal_id", "trim");
@@ -42,7 +47,7 @@ switch($action) {
 
 		$locations = $search->run();
 
-		$output = LocationHelper::getMarkerDataForLocations($locations, $min_date, $max_date);
+		$output = LocationHelper::getMarkerDataForLocations($locations, $min_date, $max_date, ["user" => $user]);
 
 		JSON::success([
 			"locations" => $output

+ 4 - 2
controllers/locations.php

@@ -11,9 +11,11 @@ Core::addBreadcrumb("/account/locations", "Locations");
 
 $customer = Customer::getForAdmin();
 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);
 
 $sorts = [
@@ -42,7 +44,7 @@ $nvp = [
 	"closed" => 0,
 ];
 
-$search = new LocationSearch($customer);
+$search = new LocationSearch($customer, $user);
 
 $id = http::value("id", "int");
 $search->setId($id);

+ 3 - 1
controllers/map_overview_ajax.php

@@ -8,6 +8,8 @@ use Helpers\LocationHelper;
 
 $date_format = "/^2\d{3}-[01]\d-[0-3]\d$/";
 
+$user = Core::$user;
+
 JSON::header();
 
 $submit = http::value("submit");
@@ -17,7 +19,7 @@ if($submit) {
 
 		Core::validateCSRFToken($submit);
 
-		$options = [];
+		$options = ["user" => $user];
 
 		$filter = http::value("filter");
 		if($filter === "untested-only") {

+ 5 - 0
engine/helpers/location_helper.php

@@ -29,6 +29,7 @@ class LocationHelper {
 
 		$failed_only = $options["failed_only"] ?? false;
 		$untested_only = $options["untested_only"] ?? false;
+		$user = $options["user"] ?? null;
 
 		$location = reset($locations);
 
@@ -54,6 +55,10 @@ class LocationHelper {
 			"location_id" => array_column($locations, "id")
 		];
 
+		if($user && $user->level <= User::LEVEL_CUSTOMER) {
+			$nvp["status"] = Test::STATUS_COMPLETED;
+		}
+
 		if($min_date && $max_date) {
 			if(preg_match(self::DATE_FORMAT, $min_date) && preg_match(self::DATE_FORMAT, $max_date)) {
 				$min_dts = $min_date;

+ 9 - 1
engine/searches/location_search.php

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