Move "Lock Project" to a separate action

Summary:
Ref T10010. Three motivations:

  - Primarily: this makes conversion to EditEngine easier since I don't have to convert this weird control.
  - This probably needs to have "Lock", "Unlock" and "Use Parent Project Setting" values after subprojects? But maybe just locking any parent locks all the children? Anyway, doesn't make sense to put it on the main edit form if it's weird like this, I think, since we'll want some kind of explanatory text.
  - I probably want to move this to the "Members" tab anyway, and this won't be available on milestone projects at all.

Test Plan: Locked, unlocked, edited projects.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10010

Differential Revision: https://secure.phabricator.com/D14895
This commit is contained in:
epriestley
2015-12-27 06:56:15 -08:00
parent 11e53f2948
commit e8ddfad6db
5 changed files with 100 additions and 23 deletions

View File

@@ -0,0 +1,76 @@
<?php
final class PhabricatorProjectLockController
extends PhabricatorProjectController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$this->requireApplicationCapability(
ProjectCanLockProjectsCapability::CAPABILITY);
$id = $request->getURIData('id');
$project = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->withIDs(array($id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$project) {
return new Aphront404Response();
}
$done_uri = $project->getURI();
$is_locked = $project->getIsMembershipLocked();
if ($request->isFormPost()) {
$xactions = array();
if ($is_locked) {
$new_value = 0;
} else {
$new_value = 1;
}
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType(PhabricatorProjectTransaction::TYPE_LOCKED)
->setNewValue($new_value);
$editor = id(new PhabricatorProjectTransactionEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true)
->applyTransactions($project, $xactions);
return id(new AphrontRedirectResponse())->setURI($done_uri);
}
if ($project->getIsMembershipLocked()) {
$title = pht('Unlock Project');
$body = pht(
'If you unlock this project, members will be free to leave.');
$button = pht('Unlock Project');
} else {
$title = pht('Lock Project');
$body = pht(
'If you lock this project, members will be prevented from '.
'leaving it.');
$button = pht('Lock Project');
}
return $this->newDialog()
->setTitle($title)
->appendParagraph($body)
->addSubmitbutton($button)
->addCancelButton($done_uri);
}
}