* Check if the current state is compliant with MDM policy
()
| 60 | * Check if the current state is compliant with MDM policy |
| 61 | */ |
| 62 | public isCompliant(): ComplianceResult { |
| 63 | // If no MDM policy, always compliant |
| 64 | if (!this.requiresCloudAuth()) { |
| 65 | return { compliant: true } |
| 66 | } |
| 67 | |
| 68 | // Check if cloud service is available and has active or attempting session |
| 69 | if (!CloudService.hasInstance() || !CloudService.instance.hasOrIsAcquiringActiveSession()) { |
| 70 | return { |
| 71 | compliant: false, |
| 72 | reason: t("mdm.errors.cloud_auth_required"), |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | // Check organization match if specified |
| 77 | const requiredOrgId = this.getRequiredOrganizationId() |
| 78 | if (requiredOrgId) { |
| 79 | try { |
| 80 | // First try to get from active session |
| 81 | let currentOrgId = CloudService.instance.getOrganizationId() |
| 82 | |
| 83 | // If no active session, check stored credentials |
| 84 | if (!currentOrgId) { |
| 85 | const storedOrgId = CloudService.instance.getStoredOrganizationId() |
| 86 | |
| 87 | // null means personal account, which is not compliant for org requirements |
| 88 | if (storedOrgId === null || storedOrgId !== requiredOrgId) { |
| 89 | return { |
| 90 | compliant: false, |
| 91 | reason: t("mdm.errors.organization_mismatch"), |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | currentOrgId = storedOrgId |
| 96 | } |
| 97 | |
| 98 | if (currentOrgId !== requiredOrgId) { |
| 99 | return { |
| 100 | compliant: false, |
| 101 | reason: t("mdm.errors.organization_mismatch"), |
| 102 | } |
| 103 | } |
| 104 | } catch (error) { |
| 105 | this.log("[MDM] Error checking organization ID:", error) |
| 106 | return { |
| 107 | compliant: false, |
| 108 | reason: t("mdm.errors.verification_failed"), |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | return { compliant: true } |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Load MDM configuration from system location |
no test coverage detected