Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2893164
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
5 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/applications/phortune/__tests__/PhabricatorPhortuneTestCase.php b/src/applications/phortune/__tests__/PhabricatorPhortuneTestCase.php
index b4d6a0e89d..7be37483be 100644
--- a/src/applications/phortune/__tests__/PhabricatorPhortuneTestCase.php
+++ b/src/applications/phortune/__tests__/PhabricatorPhortuneTestCase.php
@@ -1,26 +1,43 @@
<?php
final class PhabricatorPhortuneTestCase
extends PhabricatorTestCase {
protected function getPhabricatorTestCaseConfiguration() {
return array(
self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
);
}
public function testNewPhortuneAccount() {
$user = $this->generateNewTestUser();
$content_source = $this->newContentSource();
$accounts = PhortuneAccountQuery::loadAccountsForUser(
$user,
$content_source);
$this->assertEqual(
1,
count($accounts),
pht('Creation of default account for users with no accounts.'));
+
+ // Reload the account. The user should be able to view and edit it, and
+ // should be a member.
+
+ $account = head($accounts);
+ $account = id(new PhortuneAccountQuery())
+ ->setViewer($user)
+ ->withPHIDs(array($account->getPHID()))
+ ->requireCapabilities(
+ array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ PhabricatorPolicyCapability::CAN_EDIT,
+ ))
+ ->executeOne();
+
+ $this->assertEqual(true, ($account instanceof PhortuneAccount));
+ $this->assertEqual(array($user->getPHID()), $account->getMemberPHIDs());
}
}
diff --git a/src/applications/phortune/editor/PhortuneAccountEditor.php b/src/applications/phortune/editor/PhortuneAccountEditor.php
index 8672c62417..50a71c476f 100644
--- a/src/applications/phortune/editor/PhortuneAccountEditor.php
+++ b/src/applications/phortune/editor/PhortuneAccountEditor.php
@@ -1,81 +1,82 @@
<?php
final class PhortuneAccountEditor
extends PhabricatorApplicationTransactionEditor {
public function getEditorApplicationClass() {
return 'PhabricatorPhortuneApplication';
}
public function getEditorObjectsDescription() {
return pht('Phortune Accounts');
}
public function getCreateObjectTitle($author, $object) {
return pht('%s created this payment account.', $author);
}
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_EDGE;
return $types;
}
protected function validateTransaction(
PhabricatorLiskDAO $object,
$type,
array $xactions) {
$errors = parent::validateTransaction($object, $type, $xactions);
+ $viewer = $this->requireActor();
+
switch ($type) {
case PhabricatorTransactions::TYPE_EDGE:
foreach ($xactions as $xaction) {
switch ($xaction->getMetadataValue('edge:type')) {
case PhortuneAccountHasMemberEdgeType::EDGECONST:
- $actor_phid = $this->requireActor()->getPHID();
- $new = $xaction->getNewValue();
$old = $object->getMemberPHIDs();
+ $new = $this->getPHIDTransactionNewValue($xaction, $old);
- // Check if user is trying to not set themselves on creation
- if (!$old) {
- $set = idx($new, '+', array());
- $actor_set = false;
- foreach ($set as $phid) {
- if ($actor_phid == $phid) {
- $actor_set = true;
- }
- }
- if (!$actor_set) {
- $error = new PhabricatorApplicationTransactionValidationError(
- $type,
- pht('Invalid'),
- pht('You can not remove yourself as an account manager.'),
- $xaction);
- $errors[] = $error;
+ $old = array_fuse($old);
+ $new = array_fuse($new);
+ foreach ($new as $new_phid) {
+ if (isset($old[$new_phid])) {
+ continue;
}
- }
- // Check if user is trying to remove themselves on edit
- $set = idx($new, '-', array());
- foreach ($set as $phid) {
- if ($actor_phid == $phid) {
+ $user = id(new PhabricatorPeopleQuery())
+ ->setViewer($viewer)
+ ->withPHIDs(array($new_phid))
+ ->executeOne();
+ if (!$user) {
$error = new PhabricatorApplicationTransactionValidationError(
$type,
pht('Invalid'),
- pht('You can not remove yourself as an account manager.'),
- $xaction);
+ pht(
+ 'Account managers must be valid users, "%s" is not.',
+ $new_phid));
$errors[] = $error;
-
+ continue;
}
}
+
+ $actor_phid = $this->getActingAsPHID();
+ if (!isset($new[$actor_phid])) {
+ $error = new PhabricatorApplicationTransactionValidationError(
+ $type,
+ pht('Invalid'),
+ pht('You can not remove yourself as an account manager.'),
+ $xaction);
+ $errors[] = $error;
+ }
break;
}
}
break;
}
return $errors;
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Jan 19, 17:58 (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1127199
Default Alt Text
(5 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment