summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/private/NavigationManager.php190
-rw-r--r--lib/private/Server.php8
-rw-r--r--lib/private/TemplateLayout.php6
-rw-r--r--lib/private/legacy/app.php110
4 files changed, 174 insertions, 140 deletions
diff --git a/lib/private/NavigationManager.php b/lib/private/NavigationManager.php
index f7bc02943a3..300c24ff940 100644
--- a/lib/private/NavigationManager.php
+++ b/lib/private/NavigationManager.php
@@ -27,7 +27,9 @@
namespace OC;
use OC\App\AppManager;
+use OC\Group\Manager;
use OCP\App\IAppManager;
+use OCP\IConfig;
use OCP\IGroupManager;
use OCP\INavigationManager;
use OCP\IURLGenerator;
@@ -52,19 +54,23 @@ class NavigationManager implements INavigationManager {
private $l10nFac;
/** @var IUserSession */
private $userSession;
- /** @var IGroupManager */
+ /** @var IGroupManager|Manager */
private $groupManager;
+ /** @var IConfig */
+ private $config;
- public function __construct(IAppManager $appManager = null,
- IURLGenerator $urlGenerator = null,
- IFactory $l10nFac = null,
- IUserSession $userSession = null,
- IGroupManager$groupManager = null) {
+ public function __construct(IAppManager $appManager,
+ IURLGenerator $urlGenerator,
+ IFactory $l10nFac,
+ IUserSession $userSession,
+ IGroupManager $groupManager,
+ IConfig $config) {
$this->appManager = $appManager;
$this->urlGenerator = $urlGenerator;
$this->l10nFac = $l10nFac;
$this->userSession = $userSession;
$this->groupManager = $groupManager;
+ $this->config = $config;
}
/**
@@ -85,29 +91,40 @@ class NavigationManager implements INavigationManager {
if(!isset($entry['icon'])) {
$entry['icon'] = '';
}
+ if(!isset($entry['type'])) {
+ $entry['type'] = 'link';
+ }
$this->entries[] = $entry;
}
/**
* returns all the added Menu entries
+ * @param string $type
* @return array an array of the added entries
*/
- public function getAll() {
+ public function getAll($type = 'link') {
$this->init();
foreach ($this->closureEntries as $c) {
$this->add($c());
}
$this->closureEntries = array();
- return $this->entries;
+
+ if ($type === 'all') {
+ return $this->entries;
+ }
+
+ return array_filter($this->entries, function($entry) use ($type) {
+ return $entry['type'] === $type;
+ });
}
/**
* removes all the entries
*/
- public function clear() {
+ public function clear($loadDefaultLinks = true) {
$this->entries = [];
$this->closureEntries = [];
- $this->init = false;
+ $this->init = !$loadDefaultLinks;
}
/**
@@ -134,49 +151,127 @@ class NavigationManager implements INavigationManager {
return;
}
$this->init = true;
- if (is_null($this->appManager)) {
+
+ $l = $this->l10nFac->get('lib');
+ if ($this->config->getSystemValue('knowledgebaseenabled', true)) {
+ $this->add([
+ 'type' => 'settings',
+ 'id' => 'help',
+ 'order' => 5,
+ 'href' => $this->urlGenerator->linkToRoute('settings_help'),
+ 'name' => $l->t('Help'),
+ 'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'),
+ ]);
+ }
+
+ if ($this->userSession->isLoggedIn()) {
+ if ($this->isAdmin()) {
+ // App management
+ $this->add([
+ 'type' => 'settings',
+ 'id' => 'core_apps',
+ 'order' => 3,
+ 'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'),
+ 'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'),
+ 'name' => $l->t('Apps'),
+ ]);
+ }
+
+ // Personal settings
+ $this->add([
+ 'type' => 'settings',
+ 'id' => 'personal',
+ 'order' => 1,
+ 'href' => $this->urlGenerator->linkToRoute('settings_personal'),
+ 'name' => $l->t('Personal'),
+ 'icon' => $this->urlGenerator->imagePath('settings', 'personal.svg'),
+ ]);
+
+ // Logout
+ $this->add([
+ 'type' => 'settings',
+ 'id' => 'logout',
+ 'order' => 99999,
+ 'href' => $this->urlGenerator->linkToRouteAbsolute(
+ 'core.login.logout',
+ ['requesttoken' => \OCP\Util::callRegister()]
+ ),
+ 'name' => $l->t('Log out'),
+ 'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'),
+ ]);
+
+ if ($this->isSubadmin()) {
+ // User management
+ $this->add([
+ 'type' => 'settings',
+ 'id' => 'core_users',
+ 'order' => 4,
+ 'href' => $this->urlGenerator->linkToRoute('settings_users'),
+ 'name' => $l->t('Users'),
+ 'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'),
+ ]);
+ }
+
+ if ($this->isAdmin()) {
+ // Admin settings
+ $this->add([
+ 'type' => 'settings',
+ 'id' => 'admin',
+ 'order' => 2,
+ 'href' => $this->urlGenerator->linkToRoute('settings.AdminSettings.index'),
+ 'name' => $l->t('Admin'),
+ 'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'),
+ ]);
+ }
+ }
+
+ if ($this->appManager === 'null') {
return;
}
foreach ($this->appManager->getInstalledApps() as $app) {
// load plugins and collections from info.xml
$info = $this->appManager->getAppInfo($app);
- if (!isset($info['navigation'])) {
- continue;
- }
- $nav = $info['navigation'];
- if (!isset($nav['name'])) {
+ if (empty($info['navigations'])) {
continue;
}
- if (!isset($nav['route'])) {
- continue;
- }
- $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all';
- if ($role === 'admin' && !$this->isAdmin()) {
- continue;
- }
- $l = $this->l10nFac->get($app);
- $order = isset($nav['order']) ? $nav['order'] : 100;
- $route = $this->urlGenerator->linkToRoute($nav['route']);
- $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg';
- foreach ([$icon, "$app.svg"] as $i) {
- try {
- $icon = $this->urlGenerator->imagePath($app, $i);
- break;
- } catch (\RuntimeException $ex) {
- // no icon? - ignore it then
+ foreach ($info['navigations'] as $nav) {
+ if (!isset($nav['name'])) {
+ continue;
+ }
+ if (!isset($nav['route'])) {
+ continue;
+ }
+ $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all';
+ if ($role === 'admin' && !$this->isAdmin()) {
+ continue;
+ }
+ $l = $this->l10nFac->get($app);
+ $id = isset($nav['id']) ? $nav['id'] : $app;
+ $order = isset($nav['order']) ? $nav['order'] : 100;
+ $type = isset($nav['type']) ? $nav['type'] : 'link';
+ $route = $this->urlGenerator->linkToRoute($nav['route']);
+ $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg';
+ foreach ([$icon, "$app.svg"] as $i) {
+ try {
+ $icon = $this->urlGenerator->imagePath($app, $i);
+ break;
+ } catch (\RuntimeException $ex) {
+ // no icon? - ignore it then
+ }
+ }
+ if ($icon === null) {
+ $icon = $this->urlGenerator->imagePath('core', 'default-app-icon');
}
- }
- if (is_null($icon)) {
- $icon = $this->urlGenerator->imagePath('core', 'default-app-icon');
- }
- $this->add([
- 'id' => $app,
- 'order' => $order,
- 'href' => $route,
- 'icon' => $icon,
- 'name' => $l->t($nav['name']),
- ]);
+ $this->add([
+ 'id' => $id,
+ 'order' => $order,
+ 'href' => $route,
+ 'icon' => $icon,
+ 'type' => $type,
+ 'name' => $l->t($nav['name']),
+ ]);
+ }
}
}
@@ -188,4 +283,11 @@ class NavigationManager implements INavigationManager {
return false;
}
+ private function isSubadmin() {
+ $user = $this->userSession->getUser();
+ if ($user !== null) {
+ return $this->groupManager->getSubAdmin()->isSubAdmin($user);
+ }
+ return false;
+ }
}
diff --git a/lib/private/Server.php b/lib/private/Server.php
index c21ff650b24..10f9a810de9 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -353,13 +353,7 @@ class Server extends ServerContainer implements IServerContainer {
return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
});
- $this->registerService(\OCP\INavigationManager::class, function (Server $c) {
- return new \OC\NavigationManager($c->getAppManager(),
- $c->getURLGenerator(),
- $c->getL10NFactory(),
- $c->getUserSession(),
- $c->getGroupManager());
- });
+ $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
$this->registerService(\OC\AllConfig::class, function (Server $c) {
diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php
index 956cba40086..6dc925f8f8c 100644
--- a/lib/private/TemplateLayout.php
+++ b/lib/private/TemplateLayout.php
@@ -95,14 +95,8 @@ class TemplateLayout extends \OC_Template {
}
}
$userDisplayName = \OC_User::getDisplayName();
- $appsMgmtActive = strpos(\OC::$server->getRequest()->getRequestUri(), \OC::$server->getURLGenerator()->linkToRoute('settings.AppSettings.viewApps')) === 0;
- if ($appsMgmtActive) {
- $l = \OC::$server->getL10N('lib');
- $this->assign('application', $l->t('Apps'));
- }
$this->assign('user_displayname', $userDisplayName);
$this->assign('user_uid', \OC_User::getUser());
- $this->assign('appsmanagement_active', $appsMgmtActive);
if (\OC_User::getUser() === false) {
$this->assign('userAvatarSet', false);
diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php
index 5343e7ad172..68a8383afbf 100644
--- a/lib/private/legacy/app.php
+++ b/lib/private/legacy/app.php
@@ -457,83 +457,8 @@ class OC_App {
$appManager->disableApp($app);
}
- /**
- * Returns the Settings Navigation
- *
- * @return string[]
- *
- * This function returns an array containing all settings pages added. The
- * entries are sorted by the key 'order' ascending.
- */
- public static function getSettingsNavigation() {
- $l = \OC::$server->getL10N('lib');
- $urlGenerator = \OC::$server->getURLGenerator();
-
- $settings = array();
- // by default, settings only contain the help menu
- if (\OC::$server->getSystemConfig()->getValue('knowledgebaseenabled', true)) {
- $settings = array(
- array(
- "id" => "help",
- "order" => 4,
- "href" => $urlGenerator->linkToRoute('settings_help'),
- "name" => $l->t("Help"),
- "icon" => $urlGenerator->imagePath("settings", "help.svg")
- )
- );
- }
-
- // if the user is logged-in
- if (\OC::$server->getUserSession()->isLoggedIn()) {
- // personal menu
- $settings[] = array(
- "id" => "personal",
- "order" => 1,
- "href" => $urlGenerator->linkToRoute('settings_personal'),
- "name" => $l->t("Personal"),
- "icon" => $urlGenerator->imagePath("settings", "personal.svg")
- );
-
- //SubAdmins are also allowed to access user management
- $userObject = \OC::$server->getUserSession()->getUser();
- $isSubAdmin = false;
- if($userObject !== null) {
- $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
- }
- if ($isSubAdmin) {
- // admin users menu
- $settings[] = array(
- "id" => "core_users",
- "order" => 3,
- "href" => $urlGenerator->linkToRoute('settings_users'),
- "name" => $l->t("Users"),
- "icon" => $urlGenerator->imagePath("settings", "users.svg")
- );
- }
-
- // if the user is an admin
- if (OC_User::isAdminUser(OC_User::getUser())) {
- // admin settings
- $settings[] = array(
- "id" => "admin",
- "order" => 2,
- "href" => $urlGenerator->linkToRoute('settings.AdminSettings.index'),
- "name" => $l->t("Admin"),
- "icon" => $urlGenerator->imagePath("settings", "admin.svg")
- );
- }
- }
-
- $navigation = self::proceedNavigation($settings);
- return $navigation;
- }
-
// This is private as well. It simply works, so don't ask for more details
private static function proceedNavigation($list) {
- $headerIconCount = 8;
- if(OC_User::isAdminUser(OC_User::getUser())) {
- $headerIconCount--;
- }
usort($list, function($a, $b) {
if (isset($a['order']) && isset($b['order'])) {
return ($a['order'] < $b['order']) ? -1 : 1;
@@ -556,6 +481,11 @@ class OC_App {
}
unset($navEntry);
+ if (count($list) <= 8) {
+ return $list;
+ }
+
+ $headerIconCount = 7;
if($activeAppIndex > ($headerIconCount-1)) {
$active = $list[$activeAppIndex];
$lastInHeader = $list[$headerIconCount-1];
@@ -576,10 +506,6 @@ class OC_App {
}
public static function proceedAppNavigation($entries) {
- $headerIconCount = 8;
- if(OC_User::isAdminUser(OC_User::getUser())) {
- $headerIconCount--;
- }
$activeAppIndex = -1;
$list = self::proceedNavigation($entries);
@@ -592,6 +518,13 @@ class OC_App {
$navEntry['active'] = false;
}
}
+
+
+ if (count($list) <= 8) {
+ return $list;
+ }
+
+ $headerIconCount = 7;
// move active item to last position
if($activeAppIndex > ($headerIconCount-1)) {
$active = $list[$activeAppIndex];
@@ -789,8 +722,7 @@ class OC_App {
*/
public static function getNavigation() {
$entries = OC::$server->getNavigationManager()->getAll();
- $navigation = self::proceedNavigation($entries);
- return $navigation;
+ return self::proceedNavigation($entries);
}
/**
@@ -805,8 +737,20 @@ class OC_App {
*/
public static function getHeaderNavigation() {
$entries = OC::$server->getNavigationManager()->getAll();
- $navigation = self::proceedAppNavigation($entries);
- return $navigation;
+ return self::proceedAppNavigation($entries);
+ }
+
+ /**
+ * Returns the Settings Navigation
+ *
+ * @return string[]
+ *
+ * This function returns an array containing all settings pages added. The
+ * entries are sorted by the key 'order' ascending.
+ */
+ public static function getSettingsNavigation() {
+ $entries = OC::$server->getNavigationManager()->getAll('settings');
+ return self::proceedNavigation($entries);
}
/**