diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 25 | ||||
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 3 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 3 | ||||
-rw-r--r-- | lib/private/App/AppManager.php | 75 | ||||
-rw-r--r-- | lib/private/Files/Node/Folder.php | 7 | ||||
-rw-r--r-- | lib/private/Log/File.php | 61 | ||||
-rw-r--r-- | lib/private/Log/LogDetails.php | 101 | ||||
-rw-r--r-- | lib/private/Log/Syslog.php | 9 | ||||
-rw-r--r-- | lib/private/Log/Systemdlog.php | 10 | ||||
-rw-r--r-- | lib/private/Repair.php | 2 | ||||
-rw-r--r-- | lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php | 4 | ||||
-rw-r--r-- | lib/private/Repair/NC17/SetEnterpriseLogo.php | 117 | ||||
-rw-r--r-- | lib/private/Server.php | 3 | ||||
-rw-r--r-- | lib/private/Setup/MySQL.php | 2 | ||||
-rw-r--r-- | lib/public/App/IAppManager.php | 15 | ||||
-rw-r--r-- | lib/public/FullTextSearch/Model/ISearchRequest.php | 22 |
16 files changed, 387 insertions, 72 deletions
diff --git a/lib/base.php b/lib/base.php index 30d57153de9..7812922c168 100644 --- a/lib/base.php +++ b/lib/base.php @@ -717,6 +717,7 @@ class OC { self::registerEncryptionHooks(); self::registerAccountHooks(); self::registerResourceCollectionHooks(); + self::registerAppRestrictionsHooks(); // Make sure that the application class is not loaded before the database is setup if ($systemConfig->getValue("installed", false)) { @@ -848,6 +849,30 @@ class OC { \OCP\Util::connectHook('OC_User', 'changeUser', $hookHandler, 'changeUserHook'); } + private static function registerAppRestrictionsHooks() { + $groupManager = self::$server->query(\OCP\IGroupManager::class); + $groupManager->listen ('\OC\Group', 'postDelete', function (\OCP\IGroup $group) { + $appManager = self::$server->getAppManager(); + $apps = $appManager->getEnabledAppsForGroup($group); + foreach ($apps as $appId) { + $restrictions = $appManager->getAppRestriction($appId); + if (empty($restrictions)) { + continue; + } + $key = array_search($group->getGID(), $restrictions); + unset($restrictions[$key]); + $restrictions = array_values($restrictions); + if (empty($restrictions)) { + $appManager->disableApp($appId); + } + else{ + $appManager->enableAppForGroups($appId, $restrictions); + } + + } + }); + } + private static function registerResourceCollectionHooks() { \OC\Collaboration\Resources\Listener::register(\OC::$server->getEventDispatcher()); } diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index fa38232afc2..d8d9227cb07 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -758,6 +758,7 @@ return array( 'OC\\Core\\Migrations\\Version16000Date20190212081545' => $baseDir . '/core/Migrations/Version16000Date20190212081545.php', 'OC\\Core\\Migrations\\Version16000Date20190427105638' => $baseDir . '/core/Migrations/Version16000Date20190427105638.php', 'OC\\Core\\Migrations\\Version16000Date20190428150708' => $baseDir . '/core/Migrations/Version16000Date20190428150708.php', + 'OC\\Core\\Migrations\\Version17000Date20190514105811' => $baseDir . '/core/Migrations/Version17000Date20190514105811.php', 'OC\\Core\\Notification\\RemoveLinkSharesNotifier' => $baseDir . '/core/Notification/RemoveLinkSharesNotifier.php', 'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php', 'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php', @@ -975,6 +976,7 @@ return array( 'OC\\Log\\Errorlog' => $baseDir . '/lib/private/Log/Errorlog.php', 'OC\\Log\\ExceptionSerializer' => $baseDir . '/lib/private/Log/ExceptionSerializer.php', 'OC\\Log\\File' => $baseDir . '/lib/private/Log/File.php', + 'OC\\Log\\LogDetails' => $baseDir . '/lib/private/Log/LogDetails.php', 'OC\\Log\\LogFactory' => $baseDir . '/lib/private/Log/LogFactory.php', 'OC\\Log\\Rotate' => $baseDir . '/lib/private/Log/Rotate.php', 'OC\\Log\\Syslog' => $baseDir . '/lib/private/Log/Syslog.php', @@ -1068,6 +1070,7 @@ return array( 'OC\\Repair\\NC16\\AddClenupLoginFlowV2BackgroundJob' => $baseDir . '/lib/private/Repair/NC16/AddClenupLoginFlowV2BackgroundJob.php', 'OC\\Repair\\NC16\\CleanupCardDAVPhotoCache' => $baseDir . '/lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php', 'OC\\Repair\\NC16\\RemoveCypressFiles' => $baseDir . '/lib/private/Repair/NC16/RemoveCypressFiles.php', + 'OC\\Repair\\NC17\\SetEnterpriseLogo' => $baseDir . '/lib/private/Repair/NC17/SetEnterpriseLogo.php', 'OC\\Repair\\NC17\\SwitchUpdateChannel' => $baseDir . '/lib/private/Repair/NC17/SwitchUpdateChannel.php', 'OC\\Repair\\OldGroupMembershipShares' => $baseDir . '/lib/private/Repair/OldGroupMembershipShares.php', 'OC\\Repair\\Owncloud\\DropAccountTermsTable' => $baseDir . '/lib/private/Repair/Owncloud/DropAccountTermsTable.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 4cea0319a0e..043846e04df 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -792,6 +792,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Core\\Migrations\\Version16000Date20190212081545' => __DIR__ . '/../../..' . '/core/Migrations/Version16000Date20190212081545.php', 'OC\\Core\\Migrations\\Version16000Date20190427105638' => __DIR__ . '/../../..' . '/core/Migrations/Version16000Date20190427105638.php', 'OC\\Core\\Migrations\\Version16000Date20190428150708' => __DIR__ . '/../../..' . '/core/Migrations/Version16000Date20190428150708.php', + 'OC\\Core\\Migrations\\Version17000Date20190514105811' => __DIR__ . '/../../..' . '/core/Migrations/Version17000Date20190514105811.php', 'OC\\Core\\Notification\\RemoveLinkSharesNotifier' => __DIR__ . '/../../..' . '/core/Notification/RemoveLinkSharesNotifier.php', 'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php', 'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php', @@ -1009,6 +1010,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Log\\Errorlog' => __DIR__ . '/../../..' . '/lib/private/Log/Errorlog.php', 'OC\\Log\\ExceptionSerializer' => __DIR__ . '/../../..' . '/lib/private/Log/ExceptionSerializer.php', 'OC\\Log\\File' => __DIR__ . '/../../..' . '/lib/private/Log/File.php', + 'OC\\Log\\LogDetails' => __DIR__ . '/../../..' . '/lib/private/Log/LogDetails.php', 'OC\\Log\\LogFactory' => __DIR__ . '/../../..' . '/lib/private/Log/LogFactory.php', 'OC\\Log\\Rotate' => __DIR__ . '/../../..' . '/lib/private/Log/Rotate.php', 'OC\\Log\\Syslog' => __DIR__ . '/../../..' . '/lib/private/Log/Syslog.php', @@ -1102,6 +1104,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Repair\\NC16\\AddClenupLoginFlowV2BackgroundJob' => __DIR__ . '/../../..' . '/lib/private/Repair/NC16/AddClenupLoginFlowV2BackgroundJob.php', 'OC\\Repair\\NC16\\CleanupCardDAVPhotoCache' => __DIR__ . '/../../..' . '/lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php', 'OC\\Repair\\NC16\\RemoveCypressFiles' => __DIR__ . '/../../..' . '/lib/private/Repair/NC16/RemoveCypressFiles.php', + 'OC\\Repair\\NC17\\SetEnterpriseLogo' => __DIR__ . '/../../..' . '/lib/private/Repair/NC17/SetEnterpriseLogo.php', 'OC\\Repair\\NC17\\SwitchUpdateChannel' => __DIR__ . '/../../..' . '/lib/private/Repair/NC17/SwitchUpdateChannel.php', 'OC\\Repair\\OldGroupMembershipShares' => __DIR__ . '/../../..' . '/lib/private/Repair/OldGroupMembershipShares.php', 'OC\\Repair\\Owncloud\\DropAccountTermsTable' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/DropAccountTermsTable.php', diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index 7d4dbbbd34e..17addc86c9d 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -37,7 +37,9 @@ use OCP\App\AppPathNotFoundException; use OCP\App\IAppManager; use OCP\App\ManagerEvent; use OCP\ICacheFactory; +use OCP\IGroup; use OCP\IGroupManager; +use OCP\ILogger; use OCP\IUser; use OCP\IUserSession; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -71,6 +73,9 @@ class AppManager implements IAppManager { /** @var EventDispatcherInterface */ private $dispatcher; + /** @var ILogger */ + private $logger; + /** @var string[] $appId => $enabled */ private $installedAppsCache; @@ -97,12 +102,14 @@ class AppManager implements IAppManager { AppConfig $appConfig, IGroupManager $groupManager, ICacheFactory $memCacheFactory, - EventDispatcherInterface $dispatcher) { + EventDispatcherInterface $dispatcher, + ILogger $logger) { $this->userSession = $userSession; $this->appConfig = $appConfig; $this->groupManager = $groupManager; $this->memCacheFactory = $memCacheFactory; $this->dispatcher = $dispatcher; + $this->logger = $logger; } /** @@ -149,6 +156,36 @@ class AppManager implements IAppManager { } /** + * @param \OCP\IGroup $group + * @return array + */ + public function getEnabledAppsForGroup(IGroup $group): array { + $apps = $this->getInstalledAppsValues(); + $appsForGroups = array_filter($apps, function ($enabled) use ($group) { + return $this->checkAppForGroups($enabled, $group); + }); + return array_keys($appsForGroups); + } + + /** + * @param string $appId + * @return array + */ + public function getAppRestriction(string $appId): array { + $values = $this->getInstalledAppsValues(); + + if (!isset($values[$appId])) { + return []; + } + + if ($values[$appId] === 'yes' || $values[$appId] === 'no') { + return []; + } + return json_decode($values[$appId]); + } + + + /** * Check if an app is enabled for user * * @param string $appId @@ -189,7 +226,7 @@ class AppManager implements IAppManager { if (!is_array($groupIds)) { $jsonError = json_last_error(); - \OC::$server->getLogger()->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); + $this->logger->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); return false; } @@ -204,11 +241,39 @@ class AppManager implements IAppManager { } /** + * @param string $enabled + * @param IGroup $group + * @return bool + */ + private function checkAppForGroups(string $enabled, IGroup $group): bool { + if ($enabled === 'yes') { + return true; + } elseif ($group === null) { + return false; + } else { + if (empty($enabled)) { + return false; + } + + $groupIds = json_decode($enabled); + + if (!is_array($groupIds)) { + $jsonError = json_last_error(); + $this->logger->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); + return false; + } + + return in_array($group->getGID(), $groupIds); + } + } + + /** * Check if an app is enabled in the instance * * Notice: This actually checks if the app is enabled and not only if it is installed. * * @param string $appId + * @param \OCP\IGroup[]|String[] $groups * @return bool */ public function isInstalled($appId) { @@ -268,14 +333,18 @@ class AppManager implements IAppManager { $groupIds = array_map(function ($group) { /** @var \OCP\IGroup $group */ - return $group->getGID(); + return ($group instanceof IGroup) + ? $group->getGID() + : $group; }, $groups); + $this->installedAppsCache[$appId] = json_encode($groupIds); $this->appConfig->setValue($appId, 'enabled', json_encode($groupIds)); $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent( ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups )); $this->clearAppsCache(); + } /** diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index 1e9088a7c19..b0569a24aa1 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -383,6 +383,8 @@ class Folder extends Node implements \OCP\Files\Folder { // Search in batches of 500 entries $searchLimit = 500; $results = []; + $searchResultCount = 0; + $count = 0; do { $searchResult = $this->recentSearch($searchLimit, $offset, $storageIds, $folderMimetype); @@ -391,6 +393,8 @@ class Folder extends Node implements \OCP\Files\Folder { break; } + $searchResultCount += count($searchResult); + $parseResult = $this->recentParse($searchResult, $mountMap, $mimetypeLoader); foreach ($parseResult as $result) { @@ -398,7 +402,8 @@ class Folder extends Node implements \OCP\Files\Folder { } $offset += $searchLimit; - } while (count($results) < $limit); + $count++; + } while (count($results) < $limit && ($searchResultCount < (3 * $limit) || $count < 5)); return array_slice($results, 0, $limit); } diff --git a/lib/private/Log/File.php b/lib/private/Log/File.php index 6810e2598cf..fe2bbf30a26 100644 --- a/lib/private/Log/File.php +++ b/lib/private/Log/File.php @@ -47,7 +47,7 @@ use OCP\ILogger; * Log is saved at data/nextcloud.log (on default) */ -class File implements IWriter, IFileBased { +class File extends LogDetails implements IWriter, IFileBased { /** @var string */ protected $logFile; /** @var int */ @@ -56,6 +56,7 @@ class File implements IWriter, IFileBased { private $config; public function __construct(string $path, string $fallbackPath = '', SystemConfig $config) { + parent::__construct($config); $this->logFile = $path; if (!file_exists($this->logFile)) { if( @@ -79,63 +80,7 @@ class File implements IWriter, IFileBased { * @param int $level */ public function write(string $app, $message, int $level) { - // default to ISO8601 - $format = $this->config->getValue('logdateformat', \DateTime::ATOM); - $logTimeZone = $this->config->getValue('logtimezone', 'UTC'); - try { - $timezone = new \DateTimeZone($logTimeZone); - } catch (\Exception $e) { - $timezone = new \DateTimeZone('UTC'); - } - $time = \DateTime::createFromFormat("U.u", number_format(microtime(true), 4, ".", "")); - if ($time === false) { - $time = new \DateTime(null, $timezone); - } else { - // apply timezone if $time is created from UNIX timestamp - $time->setTimezone($timezone); - } - $request = \OC::$server->getRequest(); - $reqId = $request->getId(); - $remoteAddr = $request->getRemoteAddress(); - // remove username/passwords from URLs before writing the to the log file - $time = $time->format($format); - $url = ($request->getRequestUri() !== '') ? $request->getRequestUri() : '--'; - $method = is_string($request->getMethod()) ? $request->getMethod() : '--'; - if($this->config->getValue('installed', false)) { - $user = \OC_User::getUser() ? \OC_User::getUser() : '--'; - } else { - $user = '--'; - } - $userAgent = $request->getHeader('User-Agent'); - if ($userAgent === '') { - $userAgent = '--'; - } - $version = $this->config->getValue('version', ''); - $entry = compact( - 'reqId', - 'level', - 'time', - 'remoteAddr', - 'user', - 'app', - 'method', - 'url', - 'message', - 'userAgent', - 'version' - ); - // PHP's json_encode only accept proper UTF-8 strings, loop over all - // elements to ensure that they are properly UTF-8 compliant or convert - // them manually. - foreach($entry as $key => $value) { - if(is_string($value)) { - $testEncode = json_encode($value); - if($testEncode === false) { - $entry[$key] = utf8_encode($value); - } - } - } - $entry = json_encode($entry, JSON_PARTIAL_OUTPUT_ON_ERROR); + $entry = $this->logDetailsAsJSON($app, $message, $level); $handle = @fopen($this->logFile, 'a'); if ($this->logFileMode > 0 && (fileperms($this->logFile) & 0777) != $this->logFileMode) { @chmod($this->logFile, $this->logFileMode); diff --git a/lib/private/Log/LogDetails.php b/lib/private/Log/LogDetails.php new file mode 100644 index 00000000000..712b5403ca0 --- /dev/null +++ b/lib/private/Log/LogDetails.php @@ -0,0 +1,101 @@ +<?php +/** + * @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OC\Log; + +use OC\SystemConfig; + +abstract class LogDetails { + + /** @var SystemConfig */ + private $config; + + public function __construct(SystemConfig $config) { + $this->config = $config; + } + + public function logDetails(string $app, $message, int $level): array { + // default to ISO8601 + $format = $this->config->getValue('logdateformat', \DateTime::ATOM); + $logTimeZone = $this->config->getValue('logtimezone', 'UTC'); + try { + $timezone = new \DateTimeZone($logTimeZone); + } catch (\Exception $e) { + $timezone = new \DateTimeZone('UTC'); + } + $time = \DateTime::createFromFormat("U.u", number_format(microtime(true), 4, ".", "")); + if ($time === false) { + $time = new \DateTime(null, $timezone); + } else { + // apply timezone if $time is created from UNIX timestamp + $time->setTimezone($timezone); + } + $request = \OC::$server->getRequest(); + $reqId = $request->getId(); + $remoteAddr = $request->getRemoteAddress(); + // remove username/passwords from URLs before writing the to the log file + $time = $time->format($format); + $url = ($request->getRequestUri() !== '') ? $request->getRequestUri() : '--'; + $method = is_string($request->getMethod()) ? $request->getMethod() : '--'; + if($this->config->getValue('installed', false)) { + $user = \OC_User::getUser() ? \OC_User::getUser() : '--'; + } else { + $user = '--'; + } + $userAgent = $request->getHeader('User-Agent'); + if ($userAgent === '') { + $userAgent = '--'; + } + $version = $this->config->getValue('version', ''); + $entry = compact( + 'reqId', + 'level', + 'time', + 'remoteAddr', + 'user', + 'app', + 'method', + 'url', + 'message', + 'userAgent', + 'version' + ); + return $entry; + } + + public function logDetailsAsJSON(string $app, $message, int $level): string { + $entry = $this->logDetails($app, $message, $level); + // PHP's json_encode only accept proper UTF-8 strings, loop over all + // elements to ensure that they are properly UTF-8 compliant or convert + // them manually. + foreach($entry as $key => $value) { + if(is_string($value)) { + $testEncode = json_encode($value); + if($testEncode === false) { + $entry[$key] = utf8_encode($value); + } + } + } + return json_encode($entry, JSON_PARTIAL_OUTPUT_ON_ERROR); + } +} diff --git a/lib/private/Log/Syslog.php b/lib/private/Log/Syslog.php index b652eb4343d..b8fba34d62b 100644 --- a/lib/private/Log/Syslog.php +++ b/lib/private/Log/Syslog.php @@ -25,11 +25,11 @@ namespace OC\Log; +use OC\SystemConfig; use OCP\ILogger; -use OCP\IConfig; use OCP\Log\IWriter; -class Syslog implements IWriter { +class Syslog extends LogDetails implements IWriter { protected $levels = [ ILogger::DEBUG => LOG_DEBUG, ILogger::INFO => LOG_INFO, @@ -38,7 +38,8 @@ class Syslog implements IWriter { ILogger::FATAL => LOG_CRIT, ]; - public function __construct(IConfig $config) { + public function __construct(SystemConfig $config) { + parent::__construct($config); openlog($config->getSystemValue('syslog_tag', 'Nextcloud'), LOG_PID | LOG_CONS, LOG_USER); } @@ -54,6 +55,6 @@ class Syslog implements IWriter { */ public function write(string $app, $message, int $level) { $syslog_level = $this->levels[$level]; - syslog($syslog_level, '{'.$app.'} '.$message); + syslog($syslog_level, $this->logDetailsAsJSON($app, $message, $level)); } } diff --git a/lib/private/Log/Systemdlog.php b/lib/private/Log/Systemdlog.php index 40e9c12386e..c40e4860f95 100644 --- a/lib/private/Log/Systemdlog.php +++ b/lib/private/Log/Systemdlog.php @@ -23,6 +23,7 @@ namespace OC\Log; use OC\HintException; +use OC\SystemConfig; use OCP\ILogger; use OCP\IConfig; use OCP\Log\IWriter; @@ -42,7 +43,7 @@ use OCP\Log\IWriter; // SYSLOG_FACILITY=, SYSLOG_IDENTIFIER=, SYSLOG_PID= // Syslog compatibility fields -class Systemdlog implements IWriter { +class Systemdlog extends LogDetails implements IWriter { protected $levels = [ ILogger::DEBUG => 7, ILogger::INFO => 6, @@ -53,14 +54,15 @@ class Systemdlog implements IWriter { protected $syslogId; - public function __construct(IConfig $config) { + public function __construct(SystemConfig $config) { + parent::__construct($config); if(!function_exists('sd_journal_send')) { throw new HintException( 'PHP extension php-systemd is not available.', 'Please install and enable PHP extension systemd if you wish to log to the Systemd journal.'); } - $this->syslogId = $config->getSystemValue('syslog_tag', 'Nextcloud'); + $this->syslogId = $config->getValue('syslog_tag', 'Nextcloud'); } /** @@ -73,6 +75,6 @@ class Systemdlog implements IWriter { $journal_level = $this->levels[$level]; sd_journal_send('PRIORITY='.$journal_level, 'SYSLOG_IDENTIFIER='.$this->syslogId, - 'MESSAGE={'.$app.'} '.$message); + 'MESSAGE=' . $this->logDetailsAsJSON($app, $message, $level)); } } diff --git a/lib/private/Repair.php b/lib/private/Repair.php index bd2fc081131..35e6856e429 100644 --- a/lib/private/Repair.php +++ b/lib/private/Repair.php @@ -43,6 +43,7 @@ use OC\Repair\NC14\AddPreviewBackgroundCleanupJob; use OC\Repair\NC16\AddClenupLoginFlowV2BackgroundJob; use OC\Repair\NC16\CleanupCardDAVPhotoCache; use OC\Repair\NC16\RemoveCypressFiles; +use OC\Repair\NC17\SetEnterpriseLogo; use OC\Repair\NC17\SwitchUpdateChannel; use OC\Repair\OldGroupMembershipShares; use OC\Repair\Owncloud\DropAccountTermsTable; @@ -151,6 +152,7 @@ class Repair implements IOutput { new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->getNotificationManager(), \OC::$server->query(ITimeFactory::class)), \OC::$server->query(RemoveCypressFiles::class), \OC::$server->query(SwitchUpdateChannel::class), + \OC::$server->query(SetEnterpriseLogo::class), ]; } diff --git a/lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php b/lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php index c9c7b5cf1c0..f0e5c2b2a1f 100644 --- a/lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php +++ b/lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php @@ -29,6 +29,7 @@ use OCP\IConfig; use OCP\ILogger; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; +use RuntimeException; /** * Class CleanupCardDAVPhotoCache @@ -65,6 +66,9 @@ class CleanupCardDAVPhotoCache implements IRepairStep { $folders = $this->appData->getDirectoryListing(); } catch (NotFoundException $e) { return; + } catch (RuntimeException $e) { + $this->logger->logException($e, ['message' => 'Failed to fetch directory listing in CleanupCardDAVPhotoCache']); + return; } $folders = array_filter($folders, function (ISimpleFolder $folder) { diff --git a/lib/private/Repair/NC17/SetEnterpriseLogo.php b/lib/private/Repair/NC17/SetEnterpriseLogo.php new file mode 100644 index 00000000000..2ba8d3c206b --- /dev/null +++ b/lib/private/Repair/NC17/SetEnterpriseLogo.php @@ -0,0 +1,117 @@ +<?php +declare(strict_types=1); +/** + * @copyright Copyright (c) 2019, Morris Jobke <hey@morrisjobke.de> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OC\Repair\NC17; + +use OC\Files\AppData\Factory; +use OC\Template\SCSSCacher; +use OCA\Theming\ThemingDefaults; +use OCP\Files\IAppData; +use OCP\Files\NotFoundException; +use OCP\IConfig; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; +use OCP\Support\Subscription\IRegistry; + +/** + * @deprecated - can be removed in 18 + */ +class SetEnterpriseLogo implements IRepairStep { + + /** @var IConfig $config */ + private $config; + + /** @var IRegistry $subscriptionRegistry */ + private $subscriptionRegistry; + + /** @var IAppData $appData */ + private $appData; + + /** @var SCSSCacher $scssCacher */ + private $scssCacher; + + /** @var \OC_Defaults|ThemingDefaults */ + private $themingDefaults; + + public function getName(): string { + return 'Sets the enterprise logo'; + } + + public function __construct( + IConfig $config, + IRegistry $subscriptionRegistry, + Factory $appDataFactory, + SCSSCacher $SCSSCacher, + $ThemingDefaults + ) { + $this->config = $config; + $this->subscriptionRegistry = $subscriptionRegistry; + $this->appData = $appDataFactory->get('theming'); + $this->scssCacher = $SCSSCacher; + $this->themingDefaults = $ThemingDefaults; + } + + public function run(IOutput $output): void { + // only run once + if ($this->config->getAppValue('core', 'enterpriseLogoChecked') === 'yes') { + $output->info('Repair step already executed'); + return; + } + + if (!$this->subscriptionRegistry->delegateHasValidSubscription()) { + // no need to set the enterprise logo + $this->config->setAppValue('core', 'enterpriseLogoChecked', 'yes'); + return; + } + + if ($this->themingDefaults instanceof ThemingDefaults) { + $output->info('Theming is enabled - trying to set logo.'); + try { + $folder = $this->appData->getFolder('images'); + } catch (NotFoundException $e) { + $folder = $this->appData->newFolder('images'); + } + + if (!$folder->fileExists('logo') || $folder->getFile('logo')->getSize() === 0) { + $output->info('Logo does not exist yet - setting it.'); + + if ($folder->fileExists('logo')) { + $folder->getFile('logo')->delete(); + } + $target = $folder->newFile('logo'); + + $target->putContent(file_get_contents(__DIR__ . '/../../../../core/img/logo/logo-enterprise.png')); + + $this->themingDefaults->set('logoMime', 'image/png'); + + $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/css-variables.scss', 'core'); + } else { + $output->info('Logo already set - skipping.'); + } + } else { + $output->info('Theming is not enabled - skipping.'); + } + + // if all were done, no need to redo the repair during next upgrade + $this->config->setAppValue('core', 'enterpriseLogoChecked', 'yes'); + } +} diff --git a/lib/private/Server.php b/lib/private/Server.php index 28cd204a519..64180f1cd7c 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -694,7 +694,8 @@ class Server extends ServerContainer implements IServerContainer { $c->query(\OC\AppConfig::class), $c->getGroupManager(), $c->getMemCacheFactory(), - $c->getEventDispatcher() + $c->getEventDispatcher(), + $c->getLogger() ); }); $this->registerAlias('AppManager', AppManager::class); diff --git a/lib/private/Setup/MySQL.php b/lib/private/Setup/MySQL.php index dd215f96cbe..eb4fedefd4b 100644 --- a/lib/private/Setup/MySQL.php +++ b/lib/private/Setup/MySQL.php @@ -79,7 +79,7 @@ class MySQL extends AbstractDatabase { try { //this query will fail if there aren't the right permissions, ignore the error - $query="GRANT ALL PRIVILEGES ON `$name` . * TO '$user'"; + $query="GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER ON `$name` . * TO '$user'"; $connection->executeUpdate($query); } catch (\Exception $ex) { $this->logger->logException($ex, [ diff --git a/lib/public/App/IAppManager.php b/lib/public/App/IAppManager.php index b0d04500f35..6213227bfd1 100644 --- a/lib/public/App/IAppManager.php +++ b/lib/public/App/IAppManager.php @@ -28,6 +28,7 @@ namespace OCP\App; use OCP\IUser; +use OCP\IGroup; /** * Interface IAppManager @@ -158,4 +159,18 @@ interface IAppManager { * @since 9.0.0 */ public function getAlwaysEnabledApps(); + + /** + * @param \OCP\IGroup $group + * @return String[] + * @since 17.0.0 + */ + public function getEnabledAppsForGroup(IGroup $group): array; + + /** + * @param String $appId + * @return string[] + * @since 17.0.0 + */ + public function getAppRestriction(string $appId): array; } diff --git a/lib/public/FullTextSearch/Model/ISearchRequest.php b/lib/public/FullTextSearch/Model/ISearchRequest.php index c7e96913018..6874cf161b6 100644 --- a/lib/public/FullTextSearch/Model/ISearchRequest.php +++ b/lib/public/FullTextSearch/Model/ISearchRequest.php @@ -91,6 +91,28 @@ interface ISearchRequest { */ public function getSearch(): string; + /** + * Set the searched string. + * + * @param string $search + * + * @since 17.0.0 + * + * @return ISearchRequest + */ + public function setSearch(string $search): ISearchRequest; + + /** + * Extends the searched string. + * + * @since 17.0.0 + * + * @param string $search + * + * @return ISearchRequest + */ + public function addSearch(string $search): ISearchRequest; + /** * Get the value of an option (as string). |