2014-03-20 03:30:27 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorProjectMembersRemoveController
|
|
|
|
extends PhabricatorProjectController {
|
|
|
|
|
2015-08-08 19:34:55 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
$id = $request->getURIData('id');
|
2016-01-20 02:33:11 +01:00
|
|
|
$type = $request->getURIData('type');
|
2014-03-20 03:30:27 +01:00
|
|
|
|
|
|
|
$project = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer($viewer)
|
2015-08-08 19:34:55 +02:00
|
|
|
->withIDs(array($id))
|
2014-03-20 03:30:27 +01:00
|
|
|
->needMembers(true)
|
2016-01-20 02:33:11 +01:00
|
|
|
->needWatchers(true)
|
2014-03-20 03:30:27 +01:00
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
|
|
|
if (!$project) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2016-01-20 02:33:11 +01:00
|
|
|
if ($type == 'watchers') {
|
|
|
|
$is_watcher = true;
|
|
|
|
$edge_type = PhabricatorObjectHasWatcherEdgeType::EDGECONST;
|
|
|
|
} else {
|
|
|
|
if (!$project->supportsEditMembers()) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
2014-03-20 03:30:27 +01:00
|
|
|
|
2016-01-20 02:33:11 +01:00
|
|
|
$is_watcher = false;
|
|
|
|
$edge_type = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST;
|
2014-03-20 03:30:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$members_uri = $this->getApplicationURI('members/'.$project->getID().'/');
|
2016-01-20 02:33:11 +01:00
|
|
|
$remove_phid = $request->getStr('phid');
|
2014-03-20 03:30:27 +01:00
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$xactions = array();
|
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
|
2016-01-20 02:33:11 +01:00
|
|
|
->setMetadataValue('edge:type', $edge_type)
|
|
|
|
->setNewValue(
|
|
|
|
array(
|
|
|
|
'-' => array($remove_phid => $remove_phid),
|
|
|
|
));
|
2014-03-20 03:30:27 +01:00
|
|
|
|
|
|
|
$editor = id(new PhabricatorProjectTransactionEditor($project))
|
|
|
|
->setActor($viewer)
|
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContinueOnMissingFields(true)
|
|
|
|
->applyTransactions($project, $xactions);
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI($members_uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
$handle = id(new PhabricatorHandleQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs(array($remove_phid))
|
|
|
|
->executeOne();
|
|
|
|
|
2016-01-20 02:33:11 +01:00
|
|
|
$target_name = phutil_tag('strong', array(), $handle->getName());
|
|
|
|
$project_name = phutil_tag('strong', array(), $project->getName());
|
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
2014-03-20 03:30:27 +01:00
|
|
|
|
2016-01-20 02:33:11 +01:00
|
|
|
return $this->newDialog()
|
|
|
|
->setTitle($title)
|
|
|
|
->addHiddenInput('phid', $remove_phid)
|
|
|
|
->appendParagraph($body)
|
|
|
|
->addCancelButton($members_uri)
|
|
|
|
->addSubmitButton($button);
|
2014-03-20 03:30:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|