Path: blob/master/src/applications/auth/xaction/PhabricatorAuthFactorProviderStatusTransaction.php
12256 views
<?php12final class PhabricatorAuthFactorProviderStatusTransaction3extends PhabricatorAuthFactorProviderTransactionType {45const TRANSACTIONTYPE = 'status';67public function generateOldValue($object) {8return $object->getStatus();9}1011public function applyInternalEffects($object, $value) {12$object->setStatus($value);13}1415public function getTitle() {16$old = $this->getOldValue();17$new = $this->getNewValue();1819$old_display = PhabricatorAuthFactorProviderStatus::newForStatus($old)20->getName();21$new_display = PhabricatorAuthFactorProviderStatus::newForStatus($new)22->getName();2324return pht(25'%s changed the status of this provider from %s to %s.',26$this->renderAuthor(),27$this->renderValue($old_display),28$this->renderValue($new_display));29}3031public function validateTransactions($object, array $xactions) {32$errors = array();33$actor = $this->getActor();3435$map = PhabricatorAuthFactorProviderStatus::getMap();36foreach ($xactions as $xaction) {37$new_value = $xaction->getNewValue();3839if (!isset($map[$new_value])) {40$errors[] = $this->newInvalidError(41pht(42'Status "%s" is invalid. Valid statuses are: %s.',43$new_value,44implode(', ', array_keys($map))),45$xaction);46continue;47}4849$require_key = 'security.require-multi-factor-auth';50$require_mfa = PhabricatorEnv::getEnvConfig($require_key);5152if ($require_mfa) {53$status_active = PhabricatorAuthFactorProviderStatus::STATUS_ACTIVE;54if ($new_value !== $status_active) {55$active_providers = id(new PhabricatorAuthFactorProviderQuery())56->setViewer($actor)57->withStatuses(58array(59$status_active,60))61->execute();62$active_providers = mpull($active_providers, null, 'getID');63unset($active_providers[$object->getID()]);6465if (!$active_providers) {66$errors[] = $this->newInvalidError(67pht(68'You can not deprecate or disable the last active MFA '.69'provider while "%s" is enabled, because new users would '.70'be unable to enroll in MFA. Disable the MFA requirement '.71'in Config, or create or enable another MFA provider first.',72$require_key));73continue;74}75}76}77}7879return $errors;80}8182public function didCommitTransaction($object, $value) {83$status = PhabricatorAuthFactorProviderStatus::newForStatus($value);8485// If a provider has undergone a status change, reset the MFA enrollment86// cache for all users. This may immediately force a lot of users to redo87// MFA enrollment.8889// We could be more surgical about this: we only really need to affect90// users who had a factor under the provider, and only really need to91// do anything if a provider was disabled. This is just a little simpler.9293$table = new PhabricatorUser();94$conn = $table->establishConnection('w');9596queryfx(97$conn,98'UPDATE %R SET isEnrolledInMultiFactor = 0',99$table);100}101102}103104105