1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 12:00:55 +01:00

Allow project editors to remove watchers

Summary: Ref T10054. There is no technical or product reason not to support this, and it is largely analogous to removing subscribers.

Test Plan:
  - Removed watchers.
  - Removed members.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10054

Differential Revision: https://secure.phabricator.com/D15062
This commit is contained in:
epriestley 2016-01-19 17:33:11 -08:00
parent a8dd74d292
commit 01afb50406
3 changed files with 52 additions and 25 deletions

View file

@ -51,7 +51,7 @@ final class PhabricatorProjectApplication extends PhabricatorApplication {
=> 'PhabricatorProjectMembersViewController', => 'PhabricatorProjectMembersViewController',
'members/(?P<id>[1-9]\d*)/add/' 'members/(?P<id>[1-9]\d*)/add/'
=> 'PhabricatorProjectMembersAddController', => 'PhabricatorProjectMembersAddController',
'members/(?P<id>[1-9]\d*)/remove/' '(?P<type>members|watchers)/(?P<id>[1-9]\d*)/remove/'
=> 'PhabricatorProjectMembersRemoveController', => 'PhabricatorProjectMembersRemoveController',
'profile/(?P<id>[1-9]\d*)/' 'profile/(?P<id>[1-9]\d*)/'
=> 'PhabricatorProjectProfileController', => 'PhabricatorProjectProfileController',

View file

@ -6,11 +6,13 @@ final class PhabricatorProjectMembersRemoveController
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer(); $viewer = $request->getViewer();
$id = $request->getURIData('id'); $id = $request->getURIData('id');
$type = $request->getURIData('type');
$project = id(new PhabricatorProjectQuery()) $project = id(new PhabricatorProjectQuery())
->setViewer($viewer) ->setViewer($viewer)
->withIDs(array($id)) ->withIDs(array($id))
->needMembers(true) ->needMembers(true)
->needWatchers(true)
->requireCapabilities( ->requireCapabilities(
array( array(
PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_VIEW,
@ -21,27 +23,31 @@ final class PhabricatorProjectMembersRemoveController
return new Aphront404Response(); return new Aphront404Response();
} }
$member_phids = $project->getMemberPHIDs(); if ($type == 'watchers') {
$remove_phid = $request->getStr('phid'); $is_watcher = true;
$edge_type = PhabricatorObjectHasWatcherEdgeType::EDGECONST;
} else {
if (!$project->supportsEditMembers()) {
return new Aphront404Response();
}
if (!in_array($remove_phid, $member_phids)) { $is_watcher = false;
return new Aphront404Response(); $edge_type = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST;
} }
$members_uri = $this->getApplicationURI('members/'.$project->getID().'/'); $members_uri = $this->getApplicationURI('members/'.$project->getID().'/');
$remove_phid = $request->getStr('phid');
if ($request->isFormPost()) { if ($request->isFormPost()) {
$member_spec = array();
$member_spec['-'] = array($remove_phid => $remove_phid);
$type_member = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST;
$xactions = array(); $xactions = array();
$xactions[] = id(new PhabricatorProjectTransaction()) $xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_EDGE) ->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
->setMetadataValue('edge:type', $type_member) ->setMetadataValue('edge:type', $edge_type)
->setNewValue($member_spec); ->setNewValue(
array(
'-' => array($remove_phid => $remove_phid),
));
$editor = id(new PhabricatorProjectTransactionEditor($project)) $editor = id(new PhabricatorProjectTransactionEditor($project))
->setActor($viewer) ->setActor($viewer)
@ -59,18 +65,31 @@ final class PhabricatorProjectMembersRemoveController
->withPHIDs(array($remove_phid)) ->withPHIDs(array($remove_phid))
->executeOne(); ->executeOne();
$dialog = id(new AphrontDialogView()) $target_name = phutil_tag('strong', array(), $handle->getName());
->setUser($viewer) $project_name = phutil_tag('strong', array(), $project->getName());
->setTitle(pht('Really Remove Member?'))
->appendParagraph(
pht(
'Really remove %s from the project %s?',
phutil_tag('strong', array(), $handle->getName()),
phutil_tag('strong', array(), $project->getName())))
->addCancelButton($members_uri)
->addSubmitButton(pht('Remove Project Member'));
return id(new AphrontDialogResponse())->setDialog($dialog); if ($is_watcher) {
$title = pht('Remove Watcher');
$body = pht(
'Remove %s as a watcher of %s?',
$target_name,
$project_name);
$button = pht('Remove Watcher');
} else {
$title = pht('Remove Member');
$body = pht(
'Remove %s as a project member of %s?',
$target_name,
$project_name);
$button = pht('Remove Member');
}
return $this->newDialog()
->setTitle($title)
->addHiddenInput('phid', $remove_phid)
->appendParagraph($body)
->addCancelButton($members_uri)
->addSubmitButton($button);
} }
} }

View file

@ -4,7 +4,13 @@ final class PhabricatorProjectWatcherListView
extends PhabricatorProjectUserListView { extends PhabricatorProjectUserListView {
protected function canEditList() { protected function canEditList() {
return false; $viewer = $this->getUser();
$project = $this->getProject();
return PhabricatorPolicyFilter::hasCapability(
$viewer,
$project,
PhabricatorPolicyCapability::CAN_EDIT);
} }
protected function getNoDataString() { protected function getNoDataString() {
@ -12,7 +18,9 @@ final class PhabricatorProjectWatcherListView
} }
protected function getRemoveURI($phid) { protected function getRemoveURI($phid) {
return null; $project = $this->getProject();
$id = $project->getID();
return "/project/watchers/{$id}/remove/?phid={$phid}";
} }
protected function getHeaderText() { protected function getHeaderText() {