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:
epriestley
2015-06-10 15:52:18 -07:00
parent 8a10cfbc98
commit 739bdeccab
7 changed files with 116 additions and 65 deletions

View File

@@ -90,6 +90,17 @@ final class PhabricatorSpacesNamespaceQuery
return (bool)self::getAllSpaces();
}
public static function getViewerSpacesExist(PhabricatorUser $viewer) {
if (!self::getSpacesExist()) {
return false;
}
// If the viewer has access to only one space, pretend spaces simply don't
// exist.
$spaces = self::getViewerSpaces($viewer);
return (count($spaces) > 1);
}
public static function getAllSpaces() {
$cache = PhabricatorCaches::getRequestCache();
$cache_key = self::KEY_ALL;

View File

@@ -21,7 +21,20 @@ final class PHUISpacesNamespaceContextView extends AphrontView {
return null;
}
// If the viewer can't see spaces, pretend they don't exist.
$viewer = $this->getUser();
if (!PhabricatorSpacesNamespaceQuery::getViewerSpacesExist($viewer)) {
return null;
}
// If this is the default space, don't show a space label.
$default = PhabricatorSpacesNamespaceQuery::getDefaultSpace();
if ($default) {
if ($default->getPHID() == $space_phid) {
return null;
}
}
return phutil_tag(
'span',
array(

View File

@@ -1,49 +0,0 @@
<?php
final class PhabricatorSpacesControl extends AphrontFormControl {
private $object;
protected function shouldRender() {
// Render this control only if some Spaces exist.
return PhabricatorSpacesNamespaceQuery::getAllSpaces();
}
public function setObject(PhabricatorSpacesInterface $object) {
$this->object = $object;
return $this;
}
protected function getCustomControlClass() {
return '';
}
protected function getOptions() {
$viewer = $this->getUser();
$viewer_spaces = PhabricatorSpacesNamespaceQuery::getViewerSpaces($viewer);
$map = mpull($viewer_spaces, 'getNamespaceName', 'getPHID');
asort($map);
return $map;
}
protected function renderInput() {
$viewer = $this->getUser();
$this->setLabel(pht('Space'));
$value = $this->getValue();
if ($value === null) {
$value = $viewer->getDefaultSpacePHID();
}
return AphrontFormSelectControl::renderSelectTag(
$value,
$this->getOptions(),
array(
'name' => $this->getName(),
));
}
}