From bac84c4c1e2fd571f51179597bc15e7023dc0ac2 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Wed, 20 May 2026 11:22:35 +0100 Subject: [PATCH] refactor(policies): export via per-policy SDK methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The /v1/project response doesn't expose per-policy fields at the top level — they live inside the project document's `auths` attribute which the public Project response model omits. Switch from a raw `GET /v1/project` call to per-policy SDK methods (Project::getPolicy(ProjectPolicyId::*)) which return typed policy models (PolicyPasswordHistory, PolicySessionAlert, etc.). Each of the 9 sub-policies maps to one method call. --- src/Migration/Sources/Appwrite.php | 66 +++++++++++++++++++----------- 1 file changed, 43 insertions(+), 23 deletions(-) diff --git a/src/Migration/Sources/Appwrite.php b/src/Migration/Sources/Appwrite.php index 413bfc6d26..fcea1bb09d 100644 --- a/src/Migration/Sources/Appwrite.php +++ b/src/Migration/Sources/Appwrite.php @@ -4,6 +4,7 @@ namespace Utopia\Migration\Sources; use Appwrite\AppwriteException; use Appwrite\Client; +use Appwrite\Enums\ProjectPolicyId; use Appwrite\Query; use Appwrite\Services\Functions; use Appwrite\Services\Messaging; @@ -650,35 +651,54 @@ class Appwrite extends Source } /** - * Read project security policies from /v1/project. 9 sub-policies collapse - * into a single Policies resource carrying 13 fields (MembershipPrivacy - * alone has 5 sub-flags). + * Read project security policies via the per-policy SDK endpoints. + * + * The /v1/project response doesn't expose the per-policy fields at the + * top level — they live inside the project document's `auths` attribute + * which the public Project response model omits. The dedicated per-policy + * SDK methods read each policy individually and return per-policy typed + * models (PolicyPasswordHistory, PolicySessionAlert, etc.), avoiding the + * Project response model entirely. + * + * 9 single-policy reads collapse into one Policies resource carrying 13 + * fields (MembershipPrivacy alone has 5 sub-flags). */ private function exportPolicies(): void { - $response = $this->call('GET', '/project'); - - if (!\is_array($response)) { - return; - } + /** @var \Appwrite\Models\PolicyPasswordHistory $passwordHistory */ + $passwordHistory = $this->project->getPolicy(ProjectPolicyId::PASSWORDHISTORY()); + /** @var \Appwrite\Models\PolicyPasswordDictionary $passwordDictionary */ + $passwordDictionary = $this->project->getPolicy(ProjectPolicyId::PASSWORDDICTIONARY()); + /** @var \Appwrite\Models\PolicyPasswordPersonalData $passwordPersonalData */ + $passwordPersonalData = $this->project->getPolicy(ProjectPolicyId::PASSWORDPERSONALDATA()); + /** @var \Appwrite\Models\PolicySessionAlert $sessionAlert */ + $sessionAlert = $this->project->getPolicy(ProjectPolicyId::SESSIONALERT()); + /** @var \Appwrite\Models\PolicySessionDuration $sessionDuration */ + $sessionDuration = $this->project->getPolicy(ProjectPolicyId::SESSIONDURATION()); + /** @var \Appwrite\Models\PolicySessionInvalidation $sessionInvalidation */ + $sessionInvalidation = $this->project->getPolicy(ProjectPolicyId::SESSIONINVALIDATION()); + /** @var \Appwrite\Models\PolicySessionLimit $sessionLimit */ + $sessionLimit = $this->project->getPolicy(ProjectPolicyId::SESSIONLIMIT()); + /** @var \Appwrite\Models\PolicyUserLimit $userLimit */ + $userLimit = $this->project->getPolicy(ProjectPolicyId::USERLIMIT()); + /** @var \Appwrite\Models\PolicyMembershipPrivacy $membershipPrivacy */ + $membershipPrivacy = $this->project->getPolicy(ProjectPolicyId::MEMBERSHIPPRIVACY()); $policies = new Policies( $this->projectId, - (int) ($response['authPasswordHistory'] ?? 0), - (int) ($response['authDuration'] ?? 31536000), - (int) ($response['authSessionsLimit'] ?? 100), - (int) ($response['authLimit'] ?? 0), - (bool) ($response['authPasswordDictionary'] ?? false), - (bool) ($response['authPersonalDataCheck'] ?? false), - (bool) ($response['authSessionAlerts'] ?? false), - (bool) ($response['authInvalidateSessions'] ?? false), - (bool) ($response['authMembershipsUserId'] ?? true), - (bool) ($response['authMembershipsUserEmail'] ?? true), - (bool) ($response['authMembershipsUserName'] ?? true), - (bool) ($response['authMembershipsMfa'] ?? true), - (bool) ($response['authMembershipsUserPhone'] ?? true), - createdAt: $response['$createdAt'] ?? '', - updatedAt: $response['$updatedAt'] ?? '', + $passwordHistory->total, + $sessionDuration->duration, + $sessionLimit->total, + $userLimit->total, + $passwordDictionary->enabled, + $passwordPersonalData->enabled, + $sessionAlert->enabled, + $sessionInvalidation->enabled, + $membershipPrivacy->userId, + $membershipPrivacy->userEmail, + $membershipPrivacy->userName, + $membershipPrivacy->userMFA, + $membershipPrivacy->userPhone, ); $this->callback([$policies]);