public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { $query = id(new PhortuneSubscriptionQuery()); $viewer = $this->requireViewer(); $merchant = $this->getMerchant(); $account = $this->getAccount(); if ($merchant) { $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $merchant, PhabricatorPolicyCapability::CAN_EDIT); if (!$can_edit) { throw new Exception(pht('You can not query subscriptions for a merchant you do not ' . 'control.')); } $query->withMerchantPHIDs(array($merchant->getPHID())); } else { if ($account) { $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $account, PhabricatorPolicyCapability::CAN_EDIT); if (!$can_edit) { throw new Exception(pht('You can not query subscriptions for an account you are not ' . 'a member of.')); } $query->withAccountPHIDs(array($account->getPHID())); } else { $accounts = id(new PhortuneAccountQuery())->withMemberPHIDs(array($viewer->getPHID()))->execute(); if ($accounts) { $query->withAccountPHIDs(mpull($accounts, 'getPHID')); } else { throw new Exception(pht('You have no accounts!')); } } } return $query; }
protected function willFilterPage(array $comments) { if ($this->needReplyToComments) { $reply_phids = array(); foreach ($comments as $comment) { $reply_phid = $comment->getReplyToCommentPHID(); if ($reply_phid) { $reply_phids[] = $reply_phid; } } if ($reply_phids) { $reply_comments = newv(get_class($this), array())->setViewer($this->getViewer())->setParentQuery($this)->withPHIDs($reply_phids)->execute(); $reply_comments = mpull($reply_comments, null, 'getPHID'); } else { $reply_comments = array(); } foreach ($comments as $key => $comment) { $reply_phid = $comment->getReplyToCommentPHID(); if (!$reply_phid) { $comment->attachReplyToComment(null); continue; } $reply = idx($reply_comments, $reply_phid); if (!$reply) { $this->didRejectResult($comment); unset($comments[$key]); continue; } $comment->attachReplyToComment($reply); } } return $comments; }
public function execute(PhutilArgumentParser $args) { $can_recover = id(new PhabricatorPeopleQuery())->setViewer($this->getViewer())->withIsAdmin(true)->execute(); if (!$can_recover) { throw new PhutilArgumentUsageException(pht('This Phabricator installation has no recoverable administrator ' . 'accounts. You can use `bin/accountadmin` to create a new ' . 'administrator account or make an existing user an administrator.')); } $can_recover = mpull($can_recover, 'getUsername'); sort($can_recover); $can_recover = implode(', ', $can_recover); $usernames = $args->getArg('username'); if (!$usernames) { throw new PhutilArgumentUsageException(pht('You must specify the username of the account to recover.')); } else { if (count($usernames) > 1) { throw new PhutilArgumentUsageException(pht('You can only recover the username for one account.')); } } $username = head($usernames); $user = id(new PhabricatorPeopleQuery())->setViewer($this->getViewer())->withUsernames(array($username))->executeOne(); if (!$user) { throw new PhutilArgumentUsageException(pht('No such user "%s". Recoverable administrator accounts are: %s.', $username, $can_recover)); } if (!$user->getIsAdmin()) { throw new PhutilArgumentUsageException(pht('You can only recover administrator accounts, but %s is not an ' . 'administrator. Recoverable administrator accounts are: %s.', $username, $can_recover)); } $engine = new PhabricatorAuthSessionEngine(); $onetime_uri = $engine->getOneTimeLoginURI($user, null, PhabricatorAuthSessionEngine::ONETIME_RECOVER); $console = PhutilConsole::getConsole(); $console->writeOut(pht('Use this link to recover access to the "%s" account from the web ' . 'interface:', $username)); $console->writeOut("\n\n"); $console->writeOut(' %s', $onetime_uri); $console->writeOut("\n\n"); $console->writeOut(pht('After logging in, you can use the "Auth" application to add or ' . 'restore authentication providers and allow normal logins to ' . 'succeed.') . "\n"); return 0; }
protected function getGitResult(ConduitAPIRequest $request) { $drequest = $this->getDiffusionRequest(); $repository = $drequest->getRepository(); $commit = $drequest->getSymbolicCommit(); $commit_filter = null; if ($commit) { $commit_filter = $this->loadTagNamesForCommit($commit); } $name_filter = $request->getValue('names', null); $all_tags = $this->loadGitTagList(); $all_tags = mpull($all_tags, null, 'getName'); if ($name_filter !== null) { $all_tags = array_intersect_key($all_tags, array_fuse($name_filter)); } if ($commit_filter !== null) { $all_tags = array_intersect_key($all_tags, $commit_filter); } $tags = array_values($all_tags); $offset = $request->getValue('offset'); $limit = $request->getValue('limit'); if ($offset) { $tags = array_slice($tags, $offset); } if ($limit) { $tags = array_slice($tags, 0, $limit); } if ($request->getValue('needMessages')) { $this->loadMessagesForTags($all_tags); } return mpull($tags, 'toDictionary'); }
protected function willFilterPage(array $page) { if ($this->needSecrets) { $secret_ids = mpull($page, 'getSecretID'); $secret_ids = array_filter($secret_ids); $secrets = array(); if ($secret_ids) { $secret_objects = id(new PassphraseSecret())->loadAllWhere('id IN (%Ld)', $secret_ids); foreach ($secret_objects as $secret) { $secret_data = $secret->getSecretData(); $secrets[$secret->getID()] = new PhutilOpaqueEnvelope($secret_data); } } foreach ($page as $key => $credential) { $secret_id = $credential->getSecretID(); if (!$secret_id) { $credential->attachSecret(null); } else { if (isset($secrets[$secret_id])) { $credential->attachSecret($secrets[$secret_id]); } else { unset($page[$key]); } } } } return $page; }
public function renderEditControl(array $handles) { $engines = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorApplicationSearchEngine')->loadObjects(); $value = $this->getFieldValue(); $queries = array(); $seen = false; foreach ($engines as $engine_class => $engine) { $engine->setViewer($this->getViewer()); $engine_queries = $engine->loadEnabledNamedQueries(); $query_map = mpull($engine_queries, 'getQueryName', 'getQueryKey'); asort($query_map); foreach ($query_map as $key => $name) { $queries[$engine_class][] = array('key' => $key, 'name' => $name); if ($key == $value) { $seen = true; } } } if (strlen($value) && !$seen) { $name = pht('Custom Query ("%s")', $value); } else { $name = pht('(None)'); } $options = array($value => $name); $app_control_key = $this->getFieldConfigValue('control.application'); Javelin::initBehavior('dashboard-query-panel-select', array('applicationID' => $this->getFieldControlID($app_control_key), 'queryID' => $this->getFieldControlID(), 'options' => $queries, 'value' => array('key' => strlen($value) ? $value : null, 'name' => $name))); return id(new AphrontFormSelectControl())->setID($this->getFieldControlID())->setLabel($this->getFieldName())->setCaption($this->getCaption())->setName($this->getFieldKey())->setValue($this->getFieldValue())->setOptions($options); }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $pager = new PHUIPagerView(); $pager->setURI($request->getRequestURI(), 'page'); $pager->setOffset($request->getInt('page')); $query = id(new PhabricatorTokenReceiverQuery()); $objects = $query->setViewer($viewer)->executeWithOffsetPager($pager); $counts = $query->getTokenCounts(); $handles = array(); $phids = array(); if ($counts) { $phids = mpull($objects, 'getPHID'); $handles = id(new PhabricatorHandleQuery())->setViewer($viewer)->withPHIDs($phids)->execute(); } $list = new PHUIObjectItemListView(); foreach ($phids as $object) { $count = idx($counts, $object, 0); $item = id(new PHUIObjectItemView()); $handle = $handles[$object]; $item->setHeader($handle->getFullName()); $item->setHref($handle->getURI()); $item->addAttribute(pht('Tokens: %s', $count)); $list->addItem($item); } $title = pht('Token Leader Board'); $box = id(new PHUIObjectBoxView())->setHeaderText($title)->setObjectList($list); $nav = $this->buildSideNav(); $nav->setCrumbs($this->buildApplicationCrumbs()->addTextCrumb($title)); $nav->selectFilter('leaders/'); $nav->appendChild($box); $nav->appendChild($pager); return $this->newPage()->setTitle($title)->appendChild($nav); }
protected function renderResultList(array $polls, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($polls, 'PhabricatorSlowvotePoll'); $viewer = $this->requireViewer(); $list = id(new PHUIObjectItemListView())->setUser($viewer); $phids = mpull($polls, 'getAuthorPHID'); foreach ($polls as $poll) { $date_created = phabricator_datetime($poll->getDateCreated(), $viewer); if ($poll->getAuthorPHID()) { $author = $handles[$poll->getAuthorPHID()]->renderLink(); } else { $author = null; } $item = id(new PHUIObjectItemView())->setUser($viewer)->setObject($poll)->setObjectName('V' . $poll->getID())->setHeader($poll->getQuestion())->setHref('/V' . $poll->getID())->addIcon('none', $date_created); if ($poll->getIsClosed()) { $item->setStatusIcon('fa-ban grey'); $item->setDisabled(true); } else { $item->setStatusIcon('fa-bar-chart'); } $description = $poll->getDescription(); if (strlen($description)) { $item->addAttribute(id(new PhutilUTF8StringTruncator())->setMaximumGlyphs(120)->truncateString($poll->getDescription())); } if ($author) { $item->addByline(pht('Author: %s', $author)); } $list->addItem($item); } $result = new PhabricatorApplicationSearchResultView(); $result->setObjectList($list); $result->setNoDataString(pht('No polls found.')); return $result; }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $post = id(new PhamePostQuery())->setViewer($viewer)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_EDIT, PhabricatorPolicyCapability::CAN_VIEW))->executeOne(); if (!$post) { return new Aphront404Response(); } $view_uri = '/post/view/' . $post->getID() . '/'; $view_uri = $this->getApplicationURI($view_uri); if ($request->isFormPost()) { $blog = id(new PhameBlogQuery())->setViewer($viewer)->withIDs(array($request->getInt('blog')))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_EDIT))->executeOne(); if ($blog) { $post->setBlogPHID($blog->getPHID()); $post->save(); return id(new AphrontRedirectResponse())->setURI($view_uri . '?moved=1'); } } $blogs = id(new PhameBlogQuery())->setViewer($viewer)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_EDIT))->execute(); $options = mpull($blogs, 'getName', 'getID'); asort($options); $selected_value = null; if ($post && $post->getBlog()) { $selected_value = $post->getBlog()->getID(); } $form = id(new PHUIFormLayoutView())->setUser($viewer)->appendChild(id(new AphrontFormSelectControl())->setLabel(pht('Blog'))->setName('blog')->setOptions($options)->setValue($selected_value)); return $this->newDialog()->setTitle(pht('Move Post'))->appendChild($form)->addSubmitButton(pht('Move Post'))->addCancelButton($view_uri); }
private function buildPaymentMethodsSection(PhortuneAccount $account) { $request = $this->getRequest(); $viewer = $request->getUser(); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $account, PhabricatorPolicyCapability::CAN_EDIT); $id = $account->getID(); $header = id(new PHUIHeaderView())->setHeader(pht('Payment Methods'))->addActionLink(id(new PHUIButtonView())->setTag('a')->setHref($this->getApplicationURI($id . '/card/new/'))->setText(pht('Add Payment Method'))->setIcon(id(new PHUIIconView())->setIconFont('fa-plus'))); $list = id(new PHUIObjectItemListView())->setUser($viewer)->setNoDataString(pht('No payment methods associated with this account.')); $methods = id(new PhortunePaymentMethodQuery())->setViewer($viewer)->withAccountPHIDs(array($account->getPHID()))->execute(); if ($methods) { $this->loadHandles(mpull($methods, 'getAuthorPHID')); } foreach ($methods as $method) { $id = $method->getID(); $item = new PHUIObjectItemView(); $item->setHeader($method->getFullDisplayName()); switch ($method->getStatus()) { case PhortunePaymentMethod::STATUS_ACTIVE: $item->setBarColor('green'); $disable_uri = $this->getApplicationURI('card/' . $id . '/disable/'); $item->addAction(id(new PHUIListItemView())->setIcon('fa-times')->setHref($disable_uri)->setDisabled(!$can_edit)->setWorkflow(true)); break; case PhortunePaymentMethod::STATUS_DISABLED: $item->setDisabled(true); break; } $provider = $method->buildPaymentProvider(); $item->addAttribute($provider->getPaymentMethodProviderDescription()); $item->setImageURI($provider->getPaymentMethodIcon()); $edit_uri = $this->getApplicationURI('card/' . $id . '/edit/'); $item->addAction(id(new PHUIListItemView())->setIcon('fa-pencil')->setHref($edit_uri)->setDisabled(!$can_edit)->setWorkflow(!$can_edit)); $list->addItem($item); } return id(new PHUIObjectBoxView())->setHeader($header)->appendChild($list); }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $authority = $this->loadMerchantAuthority(); $cart_query = id(new PhortuneCartQuery())->setViewer($viewer)->withIDs(array($id))->needPurchases(true); if ($authority) { $cart_query->withMerchantPHIDs(array($authority->getPHID())); } $cart = $cart_query->executeOne(); if (!$cart) { return new Aphront404Response(); } $charges = id(new PhortuneChargeQuery())->setViewer($viewer)->withCartPHIDs(array($cart->getPHID()))->needCarts(true)->withStatuses(array(PhortuneCharge::STATUS_HOLD, PhortuneCharge::STATUS_CHARGED))->execute(); if ($charges) { $providers = id(new PhortunePaymentProviderConfigQuery())->setViewer($viewer)->withPHIDs(mpull($charges, 'getProviderPHID'))->execute(); $providers = mpull($providers, null, 'getPHID'); } else { $providers = array(); } foreach ($charges as $charge) { if ($charge->isRefund()) { // Don't update refunds. continue; } $provider_config = idx($providers, $charge->getProviderPHID()); if (!$provider_config) { throw new Exception(pht('Unable to load provider for charge!')); } $provider = $provider_config->buildProvider(); $provider->updateCharge($charge); } return id(new AphrontRedirectResponse())->setURI($cart->getDetailURI($authority)); }
protected function willFilterPage(array $accounts) { if ($this->needImages) { $file_phids = mpull($accounts, 'getProfileImagePHID'); $file_phids = array_filter($file_phids); if ($file_phids) { // NOTE: We use the omnipotent viewer here because these files are // usually created during registration and can't be associated with // the correct policies, since the relevant user account does not exist // yet. In effect, if you can see an ExternalAccount, you can see its // profile image. $files = id(new PhabricatorFileQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withPHIDs($file_phids)->execute(); $files = mpull($files, null, 'getPHID'); } else { $files = array(); } $default_file = null; foreach ($accounts as $account) { $image_phid = $account->getProfileImagePHID(); if ($image_phid && isset($files[$image_phid])) { $account->attachProfileImageFile($files[$image_phid]); } else { if ($default_file === null) { $default_file = PhabricatorFile::loadBuiltin($this->getViewer(), 'profile.png'); } $account->attachProfileImageFile($default_file); } } } return $accounts; }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $views = array(self::VIEW_ALL => 'All Slowvotes', self::VIEW_CREATED => 'Created', self::VIEW_VOTED => 'Voted In'); $view = isset($views[$this->view]) ? $this->view : self::VIEW_ALL; $side_nav = $this->renderSideNav($views, $view); $pager = new AphrontPagerView(); $pager->setOffset($request->getInt('page')); $pager->setURI($request->getRequestURI(), 'page'); $polls = $this->loadPolls($pager, $view); $phids = mpull($polls, 'getAuthorPHID'); $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); $rows = array(); foreach ($polls as $poll) { $rows[] = array('V' . $poll->getID(), phutil_render_tag('a', array('href' => '/V' . $poll->getID()), phutil_escape_html($poll->getQuestion())), $handles[$poll->getAuthorPHID()]->renderLink(), phabricator_date($poll->getDateCreated(), $user), phabricator_time($poll->getDateCreated(), $user)); } $table = new AphrontTableView($rows); $table->setColumnClasses(array('', 'pri wide', '', '', 'right')); $table->setHeaders(array('ID', 'Poll', 'Author', 'Date', 'Time')); $panel = new AphrontPanelView(); $panel->setHeader($this->getTableHeader($view)); $panel->setCreateButton('Create Slowvote', '/vote/create/'); $panel->appendChild($table); $panel->appendChild($pager); $side_nav->appendChild($panel); return $this->buildStandardPageResponse($side_nav, array('title' => 'Slowvotes')); }
private function buildPackagePropertyView(PhabricatorOwnersPackage $package) { $viewer = $this->getViewer(); $view = id(new PHUIPropertyListView())->setUser($viewer); $primary_phid = $package->getPrimaryOwnerPHID(); if ($primary_phid) { $primary_owner = $viewer->renderHandle($primary_phid); } else { $primary_owner = phutil_tag('em', array(), pht('None')); } $view->addProperty(pht('Primary Owner'), $primary_owner); // TODO: needOwners() this on the Query. $owners = $package->loadOwners(); if ($owners) { $owner_list = $viewer->renderHandleList(mpull($owners, 'getUserPHID')); } else { $owner_list = phutil_tag('em', array(), pht('None')); } $view->addProperty(pht('Owners'), $owner_list); if ($package->getAuditingEnabled()) { $auditing = pht('Enabled'); } else { $auditing = pht('Disabled'); } $view->addProperty(pht('Auditing'), $auditing); $description = $package->getDescription(); if (strlen($description)) { $view->addSectionHeader(pht('Description')); $view->addTextContent($output = PhabricatorMarkupEngine::renderOneObject(id(new PhabricatorMarkupOneOff())->setContent($description), 'default', $viewer)); } return $view; }
public function willApplyRules(PhabricatorUser $viewer, array $values, array $objects) { $viewer_phid = $viewer->getPHID(); if (!$viewer_phid) { return; } if (empty($this->memberships[$viewer_phid])) { $this->memberships[$viewer_phid] = array(); } foreach ($objects as $key => $object) { $cache = $this->getTransactionHint($object); if ($cache === null) { continue; } unset($objects[$key]); if (isset($cache[$viewer_phid])) { $this->memberships[$viewer_phid][$object->getPHID()] = true; } } if (!$objects) { return; } $object_phids = mpull($objects, 'getPHID'); $edge_query = id(new PhabricatorEdgeQuery())->withSourcePHIDs(array($viewer_phid))->withDestinationPHIDs($object_phids)->withEdgeTypes(array(PhabricatorProjectMemberOfProjectEdgeType::EDGECONST)); $edge_query->execute(); $memberships = $edge_query->getDestinationPHIDs(); if (!$memberships) { return; } $this->memberships[$viewer_phid] += array_fill_keys($memberships, true); }
public function renderBreadcrumbs($slug) { $ancestor_handles = array(); $ancestral_slugs = PhabricatorSlug::getAncestry($slug); $ancestral_slugs[] = $slug; if ($ancestral_slugs) { $empty_slugs = array_fill_keys($ancestral_slugs, null); $ancestors = id(new PhrictionDocumentQuery())->setViewer($this->getRequest()->getUser())->withSlugs($ancestral_slugs)->execute(); $ancestors = mpull($ancestors, null, 'getSlug'); $ancestor_phids = mpull($ancestors, 'getPHID'); $handles = array(); if ($ancestor_phids) { $handles = $this->loadViewerHandles($ancestor_phids); } $ancestor_handles = array(); foreach ($ancestral_slugs as $slug) { if (isset($ancestors[$slug])) { $ancestor_handles[] = $handles[$ancestors[$slug]->getPHID()]; } else { $handle = new PhabricatorObjectHandle(); $handle->setName(PhabricatorSlug::getDefaultTitle($slug)); $handle->setURI(PhrictionDocument::getSlugURI($slug)); $ancestor_handles[] = $handle; } } } $breadcrumbs = array(); foreach ($ancestor_handles as $ancestor_handle) { $breadcrumbs[] = id(new PHUICrumbView())->setName($ancestor_handle->getName())->setHref($ancestor_handle->getUri()); } return $breadcrumbs; }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $post = id(new PhamePostQuery())->setViewer($viewer)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_EDIT, PhabricatorPolicyCapability::CAN_VIEW))->executeOne(); if (!$post) { return new Aphront404Response(); } $view_uri = $post->getViewURI(); $v_blog = $post->getBlog()->getPHID(); if ($request->isFormPost()) { $v_blog = $request->getStr('blogPHID'); $xactions = array(); $xactions[] = id(new PhamePostTransaction())->setTransactionType(PhamePostTransaction::TYPE_BLOG)->setNewValue($v_blog); $editor = id(new PhamePostEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnMissingFields(true)->setContinueOnNoEffect(true); $editor->applyTransactions($post, $xactions); $view_uri = $post->getViewURI(); return id(new AphrontRedirectResponse())->setURI($view_uri . '?moved=1'); } $blogs = id(new PhameBlogQuery())->setViewer($viewer)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->execute(); $options = mpull($blogs, 'getName', 'getPHID'); asort($options); $form = id(new PHUIFormLayoutView())->setUser($viewer)->appendChild(id(new AphrontFormSelectControl())->setLabel(pht('Blog'))->setName('blogPHID')->setOptions($options)->setValue($v_blog)); return $this->newDialog()->setTitle(pht('Move Post'))->appendChild($form)->addSubmitButton(pht('Move Post'))->addCancelButton($view_uri); }
protected function execute(ConduitAPIRequest $request) { $results = array(); $task_ids = $request->getValue('ids'); if (!$task_ids) { return $results; } $tasks = id(new ManiphestTaskQuery())->setViewer($request->getUser())->withIDs($task_ids)->execute(); $tasks = mpull($tasks, null, 'getPHID'); $transactions = array(); if ($tasks) { $transactions = id(new ManiphestTransactionQuery())->setViewer($request->getUser())->withObjectPHIDs(mpull($tasks, 'getPHID'))->needComments(true)->execute(); } foreach ($transactions as $transaction) { $task_phid = $transaction->getObjectPHID(); if (empty($tasks[$task_phid])) { continue; } $task_id = $tasks[$task_phid]->getID(); $comments = null; if ($transaction->hasComment()) { $comments = $transaction->getComment()->getContent(); } $results[$task_id][] = array('taskID' => $task_id, 'transactionPHID' => $transaction->getPHID(), 'transactionType' => $transaction->getTransactionType(), 'oldValue' => $transaction->getOldValue(), 'newValue' => $transaction->getNewValue(), 'comments' => $comments, 'authorPHID' => $transaction->getAuthorPHID(), 'dateCreated' => $transaction->getDateCreated()); } return $results; }
public function processRequest() { $drequest = $this->getDiffusionRequest(); $request = $this->getRequest(); $viewer = $request->getUser(); $repository = $drequest->getRepository(); $pager = new AphrontPagerView(); $pager->setURI($request->getRequestURI(), 'offset'); $pager->setOffset($request->getInt('offset')); // TODO: Add support for branches that contain commit $branches = $this->callConduitWithDiffusionRequest('diffusion.branchquery', array('offset' => $pager->getOffset(), 'limit' => $pager->getPageSize() + 1)); $branches = $pager->sliceResults($branches); $branches = DiffusionRepositoryRef::loadAllFromDictionaries($branches); $content = null; if (!$branches) { $content = $this->renderStatusMessage(pht('No Branches'), pht('This repository has no branches.')); } else { $commits = id(new DiffusionCommitQuery())->setViewer($viewer)->withIdentifiers(mpull($branches, 'getCommitIdentifier'))->withRepository($repository)->execute(); $view = id(new DiffusionBranchTableView())->setUser($viewer)->setBranches($branches)->setCommits($commits)->setDiffusionRequest($drequest); $panel = id(new AphrontPanelView())->setNoBackground(true)->appendChild($view)->appendChild($pager); $content = $panel; } $crumbs = $this->buildCrumbs(array('branches' => true)); return $this->buildApplicationPage(array($crumbs, $content), array('title' => array(pht('Branches'), 'r' . $repository->getCallsign()), 'device' => false)); }
public function render() { $conpherence = $this->getConpherence(); $widget_data = $conpherence->getWidgetData(); $viewer = $this->getUser(); $participants = $conpherence->getParticipants(); $handles = $conpherence->getHandles(); $head_handles = array_select_keys($handles, array($viewer->getPHID())); $handle_list = mpull($handles, 'getName'); natcasesort($handle_list); $handles = mpull($handles, null, 'getName'); $handles = array_select_keys($handles, $handle_list); $head_handles = mpull($head_handles, null, 'getName'); $handles = $head_handles + $handles; $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $conpherence, PhabricatorPolicyCapability::CAN_EDIT); $body = array(); foreach ($handles as $handle) { $user_phid = $handle->getPHID(); if ($user_phid == $viewer->getPHID() || $can_edit) { $icon = id(new PHUIIconView())->setIcon('fa-times lightbluetext'); $remove_html = javelin_tag('a', array('class' => 'remove', 'sigil' => 'remove-person', 'meta' => array('remove_person' => $user_phid, 'action' => 'remove_person')), $icon); } else { $remove_html = null; } $body[] = phutil_tag('div', array('class' => 'person-entry grouped'), array(phutil_tag('a', array('class' => 'pic', 'href' => $handle->getURI()), phutil_tag('img', array('src' => $handle->getImageURI()), '')), $handle->renderLink(), $remove_html)); } return $body; }
private function resolvePHIDs(array $phids) { // If we have a function like `projects(alincoln)`, try to resolve the // username first. This won't happen normally, but can be passed in from // the query string. // The user might also give us an invalid username. In this case, we // preserve it and return it in-place so we get an "invalid" token rendered // in the UI. This shows the user where the issue is and best represents // the user's input. $usernames = array(); foreach ($phids as $key => $phid) { if (phid_get_type($phid) != PhabricatorPeopleUserPHIDType::TYPECONST) { $usernames[$key] = $phid; } } if ($usernames) { $users = id(new PhabricatorPeopleQuery())->setViewer($this->getViewer())->withUsernames($usernames)->execute(); $users = mpull($users, null, 'getUsername'); foreach ($usernames as $key => $username) { $user = idx($users, $username); if ($user) { $phids[$key] = $user->getPHID(); } } } return $phids; }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $blogs = id(new PhameBlogQuery())->setViewer($viewer)->withStatuses(array(PhameBlog::STATUS_ACTIVE))->needProfileImage(true)->execute(); $post_list = null; if ($blogs) { $blog_phids = mpull($blogs, 'getPHID'); $pager = id(new AphrontCursorPagerView())->readFromRequest($request); $posts = id(new PhamePostQuery())->setViewer($viewer)->withBlogPHIDs($blog_phids)->withVisibility(array(PhameConstants::VISIBILITY_PUBLISHED))->setOrder('datePublished')->executeWithCursorPager($pager); if ($posts) { $post_list = id(new PhamePostListView())->setPosts($posts)->setViewer($viewer)->showBlog(true); } else { $post_list = id(new PHUIBigInfoView())->setIcon('fa-star')->setTitle('No Visible Posts')->setDescription(pht('There aren\'t any visible blog posts.')); } } else { $create_button = id(new PHUIButtonView())->setTag('a')->setText(pht('Create a Blog'))->setHref('/phame/blog/edit/')->setColor(PHUIButtonView::GREEN); $post_list = id(new PHUIBigInfoView())->setIcon('fa-star')->setTitle('Welcome to Phame')->setDescription(pht('There aren\'t any visible blog posts.'))->addAction($create_button); } $view_all = id(new PHUIButtonView())->setTag('a')->setText(pht('View All'))->setHref($this->getApplicationURI('post/'))->setIcon('fa-list-ul'); $title = pht('Recent Posts'); $header = id(new PHUIHeaderView())->setHeader($title)->addActionLink($view_all); $crumbs = $this->buildApplicationCrumbs(); $crumbs->setBorder(true); $crumbs->addTextCrumb(pht('Recent Posts'), $this->getApplicationURI('post/')); $page = id(new PHUIDocumentViewPro())->setHeader($header)->appendChild($post_list); $blog_list = id(new PhameBlogListView())->setBlogs($blogs)->setViewer($viewer); $draft_list = null; if ($viewer->isLoggedIn() && $blogs) { $drafts = id(new PhamePostQuery())->setViewer($viewer)->withBloggerPHIDs(array($viewer->getPHID()))->withBlogPHIDs(mpull($blogs, 'getPHID'))->withVisibility(array(PhameConstants::VISIBILITY_DRAFT))->setLimit(5)->execute(); $draft_list = id(new PhameDraftListView())->setPosts($drafts)->setBlogs($blogs)->setViewer($viewer); } $phame_view = id(new PHUITwoColumnView())->setMainColumn(array($page))->setSideColumn(array($blog_list, $draft_list))->addClass('phame-home-container'); $phame_home = phutil_tag_div('phame-home-view', $phame_view); return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild(array($phame_home)); }
private function buildPanels() { $panel_specs = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorSettingsPanel')->setConcreteOnly(true)->selectAndLoadSymbols(); $panels = array(); foreach ($panel_specs as $spec) { $class = newv($spec['name'], array()); $panels[] = $class->buildPanels(); } $panels = array_mergev($panels); $panels = mpull($panels, null, 'getPanelKey'); $result = array(); foreach ($panels as $key => $panel) { $panel->setUser($this->user); if (!$panel->isEnabled()) { continue; } if (!$this->isSelf()) { if (!$panel->isEditableByAdministrators()) { continue; } } if (!empty($result[$key])) { throw new Exception(pht("Two settings panels share the same panel key ('%s'): %s, %s.", $key, get_class($panel), get_class($result[$key]))); } $result[$key] = $panel; } $result = msort($result, 'getPanelSortKey'); if (!$result) { throw new Exception(pht('No settings panels are available.')); } return $result; }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $pager = new AphrontPagerView(); $pager->setOffset($request->getInt('page')); $pager->setURI($request->getRequestURI(), 'page'); $mails = id(new PhabricatorMetaMTAReceivedMail())->loadAllWhere('1 = 1 ORDER BY id DESC LIMIT %d, %d', $pager->getOffset(), $pager->getPageSize() + 1); $mails = $pager->sliceResults($mails); $phids = array_merge(mpull($mails, 'getAuthorPHID'), mpull($mails, 'getRelatedPHID')); $phids = array_unique(array_filter($phids)); $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); $rows = array(); foreach ($mails as $mail) { $rows[] = array($mail->getID(), phabricator_date($mail->getDateCreated(), $user), phabricator_time($mail->getDateCreated(), $user), $mail->getAuthorPHID() ? $handles[$mail->getAuthorPHID()]->renderLink() : '-', $mail->getRelatedPHID() ? $handles[$mail->getRelatedPHID()]->renderLink() : '-', phutil_escape_html($mail->getMessage())); } $table = new AphrontTableView($rows); $table->setHeaders(array('ID', 'Date', 'Time', 'Author', 'Object', 'Message')); $table->setColumnClasses(array(null, null, 'right', null, null, 'wide')); $panel = new AphrontPanelView(); $panel->setHeader('Received Mail'); $panel->appendChild($table); $panel->appendChild($pager); $nav = $this->buildSideNavView(); $nav->selectFilter('received'); $nav->appendChild($panel); return $this->buildApplicationPage($nav, array('title' => 'Received Mail')); }
private function buildPackagePropertyView(PhabricatorOwnersPackage $package, PhabricatorCustomFieldList $field_list) { $viewer = $this->getViewer(); $view = id(new PHUIPropertyListView())->setUser($viewer); $owners = $package->getOwners(); if ($owners) { $owner_list = $viewer->renderHandleList(mpull($owners, 'getUserPHID')); } else { $owner_list = phutil_tag('em', array(), pht('None')); } $view->addProperty(pht('Owners'), $owner_list); if ($package->getAuditingEnabled()) { $auditing = pht('Enabled'); } else { $auditing = pht('Disabled'); } $view->addProperty(pht('Auditing'), $auditing); $description = $package->getDescription(); if (strlen($description)) { $view->addSectionHeader(pht('Description')); $view->addTextContent($output = PhabricatorMarkupEngine::renderOneObject(id(new PhabricatorMarkupOneOff())->setContent($description), 'default', $viewer)); } $view->invokeWillRenderEvent(); $field_list->appendFieldsToPropertyList($package, $viewer, $view); return $view; }
public static function dispatchEvent(PhutilEvent $event) { $instance = self::getInstance(); $listeners = idx($instance->listeners, $event->getType(), array()); $global_listeners = idx($instance->listeners, PhutilEventType::TYPE_ALL, array()); // Merge and deduplicate listeners (we want to send the event to each // listener only once, even if it satisfies multiple criteria for the // event). $listeners = array_merge($listeners, $global_listeners); $listeners = mpull($listeners, null, 'getListenerID'); $profiler = PhutilServiceProfiler::getInstance(); $profiler_id = $profiler->beginServiceCall(array('type' => 'event', 'kind' => $event->getType(), 'count' => count($listeners))); $caught = null; try { foreach ($listeners as $listener) { if ($event->isStopped()) { // Do this first so if someone tries to dispatch a stopped event it // doesn't go anywhere. Silly but less surprising. break; } $listener->handleEvent($event); } } catch (Exception $ex) { $profiler->endServiceCall($profiler_id, array()); throw $ex; } $profiler->endServiceCall($profiler_id, array()); }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $paste = id(new PhabricatorPasteQuery())->setViewer($viewer)->withIDs(array($id))->needContent(true)->executeOne(); if (!$paste) { return new Aphront404Response(); } $file = id(new PhabricatorFileQuery())->setViewer($viewer)->withPHIDs(array($paste->getFilePHID()))->executeOne(); if (!$file) { return new Aphront400Response(); } $forks = id(new PhabricatorPasteQuery())->setViewer($viewer)->withParentPHIDs(array($paste->getPHID()))->execute(); $fork_phids = mpull($forks, 'getPHID'); $header = $this->buildHeaderView($paste); $actions = $this->buildActionView($viewer, $paste, $file); $properties = $this->buildPropertyView($paste, $fork_phids, $actions); $object_box = id(new PHUIObjectBoxView())->setHeader($header)->addPropertyList($properties); $source_code = $this->buildSourceCodeView($paste, null, $this->highlightMap); $source_code = id(new PHUIBoxView())->appendChild($source_code)->addMargin(PHUI::MARGIN_LARGE_LEFT)->addMargin(PHUI::MARGIN_LARGE_RIGHT)->addMargin(PHUI::MARGIN_LARGE_TOP); $crumbs = $this->buildApplicationCrumbs($this->buildSideNavView())->addTextCrumb('P' . $paste->getID(), '/P' . $paste->getID()); $timeline = $this->buildTransactionTimeline($paste, new PhabricatorPasteTransactionQuery()); $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); $add_comment_header = $is_serious ? pht('Add Comment') : pht('Eat Paste'); $draft = PhabricatorDraft::newFromUserAndKey($viewer, $paste->getPHID()); $add_comment_form = id(new PhabricatorApplicationTransactionCommentView())->setUser($viewer)->setObjectPHID($paste->getPHID())->setDraft($draft)->setHeaderText($add_comment_header)->setAction($this->getApplicationURI('/comment/' . $paste->getID() . '/'))->setSubmitButtonName(pht('Add Comment')); return $this->buildApplicationPage(array($crumbs, $object_box, $source_code, $timeline, $add_comment_form), array('title' => $paste->getFullName(), 'pageObjects' => array($paste->getPHID()))); }
protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object) { $revision = id(new DifferentialRevisionQuery())->setViewer($this->getViewer())->withPHIDs(array($object->getPHID()))->needReviewerStatus(true)->executeOne(); // TODO: This isn't very clean, but custom fields currently rely on it. $object->attachReviewerStatus($revision->getReviewerStatus()); $document->setDocumentTitle($revision->getTitle()); $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $revision->getAuthorPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $revision->getDateCreated()); $document->addRelationship($revision->isClosed() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $revision->getPHID(), DifferentialRevisionPHIDType::TYPECONST, PhabricatorTime::getNow()); // If a revision needs review, the owners are the reviewers. Otherwise, the // owner is the author (e.g., accepted, rejected, closed). $status_review = ArcanistDifferentialRevisionStatus::NEEDS_REVIEW; if ($revision->getStatus() == $status_review) { $reviewers = $revision->getReviewerStatus(); $reviewers = mpull($reviewers, 'getReviewerPHID', 'getReviewerPHID'); if ($reviewers) { foreach ($reviewers as $phid) { $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_OWNER, $phid, PhabricatorPeopleUserPHIDType::TYPECONST, $revision->getDateModified()); // Bogus timestamp. } } else { $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_UNOWNED, $revision->getPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $revision->getDateModified()); // Bogus timestamp. } } else { $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_OWNER, $revision->getAuthorPHID(), PhabricatorPHIDConstants::PHID_TYPE_VOID, $revision->getDateCreated()); } }
private function getBlockers(PhabricatorRepositoryCommit $commit, HarbormasterBuildPlan $plan, HarbormasterBuild $source) { $call = new ConduitCall('diffusion.commitparentsquery', array('commit' => $commit->getCommitIdentifier(), 'repository' => $commit->getRepository()->getPHID())); $call->setUser(PhabricatorUser::getOmnipotentUser()); $parents = $call->execute(); $parents = id(new DiffusionCommitQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withRepository($commit->getRepository())->withIdentifiers($parents)->execute(); $blockers = array(); $build_objects = array(); foreach ($parents as $parent) { if (!$parent->isImported()) { $blockers[] = pht('Commit %s', $parent->getCommitIdentifier()); } else { $build_objects[] = $parent->getPHID(); } } if ($build_objects) { $buildables = id(new HarbormasterBuildableQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withBuildablePHIDs($build_objects)->withManualBuildables(false)->execute(); $buildable_phids = mpull($buildables, 'getPHID'); if ($buildable_phids) { $builds = id(new HarbormasterBuildQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withBuildablePHIDs($buildable_phids)->withBuildPlanPHIDs(array($plan->getPHID()))->execute(); foreach ($builds as $build) { if (!$build->isComplete()) { $blockers[] = pht('Build %d', $build->getID()); } } } } return $blockers; }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); // TODO: These should be user-based and navigable in the interface. $year = idate('Y'); $month = idate('m'); $holidays = id(new PhabricatorCalendarHoliday())->loadAllWhere('day BETWEEN %s AND %s', "{$year}-{$month}-01", "{$year}-{$month}-31"); $statuses = id(new PhabricatorUserStatus())->loadAllWhere('dateTo >= %d AND dateFrom <= %d', strtotime("{$year}-{$month}-01"), strtotime("{$year}-{$month}-01 next month")); $month_view = new AphrontCalendarMonthView($month, $year); $month_view->setUser($user); $month_view->setHolidays($holidays); $phids = mpull($statuses, 'getUserPHID'); $handles = $this->loadViewerHandles($phids); foreach ($statuses as $status) { $event = new AphrontCalendarEventView(); $event->setEpochRange($status->getDateFrom(), $status->getDateTo()); $name_text = $handles[$status->getUserPHID()]->getName(); $status_text = $status->getTextStatus(); $event->setUserPHID($status->getUserPHID()); $event->setName("{$name_text} ({$status_text})"); $event->setDescription($status->getStatusDescription($user)); $month_view->addEvent($event); } return $this->buildStandardPageResponse(array('<div style="padding: 2em;">', $month_view, '</div>'), array('title' => 'Calendar')); }