1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Transactions - add "and X others" dialog support to application transactions

Summary: Fixes T4430. Basically does a little code massage from the new stuff in D8525 and application transactions to get this working. Adds a new controller to the subscriptions app to make rendering these pretty easy peasy.

Test Plan: Used my test task in D8525 to verify both add and rem versions of these dialogs worked correctly.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: epriestley, chad, Korvin

Maniphest Tasks: T4430

Differential Revision: https://secure.phabricator.com/D8540
This commit is contained in:
Bob Trahan 2014-03-14 14:27:45 -07:00
parent 6b4887ab22
commit 3ff9f5f48a
5 changed files with 119 additions and 6 deletions

View file

@ -2095,6 +2095,7 @@ phutil_register_library_map(array(
'PhabricatorSubscriptionsEditController' => 'applications/subscriptions/controller/PhabricatorSubscriptionsEditController.php',
'PhabricatorSubscriptionsEditor' => 'applications/subscriptions/editor/PhabricatorSubscriptionsEditor.php',
'PhabricatorSubscriptionsListController' => 'applications/subscriptions/controller/PhabricatorSubscriptionsListController.php',
'PhabricatorSubscriptionsTransactionController' => 'applications/subscriptions/controller/PhabricatorSubscriptionsTransactionController.php',
'PhabricatorSubscriptionsUIEventListener' => 'applications/subscriptions/events/PhabricatorSubscriptionsUIEventListener.php',
'PhabricatorSymbolNameLinter' => 'infrastructure/lint/hook/PhabricatorSymbolNameLinter.php',
'PhabricatorSyntaxHighlighter' => 'infrastructure/markup/PhabricatorSyntaxHighlighter.php',
@ -4897,6 +4898,7 @@ phutil_register_library_map(array(
'PhabricatorSubscriptionsEditController' => 'PhabricatorController',
'PhabricatorSubscriptionsEditor' => 'PhabricatorEditor',
'PhabricatorSubscriptionsListController' => 'PhabricatorController',
'PhabricatorSubscriptionsTransactionController' => 'PhabricatorController',
'PhabricatorSubscriptionsUIEventListener' => 'PhabricatorEventListener',
'PhabricatorSymbolNameLinter' => 'ArcanistXHPASTLintNamingHook',
'PhabricatorSyntaxHighlightingConfigOptions' => 'PhabricatorApplicationConfigOptions',

View file

@ -22,6 +22,8 @@ final class PhabricatorApplicationSubscriptions extends PhabricatorApplication {
'(?P<action>add|delete)/'.
'(?P<phid>[^/]+)/' => 'PhabricatorSubscriptionsEditController',
'list/(?P<phid>[^/]+)/' => 'PhabricatorSubscriptionsListController',
'transaction/(?P<type>add|rem)/(?<phid>[^/]+)/' =>
'PhabricatorSubscriptionsTransactionController',
),
);
}

View file

@ -0,0 +1,81 @@
<?php
final class PhabricatorSubscriptionsTransactionController
extends PhabricatorController {
private $phid;
private $changeType;
public function willProcessRequest(array $data) {
$this->phid = idx($data, 'phid');
$this->changeType = idx($data, 'type');
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$xaction_phid = $this->phid;
$xaction = id(new PhabricatorObjectQuery())
->withPHIDs(array($xaction_phid))
->setViewer($viewer)
->executeOne();
if (!$xaction) {
return new Aphront404Response();
}
$old = $xaction->getOldValue();
$new = $xaction->getNewValue();
switch ($this->changeType) {
case 'add':
$subscriber_phids = array_diff($new, $old);
break;
case 'rem':
$subscriber_phids = array_diff($old, $new);
break;
default:
return id(new Aphront404Response());
}
$object_phid = $xaction->getObjectPHID();
$author_phid = $xaction->getAuthorPHID();
$handle_phids = $subscriber_phids;
$handle_phids[] = $object_phid;
$handle_phids[] = $author_phid;
$handles = id(new PhabricatorHandleQuery())
->setViewer($viewer)
->withPHIDs($handle_phids)
->execute();
$author_handle = $handles[$author_phid];
if (!in_array($author_phid, $subscriber_phids)) {
unset($handles[$author_phid]);
}
switch ($this->changeType) {
case 'add':
$title = pht(
'All %d subscribers added by %s',
count($subscriber_phids),
$author_handle->renderLink());
break;
case 'rem':
$title = pht(
'All %d subscribers removed by %s',
count($subscriber_phids),
$author_handle->renderLink());
break;
}
$dialog = id(new SubscriptionListDialogBuilder())
->setViewer($viewer)
->setTitle($title)
->setObjectPHID($object_phid)
->setHandles($handles)
->buildDialog();
return id(new AphrontDialogResponse())->setDialog($dialog);
}
}

View file

@ -24,13 +24,29 @@ final class SubscriptionListStringBuilder {
return $this->objectPHID;
}
public function buildTransactionString($change_type) {
$handles = $this->getHandles();
if (!$handles) {
return;
}
$list_uri = '/subscriptions/transaction/'.
$change_type.'/'.
$this->getObjectPHID().'/';
return $this->buildString($list_uri);
}
public function buildPropertyString() {
$phid = $this->getObjectPHID();
$handles = $this->getHandles();
if (!$handles) {
return phutil_tag('em', array(), pht('None'));
}
$list_uri = '/subscriptions/list/'.$this->getObjectPHID().'/';
return $this->buildString($list_uri);
}
private function buildString($list_uri) {
$handles = $this->getHandles();
$html = array();
$show_count = 3;
@ -53,7 +69,7 @@ final class SubscriptionListStringBuilder {
$args[] = javelin_tag(
'a',
array(
'href' => '/subscriptions/list/'.$phid.'/',
'href' => $list_uri,
'sigil' => 'workflow'
),
$not_shown_txt);

View file

@ -289,6 +289,18 @@ abstract class PhabricatorApplicationTransaction
}
}
private function renderSubscriberList(array $phids, $change_type) {
if ($this->getRenderingTarget() == self::TARGET_TEXT) {
return $this->renderHandleList($phids);
} else {
$handles = array_select_keys($this->getHandles(), $phids);
return id(new SubscriptionListStringBuilder())
->setHandles($handles)
->setObjectPHID($this->getPHID())
->buildTransactionString($change_type);
}
}
public function renderPolicyName($phid) {
$policy = PhabricatorPolicy::newFromPolicyAndHandle(
$phid,
@ -455,21 +467,21 @@ abstract class PhabricatorApplicationTransaction
'%s edited subscriber(s), added %d: %s; removed %d: %s.',
$this->renderHandleLink($author_phid),
count($add),
$this->renderHandleList($add),
$this->renderSubscriberList($add, 'add'),
count($rem),
$this->renderHandleList($rem));
$this->renderSubscriberList($rem, 'rem'));
} else if ($add) {
return pht(
'%s added %d subscriber(s): %s.',
$this->renderHandleLink($author_phid),
count($add),
$this->renderHandleList($add));
$this->renderSubscriberList($add, 'add'));
} else if ($rem) {
return pht(
'%s removed %d subscriber(s): %s.',
$this->renderHandleLink($author_phid),
count($rem),
$this->renderHandleList($rem));
$this->renderSubscriberList($rem, 'rem'));
} else {
// This is used when rendering previews, before the user actually
// selects any CCs.