diff --git a/zmscitizenapi/src/Zmscitizenapi/Application.php b/zmscitizenapi/src/Zmscitizenapi/Application.php index f0ab59159..d4432a7c1 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Application.php +++ b/zmscitizenapi/src/Zmscitizenapi/Application.php @@ -68,6 +68,8 @@ class Application extends \BO\Slim\Application // IP Filter config public static string $IP_BLACKLIST; + public static string $ACCESS_UNPUBLISHED_ON_DOMAIN; + public static function initialize(): void { self::initializeMaintenanceMode(); @@ -153,6 +155,8 @@ private static function initializeMiddleware(): void // IP Filter self::$IP_BLACKLIST = getenv('IP_BLACKLIST') ?: ''; + + self::$ACCESS_UNPUBLISHED_ON_DOMAIN = getenv('ACCESS_UNPUBLISHED_ON_DOMAIN') ?: ''; } public static function reinitializeMiddlewareConfig(): void @@ -240,7 +244,10 @@ public static function getIpBlacklist(): string return self::$IP_BLACKLIST ?: ''; } - + public static function getAccessUnpublishedOnDomain(): ?string + { + return self::$ACCESS_UNPUBLISHED_ON_DOMAIN ?: null; + } } Application::initialize(); \ No newline at end of file diff --git a/zmscitizenapi/src/Zmscitizenapi/Controllers/Office/OfficesServicesRelationsController.php b/zmscitizenapi/src/Zmscitizenapi/Controllers/Office/OfficesServicesRelationsController.php index 0f25c7b42..c8dfea8df 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Controllers/Office/OfficesServicesRelationsController.php +++ b/zmscitizenapi/src/Zmscitizenapi/Controllers/Office/OfficesServicesRelationsController.php @@ -3,6 +3,7 @@ namespace BO\Zmscitizenapi\Controllers\Office; +use App; use BO\Zmscitizenapi\BaseController; use BO\Zmscitizenapi\Localization\ErrorMessages; use BO\Zmscitizenapi\Services\Office\OfficesServicesRelationsService; @@ -13,32 +14,37 @@ class OfficesServicesRelationsController extends BaseController { private OfficesServicesRelationsService $service; + private ?string $showUnpublishedOnDomain; public function __construct() { $this->service = new OfficesServicesRelationsService(); + $this->showUnpublishedOnDomain = App::getAccessUnpublishedOnDomain(); } public function readResponse(RequestInterface $request, ResponseInterface $response, array $args): ResponseInterface { - $requestErrors = ValidationService::validateServerGetRequest($request); - if (!empty($requestErrors['errors'])) { - return $this->createJsonResponse( - $response, - $requestErrors, - ErrorMessages::get('invalidRequest', $this->language)['statusCode'] - ); - } - - $result = $this->service->getServicesAndOfficesList(); - - return is_array($result) && isset($result['errors']) - ? $this->createJsonResponse( - $response, - $result, - ErrorMessages::getHighestStatusCode($result['errors']) - ) - : $this->createJsonResponse($response, $result->toArray(), 200); + $domain = $request->getUri()->getHost(); + $showUnpublished = !empty($this->showUnpublishedOnDomain) + && strpos($domain, $this->showUnpublishedOnDomain) !== false; + $requestErrors = ValidationService::validateServerGetRequest($request); + if (!empty($requestErrors['errors'])) { + return $this->createJsonResponse( + $response, + $requestErrors, + ErrorMessages::get('invalidRequest', $this->language)['statusCode'] + ); + } + + $result = $this->service->getServicesAndOfficesList($showUnpublished); + + return is_array($result) && isset($result['errors']) + ? $this->createJsonResponse( + $response, + $result, + ErrorMessages::getHighestStatusCode($result['errors']) + ) + : $this->createJsonResponse($response, $result->toArray(), 200); } } \ No newline at end of file diff --git a/zmscitizenapi/src/Zmscitizenapi/Services/Core/MapperService.php b/zmscitizenapi/src/Zmscitizenapi/Services/Core/MapperService.php index 4518c3ec1..4600cc703 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Services/Core/MapperService.php +++ b/zmscitizenapi/src/Zmscitizenapi/Services/Core/MapperService.php @@ -47,7 +47,7 @@ public static function mapScopeForProvider(int $providerId, ?ThinnedScopeList $s return $matchingScope; } - public static function mapOfficesWithScope(ProviderList $providerList): OfficeList + public static function mapOfficesWithScope(ProviderList $providerList, bool $showUnpublished = false): OfficeList { $offices = []; $scopes = ZmsApiFacadeService::getScopes(); @@ -58,7 +58,11 @@ public static function mapOfficesWithScope(ProviderList $providerList): OfficeLi foreach ($providerList as $provider) { $providerScope = self::mapScopeForProvider((int) $provider->id, $scopes); - + + if (! $showUnpublished && ! (bool) $provider->data['public']) { + continue; + } + $offices[] = new Office( id: isset($provider->id) ? (int) $provider->id : 0, name: isset($provider->displayName) ? $provider->displayName : (isset($provider->name) ? $provider->name : null), @@ -98,7 +102,10 @@ public static function mapCombinable(array $serviceCombinations): ?Combinable * @param RequestRelationList $relationList * @return ServiceList */ - public static function mapServicesWithCombinations(RequestList $requestList, RequestRelationList $relationList): ServiceList + public static function mapServicesWithCombinations( + RequestList $requestList, + RequestRelationList $relationList, + bool $showUnpublished = false): ServiceList { /** @var array> $servicesProviderIds */ $servicesProviderIds = []; @@ -118,7 +125,10 @@ public static function mapServicesWithCombinations(RequestList $requestList, Req }); foreach ($requestArray as $service) { - + if (! $showUnpublished && ! (bool) $service->getAdditionalData()['public']) { + continue; + } + /** @var array> $serviceCombinations */ $serviceCombinations = []; $combinableData = $service->getAdditionalData()['combinable'] ?? []; diff --git a/zmscitizenapi/src/Zmscitizenapi/Services/Core/ZmsApiFacadeService.php b/zmscitizenapi/src/Zmscitizenapi/Services/Core/ZmsApiFacadeService.php index f2dbb601f..20f68e80b 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Services/Core/ZmsApiFacadeService.php +++ b/zmscitizenapi/src/Zmscitizenapi/Services/Core/ZmsApiFacadeService.php @@ -139,14 +139,18 @@ public static function getServices(): ServiceList|array return new ServiceList($services); } - public static function getServicesAndOffices(): OfficeServiceAndRelationList|array + public static function getServicesAndOffices(bool $showUnpublished = false): OfficeServiceAndRelationList|array { $providerList = ZmsApiClientService::getOffices() ?? new ProviderList(); $requestList = ZmsApiClientService::getServices() ?? new RequestList(); $relationList = ZmsApiClientService::getRequestRelationList() ?? new RequestRelationList(); - $offices = MapperService::mapOfficesWithScope($providerList) ?? new OfficeList; - $services = MapperService::mapServicesWithCombinations($requestList, $relationList) ?? new ServiceList(); + $offices = MapperService::mapOfficesWithScope($providerList, $showUnpublished) ?? new OfficeList; + $services = MapperService::mapServicesWithCombinations( + $requestList, + $relationList, + $showUnpublished + ) ?? new ServiceList(); $relations = MapperService::mapRelations($relationList) ?? new OfficeServiceRelationList(); return new OfficeServiceAndRelationList($offices, $services, $relations); diff --git a/zmscitizenapi/src/Zmscitizenapi/Services/Office/OfficesServicesRelationsService.php b/zmscitizenapi/src/Zmscitizenapi/Services/Office/OfficesServicesRelationsService.php index e575c32f4..46002e179 100644 --- a/zmscitizenapi/src/Zmscitizenapi/Services/Office/OfficesServicesRelationsService.php +++ b/zmscitizenapi/src/Zmscitizenapi/Services/Office/OfficesServicesRelationsService.php @@ -8,13 +8,13 @@ class OfficesServicesRelationsService { - public function getServicesAndOfficesList(): OfficeServiceAndRelationList|array + public function getServicesAndOfficesList(bool $showUnpublished = false): OfficeServiceAndRelationList|array { - return $this->getServicesAndOffices(); + return $this->getServicesAndOffices($showUnpublished); } - private function getServicesAndOffices(): array|OfficeServiceAndRelationList + private function getServicesAndOffices(bool $showUnpublished): array|OfficeServiceAndRelationList { - return ZmsApiFacadeService::getServicesAndOffices(); + return ZmsApiFacadeService::getServicesAndOffices($showUnpublished); } } \ No newline at end of file