From 49e53d5709dae32d3c75c3b4fb94eb7540f9163f Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Thu, 4 Dec 2014 11:54:17 -0800 Subject: [PATCH] Conpherence - fix permissions issue creating new Conpherences Summary: Fixes T6690. The editor innards end up loading the conpherence object, whose policy is dictated by these participation objects. Test Plan: pre patch could not create new conpherences. post patch I can create conpherences! i can also add people to conpherences and it works. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T6690 Differential Revision: https://secure.phabricator.com/D10927 --- .../conpherence/editor/ConpherenceEditor.php | 64 +++++++++++++++---- 1 file changed, 50 insertions(+), 14 deletions(-) diff --git a/src/applications/conpherence/editor/ConpherenceEditor.php b/src/applications/conpherence/editor/ConpherenceEditor.php index d680472c9e..7268b91fc8 100644 --- a/src/applications/conpherence/editor/ConpherenceEditor.php +++ b/src/applications/conpherence/editor/ConpherenceEditor.php @@ -203,6 +203,36 @@ final class ConpherenceEditor extends PhabricatorApplicationTransactionEditor { case ConpherenceTransactionType::TYPE_TITLE: $object->setTitle($xaction->getNewValue()); break; + case ConpherenceTransactionType::TYPE_PARTICIPANTS: + // If 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. + if ($this->getIsNewObject()) { + $participants = array(); + foreach ($xaction->getNewValue() 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; } $this->updateRecentParticipantPHIDs($object, $xaction); } @@ -259,22 +289,28 @@ final class ConpherenceEditor extends PhabricatorApplicationTransactionEditor { $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(); + if ($this->getIsNewObject()) { + $participants[$phid] + ->setBehindTransactionPHID($xaction->getPHID()) + ->save(); } else { - $status = ConpherenceParticipationStatus::BEHIND; - $message_count = 0; + 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(); } - $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;