Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phortune/editor/PhortuneAccountEditor.php
| Show All 22 Lines | final class PhortuneAccountEditor | ||||
| protected function validateTransaction( | protected function validateTransaction( | ||||
| PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
| $type, | $type, | ||||
| array $xactions) { | array $xactions) { | ||||
| $errors = parent::validateTransaction($object, $type, $xactions); | $errors = parent::validateTransaction($object, $type, $xactions); | ||||
| $viewer = $this->requireActor(); | |||||
| switch ($type) { | switch ($type) { | ||||
| case PhabricatorTransactions::TYPE_EDGE: | case PhabricatorTransactions::TYPE_EDGE: | ||||
| foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
| switch ($xaction->getMetadataValue('edge:type')) { | switch ($xaction->getMetadataValue('edge:type')) { | ||||
| case PhortuneAccountHasMemberEdgeType::EDGECONST: | case PhortuneAccountHasMemberEdgeType::EDGECONST: | ||||
| $actor_phid = $this->requireActor()->getPHID(); | |||||
| $new = $xaction->getNewValue(); | |||||
| $old = $object->getMemberPHIDs(); | $old = $object->getMemberPHIDs(); | ||||
| $new = $this->getPHIDTransactionNewValue($xaction, $old); | |||||
| // Check if user is trying to not set themselves on creation | $old = array_fuse($old); | ||||
| if (!$old) { | $new = array_fuse($new); | ||||
| $set = idx($new, '+', array()); | |||||
| $actor_set = false; | foreach ($new as $new_phid) { | ||||
| foreach ($set as $phid) { | if (isset($old[$new_phid])) { | ||||
| if ($actor_phid == $phid) { | continue; | ||||
| $actor_set = true; | |||||
| } | |||||
| } | } | ||||
| if (!$actor_set) { | |||||
| $user = id(new PhabricatorPeopleQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withPHIDs(array($new_phid)) | |||||
| ->executeOne(); | |||||
| if (!$user) { | |||||
| $error = new PhabricatorApplicationTransactionValidationError( | $error = new PhabricatorApplicationTransactionValidationError( | ||||
| $type, | $type, | ||||
| pht('Invalid'), | pht('Invalid'), | ||||
| pht('You can not remove yourself as an account manager.'), | pht( | ||||
| $xaction); | 'Account managers must be valid users, "%s" is not.', | ||||
| $new_phid)); | |||||
| $errors[] = $error; | $errors[] = $error; | ||||
| continue; | |||||
| } | } | ||||
| } | } | ||||
| // Check if user is trying to remove themselves on edit | $actor_phid = $this->getActingAsPHID(); | ||||
| $set = idx($new, '-', array()); | if (!isset($new[$actor_phid])) { | ||||
| foreach ($set as $phid) { | |||||
| if ($actor_phid == $phid) { | |||||
| $error = new PhabricatorApplicationTransactionValidationError( | $error = new PhabricatorApplicationTransactionValidationError( | ||||
| $type, | $type, | ||||
| pht('Invalid'), | pht('Invalid'), | ||||
| pht('You can not remove yourself as an account manager.'), | pht('You can not remove yourself as an account manager.'), | ||||
| $xaction); | $xaction); | ||||
| $errors[] = $error; | $errors[] = $error; | ||||
| } | |||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| return $errors; | return $errors; | ||||
| } | } | ||||
| } | } | ||||