diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 628ae29168..903d6bad21 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -379,6 +379,7 @@ phutil_register_library_map(array( 'ConpherenceConduitAPIMethod' => 'applications/conpherence/conduit/ConpherenceConduitAPIMethod.php', 'ConpherenceConstants' => 'applications/conpherence/constants/ConpherenceConstants.php', 'ConpherenceController' => 'applications/conpherence/controller/ConpherenceController.php', + 'ConpherenceCreateRoomCapability' => 'applications/conpherence/capability/ConpherenceCreateRoomCapability.php', 'ConpherenceCreateThreadConduitAPIMethod' => 'applications/conpherence/conduit/ConpherenceCreateThreadConduitAPIMethod.php', 'ConpherenceDAO' => 'applications/conpherence/storage/ConpherenceDAO.php', 'ConpherenceDurableColumnView' => 'applications/conpherence/view/ConpherenceDurableColumnView.php', @@ -6403,6 +6404,7 @@ phutil_register_library_map(array( 'ConpherenceConduitAPIMethod' => 'ConduitAPIMethod', 'ConpherenceConstants' => 'Phobject', 'ConpherenceController' => 'PhabricatorController', + 'ConpherenceCreateRoomCapability' => 'PhabricatorPolicyCapability', 'ConpherenceCreateThreadConduitAPIMethod' => 'ConpherenceConduitAPIMethod', 'ConpherenceDAO' => 'PhabricatorLiskDAO', 'ConpherenceDurableColumnView' => 'AphrontTagView', diff --git a/src/applications/conpherence/application/PhabricatorConpherenceApplication.php b/src/applications/conpherence/application/PhabricatorConpherenceApplication.php index f3118be9bf..2c5b5c2fd4 100644 --- a/src/applications/conpherence/application/PhabricatorConpherenceApplication.php +++ b/src/applications/conpherence/application/PhabricatorConpherenceApplication.php @@ -76,6 +76,14 @@ final class PhabricatorConpherenceApplication extends PhabricatorApplication { ); } + protected function getCustomCapabilities() { + return array( + ConpherenceCreateRoomCapability::CAPABILITY => array( + 'default' => PhabricatorPolicies::POLICY_USER, + ), + ); + } + public function getMailCommandObjects() { // TODO: Conpherence threads don't currently support any commands directly, diff --git a/src/applications/conpherence/capability/ConpherenceCreateRoomCapability.php b/src/applications/conpherence/capability/ConpherenceCreateRoomCapability.php new file mode 100644 index 0000000000..7e776d96ae --- /dev/null +++ b/src/applications/conpherence/capability/ConpherenceCreateRoomCapability.php @@ -0,0 +1,16 @@ +getURIData('id'); + if (!$id) { + $this->requireApplicationCapability( + ConpherenceCreateRoomCapability::CAPABILITY); + } + return id(new ConpherenceEditEngine()) ->setController($this) ->buildResponse(); diff --git a/src/applications/conpherence/editor/ConpherenceEditEngine.php b/src/applications/conpherence/editor/ConpherenceEditEngine.php index 7b1b7d1aa4..8e8a6633da 100644 --- a/src/applications/conpherence/editor/ConpherenceEditEngine.php +++ b/src/applications/conpherence/editor/ConpherenceEditEngine.php @@ -61,6 +61,11 @@ final class ConpherenceEditEngine return $object->getURI(); } + protected function getCreateNewObjectPolicy() { + return $this->getApplication()->getPolicy( + ConpherenceCreateRoomCapability::CAPABILITY); + } + public function isEngineConfigurable() { return false; } diff --git a/src/applications/conpherence/view/ConpherenceThreadListView.php b/src/applications/conpherence/view/ConpherenceThreadListView.php index 3701acea88..f3efc96621 100644 --- a/src/applications/conpherence/view/ConpherenceThreadListView.php +++ b/src/applications/conpherence/view/ConpherenceThreadListView.php @@ -24,6 +24,13 @@ final class ConpherenceThreadListView extends AphrontView { public function render() { require_celerity_resource('conpherence-menu-css'); + $viewer = $this->getViewer(); + $can_create_room = PhabricatorPolicyFilter::hasCapability( + $viewer, + PhabricatorApplication::getByClass( + PhabricatorConpherenceApplication::class), + ConpherenceCreateRoomCapability::CAPABILITY); + $menu = id(new PHUIListView()) ->addClass('conpherence-menu') ->setID('conpherence-menu'); @@ -43,6 +50,7 @@ final class ConpherenceThreadListView extends AphrontView { ->setType(PHUIListItemView::TYPE_LINK) ->setHref('/conpherence/new/') ->setWorkflow(true) + ->setDisabled(!$can_create_room) ->setName(pht('Create a Room')); $menu->addMenuItem($create_item); } @@ -109,6 +117,13 @@ final class ConpherenceThreadListView extends AphrontView { } private function buildHeaderItemView() { + $viewer = $this->getViewer(); + $can_create_room = PhabricatorPolicyFilter::hasCapability( + $viewer, + PhabricatorApplication::getByClass( + PhabricatorConpherenceApplication::class), + ConpherenceCreateRoomCapability::CAPABILITY); + $rooms = phutil_tag( 'a', array( @@ -126,6 +141,10 @@ final class ConpherenceThreadListView extends AphrontView { 'tip' => pht('New Room'), )); + if (!$can_create_room) { + $new_icon->setColor('lightgreytext'); + } + $search_icon = id(new PHUIIconView()) ->setIcon('fa-search') ->addSigil('has-tooltip')