NavigationConfigForm: Implement method unshare()

refs #5600
This commit is contained in:
Johannes Meyer 2015-09-16 13:10:21 +02:00
parent cc66175e6c
commit dfc9c10589

View File

@ -231,19 +231,7 @@ class NavigationConfigForm extends ConfigForm
if ($this->hasBeenShared($name)) { if ($this->hasBeenShared($name)) {
if ((! isset($data['users']) || !$data['users']) && (! isset($data['groups']) || !$data['groups'])) { if ((! isset($data['users']) || !$data['users']) && (! isset($data['groups']) || !$data['groups'])) {
// It is shared but shouldn't anymore // It is shared but shouldn't anymore
$config->removeSection($name); $config = $this->unshare($name)->config; // unshare() calls setIniConfig()
$this->secondaryConfig = $config;
if (! $itemConfig->owner || $itemConfig->owner === $this->getUser()->getUsername()) {
$config = $this->getUserConfig();
} else {
$owner = new User($itemConfig->owner);
$config = $owner->loadNavigationConfig();
}
unset($itemConfig->owner);
unset($itemConfig->users);
unset($itemConfig->groups);
} }
} elseif ((isset($data['users']) && $data['users']) || (isset($data['groups']) && $data['groups'])) { } elseif ((isset($data['users']) && $data['users']) || (isset($data['groups']) && $data['groups'])) {
if ($this->getUser()->can('application/share/navigation')) { if ($this->getUser()->can('application/share/navigation')) {
@ -303,15 +291,37 @@ class NavigationConfigForm extends ConfigForm
* *
* @param string $name * @param string $name
* *
* @return bool * @return $this
* *
* @throws NotFoundError In case no navigation item with the given name is found * @throws NotFoundError In case no navigation item with the given name is found
*/ */
public function unshare($name) public function unshare($name)
{ {
$config = $this->getShareConfig();
if (! $config->hasSection($name)) {
throw new NotFoundError('No navigation item called "%s" found', $name); throw new NotFoundError('No navigation item called "%s" found', $name);
} }
$itemConfig = $config->getSection($name);
$config->removeSection($name);
$this->secondaryConfig = $config;
if (! $itemConfig->owner || $itemConfig->owner === $this->getUser()->getUsername()) {
$config = $this->getUserConfig();
} else {
$owner = new User($itemConfig->owner);
$config = $owner->loadNavigationConfig();
}
unset($itemConfig->owner);
unset($itemConfig->users);
unset($itemConfig->groups);
$config->setSection($name, $itemConfig);
$this->setIniConfig($config);
return $this;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */