diff --git a/src/applications/diviner/controller/DivinerBookController.php b/src/applications/diviner/controller/DivinerBookController.php index f7f7295bc..a96fd8606 100644 --- a/src/applications/diviner/controller/DivinerBookController.php +++ b/src/applications/diviner/controller/DivinerBookController.php @@ -1,107 +1,102 @@ bookName = $data['book']; } public function processRequest() { $request = $this->getRequest(); $viewer = $request->getUser(); $book = id(new DivinerBookQuery()) ->setViewer($viewer) ->withNames(array($this->bookName)) ->executeOne(); if (!$book) { return new Aphront404Response(); } $crumbs = $this->buildApplicationCrumbs(); $crumbs->addCrumb( id(new PhabricatorCrumbView()) ->setName($book->getShortTitle()) ->setHref('/book/'.$book->getName().'/')); - $policies = PhabricatorPolicyQuery::renderPolicyDescriptions( - $viewer, - $book, - true); - $header = id(new PHUIHeaderView()) ->setHeader($book->getTitle()) - ->addProperty(PHUIHeaderView::PROPERTY_POLICY, - $policies[PhabricatorPolicyCapability::CAN_VIEW]); + ->setUser($viewer) + ->setPolicyObject($book); $document = new PHUIDocumentView(); $document->setHeader($header); $properties = $this->buildPropertyList($book); $atoms = id(new DivinerAtomQuery()) ->setViewer($viewer) ->withBookPHIDs(array($book->getPHID())) ->execute(); $atoms = msort($atoms, 'getSortKey'); $group_spec = $book->getConfig('groups'); if (!is_array($group_spec)) { $group_spec = array(); } $groups = mgroup($atoms, 'getGroupName'); $groups = array_select_keys($groups, array_keys($group_spec)) + $groups; if (isset($groups[''])) { $no_group = $groups['']; unset($groups['']); $groups[''] = $no_group; } $out = array(); foreach ($groups as $group => $atoms) { $group_name = $book->getGroupName($group); $section = id(new DivinerSectionView()) ->setHeader($group_name); $section->addContent($this->renderAtomList($atoms)); $out[] = $section; } $document->appendChild($properties); $document->appendChild($out); return $this->buildApplicationPage( array( $crumbs, $document, ), array( 'title' => $book->getTitle(), 'device' => true, )); } private function buildPropertyList(DivinerLiveBook $book) { $user = $this->getRequest()->getUser(); $view = id(new PhabricatorPropertyListView()) ->setUser($user); $policies = PhabricatorPolicyQuery::renderPolicyDescriptions( $user, $book); $view->addProperty( pht('Updated'), phabricator_datetime($book->getDateModified(), $user)); return $view; } } diff --git a/src/applications/legalpad/controller/LegalpadDocumentViewController.php b/src/applications/legalpad/controller/LegalpadDocumentViewController.php index 4773881e0..134d94e0d 100644 --- a/src/applications/legalpad/controller/LegalpadDocumentViewController.php +++ b/src/applications/legalpad/controller/LegalpadDocumentViewController.php @@ -1,224 +1,219 @@ id = $data['id']; } public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $document = id(new LegalpadDocumentQuery()) ->setViewer($user) ->withIDs(array($this->id)) ->needDocumentBodies(true) ->needContributors(true) ->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(); - $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( - $user, - $document, - true); - $header = id(new PHUIHeaderView()) ->setHeader($title) - ->addProperty(PHUIHeaderView::PROPERTY_POLICY, - $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); + ->setUser($user) + ->setPolicyObject($document); $actions = $this->buildActionView($document); $properties = $this->buildPropertyView($document, $engine); $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->addCrumb( id(new PhabricatorCrumbView()) ->setName('L'.$document->getID()) ->setHref($this->getApplicationURI('view/'.$document->getID()))); $content = array( $crumbs, $header, $actions, $properties, $this->buildDocument($engine, $document_body), $xaction_view, $add_comment, ); return $this->buildApplicationPage( $content, array( 'title' => $title, 'device' => true, 'pageObjects' => array($document->getPHID()), )); } private function buildDocument( PhabricatorMarkupEngine $engine, LegalpadDocumentBody $body) { require_celerity_resource('legalpad-documentbody-css'); return phutil_tag( 'div', array( 'class' => 'legalpad-documentbody' ), $engine->getOutput($body, LegalpadDocumentBody::MARKUP_FIELD_TEXT)); } private function buildActionView(LegalpadDocument $document) { $user = $this->getRequest()->getUser(); $actions = id(new PhabricatorActionListView()) ->setUser($user) ->setObjectURI($this->getRequest()->getRequestURI()) ->setObject($document); $can_edit = PhabricatorPolicyFilter::hasCapability( $user, $document, PhabricatorPolicyCapability::CAN_EDIT); $actions->addAction( id(new PhabricatorActionView()) ->setIcon('edit') ->setName(pht('Edit Document')) ->setHref($this->getApplicationURI('/edit/'.$document->getID().'/')) ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); return $actions; } private function buildPropertyView( LegalpadDocument $document, PhabricatorMarkupEngine $engine) { $user = $this->getRequest()->getUser(); $properties = id(new PhabricatorPropertyListView()) ->setUser($user) ->setObject($document); $properties->addProperty( pht('Last Updated'), phabricator_datetime($document->getDateModified(), $user)); $properties->addProperty( pht('Updated By'), $this->getHandle( $document->getDocumentBody()->getCreatorPHID())->renderLink()); $properties->addProperty( pht('Versions'), $document->getVersions()); $contributor_view = array(); foreach ($document->getContributors() as $contributor) { $contributor_view[] = $this->getHandle($contributor)->renderLink(); } $contributor_view = phutil_implode_html(', ', $contributor_view); $properties->addProperty( pht('Contributors'), $contributor_view); $properties->invokeWillRenderEvent(); return $properties; } private function buildAddCommentView( LegalpadDocument $document, $comment_form_id) { $user = $this->getRequest()->getUser(); $draft = PhabricatorDraft::newFromUserAndKey($user, $document->getPHID()); $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); $title = $is_serious ? pht('Add Comment') : pht('Debate Legislation'); $header = id(new PHUIHeaderView()) ->setHeader($title); $button_name = $is_serious ? pht('Add Comment') : pht('Commence Filibuster'); $form = id(new PhabricatorApplicationTransactionCommentView()) ->setUser($user) ->setObjectPHID($document->getPHID()) ->setFormID($comment_form_id) ->setDraft($draft) ->setSubmitButtonName($button_name) ->setAction($this->getApplicationURI('/comment/'.$document->getID().'/')) ->setRequestURI($this->getRequest()->getRequestURI()); return array( $header, $form, ); } } diff --git a/src/applications/paste/controller/PhabricatorPasteViewController.php b/src/applications/paste/controller/PhabricatorPasteViewController.php index d6f0782ad..dab9f113a 100644 --- a/src/applications/paste/controller/PhabricatorPasteViewController.php +++ b/src/applications/paste/controller/PhabricatorPasteViewController.php @@ -1,231 +1,227 @@ id = $data['id']; $raw_lines = idx($data, 'lines'); $map = array(); if ($raw_lines) { $lines = explode('-', $raw_lines); $first = idx($lines, 0, 0); $last = idx($lines, 1); if ($last) { $min = min($first, $last); $max = max($first, $last); $map = array_fuse(range($min, $max)); } else { $map[$first] = $first; } } $this->highlightMap = $map; } public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $paste = id(new PhabricatorPasteQuery()) ->setViewer($user) ->withIDs(array($this->id)) ->needContent(true) ->executeOne(); if (!$paste) { return new Aphront404Response(); } $file = id(new PhabricatorFile())->loadOneWhere( 'phid = %s', $paste->getFilePHID()); if (!$file) { return new Aphront400Response(); } $forks = id(new PhabricatorPasteQuery()) ->setViewer($user) ->withParentPHIDs(array($paste->getPHID())) ->execute(); $fork_phids = mpull($forks, 'getPHID'); $this->loadHandles( array_merge( array( $paste->getAuthorPHID(), $paste->getParentPHID(), ), $fork_phids)); $header = $this->buildHeaderView($paste); $actions = $this->buildActionView($user, $paste, $file); $properties = $this->buildPropertyView($paste, $fork_phids); $source_code = $this->buildSourceCodeView( $paste, null, $this->highlightMap); $crumbs = $this->buildApplicationCrumbs($this->buildSideNavView()) ->setActionList($actions) ->addCrumb( id(new PhabricatorCrumbView()) ->setName('P'.$paste->getID()) ->setHref('/P'.$paste->getID())); $xactions = id(new PhabricatorPasteTransactionQuery()) ->setViewer($request->getUser()) ->withObjectPHIDs(array($paste->getPHID())) ->execute(); $engine = id(new PhabricatorMarkupEngine()) ->setViewer($user); foreach ($xactions as $xaction) { if ($xaction->getComment()) { $engine->addObject( $xaction->getComment(), PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT); } } $engine->process(); $timeline = id(new PhabricatorApplicationTransactionView()) ->setUser($user) ->setObjectPHID($paste->getPHID()) ->setTransactions($xactions) ->setMarkupEngine($engine); $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); $add_comment_header = id(new PHUIHeaderView()) ->setHeader( $is_serious ? pht('Add Comment') : pht('Debate Paste Accuracy')); $submit_button_name = $is_serious ? pht('Add Comment') : pht('Pity the Fool'); $draft = PhabricatorDraft::newFromUserAndKey($user, $paste->getPHID()); $add_comment_form = id(new PhabricatorApplicationTransactionCommentView()) ->setUser($user) ->setObjectPHID($paste->getPHID()) ->setDraft($draft) ->setAction($this->getApplicationURI('/comment/'.$paste->getID().'/')) ->setSubmitButtonName($submit_button_name); return $this->buildApplicationPage( array( $crumbs, $header, $actions, $properties, $source_code, $timeline, $add_comment_header, $add_comment_form ), array( 'title' => $paste->getFullName(), 'device' => true, 'pageObjects' => array($paste->getPHID()), )); } private function buildHeaderView(PhabricatorPaste $paste) { - $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( - $this->getRequest()->getUser(), - $paste, - $icon = true); - $header = id(new PHUIHeaderView()) ->setHeader($paste->getTitle()) - ->addProperty(PHUIHeaderView::PROPERTY_POLICY, - $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); + ->setUser($this->getRequest()->getUser()) + ->setPolicyObject($paste); + return $header; } private function buildActionView( PhabricatorUser $user, PhabricatorPaste $paste, PhabricatorFile $file) { $can_edit = PhabricatorPolicyFilter::hasCapability( $user, $paste, PhabricatorPolicyCapability::CAN_EDIT); $can_fork = $user->isLoggedIn(); $fork_uri = $this->getApplicationURI('/create/?parent='.$paste->getID()); return id(new PhabricatorActionListView()) ->setUser($user) ->setObject($paste) ->setObjectURI($this->getRequest()->getRequestURI()) ->addAction( id(new PhabricatorActionView()) ->setName(pht('Fork This Paste')) ->setIcon('fork') ->setDisabled(!$can_fork) ->setWorkflow(!$can_fork) ->setHref($fork_uri)) ->addAction( id(new PhabricatorActionView()) ->setName(pht('View Raw File')) ->setIcon('file') ->setHref($file->getBestURI())) ->addAction( id(new PhabricatorActionView()) ->setName(pht('Edit Paste')) ->setIcon('edit') ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit) ->setHref($this->getApplicationURI('/edit/'.$paste->getID().'/'))); } private function buildPropertyView( PhabricatorPaste $paste, array $child_phids) { $user = $this->getRequest()->getUser(); $properties = id(new PhabricatorPropertyListView()) ->setUser($user) ->setObject($paste); $properties->addProperty( pht('Author'), $this->getHandle($paste->getAuthorPHID())->renderLink()); $properties->addProperty( pht('Created'), phabricator_datetime($paste->getDateCreated(), $user)); if ($paste->getParentPHID()) { $properties->addProperty( pht('Forked From'), $this->getHandle($paste->getParentPHID())->renderLink()); } if ($child_phids) { $properties->addProperty( pht('Forks'), $this->renderHandlesForPHIDs($child_phids)); } $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( $user, $paste); return $properties; } } diff --git a/src/applications/phame/controller/blog/PhameBlogViewController.php b/src/applications/phame/controller/blog/PhameBlogViewController.php index 2e42df5e8..4b3caf889 100644 --- a/src/applications/phame/controller/blog/PhameBlogViewController.php +++ b/src/applications/phame/controller/blog/PhameBlogViewController.php @@ -1,199 +1,194 @@ id = $data['id']; } public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $blog = id(new PhameBlogQuery()) ->setViewer($user) ->withIDs(array($this->id)) ->executeOne(); if (!$blog) { return new Aphront404Response(); } $pager = id(new AphrontCursorPagerView()) ->readFromRequest($request); $posts = id(new PhamePostQuery()) ->setViewer($user) ->withBlogPHIDs(array($blog->getPHID())) ->executeWithCursorPager($pager); $nav = $this->renderSideNavFilterView(null); - $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( - $user, - $blog, - true); - $header = id(new PHUIHeaderView()) ->setHeader($blog->getName()) - ->addProperty(PHUIHeaderView::PROPERTY_POLICY, - $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); + ->setUser($user) + ->setPolicyObject($blog); $handle_phids = array_merge( mpull($posts, 'getBloggerPHID'), mpull($posts, 'getBlogPHID')); $this->loadHandles($handle_phids); $actions = $this->renderActions($blog, $user); $properties = $this->renderProperties($blog, $user); $post_list = $this->renderPostList( $posts, $user, pht('This blog has no visible posts.')); require_celerity_resource('phame-css'); $post_list = id(new PHUIBoxView()) ->addPadding(PHUI::PADDING_LARGE) ->addClass('phame-post-list') ->appendChild($post_list); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addCrumb( id(new PhabricatorCrumbView()) ->setName($blog->getName()) ->setHref($this->getApplicationURI())); $nav->appendChild( array( $crumbs, $header, $actions, $properties, $post_list, )); return $this->buildApplicationPage( $nav, array( 'device' => true, 'title' => $blog->getName(), )); } private function renderProperties(PhameBlog $blog, PhabricatorUser $user) { require_celerity_resource('aphront-tooltip-css'); Javelin::initBehavior('phabricator-tooltips'); $properties = new PhabricatorPropertyListView(); $properties->addProperty( pht('Skin'), $blog->getSkin()); $properties->addProperty( pht('Domain'), $blog->getDomain()); $feed_uri = PhabricatorEnv::getProductionURI( $this->getApplicationURI('blog/feed/'.$blog->getID().'/')); $properties->addProperty( pht('Atom URI'), javelin_tag('a', array( 'href' => $feed_uri, 'sigil' => 'has-tooltip', 'meta' => array( 'tip' => pht('Atom URI does not support custom domains.'), 'size' => 320, ) ), $feed_uri)); $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( $user, $blog); $properties->addProperty( pht('Editable By'), $descriptions[PhabricatorPolicyCapability::CAN_EDIT]); $properties->addProperty( pht('Joinable By'), $descriptions[PhabricatorPolicyCapability::CAN_JOIN]); $engine = id(new PhabricatorMarkupEngine()) ->setViewer($user) ->addObject($blog, PhameBlog::MARKUP_FIELD_DESCRIPTION) ->process(); $properties->addTextContent( phutil_tag( 'div', array( 'class' => 'phabricator-remarkup', ), $engine->getOutput($blog, PhameBlog::MARKUP_FIELD_DESCRIPTION))); return $properties; } private function renderActions(PhameBlog $blog, PhabricatorUser $user) { $actions = id(new PhabricatorActionListView()) ->setObject($blog) ->setObjectURI($this->getRequest()->getRequestURI()) ->setUser($user); $can_edit = PhabricatorPolicyFilter::hasCapability( $user, $blog, PhabricatorPolicyCapability::CAN_EDIT); $can_join = PhabricatorPolicyFilter::hasCapability( $user, $blog, PhabricatorPolicyCapability::CAN_JOIN); $must_use_form = $blog->getDomain(); $actions->addAction( id(new PhabricatorActionView()) ->setIcon('new') ->setHref($this->getApplicationURI('post/edit/?blog='.$blog->getID())) ->setName(pht('Write Post')) ->setDisabled(!$can_join) ->setWorkflow(!$can_join)); $actions->addAction( id(new PhabricatorActionView()) ->setUser($user) ->setIcon('world') ->setHref($this->getApplicationURI('live/'.$blog->getID().'/')) ->setRenderAsForm($must_use_form) ->setName(pht('View Live'))); $actions->addAction( id(new PhabricatorActionView()) ->setIcon('edit') ->setHref($this->getApplicationURI('blog/edit/'.$blog->getID().'/')) ->setName('Edit Blog') ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); $actions->addAction( id(new PhabricatorActionView()) ->setIcon('delete') ->setHref($this->getApplicationURI('blog/delete/'.$blog->getID().'/')) ->setName('Delete Blog') ->setDisabled(!$can_edit) ->setWorkflow(true)); return $actions; } } diff --git a/src/applications/phame/controller/post/PhamePostViewController.php b/src/applications/phame/controller/post/PhamePostViewController.php index 4882a87e6..471c596c5 100644 --- a/src/applications/phame/controller/post/PhamePostViewController.php +++ b/src/applications/phame/controller/post/PhamePostViewController.php @@ -1,210 +1,205 @@ id = $data['id']; } public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $post = id(new PhamePostQuery()) ->setViewer($user) ->withIDs(array($this->id)) ->executeOne(); if (!$post) { return new Aphront404Response(); } $nav = $this->renderSideNavFilterView(); $this->loadHandles( array( $post->getBlogPHID(), $post->getBloggerPHID(), )); $actions = $this->renderActions($post, $user); $properties = $this->renderProperties($post, $user); - $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( - $user, - $post, - true); - $crumbs = $this->buildApplicationCrumbs(); $crumbs->setActionList($actions); $crumbs->addCrumb( id(new PhabricatorCrumbView()) ->setName($post->getTitle()) ->setHref($this->getApplicationURI('post/view/'.$post->getID().'/'))); $nav->appendChild($crumbs); $nav->appendChild( id(new PHUIHeaderView()) ->setHeader($post->getTitle()) - ->addProperty(PHUIHeaderView::PROPERTY_POLICY, - $descriptions[PhabricatorPolicyCapability::CAN_VIEW])); + ->setUser($user) + ->setPolicyObject($post)); if ($post->isDraft()) { $nav->appendChild( id(new AphrontErrorView()) ->setSeverity(AphrontErrorView::SEVERITY_NOTICE) ->setTitle(pht('Draft Post')) ->appendChild( pht('Only you can see this draft until you publish it. '. 'Use "Preview / Publish" to publish this post.'))); } if (!$post->getBlog()) { $nav->appendChild( id(new AphrontErrorView()) ->setSeverity(AphrontErrorView::SEVERITY_WARNING) ->setTitle(pht('Not On A Blog')) ->appendChild( pht('This post is not associated with a blog (the blog may have '. 'been deleted). Use "Move Post" to move it to a new blog.'))); } $nav->appendChild( array( $actions, $properties, )); return $this->buildApplicationPage( $nav, array( 'title' => $post->getTitle(), 'device' => true, )); } private function renderActions( PhamePost $post, PhabricatorUser $user) { $actions = id(new PhabricatorActionListView()) ->setObject($post) ->setObjectURI($this->getRequest()->getRequestURI()) ->setUser($user); $can_edit = PhabricatorPolicyFilter::hasCapability( $user, $post, PhabricatorPolicyCapability::CAN_EDIT); $id = $post->getID(); $actions->addAction( id(new PhabricatorActionView()) ->setIcon('edit') ->setHref($this->getApplicationURI('post/edit/'.$id.'/')) ->setName(pht('Edit Post')) ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); $actions->addAction( id(new PhabricatorActionView()) ->setIcon('move') ->setHref($this->getApplicationURI('post/move/'.$id.'/')) ->setName(pht('Move Post')) ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); if ($post->isDraft()) { $actions->addAction( id(new PhabricatorActionView()) ->setIcon('preview') ->setHref($this->getApplicationURI('post/publish/'.$id.'/')) ->setName(pht('Preview / Publish'))); } else { $actions->addAction( id(new PhabricatorActionView()) ->setIcon('unpublish') ->setHref($this->getApplicationURI('post/unpublish/'.$id.'/')) ->setName(pht('Unpublish')) ->setWorkflow(true)); } $actions->addAction( id(new PhabricatorActionView()) ->setIcon('delete') ->setHref($this->getApplicationURI('post/delete/'.$id.'/')) ->setName(pht('Delete Post')) ->setDisabled(!$can_edit) ->setWorkflow(true)); $blog = $post->getBlog(); $can_view_live = $blog && !$post->isDraft(); $must_use_form = $blog && $blog->getDomain(); if ($can_view_live) { $live_uri = 'live/'.$blog->getID().'/post/'.$post->getPhameTitle(); } else { $live_uri = 'post/notlive/'.$post->getID().'/'; } $live_uri = $this->getApplicationURI($live_uri); $actions->addAction( id(new PhabricatorActionView()) ->setUser($user) ->setIcon('world') ->setHref($live_uri) ->setName(pht('View Live')) ->setRenderAsForm($must_use_form) ->setDisabled(!$can_view_live) ->setWorkflow(!$can_view_live)); return $actions; } private function renderProperties( PhamePost $post, PhabricatorUser $user) { $properties = id(new PhabricatorPropertyListView()) ->setUser($user) ->setObject($post); $properties->addProperty( pht('Blog'), $post->getBlogPHID() ? $this->getHandle($post->getBlogPHID())->renderLink() : null); $properties->addProperty( pht('Blogger'), $this->getHandle($post->getBloggerPHID())->renderLink()); $properties->addProperty( pht('Published'), $post->isDraft() ? pht('Draft') : phabricator_datetime($post->getDatePublished(), $user)); $engine = id(new PhabricatorMarkupEngine()) ->setViewer($user) ->addObject($post, PhamePost::MARKUP_FIELD_BODY) ->process(); $properties->invokeWillRenderEvent(); $properties->addTextContent( phutil_tag( 'div', array( 'class' => 'phabricator-remarkup', ), $engine->getOutput($post, PhamePost::MARKUP_FIELD_BODY))); return $properties; } } diff --git a/src/applications/phlux/controller/PhluxViewController.php b/src/applications/phlux/controller/PhluxViewController.php index a6849bc31..776df4461 100644 --- a/src/applications/phlux/controller/PhluxViewController.php +++ b/src/applications/phlux/controller/PhluxViewController.php @@ -1,100 +1,91 @@ key = $data['key']; } public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $var = id(new PhluxVariableQuery()) ->setViewer($user) ->withKeys(array($this->key)) ->executeOne(); if (!$var) { return new Aphront404Response(); } $crumbs = $this->buildApplicationCrumbs(); $title = $var->getVariableKey(); $crumbs->addCrumb( id(new PhabricatorCrumbView()) ->setName($title) ->setHref($request->getRequestURI())); - $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( - $user, - $var, - true); - $header = id(new PHUIHeaderView()) ->setHeader($title) - ->addProperty(PHUIHeaderView::PROPERTY_POLICY, - $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); + ->setUser($user) + ->setPolicyObject($var); $actions = id(new PhabricatorActionListView()) ->setUser($user) ->setObjectURI($request->getRequestURI()) ->setObject($var); $can_edit = PhabricatorPolicyFilter::hasCapability( $user, $var, PhabricatorPolicyCapability::CAN_EDIT); $actions->addAction( id(new PhabricatorActionView()) ->setIcon('edit') ->setName(pht('Edit Variable')) ->setHref($this->getApplicationURI('/edit/'.$var->getVariableKey().'/')) ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); $display_value = json_encode($var->getVariableValue()); $properties = id(new PhabricatorPropertyListView()) ->setUser($user) ->setObject($var) - ->addProperty(pht('Value'), $display_value) - ->addProperty( - pht('Editable By'), - $descriptions[PhabricatorPolicyCapability::CAN_EDIT]); - + ->addProperty(pht('Value'), $display_value); $xactions = id(new PhluxTransactionQuery()) ->setViewer($user) ->withObjectPHIDs(array($var->getPHID())) ->execute(); $engine = id(new PhabricatorMarkupEngine()) ->setViewer($user); $xaction_view = id(new PhabricatorApplicationTransactionView()) ->setUser($user) ->setObjectPHID($var->getPHID()) ->setTransactions($xactions) ->setMarkupEngine($engine); return $this->buildApplicationPage( array( $crumbs, $header, $actions, $properties, $xaction_view, ), array( 'title' => $title, 'device' => true, )); } } diff --git a/src/applications/pholio/controller/PholioMockViewController.php b/src/applications/pholio/controller/PholioMockViewController.php index 298aa84a4..f90a34b7e 100644 --- a/src/applications/pholio/controller/PholioMockViewController.php +++ b/src/applications/pholio/controller/PholioMockViewController.php @@ -1,265 +1,260 @@ maniphestTaskPHIDs = $maniphest_task_phids; return $this; } private function getManiphestTaskPHIDs() { return $this->maniphestTaskPHIDs; } public function shouldAllowPublic() { return true; } public function willProcessRequest(array $data) { $this->id = $data['id']; $this->imageID = idx($data, 'imageID'); } public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $mock = id(new PholioMockQuery()) ->setViewer($user) ->withIDs(array($this->id)) ->needImages(true) ->needCoverFiles(true) ->executeOne(); if (!$mock) { return new Aphront404Response(); } $xactions = id(new PholioTransactionQuery()) ->setViewer($user) ->withObjectPHIDs(array($mock->getPHID())) ->execute(); $phids = PhabricatorEdgeQuery::loadDestinationPHIDs( $mock->getPHID(), PhabricatorEdgeConfig::TYPE_MOCK_HAS_TASK); $this->setManiphestTaskPHIDs($phids); $phids[] = $mock->getAuthorPHID(); $this->loadHandles($phids); $engine = id(new PhabricatorMarkupEngine()) ->setViewer($user); $engine->addObject($mock, PholioMock::MARKUP_FIELD_DESCRIPTION); foreach ($xactions as $xaction) { if ($xaction->getComment()) { $engine->addObject( $xaction->getComment(), PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT); } } $engine->process(); $title = $mock->getName(); - $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( - $user, - $mock, - $icon = true); - $header = id(new PHUIHeaderView()) ->setHeader($title) - ->addProperty(PHUIHeaderView::PROPERTY_POLICY, - $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); + ->setUser($user) + ->setPolicyObject($mock); $actions = $this->buildActionView($mock); $properties = $this->buildPropertyView($mock, $engine); require_celerity_resource('pholio-css'); require_celerity_resource('pholio-inline-comments-css'); $image_status = $this->getImageStatus($mock, $this->imageID); $comment_form_id = celerity_generate_unique_node_id(); $output = id(new PholioMockImagesView()) ->setRequestURI($request->getRequestURI()) ->setCommentFormID($comment_form_id) ->setUser($user) ->setMock($mock) ->setImageID($this->imageID); $xaction_view = id(new PholioTransactionView()) ->setUser($this->getRequest()->getUser()) ->setObjectPHID($mock->getPHID()) ->setTransactions($xactions) ->setMarkupEngine($engine); $add_comment = $this->buildAddCommentView($mock, $comment_form_id); $crumbs = $this->buildApplicationCrumbs(); $crumbs->setActionList($actions); $crumbs->addCrumb( id(new PhabricatorCrumbView()) ->setName('M'.$mock->getID()) ->setHref('/M'.$mock->getID())); $content = array( $crumbs, $image_status, $header, $actions, $properties, $output->render(), $xaction_view, $add_comment, ); return $this->buildApplicationPage( $content, array( 'title' => 'M'.$mock->getID().' '.$title, 'device' => true, 'pageObjects' => array($mock->getPHID()), )); } private function getImageStatus(PholioMock $mock, $image_id) { $status = null; $images = $mock->getImages(); foreach ($images as $image) { if ($image->getID() == $image_id) { return $status; } } $images = $mock->getAllImages(); $images = mpull($images, null, 'getID'); $image = idx($images, $image_id); if ($image) { $history = $mock->getImageHistorySet($image_id); $latest_image = last($history); $href = $this->getApplicationURI( 'image/history/'.$latest_image->getID().'/'); $status = id(new AphrontErrorView()) ->setSeverity(AphrontErrorView::SEVERITY_NOTICE) ->setTitle(pht('The requested image is obsolete.')) ->appendChild(phutil_tag( 'p', array(), array( pht('You are viewing this mock with the latest image set.'), ' ', phutil_tag( 'a', array('href' => $href), pht( 'Click here to see the history of the now obsolete image.'))))); } return $status; } private function buildActionView(PholioMock $mock) { $user = $this->getRequest()->getUser(); $actions = id(new PhabricatorActionListView()) ->setUser($user) ->setObjectURI($this->getRequest()->getRequestURI()) ->setObject($mock); $can_edit = PhabricatorPolicyFilter::hasCapability( $user, $mock, PhabricatorPolicyCapability::CAN_EDIT); $actions->addAction( id(new PhabricatorActionView()) ->setIcon('edit') ->setName(pht('Edit Mock')) ->setHref($this->getApplicationURI('/edit/'.$mock->getID().'/')) ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); $actions->addAction( id(new PhabricatorActionView()) ->setIcon('attach') ->setName(pht('Edit Maniphest Tasks')) ->setHref("/search/attach/{$mock->getPHID()}/TASK/edge/") ->setDisabled(!$user->isLoggedIn()) ->setWorkflow(true)); return $actions; } private function buildPropertyView( PholioMock $mock, PhabricatorMarkupEngine $engine) { $user = $this->getRequest()->getUser(); $properties = id(new PhabricatorPropertyListView()) ->setUser($user) ->setObject($mock); $properties->addProperty( pht('Author'), $this->getHandle($mock->getAuthorPHID())->renderLink()); $properties->addProperty( pht('Created'), phabricator_datetime($mock->getDateCreated(), $user)); if ($this->getManiphestTaskPHIDs()) { $properties->addProperty( pht('Maniphest Tasks'), $this->renderHandlesForPHIDs($this->getManiphestTaskPHIDs())); } $properties->invokeWillRenderEvent(); $properties->addImageContent( $engine->getOutput($mock, PholioMock::MARKUP_FIELD_DESCRIPTION)); return $properties; } private function buildAddCommentView(PholioMock $mock, $comment_form_id) { $user = $this->getRequest()->getUser(); $draft = PhabricatorDraft::newFromUserAndKey($user, $mock->getPHID()); $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); $title = $is_serious ? pht('Add Comment') : pht('History Beckons'); $header = id(new PHUIHeaderView()) ->setHeader($title); $button_name = $is_serious ? pht('Add Comment') : pht('Answer The Call'); $form = id(new PhabricatorApplicationTransactionCommentView()) ->setUser($user) ->setObjectPHID($mock->getPHID()) ->setFormID($comment_form_id) ->setDraft($draft) ->setSubmitButtonName($button_name) ->setAction($this->getApplicationURI('/comment/'.$mock->getID().'/')) ->setRequestURI($this->getRequest()->getRequestURI()); return array( $header, $form, ); } } diff --git a/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php b/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php index 1bde176be..0952085ad 100644 --- a/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php +++ b/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php @@ -1,194 +1,189 @@ id = $data['id']; } public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $poll = id(new PhabricatorSlowvoteQuery()) ->setViewer($user) ->withIDs(array($this->id)) ->needOptions(true) ->needChoices(true) ->needViewerChoices(true) ->executeOne(); if (!$poll) { return new Aphront404Response(); } $poll_view = id(new SlowvoteEmbedView()) ->setHeadless(true) ->setUser($user) ->setPoll($poll); if ($request->isAjax()) { return id(new AphrontAjaxResponse()) ->setContent( array( 'pollID' => $poll->getID(), 'contentHTML' => $poll_view->render(), )); } - $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( - $user, - $poll, - true); - $header = id(new PHUIHeaderView()) ->setHeader($poll->getQuestion()) - ->addProperty(PHUIHeaderView::PROPERTY_POLICY, - $descriptions[PhabricatorPolicyCapability::CAN_VIEW]); + ->setUser($user) + ->setPolicyObject($poll); $xaction_header = id(new PHUIHeaderView()) ->setHeader(pht('Ongoing Deliberations')); $actions = $this->buildActionView($poll); $properties = $this->buildPropertyView($poll); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addCrumb( id(new PhabricatorCrumbView()) ->setName('V'.$poll->getID())); $xactions = $this->buildTransactions($poll); $add_comment = $this->buildCommentForm($poll); return $this->buildApplicationPage( array( $crumbs, $header, $actions, $properties, phutil_tag( 'div', array( 'class' => 'ml', ), $poll_view), $xaction_header, $xactions, $add_comment, ), array( 'title' => 'V'.$poll->getID().' '.$poll->getQuestion(), 'device' => true, 'pageObjects' => array($poll->getPHID()), )); } private function buildActionView(PhabricatorSlowvotePoll $poll) { $viewer = $this->getRequest()->getUser(); $view = id(new PhabricatorActionListView()) ->setUser($viewer) ->setObject($poll); $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $poll, PhabricatorPolicyCapability::CAN_EDIT); $view->addAction( id(new PhabricatorActionView()) ->setName(pht('Edit Poll')) ->setIcon('edit') ->setHref($this->getApplicationURI('edit/'.$poll->getID().'/')) ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); return $view; } private function buildPropertyView(PhabricatorSlowvotePoll $poll) { $viewer = $this->getRequest()->getUser(); $view = id(new PhabricatorPropertyListView()) ->setUser($viewer) ->setObject($poll); $view->invokeWillRenderEvent(); if (strlen($poll->getDescription())) { $view->addTextContent( $output = PhabricatorMarkupEngine::renderOneObject( id(new PhabricatorMarkupOneOff())->setContent( $poll->getDescription()), 'default', $viewer)); } return $view; } private function buildTransactions(PhabricatorSlowvotePoll $poll) { $viewer = $this->getRequest()->getUser(); $xactions = id(new PhabricatorSlowvoteTransactionQuery()) ->setViewer($viewer) ->withObjectPHIDs(array($poll->getPHID())) ->execute(); $engine = id(new PhabricatorMarkupEngine()) ->setViewer($viewer); foreach ($xactions as $xaction) { if ($xaction->getComment()) { $engine->addObject( $xaction->getComment(), PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT); } } $engine->process(); $timeline = id(new PhabricatorApplicationTransactionView()) ->setUser($viewer) ->setObjectPHID($poll->getPHID()) ->setTransactions($xactions) ->setMarkupEngine($engine); return $timeline; } private function buildCommentForm(PhabricatorSlowvotePoll $poll) { $viewer = $this->getRequest()->getUser(); $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); $add_comment_header = id(new PHUIHeaderView()) ->setHeader( $is_serious ? pht('Add Comment') : pht('Enter Deliberations')); $submit_button_name = $is_serious ? pht('Add Comment') : pht('Perhaps'); $draft = PhabricatorDraft::newFromUserAndKey($viewer, $poll->getPHID()); $add_comment_form = id(new PhabricatorApplicationTransactionCommentView()) ->setUser($viewer) ->setObjectPHID($poll->getPHID()) ->setDraft($draft) ->setAction($this->getApplicationURI('/comment/'.$poll->getID().'/')) ->setSubmitButtonName($submit_button_name); return array( $add_comment_header, $add_comment_form, ); } } diff --git a/src/view/phui/PHUIHeaderView.php b/src/view/phui/PHUIHeaderView.php index 7283be15a..ac226fb24 100644 --- a/src/view/phui/PHUIHeaderView.php +++ b/src/view/phui/PHUIHeaderView.php @@ -1,173 +1,183 @@ header = $header; return $this; } public function setObjectName($object_name) { $this->objectName = $object_name; return $this; } public function setNoBackground($nada) { $this->noBackground = $nada; return $this; } public function addTag(PhabricatorTagView $tag) { $this->tags[] = $tag; return $this; } public function setImage($uri) { $this->image = $uri; return $this; } public function setSubheader($subheader) { $this->subheader = $subheader; return $this; } public function setBleedHeader($bleed) { $this->bleedHeader = $bleed; return $this; } public function setGradient($gradient) { $this->gradient = $gradient; return $this; } + public function setPolicyObject(PhabricatorPolicyInterface $object) { + $this->policyObject = $object; + return $this; + } + public function addProperty($property, $value) { $this->properties[$property] = $value; return $this; } public function render() { require_celerity_resource('phui-header-view-css'); $classes = array(); $classes[] = 'phui-header-shell'; if ($this->noBackground) { $classes[] = 'phui-header-no-backgound'; } if ($this->bleedHeader) { $classes[] = 'phui-bleed-header'; } if ($this->gradient) { $classes[] = 'sprite-gradient'; $classes[] = 'gradient-'.$this->gradient.'-header'; } - if ($this->properties || $this->subheader) { + if ($this->properties || $this->policyObject || $this->subheader) { $classes[] = 'phui-header-tall'; } $image = null; if ($this->image) { $image = phutil_tag( 'span', array( 'class' => 'phui-header-image', 'style' => 'background-image: url('.$this->image.')', ), ''); $classes[] = 'phui-header-has-image'; } $header = array(); $header[] = $this->header; if ($this->objectName) { array_unshift( $header, phutil_tag( 'a', array( 'href' => '/'.$this->objectName, ), $this->objectName), ' '); } if ($this->tags) { $header[] = ' '; $header[] = phutil_tag( 'span', array( 'class' => 'phui-header-tags', ), array_interleave(' ', $this->tags)); } if ($this->subheader) { $header[] = phutil_tag( 'div', array( 'class' => 'phui-header-subheader', ), $this->subheader); } - if ($this->properties) { + if ($this->properties || $this->policyObject) { $property_list = array(); foreach ($this->properties as $type => $property) { switch ($type) { case self::PROPERTY_STATE: $property_list[] = $property; break; - case self::PROPERTY_POLICY: - $property_list[] = $property; - break; default: throw new Exception('Incorrect Property Passed'); break; } } + if ($this->policyObject) { + $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( + $this->getUser(), + $this->policyObject, + true); + $property_list[] = $descriptions[PhabricatorPolicyCapability::CAN_VIEW]; + } + $header[] = phutil_tag( 'div', array( 'class' => 'phui-header-subheader', ), $property_list); } return phutil_tag( 'div', array( 'class' => implode(' ', $classes), ), array( $image, phutil_tag( 'h1', array( 'class' => 'phui-header-view', ), $header), )); } }