From c1e9801ba1a2df61dddd99e39382a526ef8b1e5d Mon Sep 17 00:00:00 2001 From: Matt Smithies Date: Wed, 27 Nov 2024 15:22:37 +0000 Subject: [PATCH 1/4] Update PolicyService.php --- src/Service/PolicyService.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Service/PolicyService.php b/src/Service/PolicyService.php index 46a148c..70629fb 100644 --- a/src/Service/PolicyService.php +++ b/src/Service/PolicyService.php @@ -3,6 +3,7 @@ namespace Dovu\GuardianPhpSdk\Service; use Dovu\GuardianPhpSdk\Domain\GuardianToken; +use Dovu\GuardianPhpSdk\Domain\TaskInstance; use Exception; class PolicyService extends AbstractService @@ -17,6 +18,23 @@ public function get($id): object return (object) $this->httpClient->get("policies/{$id}")->data(); } + public function publish($id, $version): object + { + return (object) $this->httpClient->put("policies/push/{$id}/publish", [ + 'policyVersion' => $version, + ])->data(); + } + + public function publishSync(callable $callback, string $id, string $version): TaskInstance + { + $callback($id, $version); + + $import = TaskInstance::from($this->publish($id, $version)); + + return $this->runnerTask($import, $callback); + } + + public function assign(string $username, string $policy_id, bool $assign = true): object { $payload = [ From 8790c420e29ca0a5cf15c6f9857d47e178a5fbdb Mon Sep 17 00:00:00 2001 From: Matt Smithies Date: Wed, 27 Nov 2024 15:22:43 +0000 Subject: [PATCH 2/4] Update PolicyMode.php --- src/Support/PolicyMode.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Support/PolicyMode.php b/src/Support/PolicyMode.php index 098f267..210b9e4 100644 --- a/src/Support/PolicyMode.php +++ b/src/Support/PolicyMode.php @@ -2,6 +2,8 @@ namespace Dovu\GuardianPhpSdk\Support; +use Dovu\GuardianPhpSdk\Domain\TaskInstance; + enum PolicyStatus: string { case DRAFT = 'DRAFT'; @@ -23,10 +25,9 @@ public static function context(PolicyContext $context): self return new self($context); } - // TODO: Implement later to publish - public function publish() + public function publishVersion(callable $callback, string $version): TaskInstance { - + return $this->context->policies->publishSync($callback, $this->context->policyId, $version); } public function dryRun() From a6958435a5140ae205d9595ac6dc43d3d4893e75 Mon Sep 17 00:00:00 2001 From: Matt Smithies Date: Wed, 27 Nov 2024 15:23:14 +0000 Subject: [PATCH 3/4] Update ResearchElvClientGuardianTest.php --- tests/ResearchElvClientGuardianTest.php | 42 ++++++++++++++++++------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/tests/ResearchElvClientGuardianTest.php b/tests/ResearchElvClientGuardianTest.php index f7d9d1c..d390d57 100644 --- a/tests/ResearchElvClientGuardianTest.php +++ b/tests/ResearchElvClientGuardianTest.php @@ -6,7 +6,6 @@ use Dovu\GuardianPhpSdk\Constants\GuardianApprovalOption; use Dovu\GuardianPhpSdk\Constants\GuardianRole; use Dovu\GuardianPhpSdk\Domain\PolicySchemaDocument; -use Dovu\GuardianPhpSdk\Domain\Trustchain; use Dovu\GuardianPhpSdk\Domain\TrustchainQuery; use Dovu\GuardianPhpSdk\DovuGuardianAPI; use Dovu\GuardianPhpSdk\Support\DryRunScenario; @@ -125,11 +124,6 @@ $policy_id = $config->get(Env::POLICY_ID); - // TODO: Remove. mmcm elv -// $policy_id = "66b5e1e76efceb6b593efa73"; -// $policy_id = "66c616cc6efceb6b593f08de"; -// $policy_id = $config->testLocalPolicy(); - $context = PolicyContext::using($this->sdk)->for($policy_id); $this->helper = new GuardianSDKHelper($this->sdk, $policy_id); @@ -214,6 +208,28 @@ })->skip(); + it('A policy can be published', function () { + + $this->helper->authenticateAsRegistry(); + + expect($this->policy_mode->hasPolicyStatus(PolicyStatus::DRAFT) + || $this->policy_mode->hasPolicyStatus(PolicyStatus::DRY_RUN))->toBeTruthy(); + + + $publish_fn = function ($state) { + ray("Publish progress"); + ray($state); + + expect($state)->toBeTruthy(); + }; + + + $publish = $this->policy_mode->publishVersion($publish_fn, '1'); + + expect($publish->result['isValid'])->toBeTrue(); + + })->skip("Publish testing for local dev, currently."); + it('A policy can create users and view them in dry run', function () { $this->helper->authenticateAsRegistry(); @@ -527,6 +543,8 @@ $token = $this->sdk->policies->token($policy_id); + ray($token); + expect($token->hasValidToken())->toBeBool(); expect($token->id())->toBeTruthy(); @@ -537,7 +555,7 @@ expect($token->hasValidToken())->toBeTruthy(); expect($token->id())->toBeFalsy(); - }); + })->skip(); it('Fetch a specification of a schema for workflow import and validation', function () { @@ -610,9 +628,11 @@ expect($timestamp)->toBeTruthy(); // When something happens, complete - $status_update_callable = function ($state) { - ray("Status update"); - ray($state); + $status_update_callable = function ($state) use ($registry_user, $password) { + + $this->helper->authenticateAsRegistry($registry_user, $password); + + ray("Status Import Update"); if ($state->result) { ray("done"); @@ -793,7 +813,7 @@ ->setApprovalOption(ApprovalOption::APPROVE) ->setFilterValue($claim['uuid']) ->run(); - + ray('$approve_claim'); ray($result); From ed2370f12fd12ade7c6d287571f632ea050db314 Mon Sep 17 00:00:00 2001 From: mattsmithies Date: Wed, 27 Nov 2024 15:23:34 +0000 Subject: [PATCH 4/4] Fix styling --- src/Domain/CredentialDocumentBlock.php | 3 ++- src/Domain/GuardianToken.php | 5 ++--- src/Domain/TrustchainQuery.php | 2 +- src/Service/PolicyService.php | 2 -- tests/ResearchElvClientGuardianTest.php | 6 +++--- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Domain/CredentialDocumentBlock.php b/src/Domain/CredentialDocumentBlock.php index b010cab..8b6e806 100644 --- a/src/Domain/CredentialDocumentBlock.php +++ b/src/Domain/CredentialDocumentBlock.php @@ -32,7 +32,8 @@ public function __construct(object $block_data, EntityStatus $entityStatus = nul $this->credential_subject = $this->checkForOptionalSubject(); } - private function checkForOptionalSubject() : null|object { + private function checkForOptionalSubject(): null|object + { return array_key_exists('document', $this->block_data) ? (object) $this->block_data['document']['credentialSubject']['0'] : null; diff --git a/src/Domain/GuardianToken.php b/src/Domain/GuardianToken.php index 116cec6..96feaea 100644 --- a/src/Domain/GuardianToken.php +++ b/src/Domain/GuardianToken.php @@ -12,11 +12,10 @@ public static function none(): self { return new self((object) [ "adminId" => null, - "tokenId" => "" + "tokenId" => "", ]); } - /** * When "adminId" from parent obj is falsely then ignore "id()" fn in client. * @@ -26,7 +25,7 @@ public static function none(): self */ public function isTokenPublished(): bool { - return !! $this->token->adminId; + return ! ! $this->token->adminId; } public function id(): string diff --git a/src/Domain/TrustchainQuery.php b/src/Domain/TrustchainQuery.php index 73a3743..3788a1a 100644 --- a/src/Domain/TrustchainQuery.php +++ b/src/Domain/TrustchainQuery.php @@ -68,6 +68,6 @@ public function withResult(?CredentialDocumentBlock $result): self public function hasTrustchainResult(): bool { - return !! $this->result; + return ! ! $this->result; } } diff --git a/src/Service/PolicyService.php b/src/Service/PolicyService.php index 70629fb..b423cd3 100644 --- a/src/Service/PolicyService.php +++ b/src/Service/PolicyService.php @@ -4,7 +4,6 @@ use Dovu\GuardianPhpSdk\Domain\GuardianToken; use Dovu\GuardianPhpSdk\Domain\TaskInstance; -use Exception; class PolicyService extends AbstractService { @@ -34,7 +33,6 @@ public function publishSync(callable $callback, string $id, string $version): Ta return $this->runnerTask($import, $callback); } - public function assign(string $username, string $policy_id, bool $assign = true): object { $payload = [ diff --git a/tests/ResearchElvClientGuardianTest.php b/tests/ResearchElvClientGuardianTest.php index d390d57..1d16ed9 100644 --- a/tests/ResearchElvClientGuardianTest.php +++ b/tests/ResearchElvClientGuardianTest.php @@ -115,7 +115,7 @@ describe('Functional Guardian Test', function () { beforeEach(function () { $this->sdk = new DovuGuardianAPI(); -// $this->sdk->setGuardianBaseUrl("http://localhost:3000/api/v1/"); + // $this->sdk->setGuardianBaseUrl("http://localhost:3000/api/v1/"); $config = EnvConfig::instance(); @@ -530,7 +530,7 @@ expect($response->hasTrustchainResult())->toBeTruthy(); // TODO: WORK IN PROGRESS -// ray($trustchain->format()); + // ray($trustchain->format()); })->skip(); it('An admin can get the token for a policy', function () { @@ -675,7 +675,7 @@ * 3. Update the context objects with the correct uploaded "registry" user and imported policy id. */ -// $this->policy_mode->dryRun(); + // $this->policy_mode->dryRun(); /** * Create mediator object.