public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); // NOTE: We require CAN_EDIT to view this page. $document = id(new LegalpadDocumentQuery())->setViewer($viewer)->withIDs(array($id))->needDocumentBodies(true)->needContributors(true)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne(); if (!$document) { return new Aphront404Response(); } $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID($document->getPHID()); $document_body = $document->getDocumentBody(); $engine = id(new PhabricatorMarkupEngine())->setViewer($viewer); $engine->addObject($document_body, LegalpadDocumentBody::MARKUP_FIELD_TEXT); $timeline = $this->buildTransactionTimeline($document, new LegalpadTransactionQuery(), $engine); $title = $document_body->getTitle(); $header = id(new PHUIHeaderView())->setHeader($title)->setUser($viewer)->setPolicyObject($document); $actions = $this->buildActionView($document); $properties = $this->buildPropertyView($document, $engine, $actions); $comment_form_id = celerity_generate_unique_node_id(); $add_comment = $this->buildAddCommentView($document, $comment_form_id); $crumbs = $this->buildApplicationCrumbs($this->buildSideNav()); $crumbs->addTextCrumb($document->getMonogram(), '/' . $document->getMonogram()); $crumbs->addTextCrumb(pht('Manage')); $object_box = id(new PHUIObjectBoxView())->setHeader($header)->addPropertyList($properties)->addPropertyList($this->buildDocument($engine, $document_body)); $content = array($crumbs, $object_box, $timeline, $add_comment); return $this->buildApplicationPage($content, array('title' => $title, 'pageObjects' => array($document->getPHID()))); }
private function handlePropertyEvent($event) { $user = $event->getUser(); $object = $event->getValue('object'); if (!$object || !$object->getPHID()) { // No object, or the object has no PHID yet.. return; } if (!$object instanceof PhabricatorSubscribableInterface) { // This object isn't subscribable. return; } if (!$object->shouldShowSubscribersProperty()) { // This object doesn't render subscribers in its property list. return; } $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID($object->getPHID()); if ($subscribers) { $handles = id(new PhabricatorHandleQuery())->setViewer($user)->withPHIDs($subscribers)->execute(); } else { $handles = array(); } $sub_view = id(new SubscriptionListStringBuilder())->setObjectPHID($object->getPHID())->setHandles($handles)->buildPropertyString(); $view = $event->getValue('view'); $view->addProperty(pht('Subscribers'), $sub_view); }
private function performMerge(ManiphestTask $task, PhabricatorObjectHandle $handle, array $phids) { $user = $this->getRequest()->getUser(); $response = id(new AphrontReloadResponse())->setURI($handle->getURI()); $phids = array_fill_keys($phids, true); unset($phids[$task->getPHID()]); // Prevent merging a task into itself. if (!$phids) { return $response; } $targets = id(new ManiphestTaskQuery())->setViewer($user)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->withPHIDs(array_keys($phids))->needSubscriberPHIDs(true)->needProjectPHIDs(true)->execute(); if (empty($targets)) { return $response; } $editor = id(new ManiphestTransactionEditor())->setActor($user)->setContentSourceFromRequest($this->getRequest())->setContinueOnNoEffect(true)->setContinueOnMissingFields(true); $cc_vector = array(); // since we loaded this via a generic object query, go ahead and get the // attach the subscriber and project phids now $task->attachSubscriberPHIDs(PhabricatorSubscribersQuery::loadSubscribersForPHID($task->getPHID())); $task->attachProjectPHIDs(PhabricatorEdgeQuery::loadDestinationPHIDs($task->getPHID(), PhabricatorProjectObjectHasProjectEdgeType::EDGECONST)); $cc_vector[] = $task->getSubscriberPHIDs(); foreach ($targets as $target) { $cc_vector[] = $target->getSubscriberPHIDs(); $cc_vector[] = array($target->getAuthorPHID(), $target->getOwnerPHID()); $merged_into_txn = id(new ManiphestTransaction())->setTransactionType(ManiphestTransaction::TYPE_MERGED_INTO)->setNewValue($task->getPHID()); $editor->applyTransactions($target, array($merged_into_txn)); } $all_ccs = array_mergev($cc_vector); $all_ccs = array_filter($all_ccs); $all_ccs = array_unique($all_ccs); $add_ccs = id(new ManiphestTransaction())->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)->setNewValue(array('=' => $all_ccs)); $merged_from_txn = id(new ManiphestTransaction())->setTransactionType(ManiphestTransaction::TYPE_MERGED_FROM)->setNewValue(mpull($targets, 'getPHID')); $editor->applyTransactions($task, array($add_ccs, $merged_from_txn)); return $response; }
protected function readValueFromRevision(DifferentialRevision $revision) { if (!$revision->getPHID()) { return array(); } return PhabricatorSubscribersQuery::loadSubscribersForPHID($revision->getPHID()); }
public function getHeraldFieldValue($object) { $revision = $this->getAdapter()->getRevision(); if (!$revision) { return array(); } $phid = $revision->getPHID(); return PhabricatorSubscribersQuery::loadSubscribersForPHID($phid); }
protected function indexSubscribers(PhabricatorSearchAbstractDocument $doc) { $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID($doc->getPHID()); $handles = id(new PhabricatorHandleQuery())->setViewer($this->getViewer())->withPHIDs($subscribers)->execute(); foreach ($handles as $phid => $handle) { $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_SUBSCRIBER, $phid, $handle->getType(), $doc->getDocumentModified()); // Bogus timestamp. } }
public function save() { if (!$this->comment) { throw new Exception("Must set comment before saving it"); } if (!$this->question) { throw new Exception("Must set question before saving comment"); } if (!$this->targetPHID) { throw new Exception("Must set target before saving comment"); } if (!$this->viewer) { throw new Exception("Must set viewer before saving comment"); } $comment = $this->comment; $question = $this->question; $target = $this->targetPHID; $viewer = $this->viewer; $comment->save(); $question->attachRelated(); PhabricatorSearchPonderIndexer::indexQuestion($question); // subscribe author and @mentions $subeditor = id(new PhabricatorSubscriptionsEditor())->setObject($question)->setUser($viewer); $subeditor->subscribeExplicit(array($comment->getAuthorPHID())); $content = $comment->getContent(); $at_mention_phids = PhabricatorMarkupEngine::extractPHIDsFromMentions(array($content)); $subeditor->subscribeImplicit($at_mention_phids); $subeditor->save(); if ($this->shouldEmail) { // now load subscribers, including implicitly-added @mention victims $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID($question->getPHID()); // @mention emails (but not for anyone who has explicitly unsubscribed) if (array_intersect($at_mention_phids, $subscribers)) { id(new PonderMentionMail($question, $comment, $viewer))->setToPHIDs($at_mention_phids)->send(); } if ($target === $question->getPHID()) { $target = $question; } else { $answers_by_phid = mgroup($question->getAnswers(), 'getPHID'); $target = head($answers_by_phid[$target]); } // only send emails to others in the same thread $thread = mpull($target->getComments(), 'getAuthorPHID'); $thread[] = $target->getAuthorPHID(); $thread[] = $question->getAuthorPHID(); $other_subs = array_diff(array_intersect($thread, $subscribers), $at_mention_phids); // 'Comment' emails for subscribers who are in the same comment thread, // including the author of the parent question and/or answer, excluding // @mentions (and excluding the author, depending on their MetaMTA // settings). if ($other_subs) { id(new PonderCommentMail($question, $comment, $viewer))->setToPHIDs($other_subs)->send(); } } }
public function buildCurtainPanel($object) { $viewer = $this->getViewer(); $object_phid = $object->getPHID(); $subscriber_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID($object_phid); $handles = $viewer->loadHandles($subscriber_phids); // TODO: This class can't accept a HandleList yet. $handles = iterator_to_array($handles); $susbscribers_view = id(new SubscriptionListStringBuilder())->setObjectPHID($object_phid)->setHandles($handles)->buildPropertyString(); return $this->newPanel()->setHeaderText(pht('Subscribers'))->setOrder(20000)->appendChild($susbscribers_view); }
public function buildCustomEditFields(PhabricatorEditEngine $engine, PhabricatorApplicationTransactionInterface $object) { $subscribers_type = PhabricatorTransactions::TYPE_SUBSCRIBERS; $object_phid = $object->getPHID(); if ($object_phid) { $sub_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID($object_phid); } else { $sub_phids = array(); } $subscribers_field = id(new PhabricatorSubscribersEditField())->setKey('subscriberPHIDs')->setLabel(pht('Subscribers'))->setEditTypeKey('subscribers')->setDescription(pht('Manage subscribers.'))->setAliases(array('subscriber', 'subscribers'))->setIsCopyable(true)->setUseEdgeTransactions(true)->setEdgeTransactionDescriptions(pht('Add subscribers.'), pht('Remove subscribers.'), pht('Set subscribers, overwriting current value.'))->setCommentActionLabel(pht('Change Subscribers'))->setTransactionType($subscribers_type)->setValue($sub_phids); return array($subscribers_field); }
public function indexFulltextObject($object, PhabricatorSearchAbstractDocument $document) { $subscriber_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID($object->getPHID()); if (!$subscriber_phids) { return; } $handles = id(new PhabricatorHandleQuery())->setViewer($this->getViewer())->withPHIDs($subscriber_phids)->execute(); foreach ($handles as $phid => $handle) { $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_SUBSCRIBER, $phid, $handle->getType(), $document->getDocumentModified()); // Bogus timestamp. } }
public function saveAnswer() { if (!$this->viewer) { throw new Exception("Must set user before saving question"); } if (!$this->question) { throw new Exception("Must set question before saving answer"); } if (!$this->answer) { throw new Exception("Must set answer before saving it"); } $question = $this->question; $answer = $this->answer; $viewer = $this->viewer; $conn = $answer->establishConnection('w'); $trans = $conn->openTransaction(); $trans->beginReadLocking(); $question->reload(); queryfx($conn, 'UPDATE %T as t SET t.`answerCount` = t.`answerCount` + 1 WHERE t.`PHID` = %s', $question->getTableName(), $question->getPHID()); $answer->setQuestionID($question->getID()); $answer->save(); $trans->endReadLocking(); $trans->saveTransaction(); $question->attachRelated(); PhabricatorSearchPonderIndexer::indexQuestion($question); // subscribe author and @mentions $subeditor = id(new PhabricatorSubscriptionsEditor())->setObject($question)->setUser($viewer); $subeditor->subscribeExplicit(array($answer->getAuthorPHID())); $content = $answer->getContent(); $at_mention_phids = PhabricatorMarkupEngine::extractPHIDsFromMentions(array($content)); $subeditor->subscribeImplicit($at_mention_phids); $subeditor->save(); if ($this->shouldEmail) { // now load subscribers, including implicitly-added @mention victims $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID($question->getPHID()); // @mention emails (but not for anyone who has explicitly unsubscribed) if (array_intersect($at_mention_phids, $subscribers)) { id(new PonderMentionMail($question, $answer, $viewer))->setToPHIDs($at_mention_phids)->send(); } $other_subs = array_diff($subscribers, $at_mention_phids); // 'Answered' emails for subscribers who are not @mentiond (and excluding // author depending on their MetaMTA settings). if ($other_subs) { id(new PonderAnsweredMail($question, $answer, $viewer))->setToPHIDs($other_subs)->send(); } } }
public function getHeraldField($field) { switch ($field) { case self::FIELD_TITLE: return $this->getMock()->getName(); case self::FIELD_BODY: return $this->getMock()->getDescription(); case self::FIELD_AUTHOR: return $this->getMock()->getAuthorPHID(); case self::FIELD_CC: return PhabricatorSubscribersQuery::loadSubscribersForPHID($this->getMock()->getPHID()); case self::FIELD_PROJECTS: return PhabricatorEdgeQuery::loadDestinationPHIDs($this->getMock()->getPHID(), PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); } return parent::getHeraldField($field); }
public function processRequest() { $request = $this->getRequest(); $viewer = $request->getUser(); $phid = $this->phid; $object = id(new PhabricatorObjectQuery())->setViewer($viewer)->withPHIDs(array($phid))->executeOne(); if ($object instanceof PhabricatorSubscribableInterface) { $subscriber_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID($phid); } $handle_phids = $subscriber_phids; $handle_phids[] = $phid; $handles = id(new PhabricatorHandleQuery())->setViewer($viewer)->withPHIDs($handle_phids)->execute(); $object_handle = $handles[$phid]; $dialog = id(new SubscriptionListDialogBuilder())->setViewer($viewer)->setTitle(pht('Subscribers'))->setObjectPHID($phid)->setHandles($handles)->buildDialog(); return id(new AphrontDialogResponse())->setDialog($dialog); }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $object = id(new PhabricatorObjectQuery())->setViewer($viewer)->withPHIDs(array($request->getURIData('phid')))->executeOne(); if (!$object) { return new Aphront404Response(); } if (!$object instanceof PhabricatorSubscribableInterface) { return new Aphront404Response(); } $phid = $object->getPHID(); $handle_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID($phid); $handle_phids[] = $phid; $handles = id(new PhabricatorHandleQuery())->setViewer($viewer)->withPHIDs($handle_phids)->execute(); $object_handle = $handles[$phid]; $dialog = id(new SubscriptionListDialogBuilder())->setViewer($viewer)->setTitle(pht('Subscribers'))->setObjectPHID($phid)->setHandles($handles)->buildDialog(); return id(new AphrontDialogResponse())->setDialog($dialog); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); // NOTE: We require CAN_EDIT to view this page. $document = id(new LegalpadDocumentQuery())->setViewer($user)->withIDs(array($this->id))->needDocumentBodies(true)->needContributors(true)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne(); if (!$document) { return new Aphront404Response(); } $xactions = id(new LegalpadTransactionQuery())->setViewer($user)->withObjectPHIDs(array($document->getPHID()))->execute(); $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID($document->getPHID()); $document_body = $document->getDocumentBody(); $phids = array(); $phids[] = $document_body->getCreatorPHID(); foreach ($subscribers as $subscriber) { $phids[] = $subscriber; } foreach ($document->getContributors() as $contributor) { $phids[] = $contributor; } $this->loadHandles($phids); $engine = id(new PhabricatorMarkupEngine())->setViewer($user); $engine->addObject($document_body, LegalpadDocumentBody::MARKUP_FIELD_TEXT); foreach ($xactions as $xaction) { if ($xaction->getComment()) { $engine->addObject($xaction->getComment(), PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT); } } $engine->process(); $title = $document_body->getTitle(); $header = id(new PHUIHeaderView())->setHeader($title)->setUser($user)->setPolicyObject($document); $actions = $this->buildActionView($document); $properties = $this->buildPropertyView($document, $engine, $actions); $comment_form_id = celerity_generate_unique_node_id(); $xaction_view = id(new LegalpadTransactionView())->setUser($this->getRequest()->getUser())->setObjectPHID($document->getPHID())->setTransactions($xactions)->setMarkupEngine($engine); $add_comment = $this->buildAddCommentView($document, $comment_form_id); $crumbs = $this->buildApplicationCrumbs($this->buildSideNav()); $crumbs->setActionList($actions); $crumbs->addTextCrumb($document->getMonogram(), '/' . $document->getMonogram()); $crumbs->addTextCrumb(pht('Manage')); $object_box = id(new PHUIObjectBoxView())->setHeader($header)->addPropertyList($properties)->addPropertyList($this->buildDocument($engine, $document_body)); $content = array($crumbs, $object_box, $xaction_view, $add_comment); return $this->buildApplicationPage($content, array('title' => $title, 'pageObjects' => array($document->getPHID()))); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $question = PonderQuestionQuery::loadSingle($user, $this->questionID); if (!$question) { return new Aphront404Response(); } $question->attachRelated(); $question->attachVotes($user->getPHID()); $object_phids = array($user->getPHID(), $question->getAuthorPHID()); $answers = $question->getAnswers(); $comments = $question->getComments(); foreach ($comments as $comment) { $object_phids[] = $comment->getAuthorPHID(); } foreach ($answers as $answer) { $object_phids[] = $answer->getAuthorPHID(); $comments = $answer->getComments(); foreach ($comments as $comment) { $object_phids[] = $comment->getAuthorPHID(); } } $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID($question->getPHID()); $object_phids = array_merge($object_phids, $subscribers); $handles = $this->loadViewerHandles($object_phids); $this->loadHandles($object_phids); $detail_panel = new PonderQuestionDetailView(); $detail_panel->setQuestion($question)->setUser($user)->setHandles($handles); $responses_panel = new PonderAnswerListView(); $responses_panel->setQuestion($question)->setHandles($handles)->setUser($user)->setAnswers($answers); $answer_add_panel = new PonderAddAnswerView(); $answer_add_panel->setQuestion($question)->setUser($user)->setActionURI("/ponder/answer/add/"); $header = id(new PhabricatorHeaderView())->setObjectName('Q' . $question->getID())->setHeader($question->getTitle()); $actions = $this->buildActionListView($question); $properties = $this->buildPropertyListView($question, $subscribers); $nav = $this->buildSideNavView($question); $nav->appendChild(array($header, $actions, $properties, $detail_panel, $responses_panel, $answer_add_panel)); $nav->selectFilter(null); return $this->buildApplicationPage($nav, array('device' => true, 'title' => 'Q' . $question->getID() . ' ' . $question->getTitle())); }
private function loadSubscribers(PhabricatorLiskDAO $object) { if ($object->getPHID() && $object instanceof PhabricatorSubscribableInterface) { $subs = PhabricatorSubscribersQuery::loadSubscribersForPHID($object->getPHID()); $this->subscribers = array_fuse($subs); } else { $this->subscribers = array(); } }
public function getUsersToNotifyOfTokenGiven() { return PhabricatorSubscribersQuery::loadSubscribersForPHID($this->phid); }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $current_version = null; if ($id) { $document = id(new PhrictionDocumentQuery())->setViewer($viewer)->withIDs(array($id))->needContent(true)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne(); if (!$document) { return new Aphront404Response(); } $current_version = $document->getContent()->getVersion(); $revert = $request->getInt('revert'); if ($revert) { $content = id(new PhrictionContent())->loadOneWhere('documentID = %d AND version = %d', $document->getID(), $revert); if (!$content) { return new Aphront404Response(); } } else { $content = $document->getContent(); } } else { $slug = $request->getStr('slug'); $slug = PhabricatorSlug::normalize($slug); if (!$slug) { return new Aphront404Response(); } $document = id(new PhrictionDocumentQuery())->setViewer($viewer)->withSlugs(array($slug))->needContent(true)->executeOne(); if ($document) { $content = $document->getContent(); $current_version = $content->getVersion(); } else { $document = PhrictionDocument::initializeNewDocument($viewer, $slug); $content = $document->getContent(); } } if ($request->getBool('nodraft')) { $draft = null; $draft_key = null; } else { if ($document->getPHID()) { $draft_key = $document->getPHID() . ':' . $content->getVersion(); } else { $draft_key = 'phriction:' . $content->getSlug(); } $draft = id(new PhabricatorDraft())->loadOneWhere('authorPHID = %s AND draftKey = %s', $viewer->getPHID(), $draft_key); } if ($draft && strlen($draft->getDraft()) && $draft->getDraft() != $content->getContent()) { $content_text = $draft->getDraft(); $discard = phutil_tag('a', array('href' => $request->getRequestURI()->alter('nodraft', true)), pht('discard this draft')); $draft_note = new PHUIInfoView(); $draft_note->setSeverity(PHUIInfoView::SEVERITY_NOTICE); $draft_note->setTitle(pht('Recovered Draft')); $draft_note->appendChild(hsprintf('<p>%s</p>', pht('Showing a saved draft of your edits, you can %s.', $discard))); } else { $content_text = $content->getContent(); $draft_note = null; } require_celerity_resource('phriction-document-css'); $e_title = true; $e_content = true; $validation_exception = null; $notes = null; $title = $content->getTitle(); $overwrite = false; $v_cc = PhabricatorSubscribersQuery::loadSubscribersForPHID($document->getPHID()); if ($request->isFormPost()) { $title = $request->getStr('title'); $content_text = $request->getStr('content'); $notes = $request->getStr('description'); $current_version = $request->getInt('contentVersion'); $v_view = $request->getStr('viewPolicy'); $v_edit = $request->getStr('editPolicy'); $v_cc = $request->getArr('cc'); $xactions = array(); $xactions[] = id(new PhrictionTransaction())->setTransactionType(PhrictionTransaction::TYPE_TITLE)->setNewValue($title); $xactions[] = id(new PhrictionTransaction())->setTransactionType(PhrictionTransaction::TYPE_CONTENT)->setNewValue($content_text); $xactions[] = id(new PhrictionTransaction())->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)->setNewValue($v_view); $xactions[] = id(new PhrictionTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)->setNewValue($v_edit); $xactions[] = id(new PhrictionTransaction())->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)->setNewValue(array('=' => $v_cc)); $editor = id(new PhrictionTransactionEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true)->setDescription($notes)->setProcessContentVersionError(!$request->getBool('overwrite'))->setContentVersion($current_version); try { $editor->applyTransactions($document, $xactions); if ($draft) { $draft->delete(); } $uri = PhrictionDocument::getSlugURI($document->getSlug()); return id(new AphrontRedirectResponse())->setURI($uri); } catch (PhabricatorApplicationTransactionValidationException $ex) { $validation_exception = $ex; $e_title = nonempty($ex->getShortMessage(PhrictionTransaction::TYPE_TITLE), true); $e_content = nonempty($ex->getShortMessage(PhrictionTransaction::TYPE_CONTENT), true); // if we're not supposed to process the content version error, then // overwrite that content...! if (!$editor->getProcessContentVersionError()) { $overwrite = true; } $document->setViewPolicy($v_view); $document->setEditPolicy($v_edit); } } if ($document->getID()) { $panel_header = pht('Edit Document: %s', $content->getTitle()); $page_title = pht('Edit Document'); $header_icon = 'fa-pencil'; if ($overwrite) { $submit_button = pht('Overwrite Changes'); } else { $submit_button = pht('Save Changes'); } } else { $panel_header = pht('Create New Phriction Document'); $submit_button = pht('Create Document'); $page_title = pht('Create Document'); $header_icon = 'fa-plus-square'; } $uri = $document->getSlug(); $uri = PhrictionDocument::getSlugURI($uri); $uri = PhabricatorEnv::getProductionURI($uri); $cancel_uri = PhrictionDocument::getSlugURI($document->getSlug()); $policies = id(new PhabricatorPolicyQuery())->setViewer($viewer)->setObject($document)->execute(); $view_capability = PhabricatorPolicyCapability::CAN_VIEW; $edit_capability = PhabricatorPolicyCapability::CAN_EDIT; $form = id(new AphrontFormView())->setUser($viewer)->addHiddenInput('slug', $document->getSlug())->addHiddenInput('nodraft', $request->getBool('nodraft'))->addHiddenInput('contentVersion', $current_version)->addHiddenInput('overwrite', $overwrite)->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Title'))->setValue($title)->setError($e_title)->setName('title'))->appendChild(id(new AphrontFormStaticControl())->setLabel(pht('URI'))->setValue($uri))->appendChild(id(new PhabricatorRemarkupControl())->setLabel(pht('Content'))->setValue($content_text)->setError($e_content)->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)->setName('content')->setID('document-textarea')->setUser($viewer))->appendControl(id(new AphrontFormTokenizerControl())->setLabel(pht('Subscribers'))->setName('cc')->setValue($v_cc)->setUser($viewer)->setDatasource(new PhabricatorMetaMTAMailableDatasource()))->appendChild(id(new AphrontFormPolicyControl())->setName('viewPolicy')->setPolicyObject($document)->setCapability($view_capability)->setPolicies($policies)->setCaption($document->describeAutomaticCapability($view_capability)))->appendChild(id(new AphrontFormPolicyControl())->setName('editPolicy')->setPolicyObject($document)->setCapability($edit_capability)->setPolicies($policies)->setCaption($document->describeAutomaticCapability($edit_capability)))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Edit Notes'))->setValue($notes)->setError(null)->setName('description'))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($cancel_uri)->setValue($submit_button)); $form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Document'))->setValidationException($validation_exception)->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setForm($form); $preview = id(new PHUIRemarkupPreviewPanel())->setHeader($content->getTitle())->setPreviewURI('/phriction/preview/' . $document->getSlug())->setControlID('document-textarea')->setPreviewType(PHUIRemarkupPreviewPanel::DOCUMENT); $crumbs = $this->buildApplicationCrumbs(); if ($document->getID()) { $crumbs->addTextCrumb($content->getTitle(), PhrictionDocument::getSlugURI($document->getSlug())); $crumbs->addTextCrumb(pht('Edit')); } else { $crumbs->addTextCrumb(pht('Create')); } $crumbs->setBorder(true); $header = id(new PHUIHeaderView())->setHeader($panel_header)->setHeaderIcon($header_icon); $view = id(new PHUITwoColumnView())->setHeader($header)->setFooter(array($draft_note, $form_box, $preview)); return $this->newPage()->setTitle($page_title)->setCrumbs($crumbs)->appendChild($view); }
protected final function buildEditFields($object) { $viewer = $this->getViewer(); $editor = $object->getApplicationTransactionEditor(); $types = $editor->getTransactionTypesForObject($object); $types = array_fuse($types); $fields = $this->buildCustomEditFields($object); if ($object instanceof PhabricatorPolicyInterface) { $policies = id(new PhabricatorPolicyQuery())->setViewer($viewer)->setObject($object)->execute(); $map = array(PhabricatorTransactions::TYPE_VIEW_POLICY => array('key' => 'policy.view', 'aliases' => array('view'), 'capability' => PhabricatorPolicyCapability::CAN_VIEW, 'label' => pht('View Policy'), 'description' => pht('Controls who can view the object.'), 'edit' => 'view'), PhabricatorTransactions::TYPE_EDIT_POLICY => array('key' => 'policy.edit', 'aliases' => array('edit'), 'capability' => PhabricatorPolicyCapability::CAN_EDIT, 'label' => pht('Edit Policy'), 'description' => pht('Controls who can edit the object.'), 'edit' => 'edit'), PhabricatorTransactions::TYPE_JOIN_POLICY => array('key' => 'policy.join', 'aliases' => array('join'), 'capability' => PhabricatorPolicyCapability::CAN_JOIN, 'label' => pht('Join Policy'), 'description' => pht('Controls who can join the object.'), 'edit' => 'join')); foreach ($map as $type => $spec) { if (empty($types[$type])) { continue; } $capability = $spec['capability']; $key = $spec['key']; $aliases = $spec['aliases']; $label = $spec['label']; $description = $spec['description']; $edit = $spec['edit']; $policy_field = id(new PhabricatorPolicyEditField())->setKey($key)->setLabel($label)->setDescription($description)->setAliases($aliases)->setCapability($capability)->setPolicies($policies)->setTransactionType($type)->setEditTypeKey($edit)->setValue($object->getPolicy($capability)); $fields[] = $policy_field; if ($object instanceof PhabricatorSpacesInterface) { if ($capability == PhabricatorPolicyCapability::CAN_VIEW) { $type_space = PhabricatorTransactions::TYPE_SPACE; if (isset($types[$type_space])) { $space_field = id(new PhabricatorSpaceEditField())->setKey('spacePHID')->setLabel(pht('Space'))->setEditTypeKey('space')->setDescription(pht('Shifts the object in the Spaces application.'))->setAliases(array('space', 'policy.space'))->setTransactionType($type_space)->setValue($object->getSpacePHID()); $fields[] = $space_field; $policy_field->setSpaceField($space_field); } } } } } $edge_type = PhabricatorTransactions::TYPE_EDGE; $object_phid = $object->getPHID(); $project_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; if ($object instanceof PhabricatorProjectInterface) { if (isset($types[$edge_type])) { if ($object_phid) { $project_phids = PhabricatorEdgeQuery::loadDestinationPHIDs($object_phid, $project_edge_type); $project_phids = array_reverse($project_phids); } else { $project_phids = array(); } $edge_field = id(new PhabricatorProjectsEditField())->setKey('projectPHIDs')->setLabel(pht('Projects'))->setEditTypeKey('projects')->setDescription(pht('Add or remove associated projects.'))->setAliases(array('project', 'projects'))->setTransactionType($edge_type)->setMetadataValue('edge:type', $project_edge_type)->setValue($project_phids); $fields[] = $edge_field; } } $subscribers_type = PhabricatorTransactions::TYPE_SUBSCRIBERS; if ($object instanceof PhabricatorSubscribableInterface) { if (isset($types[$subscribers_type])) { if ($object_phid) { $sub_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID($object_phid); } else { // TODO: Allow applications to provide default subscribers; Maniphest // does this at a minimum. $sub_phids = array(); } $subscribers_field = id(new PhabricatorSubscribersEditField())->setKey('subscriberPHIDs')->setLabel(pht('Subscribers'))->setEditTypeKey('subscribers')->setDescription(pht('Manage subscribers.'))->setAliases(array('subscriber', 'subscribers'))->setTransactionType($subscribers_type)->setValue($sub_phids); $fields[] = $subscribers_field; } } foreach ($fields as $field) { $field->setViewer($viewer)->setObject($object); } return $fields; }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); if ($id) { $mock = id(new PholioMockQuery())->setViewer($viewer)->needImages(true)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->withIDs(array($id))->executeOne(); if (!$mock) { return new Aphront404Response(); } $title = pht('Edit Mock: %s', $mock->getName()); $header_icon = 'fa-pencil'; $is_new = false; $mock_images = $mock->getImages(); $files = mpull($mock_images, 'getFile'); $mock_images = mpull($mock_images, null, 'getFilePHID'); } else { $mock = PholioMock::initializeNewMock($viewer); $title = pht('Create Mock'); $header_icon = 'fa-plus-square'; $is_new = true; $files = array(); $mock_images = array(); } if ($is_new) { $v_projects = array(); } else { $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs($mock->getPHID(), PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); $v_projects = array_reverse($v_projects); } $e_name = true; $e_images = count($mock_images) ? null : true; $errors = array(); $posted_mock_images = array(); $v_name = $mock->getName(); $v_desc = $mock->getDescription(); $v_view = $mock->getViewPolicy(); $v_edit = $mock->getEditPolicy(); $v_cc = PhabricatorSubscribersQuery::loadSubscribersForPHID($mock->getPHID()); $v_space = $mock->getSpacePHID(); if ($request->isFormPost()) { $xactions = array(); $type_name = PholioTransaction::TYPE_NAME; $type_desc = PholioTransaction::TYPE_DESCRIPTION; $type_view = PhabricatorTransactions::TYPE_VIEW_POLICY; $type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY; $type_cc = PhabricatorTransactions::TYPE_SUBSCRIBERS; $type_space = PhabricatorTransactions::TYPE_SPACE; $v_name = $request->getStr('name'); $v_desc = $request->getStr('description'); $v_view = $request->getStr('can_view'); $v_edit = $request->getStr('can_edit'); $v_cc = $request->getArr('cc'); $v_projects = $request->getArr('projects'); $v_space = $request->getStr('spacePHID'); $mock_xactions = array(); $mock_xactions[$type_name] = $v_name; $mock_xactions[$type_desc] = $v_desc; $mock_xactions[$type_view] = $v_view; $mock_xactions[$type_edit] = $v_edit; $mock_xactions[$type_cc] = array('=' => $v_cc); $mock_xactions[$type_space] = $v_space; if (!strlen($request->getStr('name'))) { $e_name = pht('Required'); $errors[] = pht('You must give the mock a name.'); } $file_phids = $request->getArr('file_phids'); if ($file_phids) { $files = id(new PhabricatorFileQuery())->setViewer($viewer)->withPHIDs($file_phids)->execute(); $files = mpull($files, null, 'getPHID'); $files = array_select_keys($files, $file_phids); } else { $files = array(); } if (!$files) { $e_images = pht('Required'); $errors[] = pht('You must add at least one image to the mock.'); } else { $mock->setCoverPHID(head($files)->getPHID()); } foreach ($mock_xactions as $type => $value) { $xactions[$type] = id(new PholioTransaction())->setTransactionType($type)->setNewValue($value); } $order = $request->getStrList('imageOrder'); $sequence_map = array_flip($order); $replaces = $request->getArr('replaces'); $replaces_map = array_flip($replaces); /** * Foreach file posted, check to see whether we are replacing an image, * adding an image, or simply updating image metadata. Create * transactions for these cases as appropos. */ foreach ($files as $file_phid => $file) { $replaces_image_phid = null; if (isset($replaces_map[$file_phid])) { $old_file_phid = $replaces_map[$file_phid]; if ($old_file_phid != $file_phid) { $old_image = idx($mock_images, $old_file_phid); if ($old_image) { $replaces_image_phid = $old_image->getPHID(); } } } $existing_image = idx($mock_images, $file_phid); $title = (string) $request->getStr('title_' . $file_phid); $description = (string) $request->getStr('description_' . $file_phid); $sequence = $sequence_map[$file_phid]; if ($replaces_image_phid) { $replace_image = id(new PholioImage())->setReplacesImagePHID($replaces_image_phid)->setFilePhid($file_phid)->attachFile($file)->setName(strlen($title) ? $title : $file->getName())->setDescription($description)->setSequence($sequence); $xactions[] = id(new PholioTransaction())->setTransactionType(PholioTransaction::TYPE_IMAGE_REPLACE)->setNewValue($replace_image); $posted_mock_images[] = $replace_image; } else { if (!$existing_image) { // this is an add $add_image = id(new PholioImage())->setFilePhid($file_phid)->attachFile($file)->setName(strlen($title) ? $title : $file->getName())->setDescription($description)->setSequence($sequence); $xactions[] = id(new PholioTransaction())->setTransactionType(PholioTransaction::TYPE_IMAGE_FILE)->setNewValue(array('+' => array($add_image))); $posted_mock_images[] = $add_image; } else { $xactions[] = id(new PholioTransaction())->setTransactionType(PholioTransaction::TYPE_IMAGE_NAME)->setNewValue(array($existing_image->getPHID() => $title)); $xactions[] = id(new PholioTransaction())->setTransactionType(PholioTransaction::TYPE_IMAGE_DESCRIPTION)->setNewValue(array($existing_image->getPHID() => $description)); $xactions[] = id(new PholioTransaction())->setTransactionType(PholioTransaction::TYPE_IMAGE_SEQUENCE)->setNewValue(array($existing_image->getPHID() => $sequence)); $posted_mock_images[] = $existing_image; } } } foreach ($mock_images as $file_phid => $mock_image) { if (!isset($files[$file_phid]) && !isset($replaces[$file_phid])) { // this is an outright delete $xactions[] = id(new PholioTransaction())->setTransactionType(PholioTransaction::TYPE_IMAGE_FILE)->setNewValue(array('-' => array($mock_image))); } } if (!$errors) { $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; $xactions[] = id(new PholioTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', $proj_edge_type)->setNewValue(array('=' => array_fuse($v_projects))); $mock->openTransaction(); $editor = id(new PholioMockEditor())->setContentSourceFromRequest($request)->setContinueOnNoEffect(true)->setActor($viewer); $xactions = $editor->applyTransactions($mock, $xactions); $mock->saveTransaction(); return id(new AphrontRedirectResponse())->setURI('/M' . $mock->getID()); } } if ($id) { $submit = id(new AphrontFormSubmitControl())->addCancelButton('/M' . $id)->setValue(pht('Save')); } else { $submit = id(new AphrontFormSubmitControl())->addCancelButton($this->getApplicationURI())->setValue(pht('Create')); } $policies = id(new PhabricatorPolicyQuery())->setViewer($viewer)->setObject($mock)->execute(); // NOTE: Make this show up correctly on the rendered form. $mock->setViewPolicy($v_view); $mock->setEditPolicy($v_edit); $image_elements = array(); if ($posted_mock_images) { $display_mock_images = $posted_mock_images; } else { $display_mock_images = $mock_images; } foreach ($display_mock_images as $mock_image) { $image_elements[] = id(new PholioUploadedImageView())->setUser($viewer)->setImage($mock_image)->setReplacesPHID($mock_image->getFilePHID()); } $list_id = celerity_generate_unique_node_id(); $drop_id = celerity_generate_unique_node_id(); $order_id = celerity_generate_unique_node_id(); $list_control = phutil_tag('div', array('id' => $list_id, 'class' => 'pholio-edit-list'), $image_elements); $drop_control = phutil_tag('a', array('id' => $drop_id, 'class' => 'pholio-edit-drop'), pht('Click here, or drag and drop images to add them to the mock.')); $order_control = phutil_tag('input', array('type' => 'hidden', 'name' => 'imageOrder', 'id' => $order_id)); Javelin::initBehavior('pholio-mock-edit', array('listID' => $list_id, 'dropID' => $drop_id, 'orderID' => $order_id, 'uploadURI' => '/file/dropupload/', 'renderURI' => $this->getApplicationURI('image/upload/'), 'pht' => array('uploading' => pht('Uploading Image...'), 'uploaded' => pht('Upload Complete...'), 'undo' => pht('Undo'), 'removed' => pht('This image will be removed from the mock.')))); require_celerity_resource('pholio-edit-css'); $form = id(new AphrontFormView())->setUser($viewer)->appendChild($order_control)->appendChild(id(new AphrontFormTextControl())->setName('name')->setValue($v_name)->setLabel(pht('Name'))->setError($e_name))->appendChild(id(new PhabricatorRemarkupControl())->setName('description')->setValue($v_desc)->setLabel(pht('Description'))->setUser($viewer))->appendControl(id(new AphrontFormTokenizerControl())->setLabel(pht('Tags'))->setName('projects')->setValue($v_projects)->setDatasource(new PhabricatorProjectDatasource()))->appendControl(id(new AphrontFormTokenizerControl())->setLabel(pht('Subscribers'))->setName('cc')->setValue($v_cc)->setUser($viewer)->setDatasource(new PhabricatorMetaMTAMailableDatasource()))->appendChild(id(new AphrontFormPolicyControl())->setUser($viewer)->setCapability(PhabricatorPolicyCapability::CAN_VIEW)->setPolicyObject($mock)->setPolicies($policies)->setSpacePHID($v_space)->setName('can_view'))->appendChild(id(new AphrontFormPolicyControl())->setUser($viewer)->setCapability(PhabricatorPolicyCapability::CAN_EDIT)->setPolicyObject($mock)->setPolicies($policies)->setName('can_edit'))->appendChild(id(new AphrontFormMarkupControl())->setValue($list_control))->appendChild(id(new AphrontFormMarkupControl())->setValue($drop_control)->setError($e_images))->appendChild($submit); $form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Mock'))->setFormErrors($errors)->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setForm($form); $crumbs = $this->buildApplicationCrumbs(); if (!$is_new) { $crumbs->addTextCrumb($mock->getMonogram(), '/' . $mock->getMonogram()); } $crumbs->addTextCrumb($title); $crumbs->setBorder(true); $header = id(new PHUIHeaderView())->setHeader($title)->setHeaderIcon($header_icon); $view = id(new PHUITwoColumnView())->setHeader($header)->setFooter($form_box); return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->addQuicksandConfig(array('mockEditConfig' => true))->appendChild($view); }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); if ($id) { $post = id(new PhamePostQuery())->setViewer($viewer)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_EDIT))->executeOne(); if (!$post) { return new Aphront404Response(); } $cancel_uri = $this->getApplicationURI('/post/view/' . $id . '/'); $submit_button = pht('Save Changes'); $page_title = pht('Edit Post'); $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs($post->getPHID(), PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); $v_projects = array_reverse($v_projects); $v_cc = PhabricatorSubscribersQuery::loadSubscribersForPHID($post->getPHID()); } else { $blog = id(new PhameBlogQuery())->setViewer($viewer)->withIDs(array($request->getInt('blog')))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne(); if (!$blog) { return new Aphront404Response(); } $v_projects = array(); $v_cc = array(); $post = PhamePost::initializePost($viewer, $blog); $cancel_uri = $this->getApplicationURI('/blog/view/' . $blog->getID() . '/'); $submit_button = pht('Create Post'); $page_title = pht('Create Post'); } $title = $post->getTitle(); $phame_title = $post->getPhameTitle(); $body = $post->getBody(); $visibility = $post->getVisibility(); $e_title = true; $e_phame_title = true; $validation_exception = null; if ($request->isFormPost()) { $title = $request->getStr('title'); $phame_title = $request->getStr('phame_title'); $phame_title = PhabricatorSlug::normalize($phame_title); $body = $request->getStr('body'); $v_projects = $request->getArr('projects'); $v_cc = $request->getArr('cc'); $visibility = $request->getInt('visibility'); $xactions = array(id(new PhamePostTransaction())->setTransactionType(PhamePostTransaction::TYPE_TITLE)->setNewValue($title), id(new PhamePostTransaction())->setTransactionType(PhamePostTransaction::TYPE_PHAME_TITLE)->setNewValue($phame_title), id(new PhamePostTransaction())->setTransactionType(PhamePostTransaction::TYPE_BODY)->setNewValue($body), id(new PhamePostTransaction())->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY)->setNewValue($visibility), id(new PhamePostTransaction())->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)->setNewValue(array('=' => $v_cc))); $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; $xactions[] = id(new PhamePostTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', $proj_edge_type)->setNewValue(array('=' => array_fuse($v_projects))); $editor = id(new PhamePostEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true); try { $editor->applyTransactions($post, $xactions); $uri = $this->getApplicationURI('/post/view/' . $post->getID() . '/'); return id(new AphrontRedirectResponse())->setURI($uri); } catch (PhabricatorApplicationTransactionValidationException $ex) { $validation_exception = $ex; $e_title = $validation_exception->getShortMessage(PhamePostTransaction::TYPE_TITLE); $e_phame_title = $validation_exception->getShortMessage(PhamePostTransaction::TYPE_PHAME_TITLE); } } $handle = id(new PhabricatorHandleQuery())->setViewer($viewer)->withPHIDs(array($post->getBlogPHID()))->executeOne(); $form = id(new AphrontFormView())->setUser($viewer)->addHiddenInput('blog', $request->getInt('blog'))->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Blog'))->setValue($handle->renderLink()))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Title'))->setName('title')->setValue($title)->setID('post-title')->setError($e_title))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Phame Title'))->setName('phame_title')->setValue(rtrim($phame_title, '/'))->setID('post-phame-title')->setCaption(pht('Up to 64 alphanumeric characters ' . 'with underscores for spaces. ' . 'Formatting is enforced.'))->setError($e_phame_title))->appendChild(id(new AphrontFormSelectControl())->setLabel(pht('Visibility'))->setName('visibility')->setvalue($visibility)->setOptions(PhameConstants::getPhamePostStatusMap()))->appendChild(id(new PhabricatorRemarkupControl())->setLabel(pht('Body'))->setName('body')->setValue($body)->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)->setID('post-body')->setUser($viewer)->setDisableMacros(true))->appendControl(id(new AphrontFormTokenizerControl())->setLabel(pht('Subscribers'))->setName('cc')->setValue($v_cc)->setUser($viewer)->setDatasource(new PhabricatorMetaMTAMailableDatasource()))->appendControl(id(new AphrontFormTokenizerControl())->setLabel(pht('Projects'))->setName('projects')->setValue($v_projects)->setDatasource(new PhabricatorProjectDatasource()))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($cancel_uri)->setValue($submit_button)); $preview = id(new PHUIRemarkupPreviewPanel())->setHeader($post->getTitle())->setPreviewURI($this->getApplicationURI('post/preview/'))->setControlID('post-body')->setPreviewType(PHUIRemarkupPreviewPanel::DOCUMENT); Javelin::initBehavior('phame-post-preview', array('title' => 'post-title', 'phame_title' => 'post-phame-title')); $form_box = id(new PHUIObjectBoxView())->setHeaderText($page_title)->setValidationException($validation_exception)->setForm($form); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($page_title, $this->getApplicationURI('/post/view/' . $id . '/')); return $this->newPage()->setTitle($page_title)->setCrumbs($crumbs)->appendChild(array($form_box, $preview)); }
public function getHeraldField($field_name) { switch ($field_name) { case self::FIELD_RULE: return null; case self::FIELD_CONTENT_SOURCE: return $this->getContentSource()->getSource(); case self::FIELD_ALWAYS: return true; case self::FIELD_IS_NEW_OBJECT: return $this->getIsNewObject(); case self::FIELD_CC: $object = $this->getObject(); if (!$object instanceof PhabricatorSubscribableInterface) { throw new Exception(pht('Adapter object (of class "%s") does not implement interface ' . '"%s", so the subscribers field value can not be determined.', get_class($object), 'PhabricatorSubscribableInterface')); } $phid = $object->getPHID(); return PhabricatorSubscribersQuery::loadSubscribersForPHID($phid); case self::FIELD_APPLICATION_EMAIL: $value = array(); // while there is only one match by implementation, we do set // comparisons on phids, so return an array with just the phid if ($this->getApplicationEmail()) { $value[] = $this->getApplicationEmail()->getPHID(); } return $value; case self::FIELD_SPACE: $object = $this->getObject(); if (!$object instanceof PhabricatorSpacesInterface) { throw new Exception(pht('Adapter object (of class "%s") does not implement interface ' . '"%s", so the Space field value can not be determined.', get_class($object), 'PhabricatorSpacesInterface')); } return PhabricatorSpacesNamespaceQuery::getObjectSpacePHID($object); default: if ($this->isHeraldCustomKey($field_name)) { return $this->getCustomFieldValue($field_name); } throw new Exception(pht("Unknown field '%s'!", $field_name)); } }
/** * @task mail */ protected function getMailCC(PhabricatorLiskDAO $object) { $phids = array(); $has_support = false; if ($object instanceof PhabricatorSubscribableInterface) { $phid = $object->getPHID(); $phids[] = PhabricatorSubscribersQuery::loadSubscribersForPHID($phid); $has_support = true; } if ($object instanceof PhabricatorProjectInterface) { $project_phids = PhabricatorEdgeQuery::loadDestinationPHIDs($object->getPHID(), PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); if ($project_phids) { $projects = id(new PhabricatorProjectQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withPHIDs($project_phids)->needWatchers(true)->execute(); $watcher_phids = array(); foreach ($projects as $project) { foreach ($project->getAllAncestorWatcherPHIDs() as $phid) { $watcher_phids[$phid] = $phid; } } if ($watcher_phids) { // We need to do a visibility check for all the watchers, as // watching a project is not a guarantee that you can see objects // associated with it. $users = id(new PhabricatorPeopleQuery())->setViewer($this->requireActor())->withPHIDs($watcher_phids)->execute(); $watchers = array(); foreach ($users as $user) { $can_see = PhabricatorPolicyFilter::hasCapability($user, $object, PhabricatorPolicyCapability::CAN_VIEW); if ($can_see) { $watchers[] = $user->getPHID(); } } $phids[] = $watchers; } } $has_support = true; } if (!$has_support) { throw new Exception(pht('Capability not supported.')); } return array_mergev($phids); }
public function handleRequest(AphrontRequest $request) { $id = $request->getURIData('id'); $is_create = !$id; $viewer = $request->getViewer(); $user_phid = $viewer->getPHID(); $error_name = true; $error_long_url = true; $validation_exception = null; $next_workflow = $request->getStr('next'); $uri_query = $request->getStr('query'); if ($is_create) { $url = PhabricatorPhurlURL::initializeNewPhurlURL($viewer); $submit_label = pht('Create'); $page_title = pht('Shorten URL'); $subscribers = array(); $cancel_uri = $this->getApplicationURI(); } else { $url = id(new PhabricatorPhurlURLQuery())->setViewer($viewer)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne(); if (!$url) { return new Aphront404Response(); } $submit_label = pht('Update'); $page_title = pht('Update URL'); $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID($url->getPHID()); $cancel_uri = '/U' . $url->getID(); } if ($is_create) { $projects = array(); } else { $projects = PhabricatorEdgeQuery::loadDestinationPHIDs($url->getPHID(), PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); $projects = array_reverse($projects); } $name = $url->getName(); $long_url = $url->getLongURL(); $description = $url->getDescription(); $edit_policy = $url->getEditPolicy(); $view_policy = $url->getViewPolicy(); $space = $url->getSpacePHID(); if ($request->isFormPost()) { $xactions = array(); $name = $request->getStr('name'); $long_url = $request->getStr('longURL'); $projects = $request->getArr('projects'); $description = $request->getStr('description'); $subscribers = $request->getArr('subscribers'); $edit_policy = $request->getStr('editPolicy'); $view_policy = $request->getStr('viewPolicy'); $space = $request->getStr('spacePHID'); $xactions[] = id(new PhabricatorPhurlURLTransaction())->setTransactionType(PhabricatorPhurlURLTransaction::TYPE_NAME)->setNewValue($name); $xactions[] = id(new PhabricatorPhurlURLTransaction())->setTransactionType(PhabricatorPhurlURLTransaction::TYPE_URL)->setNewValue($long_url); $xactions[] = id(new PhabricatorPhurlURLTransaction())->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)->setNewValue(array('=' => array_fuse($subscribers))); $xactions[] = id(new PhabricatorPhurlURLTransaction())->setTransactionType(PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION)->setNewValue($description); $xactions[] = id(new PhabricatorPhurlURLTransaction())->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)->setNewValue($view_policy); $xactions[] = id(new PhabricatorPhurlURLTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)->setNewValue($edit_policy); $xactions[] = id(new PhabricatorPhurlURLTransaction())->setTransactionType(PhabricatorTransactions::TYPE_SPACE)->setNewValue($space); $editor = id(new PhabricatorPhurlURLEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true); try { $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; $xactions[] = id(new PhabricatorPhurlURLTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', $proj_edge_type)->setNewValue(array('=' => array_fuse($projects))); $xactions = $editor->applyTransactions($url, $xactions); return id(new AphrontRedirectResponse())->setURI($url->getURI()); } catch (PhabricatorApplicationTransactionValidationException $ex) { $validation_exception = $ex; $error_name = $ex->getShortMessage(PhabricatorPhurlURLTransaction::TYPE_NAME); $error_long_url = $ex->getShortMessage(PhabricatorPhurlURLTransaction::TYPE_URL); } } $current_policies = id(new PhabricatorPolicyQuery())->setViewer($viewer)->setObject($url)->execute(); $name = id(new AphrontFormTextControl())->setLabel(pht('Name'))->setName('name')->setValue($name)->setError($error_name); $long_url = id(new AphrontFormTextControl())->setLabel(pht('URL'))->setName('longURL')->setValue($long_url)->setError($error_long_url); $projects = id(new AphrontFormTokenizerControl())->setLabel(pht('Projects'))->setName('projects')->setValue($projects)->setUser($viewer)->setDatasource(new PhabricatorProjectDatasource()); $description = id(new PhabricatorRemarkupControl())->setLabel(pht('Description'))->setName('description')->setValue($description)->setUser($viewer); $view_policies = id(new AphrontFormPolicyControl())->setUser($viewer)->setValue($view_policy)->setCapability(PhabricatorPolicyCapability::CAN_VIEW)->setPolicyObject($url)->setPolicies($current_policies)->setSpacePHID($space)->setName('viewPolicy'); $edit_policies = id(new AphrontFormPolicyControl())->setUser($viewer)->setValue($edit_policy)->setCapability(PhabricatorPolicyCapability::CAN_EDIT)->setPolicyObject($url)->setPolicies($current_policies)->setName('editPolicy'); $subscribers = id(new AphrontFormTokenizerControl())->setLabel(pht('Subscribers'))->setName('subscribers')->setValue($subscribers)->setUser($viewer)->setDatasource(new PhabricatorMetaMTAMailableDatasource()); $form = id(new AphrontFormView())->setUser($viewer)->appendChild($name)->appendChild($long_url)->appendControl($view_policies)->appendControl($edit_policies)->appendControl($subscribers)->appendChild($projects)->appendChild($description); if ($request->isAjax()) { return $this->newDialog()->setTitle($page_title)->setWidth(AphrontDialogView::WIDTH_FULL)->appendForm($form)->addCancelButton($cancel_uri)->addSubmitButton($submit_label); } $submit = id(new AphrontFormSubmitControl())->addCancelButton($cancel_uri)->setValue($submit_label); $form->appendChild($submit); $form_box = id(new PHUIObjectBoxView())->setHeaderText($page_title)->setForm($form); $crumbs = $this->buildApplicationCrumbs(); if (!$is_create) { $crumbs->addTextCrumb($url->getMonogram(), $url->getURI()); } else { $crumbs->addTextCrumb(pht('Create URL')); } $crumbs->addTextCrumb($page_title); $object_box = id(new PHUIObjectBoxView())->setHeaderText($page_title)->setValidationException($validation_exception)->appendChild($form); return $this->buildApplicationPage(array($crumbs, $object_box), array('title' => $page_title)); }
public function getCCUserPHIDs($object) { return PhabricatorSubscribersQuery::loadSubscribersForPHID($object->getPHID()); }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); if ($id) { $blog = id(new PhameBlogQuery())->setViewer($viewer)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_EDIT))->executeOne(); if (!$blog) { return new Aphront404Response(); } $submit_button = pht('Save Changes'); $page_title = pht('Edit Blog'); $cancel_uri = $this->getApplicationURI('blog/view/' . $blog->getID() . '/'); $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs($blog->getPHID(), PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); $v_projects = array_reverse($v_projects); $v_cc = PhabricatorSubscribersQuery::loadSubscribersForPHID($blog->getPHID()); } else { $this->requireApplicationCapability(PhameBlogCreateCapability::CAPABILITY); $blog = PhameBlog::initializeNewBlog($viewer); $submit_button = pht('Create Blog'); $page_title = pht('Create Blog'); $cancel_uri = $this->getApplicationURI(); $v_projects = array(); $v_cc = array(); } $name = $blog->getName(); $description = $blog->getDescription(); $custom_domain = $blog->getDomain(); $skin = $blog->getSkin(); $can_view = $blog->getViewPolicy(); $can_edit = $blog->getEditPolicy(); $e_name = true; $e_custom_domain = null; $e_view_policy = null; $validation_exception = null; if ($request->isFormPost()) { $name = $request->getStr('name'); $description = $request->getStr('description'); $custom_domain = nonempty($request->getStr('custom_domain'), null); $skin = $request->getStr('skin'); $can_view = $request->getStr('can_view'); $can_edit = $request->getStr('can_edit'); $v_projects = $request->getArr('projects'); $v_cc = $request->getArr('cc'); $xactions = array(id(new PhameBlogTransaction())->setTransactionType(PhameBlogTransaction::TYPE_NAME)->setNewValue($name), id(new PhameBlogTransaction())->setTransactionType(PhameBlogTransaction::TYPE_DESCRIPTION)->setNewValue($description), id(new PhameBlogTransaction())->setTransactionType(PhameBlogTransaction::TYPE_DOMAIN)->setNewValue($custom_domain), id(new PhameBlogTransaction())->setTransactionType(PhameBlogTransaction::TYPE_SKIN)->setNewValue($skin), id(new PhameBlogTransaction())->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)->setNewValue($can_view), id(new PhameBlogTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)->setNewValue($can_edit), id(new PhameBlogTransaction())->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)->setNewValue(array('=' => $v_cc))); $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; $xactions[] = id(new PhameBlogTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', $proj_edge_type)->setNewValue(array('=' => array_fuse($v_projects))); $editor = id(new PhameBlogEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true); try { $editor->applyTransactions($blog, $xactions); return id(new AphrontRedirectResponse())->setURI($this->getApplicationURI('blog/view/' . $blog->getID() . '/')); } catch (PhabricatorApplicationTransactionValidationException $ex) { $validation_exception = $ex; $e_name = $validation_exception->getShortMessage(PhameBlogTransaction::TYPE_NAME); $e_custom_domain = $validation_exception->getShortMessage(PhameBlogTransaction::TYPE_DOMAIN); $e_view_policy = $validation_exception->getShortMessage(PhabricatorTransactions::TYPE_VIEW_POLICY); } } $policies = id(new PhabricatorPolicyQuery())->setViewer($viewer)->setObject($blog)->execute(); $skins = PhameSkinSpecification::loadAllSkinSpecifications(); $skins = mpull($skins, 'getName'); $form = id(new AphrontFormView())->setUser($viewer)->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Name'))->setName('name')->setValue($name)->setID('blog-name')->setError($e_name))->appendChild(id(new PhabricatorRemarkupControl())->setUser($viewer)->setLabel(pht('Description'))->setName('description')->setValue($description)->setID('blog-description')->setUser($viewer)->setDisableMacros(true))->appendControl(id(new AphrontFormTokenizerControl())->setLabel(pht('Subscribers'))->setName('cc')->setValue($v_cc)->setUser($viewer)->setDatasource(new PhabricatorMetaMTAMailableDatasource()))->appendChild(id(new AphrontFormPolicyControl())->setUser($viewer)->setCapability(PhabricatorPolicyCapability::CAN_VIEW)->setPolicyObject($blog)->setPolicies($policies)->setError($e_view_policy)->setValue($can_view)->setName('can_view'))->appendChild(id(new AphrontFormPolicyControl())->setUser($viewer)->setCapability(PhabricatorPolicyCapability::CAN_EDIT)->setPolicyObject($blog)->setPolicies($policies)->setValue($can_edit)->setName('can_edit'))->appendControl(id(new AphrontFormTokenizerControl())->setLabel(pht('Projects'))->setName('projects')->setValue($v_projects)->setDatasource(new PhabricatorProjectDatasource()))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Custom Domain'))->setName('custom_domain')->setValue($custom_domain)->setCaption(pht('Must include at least one dot (.), e.g. %s', 'blog.example.com'))->setError($e_custom_domain))->appendChild(id(new AphrontFormSelectControl())->setLabel(pht('Skin'))->setName('skin')->setValue($skin)->setOptions($skins))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($cancel_uri)->setValue($submit_button)); $form_box = id(new PHUIObjectBoxView())->setHeaderText($page_title)->setValidationException($validation_exception)->setForm($form); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Blogs'), $this->getApplicationURI('blog/')); $crumbs->addTextCrumb($page_title, $this->getApplicationURI('blog/new')); return $this->newPage()->setTitle($page_title)->setCrumbs($crumbs)->appendChild(array($form_box)); }
protected function buildHeraldAdapter(PhabricatorLiskDAO $object, array $xactions) { $unsubscribed_phids = PhabricatorEdgeQuery::loadDestinationPHIDs($object->getPHID(), PhabricatorEdgeConfig::TYPE_OBJECT_HAS_UNSUBSCRIBER); $subscribed_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID($object->getPHID()); $revision = id(new DifferentialRevisionQuery())->setViewer($this->getActor())->withPHIDs(array($object->getPHID()))->needActiveDiffs(true)->needReviewerStatus(true)->executeOne(); if (!$revision) { throw new Exception(pht('Failed to load revision for Herald adapter construction!')); } $adapter = HeraldDifferentialRevisionAdapter::newLegacyAdapter($revision, $revision->getActiveDiff()); $reviewers = $revision->getReviewerStatus(); $reviewer_phids = mpull($reviewers, 'getReviewerPHID'); $adapter->setExplicitCCs($subscribed_phids); $adapter->setExplicitReviewers($reviewer_phids); $adapter->setForbiddenCCs($unsubscribed_phids); $adapter->setIsNewObject($this->getIsNewObject()); return $adapter; }
protected function getMailTo(PhabricatorLiskDAO $object) { $phids = array(); $phids[] = $object->getBloggerPHID(); $phids[] = $this->requireActor()->getPHID(); $blog_phid = $object->getBlogPHID(); if ($blog_phid) { $cc_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID($blog_phid); foreach ($cc_phids as $cc) { $phids[] = $cc; } } return $phids; }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $user_phid = $viewer->getPHID(); $this->id = $request->getURIData('id'); $error_name = true; $error_recurrence_end_date = null; $error_start_date = true; $error_end_date = true; $validation_exception = null; $is_recurring_id = celerity_generate_unique_node_id(); $recurrence_end_date_id = celerity_generate_unique_node_id(); $frequency_id = celerity_generate_unique_node_id(); $all_day_id = celerity_generate_unique_node_id(); $start_date_id = celerity_generate_unique_node_id(); $end_date_id = celerity_generate_unique_node_id(); $next_workflow = $request->getStr('next'); $uri_query = $request->getStr('query'); if ($this->isCreate()) { $mode = $request->getStr('mode'); $event = PhabricatorCalendarEvent::initializeNewCalendarEvent($viewer, $mode); $create_start_year = $request->getInt('year'); $create_start_month = $request->getInt('month'); $create_start_day = $request->getInt('day'); $create_start_time = $request->getStr('time'); if ($create_start_year) { $start = AphrontFormDateControlValue::newFromParts($viewer, $create_start_year, $create_start_month, $create_start_day, $create_start_time); if (!$start->isValid()) { return new Aphront400Response(); } $start_value = AphrontFormDateControlValue::newFromEpoch($viewer, $start->getEpoch()); $end = clone $start_value->getDateTime(); $end->modify('+1 hour'); $end_value = AphrontFormDateControlValue::newFromEpoch($viewer, $end->format('U')); } else { list($start_value, $end_value) = $this->getDefaultTimeValues($viewer); } $recurrence_end_date_value = clone $end_value; $recurrence_end_date_value->setOptional(true); $submit_label = pht('Create'); $page_title = pht('Create Event'); $redirect = 'created'; $subscribers = array(); $invitees = array($user_phid); $cancel_uri = $this->getApplicationURI(); } else { $event = id(new PhabricatorCalendarEventQuery())->setViewer($viewer)->withIDs(array($this->id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne(); if (!$event) { return new Aphront404Response(); } if ($request->getURIData('sequence')) { $index = $request->getURIData('sequence'); $result = $this->getEventAtIndexForGhostPHID($viewer, $event->getPHID(), $index); if ($result) { return id(new AphrontRedirectResponse())->setURI('/calendar/event/edit/' . $result->getID() . '/'); } $event = $this->createEventFromGhost($viewer, $event, $index); return id(new AphrontRedirectResponse())->setURI('/calendar/event/edit/' . $event->getID() . '/'); } $end_value = AphrontFormDateControlValue::newFromEpoch($viewer, $event->getDateTo()); $start_value = AphrontFormDateControlValue::newFromEpoch($viewer, $event->getDateFrom()); $recurrence_end_date_value = id(clone $end_value)->setOptional(true); $submit_label = pht('Update'); $page_title = pht('Update Event'); $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID($event->getPHID()); $invitees = array(); foreach ($event->getInvitees() as $invitee) { if ($invitee->isUninvited()) { continue; } else { $invitees[] = $invitee->getInviteePHID(); } } $cancel_uri = '/' . $event->getMonogram(); } if ($this->isCreate()) { $projects = array(); } else { $projects = PhabricatorEdgeQuery::loadDestinationPHIDs($event->getPHID(), PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); $projects = array_reverse($projects); } $name = $event->getName(); $description = $event->getDescription(); $is_all_day = $event->getIsAllDay(); $is_recurring = $event->getIsRecurring(); $is_parent = $event->getIsRecurrenceParent(); $frequency = idx($event->getRecurrenceFrequency(), 'rule'); $icon = $event->getIcon(); $edit_policy = $event->getEditPolicy(); $view_policy = $event->getViewPolicy(); $space = $event->getSpacePHID(); if ($request->isFormPost()) { $xactions = array(); $name = $request->getStr('name'); $start_value = AphrontFormDateControlValue::newFromRequest($request, 'start'); $end_value = AphrontFormDateControlValue::newFromRequest($request, 'end'); $recurrence_end_date_value = AphrontFormDateControlValue::newFromRequest($request, 'recurrenceEndDate'); $recurrence_end_date_value->setOptional(true); $projects = $request->getArr('projects'); $description = $request->getStr('description'); $subscribers = $request->getArr('subscribers'); $edit_policy = $request->getStr('editPolicy'); $view_policy = $request->getStr('viewPolicy'); $space = $request->getStr('spacePHID'); $is_recurring = $request->getStr('isRecurring') ? 1 : 0; $frequency = $request->getStr('frequency'); $is_all_day = $request->getStr('isAllDay'); $icon = $request->getStr('icon'); $invitees = $request->getArr('invitees'); $new_invitees = $this->getNewInviteeList($invitees, $event); $status_attending = PhabricatorCalendarEventInvitee::STATUS_ATTENDING; if ($this->isCreate()) { $status = idx($new_invitees, $viewer->getPHID()); if ($status) { $new_invitees[$viewer->getPHID()] = $status_attending; } } $xactions[] = id(new PhabricatorCalendarEventTransaction())->setTransactionType(PhabricatorCalendarEventTransaction::TYPE_NAME)->setNewValue($name); if ($is_recurring && $this->isCreate()) { $xactions[] = id(new PhabricatorCalendarEventTransaction())->setTransactionType(PhabricatorCalendarEventTransaction::TYPE_RECURRING)->setNewValue($is_recurring); $xactions[] = id(new PhabricatorCalendarEventTransaction())->setTransactionType(PhabricatorCalendarEventTransaction::TYPE_FREQUENCY)->setNewValue(array('rule' => $frequency)); if (!$recurrence_end_date_value->isDisabled()) { $xactions[] = id(new PhabricatorCalendarEventTransaction())->setTransactionType(PhabricatorCalendarEventTransaction::TYPE_RECURRENCE_END_DATE)->setNewValue($recurrence_end_date_value); } } if ($is_recurring && $this->isCreate() || !$is_parent) { $xactions[] = id(new PhabricatorCalendarEventTransaction())->setTransactionType(PhabricatorCalendarEventTransaction::TYPE_ALL_DAY)->setNewValue($is_all_day); $xactions[] = id(new PhabricatorCalendarEventTransaction())->setTransactionType(PhabricatorCalendarEventTransaction::TYPE_ICON)->setNewValue($icon); $xactions[] = id(new PhabricatorCalendarEventTransaction())->setTransactionType(PhabricatorCalendarEventTransaction::TYPE_START_DATE)->setNewValue($start_value); $xactions[] = id(new PhabricatorCalendarEventTransaction())->setTransactionType(PhabricatorCalendarEventTransaction::TYPE_END_DATE)->setNewValue($end_value); } $xactions[] = id(new PhabricatorCalendarEventTransaction())->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)->setNewValue(array('=' => array_fuse($subscribers))); $xactions[] = id(new PhabricatorCalendarEventTransaction())->setTransactionType(PhabricatorCalendarEventTransaction::TYPE_INVITE)->setNewValue($new_invitees); $xactions[] = id(new PhabricatorCalendarEventTransaction())->setTransactionType(PhabricatorCalendarEventTransaction::TYPE_DESCRIPTION)->setNewValue($description); $xactions[] = id(new PhabricatorCalendarEventTransaction())->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)->setNewValue($request->getStr('viewPolicy')); $xactions[] = id(new PhabricatorCalendarEventTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)->setNewValue($request->getStr('editPolicy')); $xactions[] = id(new PhabricatorCalendarEventTransaction())->setTransactionType(PhabricatorTransactions::TYPE_SPACE)->setNewValue($space); $editor = id(new PhabricatorCalendarEventEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true); try { $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; $xactions[] = id(new PhabricatorCalendarEventTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', $proj_edge_type)->setNewValue(array('=' => array_fuse($projects))); $xactions = $editor->applyTransactions($event, $xactions); $response = id(new AphrontRedirectResponse()); switch ($next_workflow) { case 'day': if (!$uri_query) { $uri_query = 'month'; } $year = $start_value->getDateTime()->format('Y'); $month = $start_value->getDateTime()->format('m'); $day = $start_value->getDateTime()->format('d'); $response->setURI('/calendar/query/' . $uri_query . '/' . $year . '/' . $month . '/' . $day . '/'); break; default: $response->setURI('/E' . $event->getID()); break; } return $response; } catch (PhabricatorApplicationTransactionValidationException $ex) { $validation_exception = $ex; $error_name = $ex->getShortMessage(PhabricatorCalendarEventTransaction::TYPE_NAME); $error_start_date = $ex->getShortMessage(PhabricatorCalendarEventTransaction::TYPE_START_DATE); $error_end_date = $ex->getShortMessage(PhabricatorCalendarEventTransaction::TYPE_END_DATE); $error_recurrence_end_date = $ex->getShortMessage(PhabricatorCalendarEventTransaction::TYPE_RECURRENCE_END_DATE); } } $is_recurring_checkbox = null; $recurrence_end_date_control = null; $recurrence_frequency_select = null; $all_day_checkbox = null; $start_control = null; $end_control = null; $recurring_date_edit_label = null; $current_policies = id(new PhabricatorPolicyQuery())->setViewer($viewer)->setObject($event)->execute(); $name = id(new AphrontFormTextControl())->setLabel(pht('Name'))->setName('name')->setValue($name)->setError($error_name); if ($this->isCreate()) { Javelin::initBehavior('recurring-edit', array('isRecurring' => $is_recurring_id, 'frequency' => $frequency_id, 'recurrenceEndDate' => $recurrence_end_date_id)); $is_recurring_checkbox = id(new AphrontFormCheckboxControl())->addCheckbox('isRecurring', 1, pht('Recurring Event'), $is_recurring, $is_recurring_id); $recurrence_end_date_control = id(new AphrontFormDateControl())->setUser($viewer)->setName('recurrenceEndDate')->setLabel(pht('Recurrence End Date'))->setError($error_recurrence_end_date)->setValue($recurrence_end_date_value)->setID($recurrence_end_date_id)->setIsTimeDisabled(true)->setIsDisabled($recurrence_end_date_value->isDisabled())->setAllowNull(true); $recurrence_frequency_select = id(new AphrontFormSelectControl())->setName('frequency')->setOptions(array(PhabricatorCalendarEvent::FREQUENCY_DAILY => pht('Daily'), PhabricatorCalendarEvent::FREQUENCY_WEEKLY => pht('Weekly'), PhabricatorCalendarEvent::FREQUENCY_MONTHLY => pht('Monthly'), PhabricatorCalendarEvent::FREQUENCY_YEARLY => pht('Yearly')))->setValue($frequency)->setLabel(pht('Recurring Event Frequency'))->setID($frequency_id)->setDisabled(!$is_recurring); } if ($this->isCreate() || !$is_parent && !$this->isCreate()) { Javelin::initBehavior('event-all-day', array('allDayID' => $all_day_id, 'startDateID' => $start_date_id, 'endDateID' => $end_date_id)); $all_day_checkbox = id(new AphrontFormCheckboxControl())->addCheckbox('isAllDay', 1, pht('All Day Event'), $is_all_day, $all_day_id); $start_control = id(new AphrontFormDateControl())->setUser($viewer)->setName('start')->setLabel(pht('Start'))->setError($error_start_date)->setValue($start_value)->setID($start_date_id)->setIsTimeDisabled($is_all_day)->setEndDateID($end_date_id); $end_control = id(new AphrontFormDateControl())->setUser($viewer)->setName('end')->setLabel(pht('End'))->setError($error_end_date)->setValue($end_value)->setID($end_date_id)->setIsTimeDisabled($is_all_day); } else { if ($is_parent) { $recurring_date_edit_label = id(new AphrontFormStaticControl())->setUser($viewer)->setValue(pht('Date and time of recurring event cannot be edited.')); if (!$recurrence_end_date_value->isDisabled()) { $disabled_recurrence_end_date_value = $recurrence_end_date_value->getValueAsFormat('M d, Y'); $recurrence_end_date_control = id(new AphrontFormStaticControl())->setUser($viewer)->setLabel(pht('Recurrence End Date'))->setValue($disabled_recurrence_end_date_value)->setDisabled(true); } $recurrence_frequency_select = id(new AphrontFormSelectControl())->setName('frequency')->setOptions(array('daily' => pht('Daily'), 'weekly' => pht('Weekly'), 'monthly' => pht('Monthly'), 'yearly' => pht('Yearly')))->setValue($frequency)->setLabel(pht('Recurring Event Frequency'))->setID($frequency_id)->setDisabled(true); $all_day_checkbox = id(new AphrontFormCheckboxControl())->addCheckbox('isAllDay', 1, pht('All Day Event'), $is_all_day, $all_day_id)->setDisabled(true); $start_disabled = $start_value->getValueAsFormat('M d, Y, g:i A'); $end_disabled = $end_value->getValueAsFormat('M d, Y, g:i A'); $start_control = id(new AphrontFormStaticControl())->setUser($viewer)->setLabel(pht('Start'))->setValue($start_disabled)->setDisabled(true); $end_control = id(new AphrontFormStaticControl())->setUser($viewer)->setLabel(pht('End'))->setValue($end_disabled); } } $projects = id(new AphrontFormTokenizerControl())->setLabel(pht('Projects'))->setName('projects')->setValue($projects)->setUser($viewer)->setDatasource(new PhabricatorProjectDatasource()); $description = id(new PhabricatorRemarkupControl())->setLabel(pht('Description'))->setName('description')->setValue($description)->setUser($viewer); $view_policies = id(new AphrontFormPolicyControl())->setUser($viewer)->setValue($view_policy)->setCapability(PhabricatorPolicyCapability::CAN_VIEW)->setPolicyObject($event)->setPolicies($current_policies)->setSpacePHID($space)->setName('viewPolicy'); $edit_policies = id(new AphrontFormPolicyControl())->setUser($viewer)->setValue($edit_policy)->setCapability(PhabricatorPolicyCapability::CAN_EDIT)->setPolicyObject($event)->setPolicies($current_policies)->setName('editPolicy'); $subscribers = id(new AphrontFormTokenizerControl())->setLabel(pht('Subscribers'))->setName('subscribers')->setValue($subscribers)->setUser($viewer)->setDatasource(new PhabricatorMetaMTAMailableDatasource()); $invitees = id(new AphrontFormTokenizerControl())->setLabel(pht('Invitees'))->setName('invitees')->setValue($invitees)->setUser($viewer)->setDatasource(new PhabricatorMetaMTAMailableDatasource()); if ($this->isCreate()) { $icon_uri = $this->getApplicationURI('icon/'); } else { $icon_uri = $this->getApplicationURI('icon/' . $event->getID() . '/'); } $icon_display = PhabricatorCalendarIcon::renderIconForChooser($icon); $icon = id(new AphrontFormChooseButtonControl())->setLabel(pht('Icon'))->setName('icon')->setDisplayValue($icon_display)->setButtonText(pht('Choose Icon...'))->setChooseURI($icon_uri)->setValue($icon); $form = id(new AphrontFormView())->addHiddenInput('next', $next_workflow)->addHiddenInput('query', $uri_query)->setUser($viewer)->appendChild($name); if ($recurring_date_edit_label) { $form->appendControl($recurring_date_edit_label); } if ($is_recurring_checkbox) { $form->appendChild($is_recurring_checkbox); } if ($recurrence_end_date_control) { $form->appendChild($recurrence_end_date_control); } if ($recurrence_frequency_select) { $form->appendControl($recurrence_frequency_select); } $form->appendChild($all_day_checkbox)->appendChild($start_control)->appendChild($end_control)->appendControl($view_policies)->appendControl($edit_policies)->appendControl($subscribers)->appendControl($invitees)->appendChild($projects)->appendChild($description)->appendChild($icon); if ($request->isAjax()) { return $this->newDialog()->setTitle($page_title)->setWidth(AphrontDialogView::WIDTH_FULL)->appendForm($form)->addCancelButton($cancel_uri)->addSubmitButton($submit_label); } $submit = id(new AphrontFormSubmitControl())->addCancelButton($cancel_uri)->setValue($submit_label); $form->appendChild($submit); $form_box = id(new PHUIObjectBoxView())->setHeaderText($page_title)->setForm($form); $crumbs = $this->buildApplicationCrumbs(); if (!$this->isCreate()) { $crumbs->addTextCrumb('E' . $event->getId(), '/E' . $event->getId()); } $crumbs->addTextCrumb($page_title); $object_box = id(new PHUIObjectBoxView())->setHeaderText($page_title)->setValidationException($validation_exception)->appendChild($form); return $this->buildApplicationPage(array($crumbs, $object_box), array('title' => $page_title)); }