예제 #1
0
 public static function createThread(PhabricatorUser $creator, array $participant_phids, $title, $message, PhabricatorContentSource $source)
 {
     $conpherence = ConpherenceThread::initializeNewRoom($creator);
     $files = array();
     $errors = array();
     if (empty($participant_phids)) {
         $errors[] = self::ERROR_EMPTY_PARTICIPANTS;
     } else {
         $participant_phids[] = $creator->getPHID();
         $participant_phids = array_unique($participant_phids);
     }
     if (empty($message)) {
         $errors[] = self::ERROR_EMPTY_MESSAGE;
     }
     $file_phids = PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles($creator, array($message));
     if ($file_phids) {
         $files = id(new PhabricatorFileQuery())->setViewer($creator)->withPHIDs($file_phids)->execute();
     }
     if (!$errors) {
         $xactions = array();
         $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)->setNewValue(array('+' => $participant_phids));
         if ($files) {
             $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_FILES)->setNewValue(array('+' => mpull($files, 'getPHID')));
         }
         if ($title) {
             $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_TITLE)->setNewValue($title);
         }
         $xactions[] = id(new ConpherenceTransaction())->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)->attachComment(id(new ConpherenceTransactionComment())->setContent($message)->setConpherencePHID($conpherence->getPHID()));
         id(new ConpherenceEditor())->setActor($creator)->setContentSource($source)->setContinueOnNoEffect(true)->applyTransactions($conpherence, $xactions);
     }
     return array($errors, $conpherence);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $user = $request->getUser();
     $title = pht('New Room');
     $e_title = true;
     $validation_exception = null;
     $conpherence = ConpherenceThread::initializeNewRoom($user);
     if ($request->isFormPost()) {
         $xactions = array();
         $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)->setNewValue(array('+' => array($user->getPHID())));
         $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_TITLE)->setNewValue($request->getStr('title'));
         $xactions[] = id(new ConpherenceTransaction())->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)->setNewValue($request->getStr('viewPolicy'));
         $xactions[] = id(new ConpherenceTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)->setNewValue($request->getStr('editPolicy'));
         $xactions[] = id(new ConpherenceTransaction())->setTransactionType(PhabricatorTransactions::TYPE_JOIN_POLICY)->setNewValue($request->getStr('joinPolicy'));
         try {
             id(new ConpherenceEditor())->setContentSourceFromRequest($request)->setContinueOnNoEffect(true)->setActor($user)->applyTransactions($conpherence, $xactions);
             return id(new AphrontRedirectResponse())->setURI('/' . $conpherence->getMonogram());
         } catch (PhabricatorApplicationTransactionValidationException $ex) {
             $validation_exception = $ex;
             $e_title = $ex->getShortMessage(ConpherenceTransaction::TYPE_TITLE);
             $conpherence->setViewPolicy($request->getStr('viewPolicy'));
             $conpherence->setEditPolicy($request->getStr('editPolicy'));
             $conpherence->setJoinPolicy($request->getStr('joinPolicy'));
         }
     }
     $policies = id(new PhabricatorPolicyQuery())->setViewer($user)->setObject($conpherence)->execute();
     $submit_uri = $this->getApplicationURI('room/new/');
     $cancel_uri = $this->getApplicationURI('search/');
     $dialog = $this->newDialog()->setWidth(AphrontDialogView::WIDTH_FORM)->setValidationException($validation_exception)->setUser($user)->setTitle($title)->addCancelButton($cancel_uri)->addSubmitButton(pht('Create Room'));
     $form = id(new PHUIFormLayoutView())->setUser($user)->setFullWidth(true)->appendChild(id(new AphrontFormTextControl())->setError($e_title)->setLabel(pht('Title'))->setName('title')->setValue($request->getStr('title')))->appendChild(id(new AphrontFormPolicyControl())->setName('viewPolicy')->setPolicyObject($conpherence)->setCapability(PhabricatorPolicyCapability::CAN_VIEW)->setPolicies($policies))->appendChild(id(new AphrontFormPolicyControl())->setName('editPolicy')->setPolicyObject($conpherence)->setCapability(PhabricatorPolicyCapability::CAN_EDIT)->setPolicies($policies))->appendChild(id(new AphrontFormPolicyControl())->setName('joinPolicy')->setPolicyObject($conpherence)->setCapability(PhabricatorPolicyCapability::CAN_JOIN)->setPolicies($policies));
     $dialog->appendChild($form);
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
 public static function createThread(PhabricatorUser $creator, array $participant_phids, $title, $message, PhabricatorContentSource $source, $topic)
 {
     $conpherence = ConpherenceThread::initializeNewRoom($creator);
     $errors = array();
     if (empty($participant_phids)) {
         $errors[] = self::ERROR_EMPTY_PARTICIPANTS;
     } else {
         $participant_phids[] = $creator->getPHID();
         $participant_phids = array_unique($participant_phids);
     }
     if (empty($message)) {
         $errors[] = self::ERROR_EMPTY_MESSAGE;
     }
     if (!$errors) {
         $xactions = array();
         $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)->setNewValue(array('+' => $participant_phids));
         if ($title) {
             $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_TITLE)->setNewValue($title);
         }
         if (strlen($topic)) {
             $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_TOPIC)->setNewValue($topic);
         }
         $xactions[] = id(new ConpherenceTransaction())->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)->attachComment(id(new ConpherenceTransactionComment())->setContent($message)->setConpherencePHID($conpherence->getPHID()));
         id(new ConpherenceEditor())->setActor($creator)->setContentSource($source)->setContinueOnNoEffect(true)->applyTransactions($conpherence, $xactions);
     }
     return array($errors, $conpherence);
 }
 private function createRoom(PhabricatorUser $creator, array $participant_phids)
 {
     $conpherence = ConpherenceThread::initializeNewRoom($creator);
     $xactions = array();
     $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)->setNewValue(array('+' => $participant_phids));
     $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_TITLE)->setNewValue(pht('Test'));
     id(new ConpherenceEditor())->setActor($creator)->setContentSource($this->newContentSource())->setContinueOnNoEffect(true)->applyTransactions($conpherence, $xactions);
     return $conpherence;
 }
 protected function processReceivedMail(PhabricatorMetaMTAReceivedMail $mail, PhabricatorUser $sender)
 {
     $users = $this->loadMailUsers($mail);
     $phids = mpull($users, 'getPHID');
     $conpherence = id(new ConpherenceReplyHandler())->setMailReceiver(ConpherenceThread::initializeNewRoom($sender))->setMailAddedParticipantPHIDs($phids)->setActor($sender)->setExcludeMailRecipientPHIDs($mail->loadAllRecipientPHIDs())->processEmail($mail);
     if ($conpherence) {
         $mail->setRelatedPHID($conpherence->getPHID());
     }
 }
 public function testObjectPolicyRuleThreadMembers()
 {
     $author = $this->generateNewTestUser();
     $viewer = $this->generateNewTestUser();
     $rule = new ConpherenceThreadMembersPolicyRule();
     $thread = ConpherenceThread::initializeNewRoom($author);
     $thread->setViewPolicy($rule->getObjectPolicyFullKey());
     $thread->save();
     $this->assertFalse(PhabricatorPolicyFilter::hasCapability($author, $thread, PhabricatorPolicyCapability::CAN_VIEW));
     $this->assertFalse(PhabricatorPolicyFilter::hasCapability($viewer, $thread, PhabricatorPolicyCapability::CAN_VIEW));
     $participant = id(new ConpherenceParticipant())->setParticipantPHID($viewer->getPHID())->setConpherencePHID($thread->getPHID());
     $thread->attachParticipants(array($viewer->getPHID() => $participant));
     $this->assertTrue(PhabricatorPolicyFilter::hasCapability($viewer, $thread, PhabricatorPolicyCapability::CAN_VIEW));
 }
 public function handleRequest(AphrontRequest $request)
 {
     $user = $request->getUser();
     $title = pht('Conpherence');
     $conpherence = null;
     $limit = ConpherenceThreadListView::SEE_MORE_LIMIT * 2 + 1;
     $all_participation = array();
     $mode = $this->determineMode();
     switch ($mode) {
         case self::SELECTED_MODE:
             $conpherence_id = $request->getURIData('id');
             $conpherence = id(new ConpherenceThreadQuery())->setViewer($user)->withIDs(array($conpherence_id))->executeOne();
             if (!$conpherence) {
                 return new Aphront404Response();
             }
             if ($conpherence->getTitle()) {
                 $title = $conpherence->getTitle();
             }
             $cursor = $conpherence->getParticipantIfExists($user->getPHID());
             $data = $this->loadDefaultParticipation($limit);
             $all_participation = $data['all_participation'];
             if (!$cursor) {
                 $menu_participation = id(new ConpherenceParticipant())->makeEphemeral()->setConpherencePHID($conpherence->getPHID())->setParticipantPHID($user->getPHID());
             } else {
                 $menu_participation = $cursor;
             }
             // check to see if the loaded conpherence is going to show up
             // within the SEE_MORE_LIMIT amount of conpherences.
             // If its not there, then we just pre-pend it as the "first"
             // conpherence so folks have a navigation item in the menu.
             $count = 0;
             $found = false;
             foreach ($all_participation as $phid => $curr_participation) {
                 if ($conpherence->getPHID() == $phid) {
                     $found = true;
                     break;
                 }
                 $count++;
                 if ($count > ConpherenceThreadListView::SEE_MORE_LIMIT) {
                     break;
                 }
             }
             if (!$found) {
                 $all_participation = array($conpherence->getPHID() => $menu_participation) + $all_participation;
             }
             break;
         case self::UNSELECTED_MODE:
         default:
             $data = $this->loadDefaultParticipation($limit);
             $all_participation = $data['all_participation'];
             break;
     }
     $threads = $this->loadConpherenceThreadData($all_participation);
     $thread_view = id(new ConpherenceThreadListView())->setUser($user)->setBaseURI($this->getApplicationURI())->setThreads($threads);
     switch ($mode) {
         case self::SELECTED_MODE:
             $response = id(new AphrontAjaxResponse())->setContent($thread_view);
             break;
         case self::UNSELECTED_MODE:
         default:
             $layout = id(new ConpherenceLayoutView())->setUser($user)->setBaseURI($this->getApplicationURI())->setThreadView($thread_view)->setRole('list');
             if ($conpherence) {
                 $layout->setThread($conpherence);
             } else {
                 // make a dummy conpherence so we can render something
                 $conpherence = ConpherenceThread::initializeNewRoom($user);
                 $conpherence->attachHandles(array());
                 $conpherence->attachTransactions(array());
                 $conpherence->makeEphemeral();
             }
             $policy_objects = id(new PhabricatorPolicyQuery())->setViewer($user)->setObject($conpherence)->execute();
             $layout->setHeader($this->buildHeaderPaneContent($conpherence, $policy_objects));
             $response = $this->newPage()->setTitle($title)->appendChild($layout);
             break;
     }
     return $response;
 }