Page MenuHomePhabricator

D17685.id42557.diff
No OneTemporary

D17685.id42557.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -321,6 +321,7 @@
'ConpherenceThreadListView' => 'applications/conpherence/view/ConpherenceThreadListView.php',
'ConpherenceThreadMailReceiver' => 'applications/conpherence/mail/ConpherenceThreadMailReceiver.php',
'ConpherenceThreadMembersPolicyRule' => 'applications/conpherence/policyrule/ConpherenceThreadMembersPolicyRule.php',
+ 'ConpherenceThreadParticipantsTransaction' => 'applications/conpherence/xaction/ConpherenceThreadParticipantsTransaction.php',
'ConpherenceThreadPictureTransaction' => 'applications/conpherence/xaction/ConpherenceThreadPictureTransaction.php',
'ConpherenceThreadQuery' => 'applications/conpherence/query/ConpherenceThreadQuery.php',
'ConpherenceThreadRemarkupRule' => 'applications/conpherence/remarkup/ConpherenceThreadRemarkupRule.php',
@@ -5113,6 +5114,7 @@
'ConpherenceThreadListView' => 'AphrontView',
'ConpherenceThreadMailReceiver' => 'PhabricatorObjectMailReceiver',
'ConpherenceThreadMembersPolicyRule' => 'PhabricatorPolicyRule',
+ 'ConpherenceThreadParticipantsTransaction' => 'ConpherenceThreadTransactionType',
'ConpherenceThreadPictureTransaction' => 'ConpherenceThreadTransactionType',
'ConpherenceThreadQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'ConpherenceThreadRemarkupRule' => 'PhabricatorObjectRemarkupRule',
diff --git a/src/applications/conpherence/__tests__/ConpherenceRoomTestCase.php b/src/applications/conpherence/__tests__/ConpherenceRoomTestCase.php
--- a/src/applications/conpherence/__tests__/ConpherenceRoomTestCase.php
+++ b/src/applications/conpherence/__tests__/ConpherenceRoomTestCase.php
@@ -107,7 +107,8 @@
$xactions = array();
$xactions[] = id(new ConpherenceTransaction())
- ->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)
+ ->setTransactionType(
+ ConpherenceThreadParticipantsTransaction::TRANSACTIONTYPE)
->setNewValue(array('+' => $participant_phids));
$xactions[] = id(new ConpherenceTransaction())
->setTransactionType(
diff --git a/src/applications/conpherence/__tests__/ConpherenceTestCase.php b/src/applications/conpherence/__tests__/ConpherenceTestCase.php
--- a/src/applications/conpherence/__tests__/ConpherenceTestCase.php
+++ b/src/applications/conpherence/__tests__/ConpherenceTestCase.php
@@ -9,7 +9,8 @@
$xactions = array(
id(new ConpherenceTransaction())
- ->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)
+ ->setTransactionType(
+ ConpherenceThreadParticipantsTransaction::TRANSACTIONTYPE)
->setNewValue(array('+' => $participant_phids)),
);
$editor = id(new ConpherenceEditor())
@@ -26,7 +27,8 @@
$xactions = array(
id(new ConpherenceTransaction())
- ->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)
+ ->setTransactionType(
+ ConpherenceThreadParticipantsTransaction::TRANSACTIONTYPE)
->setNewValue(array('-' => $participant_phids)),
);
$editor = id(new ConpherenceEditor())
diff --git a/src/applications/conpherence/conduit/ConpherenceUpdateThreadConduitAPIMethod.php b/src/applications/conpherence/conduit/ConpherenceUpdateThreadConduitAPIMethod.php
--- a/src/applications/conpherence/conduit/ConpherenceUpdateThreadConduitAPIMethod.php
+++ b/src/applications/conpherence/conduit/ConpherenceUpdateThreadConduitAPIMethod.php
@@ -69,7 +69,7 @@
if ($add_participant_phids) {
$xactions[] = id(new ConpherenceTransaction())
->setTransactionType(
- ConpherenceTransaction::TYPE_PARTICIPANTS)
+ ConpherenceThreadParticipantsTransaction::TRANSACTIONTYPE)
->setNewValue(array('+' => $add_participant_phids));
}
if ($remove_participant_phid) {
@@ -78,7 +78,7 @@
}
$xactions[] = id(new ConpherenceTransaction())
->setTransactionType(
- ConpherenceTransaction::TYPE_PARTICIPANTS)
+ ConpherenceThreadParticipantsTransaction::TRANSACTIONTYPE)
->setNewValue(array('-' => array($remove_participant_phid)));
}
if ($title) {
diff --git a/src/applications/conpherence/controller/ConpherenceNewRoomController.php b/src/applications/conpherence/controller/ConpherenceNewRoomController.php
--- a/src/applications/conpherence/controller/ConpherenceNewRoomController.php
+++ b/src/applications/conpherence/controller/ConpherenceNewRoomController.php
@@ -23,7 +23,8 @@
$participants[] = $user->getPHID();
$participants = array_unique($participants);
$xactions[] = id(new ConpherenceTransaction())
- ->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)
+ ->setTransactionType(
+ ConpherenceThreadParticipantsTransaction::TRANSACTIONTYPE)
->setNewValue(array('+' => $participants));
$xactions[] = id(new ConpherenceTransaction())
->setTransactionType(ConpherenceThreadTopicTransaction::TRANSACTIONTYPE)
diff --git a/src/applications/conpherence/controller/ConpherenceUpdateController.php b/src/applications/conpherence/controller/ConpherenceUpdateController.php
--- a/src/applications/conpherence/controller/ConpherenceUpdateController.php
+++ b/src/applications/conpherence/controller/ConpherenceUpdateController.php
@@ -61,7 +61,7 @@
case ConpherenceUpdateActions::JOIN_ROOM:
$xactions[] = id(new ConpherenceTransaction())
->setTransactionType(
- ConpherenceTransaction::TYPE_PARTICIPANTS)
+ ConpherenceThreadParticipantsTransaction::TRANSACTIONTYPE)
->setNewValue(array('+' => array($user->getPHID())));
$delete_draft = true;
$message = $request->getStr('text');
@@ -95,7 +95,7 @@
if (!empty($person_phids)) {
$xactions[] = id(new ConpherenceTransaction())
->setTransactionType(
- ConpherenceTransaction::TYPE_PARTICIPANTS)
+ ConpherenceThreadParticipantsTransaction::TRANSACTIONTYPE)
->setNewValue(array('+' => $person_phids));
}
break;
@@ -108,7 +108,7 @@
if ($person_phid) {
$xactions[] = id(new ConpherenceTransaction())
->setTransactionType(
- ConpherenceTransaction::TYPE_PARTICIPANTS)
+ ConpherenceThreadParticipantsTransaction::TRANSACTIONTYPE)
->setNewValue(array('-' => array($person_phid)));
$response_mode = 'go-home';
}
diff --git a/src/applications/conpherence/editor/ConpherenceEditor.php b/src/applications/conpherence/editor/ConpherenceEditor.php
--- a/src/applications/conpherence/editor/ConpherenceEditor.php
+++ b/src/applications/conpherence/editor/ConpherenceEditor.php
@@ -37,7 +37,8 @@
if (!$errors) {
$xactions = array();
$xactions[] = id(new ConpherenceTransaction())
- ->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)
+ ->setTransactionType(
+ ConpherenceThreadParticipantsTransaction::TRANSACTIONTYPE)
->setNewValue(array('+' => $participant_phids));
if ($title) {
$xactions[] = id(new ConpherenceTransaction())
@@ -87,8 +88,6 @@
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
- $types[] = ConpherenceTransaction::TYPE_PARTICIPANTS;
-
$types[] = PhabricatorTransactions::TYPE_COMMENT;
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
@@ -100,29 +99,6 @@
return pht('%s created this room.', $author);
}
- protected function getCustomTransactionOldValue(
- PhabricatorLiskDAO $object,
- PhabricatorApplicationTransaction $xaction) {
-
- switch ($xaction->getTransactionType()) {
- case ConpherenceTransaction::TYPE_PARTICIPANTS:
- if ($this->getIsNewObject()) {
- return array();
- }
- return $object->getParticipantPHIDs();
- }
- }
-
- protected function getCustomTransactionNewValue(
- PhabricatorLiskDAO $object,
- PhabricatorApplicationTransaction $xaction) {
-
- switch ($xaction->getTransactionType()) {
- case ConpherenceTransaction::TYPE_PARTICIPANTS:
- return $this->getPHIDTransactionNewValue($xaction);
- }
- }
-
/**
* We really only need a read lock if we have a comment. In that case, we
* must update the messagesCount field on the conpherence and
@@ -142,72 +118,6 @@
return $lock;
}
- /**
- * We need to apply initial effects IFF the conpherence is new. We must
- * save the conpherence first thing to make sure we have an id and a phid, as
- * well as create the initial set of participants so that we pass policy
- * checks.
- */
- protected function shouldApplyInitialEffects(
- PhabricatorLiskDAO $object,
- array $xactions) {
-
- return $this->getIsNewObject();
- }
-
- protected function applyInitialEffects(
- PhabricatorLiskDAO $object,
- array $xactions) {
-
- $object->save();
-
- foreach ($xactions as $xaction) {
- switch ($xaction->getTransactionType()) {
- case ConpherenceTransaction::TYPE_PARTICIPANTS:
- // Since this is a new ConpherenceThread, we have to create the
- // participation data asap to pass policy checks. For existing
- // ConpherenceThreads, the existing participation is correct
- // at this stage. Note that later in applyCustomExternalTransaction
- // this participation data will be updated, particularly the
- // behindTransactionPHID which is just a generated dummy for now.
- $participants = array();
- $phids = $this->getPHIDTransactionNewValue($xaction, array());
- foreach ($phids as $phid) {
- if ($phid == $this->getActor()->getPHID()) {
- $status = ConpherenceParticipationStatus::UP_TO_DATE;
- $message_count = 1;
- } else {
- $status = ConpherenceParticipationStatus::BEHIND;
- $message_count = 0;
- }
- $participants[$phid] =
- id(new ConpherenceParticipant())
- ->setConpherencePHID($object->getPHID())
- ->setParticipantPHID($phid)
- ->setParticipationStatus($status)
- ->setDateTouched(time())
- ->setBehindTransactionPHID($xaction->generatePHID())
- ->setSeenMessageCount($message_count)
- ->save();
- $object->attachParticipants($participants);
- }
- break;
- }
- }
- }
-
- protected function applyCustomInternalTransaction(
- PhabricatorLiskDAO $object,
- PhabricatorApplicationTransaction $xaction) {
-
- switch ($xaction->getTransactionType()) {
- case ConpherenceTransaction::TYPE_PARTICIPANTS:
- if (!$this->getIsNewObject()) {}
- break;
- }
-
- }
-
protected function applyBuiltinInternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
@@ -221,51 +131,6 @@
return parent::applyBuiltinInternalTransaction($object, $xaction);
}
- protected function applyCustomExternalTransaction(
- PhabricatorLiskDAO $object,
- PhabricatorApplicationTransaction $xaction) {
-
- switch ($xaction->getTransactionType()) {
- case ConpherenceTransaction::TYPE_PARTICIPANTS:
- if ($this->getIsNewObject()) {
- continue;
- }
- $participants = $object->getParticipants();
-
- $old_map = array_fuse($xaction->getOldValue());
- $new_map = array_fuse($xaction->getNewValue());
-
- $remove = array_keys(array_diff_key($old_map, $new_map));
- foreach ($remove as $phid) {
- $remove_participant = $participants[$phid];
- $remove_participant->delete();
- unset($participants[$phid]);
- }
-
- $add = array_keys(array_diff_key($new_map, $old_map));
- foreach ($add as $phid) {
- if ($phid == $this->getActor()->getPHID()) {
- $status = ConpherenceParticipationStatus::UP_TO_DATE;
- $message_count = $object->getMessageCount();
- } else {
- $status = ConpherenceParticipationStatus::BEHIND;
- $message_count = 0;
- }
- $participants[$phid] =
- id(new ConpherenceParticipant())
- ->setConpherencePHID($object->getPHID())
- ->setParticipantPHID($phid)
- ->setParticipationStatus($status)
- ->setDateTouched(time())
- ->setBehindTransactionPHID($xaction->getPHID())
- ->setSeenMessageCount($message_count)
- ->save();
- }
- $object->attachParticipants($participants);
- break;
- }
- }
-
protected function applyFinalEffects(
PhabricatorLiskDAO $object,
array $xactions) {
@@ -334,24 +199,10 @@
parent::requireCapabilities($object, $xaction);
switch ($xaction->getTransactionType()) {
- case ConpherenceTransaction::TYPE_PARTICIPANTS:
- $old_map = array_fuse($xaction->getOldValue());
- $new_map = array_fuse($xaction->getNewValue());
-
- $add = array_keys(array_diff_key($new_map, $old_map));
- $rem = array_keys(array_diff_key($old_map, $new_map));
-
- $actor_phid = $this->requireActor()->getPHID();
-
- // You need CAN_EDIT to change participants other than yourself.
- PhabricatorPolicyFilter::requireCapability(
- $this->requireActor(),
- $object,
- PhabricatorPolicyCapability::CAN_EDIT);
-
- break;
case ConpherenceThreadTitleTransaction::TRANSACTIONTYPE:
case ConpherenceThreadTopicTransaction::TRANSACTIONTYPE:
+ case ConpherenceThreadPictureTransaction::TRANSACTIONTYPE:
+ case ConpherenceThreadParticipantsTransaction::TRANSACTIONTYPE:
PhabricatorPolicyFilter::requireCapability(
$this->requireActor(),
$object,
@@ -360,19 +211,6 @@
}
}
- protected function mergeTransactions(
- PhabricatorApplicationTransaction $u,
- PhabricatorApplicationTransaction $v) {
-
- $type = $u->getTransactionType();
- switch ($type) {
- case ConpherenceTransaction::TYPE_PARTICIPANTS:
- return $this->mergePHIDOrEdgeTransactions($u, $v);
- }
-
- return parent::mergeTransactions($u, $v);
- }
-
protected function shouldSendMail(
PhabricatorLiskDAO $object,
array $xactions) {
@@ -475,43 +313,4 @@
return true;
}
- protected function validateTransaction(
- PhabricatorLiskDAO $object,
- $type,
- array $xactions) {
-
- $errors = parent::validateTransaction($object, $type, $xactions);
-
- switch ($type) {
- case ConpherenceTransaction::TYPE_PARTICIPANTS:
- foreach ($xactions as $xaction) {
- $new_phids = $this->getPHIDTransactionNewValue($xaction, array());
- $old_phids = nonempty($object->getParticipantPHIDs(), array());
- $phids = array_diff($new_phids, $old_phids);
-
- if (!$phids) {
- continue;
- }
-
- $users = id(new PhabricatorPeopleQuery())
- ->setViewer($this->requireActor())
- ->withPHIDs($phids)
- ->execute();
- $users = mpull($users, null, 'getPHID');
- foreach ($phids as $phid) {
- if (isset($users[$phid])) {
- continue;
- }
- $errors[] = new PhabricatorApplicationTransactionValidationError(
- $type,
- pht('Invalid'),
- pht('New room participant "%s" is not a valid user.', $phid),
- $xaction);
- }
- }
- break;
- }
-
- return $errors;
- }
}
diff --git a/src/applications/conpherence/mail/ConpherenceReplyHandler.php b/src/applications/conpherence/mail/ConpherenceReplyHandler.php
--- a/src/applications/conpherence/mail/ConpherenceReplyHandler.php
+++ b/src/applications/conpherence/mail/ConpherenceReplyHandler.php
@@ -55,7 +55,8 @@
$xactions = array();
if ($this->getMailAddedParticipantPHIDs()) {
$xactions[] = id(new ConpherenceTransaction())
- ->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)
+ ->setTransactionType(
+ ConpherenceThreadParticipantsTransaction::TRANSACTIONTYPE)
->setNewValue(array('+' => $this->getMailAddedParticipantPHIDs()));
}
diff --git a/src/applications/conpherence/storage/ConpherenceTransaction.php b/src/applications/conpherence/storage/ConpherenceTransaction.php
--- a/src/applications/conpherence/storage/ConpherenceTransaction.php
+++ b/src/applications/conpherence/storage/ConpherenceTransaction.php
@@ -3,8 +3,6 @@
final class ConpherenceTransaction
extends PhabricatorModularTransaction {
- const TYPE_PARTICIPANTS = 'participants';
-
public function getApplicationName() {
return 'conpherence';
}
@@ -21,81 +19,4 @@
return 'ConpherenceThreadTransactionType';
}
- public function getNoEffectDescription() {
- switch ($this->getTransactionType()) {
- case self::TYPE_PARTICIPANTS:
- return pht(
- 'You can not add a participant who has already been added.');
- break;
- }
-
- return parent::getNoEffectDescription();
- }
-
- public function shouldHide() {
- $old = $this->getOldValue();
-
- switch ($this->getTransactionType()) {
- case self::TYPE_PARTICIPANTS:
- return ($old === null);
- }
-
- return parent::shouldHide();
- }
-
- public function getTitle() {
- $author_phid = $this->getAuthorPHID();
-
- $old = $this->getOldValue();
- $new = $this->getNewValue();
-
- switch ($this->getTransactionType()) {
- case self::TYPE_PARTICIPANTS:
- $add = array_diff($new, $old);
- $rem = array_diff($old, $new);
-
- if ($add && $rem) {
- $title = pht(
- '%s edited participant(s), added %d: %s; removed %d: %s.',
- $this->renderHandleLink($author_phid),
- count($add),
- $this->renderHandleList($add),
- count($rem),
- $this->renderHandleList($rem));
- } else if ($add) {
- $title = pht(
- '%s added %d participant(s): %s.',
- $this->renderHandleLink($author_phid),
- count($add),
- $this->renderHandleList($add));
- } else {
- $title = pht(
- '%s removed %d participant(s): %s.',
- $this->renderHandleLink($author_phid),
- count($rem),
- $this->renderHandleList($rem));
- }
- return $title;
- break;
- }
-
- return parent::getTitle();
- }
-
- public function getRequiredHandlePHIDs() {
- $phids = parent::getRequiredHandlePHIDs();
-
- $old = $this->getOldValue();
- $new = $this->getNewValue();
-
- $phids[] = $this->getAuthorPHID();
- switch ($this->getTransactionType()) {
- case self::TYPE_PARTICIPANTS:
- $phids = array_merge($phids, $this->getOldValue());
- $phids = array_merge($phids, $this->getNewValue());
- break;
- }
-
- return $phids;
- }
}
diff --git a/src/applications/conpherence/xaction/ConpherenceThreadParticipantsTransaction.php b/src/applications/conpherence/xaction/ConpherenceThreadParticipantsTransaction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/conpherence/xaction/ConpherenceThreadParticipantsTransaction.php
@@ -0,0 +1,121 @@
+<?php
+
+final class ConpherenceThreadParticipantsTransaction
+ extends ConpherenceThreadTransactionType {
+
+ const TRANSACTIONTYPE = 'participants';
+
+ public function generateOldValue($object) {
+ return array();
+ }
+
+ public function applyExternalEffects($object, $value) {
+ $participants = $object->getParticipants();
+
+ $add_map = $this->getAddedPHIDList();
+ $rem_map = $this->getRemovedPHIDList();
+
+ foreach ($rem_map as $phid) {
+ $remove_participant = $participants[$phid];
+ $remove_participant->delete();
+ unset($participants[$phid]);
+ }
+
+ foreach ($add_map as $phid) {
+ if ($phid == $this->getActor()->getPHID()) {
+ $status = ConpherenceParticipationStatus::UP_TO_DATE;
+ $message_count = $object->getMessageCount();
+ } else {
+ $status = ConpherenceParticipationStatus::BEHIND;
+ $message_count = 0;
+ }
+ $participants[$phid] =
+ id(new ConpherenceParticipant())
+ ->setConpherencePHID($object->getPHID())
+ ->setParticipantPHID($phid)
+ ->setParticipationStatus($status)
+ ->setDateTouched(PhabricatorTime::getNow())
+ ->setBehindTransactionPHID('PHID-VOID-00000000000000000000') // LOLOLOL
+ ->setSeenMessageCount($message_count)
+ ->save();
+ }
+ $object->attachParticipants($participants);
+ }
+
+ public function getTitle() {
+ $add = $this->getAddedPHIDList();
+ $rem = $this->getRemovedPHIDList();
+
+ $author_phid = $this->getAuthorPHID();
+
+ if ($add && $rem) {
+ return pht(
+ '%s edited participant(s), added %d: %s; removed %d: %s.',
+ $this->renderAuthor(),
+ count($add),
+ $this->renderHandleList($add),
+ count($rem),
+ $this->renderHandleList($rem));
+ } else if ((in_array($author_phid, $add)) && (count($add) == 1)) {
+ return pht(
+ '%s joined the room.',
+ $this->renderAuthor());
+ } else if ((in_array($author_phid, $rem)) && (count($rem) == 1)) {
+ return pht(
+ '%s left the room.',
+ $this->renderAuthor());
+ } else if ($add) {
+ return pht(
+ '%s added %d participant(s): %s.',
+ $this->renderAuthor(),
+ count($add),
+ $this->renderHandleList($add));
+ } else {
+ return pht(
+ '%s removed %d participant(s): %s.',
+ $this->renderAuthor(),
+ count($rem),
+ $this->renderHandleList($rem));
+ }
+ }
+
+ public function validateTransactions($object, array $xactions) {
+ $errors = array();
+
+ foreach ($xactions as $xaction) {
+ $participants = $object->getParticipants();
+ $add_map = $this->getAddedPHIDList();
+ $rem_map = $this->getRemovedPHIDList();
+
+ if ($add_map) {
+ foreach ($add_map as $user_phid) {
+ // Check if a valid user
+ $user = id(new PhabricatorPeopleQuery())
+ ->setViewer($this->getActor())
+ ->withPHIDs(array($user_phid))
+ ->executeOne();
+ if (!$user) {
+ $errors[] = $this->newInvalidError(
+ pht('Participant PHID "%s" is not a valid user PHID.',
+ $user_phid));
+ continue;
+ }
+ }
+ }
+
+ if ($rem_map) {
+ foreach ($rem_map as $user_phid) {
+ if (!isset($participants[$user_phid])) {
+ $errors[] = $this->newInvalidError(
+ pht('Participant PHID "%s" is not in this room.',
+ $user_phid));
+ continue;
+ }
+ }
+ }
+
+ }
+ return $errors;
+ }
+
+}
diff --git a/src/applications/transactions/storage/PhabricatorModularTransactionType.php b/src/applications/transactions/storage/PhabricatorModularTransactionType.php
--- a/src/applications/transactions/storage/PhabricatorModularTransactionType.php
+++ b/src/applications/transactions/storage/PhabricatorModularTransactionType.php
@@ -309,4 +309,30 @@
return $this->getStorage()->getIsCreateTransaction();
}
+ final protected function getAddedPHIDList($new, $old) {
+ $old_map = $old;
+ $new_map = idx($new, '=', array());
+
+ $add = idx($new, '+', array());
+
+ if ($new_map) {
+ $add = array_keys(array_diff_key($new_map, $old_map));
+ }
+
+ return $add;
+ }
+
+ final protected function getRemovedPHIDList($new, $old) {
+ $old_map = $old;
+ $new_map = idx($new, '=', array());
+
+ $rem = idx($new, '-', array());
+
+ if ($new_map) {
+ $rem = array_keys(array_diff_key($old_map, $new_map));
+ }
+
+ return $rem;
+ }
+
}

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 30, 10:49 AM (21 h, 21 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6808827
Default Alt Text
D17685.id42557.diff (23 KB)

Event Timeline