Skip to content

Commit

Permalink
feat(ZMS-3429): show not public providers and services for specific d…
Browse files Browse the repository at this point in the history
…omain
  • Loading branch information
manjencic committed Jan 29, 2025
1 parent 21a1b2f commit be17ecc
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 30 deletions.
9 changes: 8 additions & 1 deletion zmscitizenapi/src/Zmscitizenapi/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

}
}
18 changes: 14 additions & 4 deletions zmscitizenapi/src/Zmscitizenapi/Services/Core/MapperService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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),
Expand Down Expand Up @@ -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<string, array<int>> $servicesProviderIds */
$servicesProviderIds = [];
Expand All @@ -118,7 +125,10 @@ public static function mapServicesWithCombinations(RequestList $requestList, Req
});

foreach ($requestArray as $service) {

if (! $showUnpublished && ! (bool) $service->getAdditionalData()['public']) {
continue;
}

/** @var array<string, array<int>> $serviceCombinations */
$serviceCombinations = [];
$combinableData = $service->getAdditionalData()['combinable'] ?? [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit be17ecc

Please sign in to comment.