Page MenuHomePhabricator

D14895.id36003.diff
No OneTemporary

D14895.id36003.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2853,6 +2853,7 @@
'PhabricatorProjectIconSet' => 'applications/project/icon/PhabricatorProjectIconSet.php',
'PhabricatorProjectInterface' => 'applications/project/interface/PhabricatorProjectInterface.php',
'PhabricatorProjectListController' => 'applications/project/controller/PhabricatorProjectListController.php',
+ 'PhabricatorProjectLockController' => 'applications/project/controller/PhabricatorProjectLockController.php',
'PhabricatorProjectLogicalAndDatasource' => 'applications/project/typeahead/PhabricatorProjectLogicalAndDatasource.php',
'PhabricatorProjectLogicalDatasource' => 'applications/project/typeahead/PhabricatorProjectLogicalDatasource.php',
'PhabricatorProjectLogicalOrNotDatasource' => 'applications/project/typeahead/PhabricatorProjectLogicalOrNotDatasource.php',
@@ -7198,6 +7199,7 @@
'PhabricatorProjectHeraldAction' => 'HeraldAction',
'PhabricatorProjectIconSet' => 'PhabricatorIconSet',
'PhabricatorProjectListController' => 'PhabricatorProjectController',
+ 'PhabricatorProjectLockController' => 'PhabricatorProjectController',
'PhabricatorProjectLogicalAndDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'PhabricatorProjectLogicalDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'PhabricatorProjectLogicalOrNotDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
diff --git a/src/applications/project/application/PhabricatorProjectApplication.php b/src/applications/project/application/PhabricatorProjectApplication.php
--- a/src/applications/project/application/PhabricatorProjectApplication.php
+++ b/src/applications/project/application/PhabricatorProjectApplication.php
@@ -47,6 +47,8 @@
=> 'PhabricatorProjectEditDetailsController',
'archive/(?P<id>[1-9]\d*)/'
=> 'PhabricatorProjectArchiveController',
+ 'lock/(?P<id>[1-9]\d*)/'
+ => 'PhabricatorProjectLockController',
'members/(?P<id>[1-9]\d*)/'
=> 'PhabricatorProjectMembersEditController',
'members/(?P<id>[1-9]\d*)/remove/'
diff --git a/src/applications/project/controller/PhabricatorProjectEditDetailsController.php b/src/applications/project/controller/PhabricatorProjectEditDetailsController.php
--- a/src/applications/project/controller/PhabricatorProjectEditDetailsController.php
+++ b/src/applications/project/controller/PhabricatorProjectEditDetailsController.php
@@ -54,7 +54,6 @@
$v_slugs = $project_slugs;
$v_color = $project->getColor();
$v_icon = $project->getIcon();
- $v_locked = $project->getIsMembershipLocked();
$validation_exception = null;
@@ -69,14 +68,12 @@
$v_join = $request->getStr('can_join');
$v_color = $request->getStr('color');
$v_icon = $request->getStr('icon');
- $v_locked = $request->getInt('is_membership_locked', 0);
$type_name = PhabricatorProjectTransaction::TYPE_NAME;
$type_slugs = PhabricatorProjectTransaction::TYPE_SLUGS;
$type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY;
$type_icon = PhabricatorProjectTransaction::TYPE_ICON;
$type_color = PhabricatorProjectTransaction::TYPE_COLOR;
- $type_locked = PhabricatorProjectTransaction::TYPE_LOCKED;
$xactions = array();
@@ -108,10 +105,6 @@
->setTransactionType($type_color)
->setNewValue($v_color);
- $xactions[] = id(new PhabricatorProjectTransaction())
- ->setTransactionType($type_locked)
- ->setNewValue($v_locked);
-
$xactions = array_merge(
$xactions,
$field_list->buildFieldTransactionsFromRequest(
@@ -190,11 +183,6 @@
$shades = PhabricatorProjectIconSet::getColorMap();
- list($can_lock, $lock_message) = $this->explainApplicationCapability(
- ProjectCanLockProjectsCapability::CAPABILITY,
- pht('You can update the Lock Project setting.'),
- pht('You can not update the Lock Project setting.'));
-
$form
->appendChild(
id(new PHUIFormIconSetControl())
@@ -249,17 +237,7 @@
pht('Users who can edit a project can always join a project.'))
->setPolicyObject($project)
->setPolicies($policies)
- ->setCapability(PhabricatorPolicyCapability::CAN_JOIN))
- ->appendChild(
- id(new AphrontFormCheckboxControl())
- ->setLabel(pht('Lock Project'))
- ->setDisabled(!$can_lock)
- ->addCheckbox(
- 'is_membership_locked',
- 1,
- pht('Prevent members from leaving this project.'),
- $v_locked)
- ->setCaption($lock_message));
+ ->setCapability(PhabricatorPolicyCapability::CAN_JOIN));
if ($request->isAjax()) {
$errors = array();
diff --git a/src/applications/project/controller/PhabricatorProjectLockController.php b/src/applications/project/controller/PhabricatorProjectLockController.php
new file mode 100644
--- /dev/null
+++ b/src/applications/project/controller/PhabricatorProjectLockController.php
@@ -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);
+ }
+
+}
diff --git a/src/applications/project/controller/PhabricatorProjectProfileController.php b/src/applications/project/controller/PhabricatorProjectProfileController.php
--- a/src/applications/project/controller/PhabricatorProjectProfileController.php
+++ b/src/applications/project/controller/PhabricatorProjectProfileController.php
@@ -106,6 +106,25 @@
->setWorkflow(true));
}
+ $can_lock = $can_edit && $this->hasApplicationCapability(
+ ProjectCanLockProjectsCapability::CAPABILITY);
+
+ if ($project->getIsMembershipLocked()) {
+ $lock_name = pht('Unlock Project');
+ $lock_icon = 'fa-unlock';
+ } else {
+ $lock_name = pht('Lock Project');
+ $lock_icon = 'fa-lock';
+ }
+
+ $view->addAction(
+ id(new PhabricatorActionView())
+ ->setName($lock_name)
+ ->setIcon($lock_icon)
+ ->setHref($this->getApplicationURI("lock/{$id}/"))
+ ->setDisabled(!$can_lock)
+ ->setWorkflow(true));
+
$action = null;
if (!$project->isUserMember($viewer->getPHID())) {
$can_join = PhabricatorPolicyFilter::hasCapability(

File Metadata

Mime Type
text/plain
Expires
Fri, Jan 24, 10:30 PM (19 h, 37 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7042972
Default Alt Text
D14895.id36003.diff (8 KB)

Event Timeline