Improve some Spaces behaviors
Summary: Ref T8449. Try out some more subtle behaviors: - Make the "Space" control part of the policy control, so the UI shows "Visible To: [Space][Policy]". I think this helps make the role of spaces more clear. It also makes them easier to implement. - Don't show the default space in headers: instead, show nothing. - If the user has access to only one space, pretend spaces don't exist (no edit controls, no header stuff). This might be confusing, but I think most of the time it will all align fairly well with user expectation. Test Plan: - Viewed a list of pastes (saw Space with non-default space, no space with default space, no space with user in only one space). - Viewed a paste (saw Space with non-default space, saw no space with default space, saw no space with user in only one space). - Edited spaces on objects (control as privileged user, no control as locked user). - Created a new paste in a space (got space select as privileged user, no select as locked user). Reviewers: chad, btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T8449 Differential Revision: https://secure.phabricator.com/D13229
This commit is contained in:
@@ -5,6 +5,7 @@ final class AphrontFormPolicyControl extends AphrontFormControl {
|
||||
private $object;
|
||||
private $capability;
|
||||
private $policies;
|
||||
private $spacePHID;
|
||||
|
||||
public function setPolicyObject(PhabricatorPolicyInterface $object) {
|
||||
$this->object = $object;
|
||||
@@ -17,6 +18,15 @@ final class AphrontFormPolicyControl extends AphrontFormControl {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setSpacePHID($space_phid) {
|
||||
$this->spacePHID = $space_phid;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSpacePHID() {
|
||||
return $this->spacePHID;
|
||||
}
|
||||
|
||||
public function setCapability($capability) {
|
||||
$this->capability = $capability;
|
||||
|
||||
@@ -187,11 +197,14 @@ final class AphrontFormPolicyControl extends AphrontFormControl {
|
||||
$selected_icon = idx($selected, 'icon');
|
||||
$selected_name = idx($selected, 'name');
|
||||
|
||||
$spaces_control = $this->buildSpacesControl();
|
||||
|
||||
return phutil_tag(
|
||||
'div',
|
||||
array(
|
||||
),
|
||||
array(
|
||||
$spaces_control,
|
||||
javelin_tag(
|
||||
'a',
|
||||
array(
|
||||
@@ -231,4 +244,48 @@ final class AphrontFormPolicyControl extends AphrontFormControl {
|
||||
return 'custom:placeholder';
|
||||
}
|
||||
|
||||
private function buildSpacesControl() {
|
||||
if ($this->capability != PhabricatorPolicyCapability::CAN_VIEW) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!($this->object instanceof PhabricatorSpacesInterface)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$viewer = $this->getUser();
|
||||
if (!PhabricatorSpacesNamespaceQuery::getViewerSpacesExist($viewer)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$space_phid = $this->getSpacePHID();
|
||||
if ($space_phid === null) {
|
||||
$space_phid = $viewer->getDefaultSpacePHID();
|
||||
}
|
||||
|
||||
$select = AphrontFormSelectControl::renderSelectTag(
|
||||
$space_phid,
|
||||
$this->getSpaceOptions(),
|
||||
array(
|
||||
'name' => 'spacePHID',
|
||||
));
|
||||
|
||||
return $select;
|
||||
}
|
||||
|
||||
protected function getSpaceOptions() {
|
||||
$viewer = $this->getUser();
|
||||
$viewer_spaces = PhabricatorSpacesNamespaceQuery::getViewerSpaces($viewer);
|
||||
|
||||
$map = array();
|
||||
foreach ($viewer_spaces as $space) {
|
||||
$map[$space->getPHID()] = pht(
|
||||
'Space %s: %s',
|
||||
$space->getMonogram(),
|
||||
$space->getNamespaceName());
|
||||
}
|
||||
asort($map);
|
||||
|
||||
return $map;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user