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:
parent
6b4887ab22
commit
3ff9f5f48a
5 changed files with 119 additions and 6 deletions
|
@ -2095,6 +2095,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorSubscriptionsEditController' => 'applications/subscriptions/controller/PhabricatorSubscriptionsEditController.php',
|
'PhabricatorSubscriptionsEditController' => 'applications/subscriptions/controller/PhabricatorSubscriptionsEditController.php',
|
||||||
'PhabricatorSubscriptionsEditor' => 'applications/subscriptions/editor/PhabricatorSubscriptionsEditor.php',
|
'PhabricatorSubscriptionsEditor' => 'applications/subscriptions/editor/PhabricatorSubscriptionsEditor.php',
|
||||||
'PhabricatorSubscriptionsListController' => 'applications/subscriptions/controller/PhabricatorSubscriptionsListController.php',
|
'PhabricatorSubscriptionsListController' => 'applications/subscriptions/controller/PhabricatorSubscriptionsListController.php',
|
||||||
|
'PhabricatorSubscriptionsTransactionController' => 'applications/subscriptions/controller/PhabricatorSubscriptionsTransactionController.php',
|
||||||
'PhabricatorSubscriptionsUIEventListener' => 'applications/subscriptions/events/PhabricatorSubscriptionsUIEventListener.php',
|
'PhabricatorSubscriptionsUIEventListener' => 'applications/subscriptions/events/PhabricatorSubscriptionsUIEventListener.php',
|
||||||
'PhabricatorSymbolNameLinter' => 'infrastructure/lint/hook/PhabricatorSymbolNameLinter.php',
|
'PhabricatorSymbolNameLinter' => 'infrastructure/lint/hook/PhabricatorSymbolNameLinter.php',
|
||||||
'PhabricatorSyntaxHighlighter' => 'infrastructure/markup/PhabricatorSyntaxHighlighter.php',
|
'PhabricatorSyntaxHighlighter' => 'infrastructure/markup/PhabricatorSyntaxHighlighter.php',
|
||||||
|
@ -4897,6 +4898,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorSubscriptionsEditController' => 'PhabricatorController',
|
'PhabricatorSubscriptionsEditController' => 'PhabricatorController',
|
||||||
'PhabricatorSubscriptionsEditor' => 'PhabricatorEditor',
|
'PhabricatorSubscriptionsEditor' => 'PhabricatorEditor',
|
||||||
'PhabricatorSubscriptionsListController' => 'PhabricatorController',
|
'PhabricatorSubscriptionsListController' => 'PhabricatorController',
|
||||||
|
'PhabricatorSubscriptionsTransactionController' => 'PhabricatorController',
|
||||||
'PhabricatorSubscriptionsUIEventListener' => 'PhabricatorEventListener',
|
'PhabricatorSubscriptionsUIEventListener' => 'PhabricatorEventListener',
|
||||||
'PhabricatorSymbolNameLinter' => 'ArcanistXHPASTLintNamingHook',
|
'PhabricatorSymbolNameLinter' => 'ArcanistXHPASTLintNamingHook',
|
||||||
'PhabricatorSyntaxHighlightingConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
'PhabricatorSyntaxHighlightingConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||||
|
|
|
@ -22,6 +22,8 @@ final class PhabricatorApplicationSubscriptions extends PhabricatorApplication {
|
||||||
'(?P<action>add|delete)/'.
|
'(?P<action>add|delete)/'.
|
||||||
'(?P<phid>[^/]+)/' => 'PhabricatorSubscriptionsEditController',
|
'(?P<phid>[^/]+)/' => 'PhabricatorSubscriptionsEditController',
|
||||||
'list/(?P<phid>[^/]+)/' => 'PhabricatorSubscriptionsListController',
|
'list/(?P<phid>[^/]+)/' => 'PhabricatorSubscriptionsListController',
|
||||||
|
'transaction/(?P<type>add|rem)/(?<phid>[^/]+)/' =>
|
||||||
|
'PhabricatorSubscriptionsTransactionController',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -24,13 +24,29 @@ final class SubscriptionListStringBuilder {
|
||||||
return $this->objectPHID;
|
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() {
|
public function buildPropertyString() {
|
||||||
$phid = $this->getObjectPHID();
|
|
||||||
$handles = $this->getHandles();
|
$handles = $this->getHandles();
|
||||||
|
|
||||||
if (!$handles) {
|
if (!$handles) {
|
||||||
return phutil_tag('em', array(), pht('None'));
|
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();
|
$html = array();
|
||||||
$show_count = 3;
|
$show_count = 3;
|
||||||
|
@ -53,7 +69,7 @@ final class SubscriptionListStringBuilder {
|
||||||
$args[] = javelin_tag(
|
$args[] = javelin_tag(
|
||||||
'a',
|
'a',
|
||||||
array(
|
array(
|
||||||
'href' => '/subscriptions/list/'.$phid.'/',
|
'href' => $list_uri,
|
||||||
'sigil' => 'workflow'
|
'sigil' => 'workflow'
|
||||||
),
|
),
|
||||||
$not_shown_txt);
|
$not_shown_txt);
|
||||||
|
|
|
@ -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) {
|
public function renderPolicyName($phid) {
|
||||||
$policy = PhabricatorPolicy::newFromPolicyAndHandle(
|
$policy = PhabricatorPolicy::newFromPolicyAndHandle(
|
||||||
$phid,
|
$phid,
|
||||||
|
@ -455,21 +467,21 @@ abstract class PhabricatorApplicationTransaction
|
||||||
'%s edited subscriber(s), added %d: %s; removed %d: %s.',
|
'%s edited subscriber(s), added %d: %s; removed %d: %s.',
|
||||||
$this->renderHandleLink($author_phid),
|
$this->renderHandleLink($author_phid),
|
||||||
count($add),
|
count($add),
|
||||||
$this->renderHandleList($add),
|
$this->renderSubscriberList($add, 'add'),
|
||||||
count($rem),
|
count($rem),
|
||||||
$this->renderHandleList($rem));
|
$this->renderSubscriberList($rem, 'rem'));
|
||||||
} else if ($add) {
|
} else if ($add) {
|
||||||
return pht(
|
return pht(
|
||||||
'%s added %d subscriber(s): %s.',
|
'%s added %d subscriber(s): %s.',
|
||||||
$this->renderHandleLink($author_phid),
|
$this->renderHandleLink($author_phid),
|
||||||
count($add),
|
count($add),
|
||||||
$this->renderHandleList($add));
|
$this->renderSubscriberList($add, 'add'));
|
||||||
} else if ($rem) {
|
} else if ($rem) {
|
||||||
return pht(
|
return pht(
|
||||||
'%s removed %d subscriber(s): %s.',
|
'%s removed %d subscriber(s): %s.',
|
||||||
$this->renderHandleLink($author_phid),
|
$this->renderHandleLink($author_phid),
|
||||||
count($rem),
|
count($rem),
|
||||||
$this->renderHandleList($rem));
|
$this->renderSubscriberList($rem, 'rem'));
|
||||||
} else {
|
} else {
|
||||||
// This is used when rendering previews, before the user actually
|
// This is used when rendering previews, before the user actually
|
||||||
// selects any CCs.
|
// selects any CCs.
|
||||||
|
|
Loading…
Reference in a new issue