Skip to content
2 changes: 1 addition & 1 deletion apps/settings/templates/help.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
\OC_Util::addStyle('settings', 'help');
\OCP\Util::addStyle('settings', 'help');
?>
<?php if ($_['knowledgebaseEmbedded'] === true) : ?>
<div id="app-navigation" role="navigation" tabindex="0">
Expand Down
5 changes: 0 additions & 5 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2607,11 +2607,6 @@
<code><![CDATA[\Test\Util\User\Dummy]]></code>
</UndefinedClass>
</file>
<file src="lib/private/legacy/OC_Util.php">
<InvalidReturnType>
<code><![CDATA[void]]></code>
</InvalidReturnType>
</file>
<file src="lib/public/AppFramework/ApiController.php">
<NoInterfaceProperties>
<code><![CDATA[$this->request->server]]></code>
Expand Down
2 changes: 1 addition & 1 deletion core/Listener/BeforeTemplateRenderedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function handle(Event $event): void {
Util::addScript('core', 'public');
}

\OC_Util::addStyle('server', null, true);
Util::addStyle('server', null, true);

if ($event instanceof BeforeLoginTemplateRenderedEvent) {
// todo: make login work without these
Expand Down
2 changes: 1 addition & 1 deletion core/js/tests/specs/coreSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ describe('Core base tests', function() {
// to make sure they run.
var cit = window.isPhantom?xit:it;

// must provide the same results as \OC_Util::naturalSortCompare
// must provide the same results as \OCP\Util::naturalSortCompare
it('sorts alphabetically', function() {
var a = [
'def',
Expand Down
5 changes: 3 additions & 2 deletions cypress/e2e/settings/users.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,13 @@ describe('Settings: Create and delete accounts', function() {

// The "Delete account" action in the actions menu is shown and clicked
cy.get('.action-item__popper .action').contains('Delete account').should('exist').click({ force: true })
// And confirmation dialog accepted
cy.get('.nc-generic-dialog button').contains(`Delete ${testUser.userId}`).click({ force: true })

// Make sure no confirmation modal is shown
handlePasswordConfirmation(admin.password)

// And confirmation dialog accepted
cy.get('.nc-generic-dialog button').contains(`Delete ${testUser.userId}`).click({ force: true })

// deleted clicked the user is not shown anymore
getUserListRow(testUser.userId).should('not.exist')
})
Expand Down
2 changes: 1 addition & 1 deletion lib/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ public static function init(): void {
if (count($errors) > 0) {
if (!self::$CLI) {
http_response_code(503);
OC_Util::addStyle('guest');
Util::addStyle('guest');
try {
Server::get(ITemplateManager::class)->printGuestPage('', 'error', ['errors' => $errors]);
exit;
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(
$this->appConfig = $appConfig ?? Server::get(IAppConfig::class);
$this->config = $config ?? Server::get(IConfig::class);

if (\OC_Util::fileInfoLoaded()) {
if (class_exists(finfo::class)) {
$this->fileInfo = new finfo(FILEINFO_MIME_TYPE);
}
}
Expand Down
86 changes: 84 additions & 2 deletions lib/private/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\Defaults;
use OCP\Http\Client\IClientService;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory as IL10NFactory;
Expand Down Expand Up @@ -170,8 +172,7 @@ public function getSystemInfo(bool $allowAllDatabases = false): array {
self::protectDataDirectory();

try {
$util = new \OC_Util();
$htAccessWorking = $util->isHtaccessWorking(Server::get(IConfig::class));
$htAccessWorking = $this->isHtaccessWorking($dataDir);
} catch (\OCP\HintException $e) {
$errors[] = [
'error' => $e->getMessage(),
Expand Down Expand Up @@ -212,6 +213,87 @@ public function getSystemInfo(bool $allowAllDatabases = false): array {
];
}

public function createHtaccessTestFile(string $dataDir): string|false {
// php dev server does not support htaccess
if (php_sapi_name() === 'cli-server') {
return false;
}

// testdata
$fileName = '/htaccesstest.txt';
$testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.';

// creating a test file
$testFile = $dataDir . '/' . $fileName;

if (file_exists($testFile)) {// already running this test, possible recursive call
return false;
}

$fp = @fopen($testFile, 'w');
if (!$fp) {
throw new \OCP\HintException('Can\'t create test file to check for working .htaccess file.',
'Make sure it is possible for the web server to write to ' . $testFile);
}
fwrite($fp, $testContent);
fclose($fp);

return $testContent;
}

/**
* Check if the .htaccess file is working
*
* @param \OCP\IConfig $config
* @return bool
* @throws Exception
* @throws \OCP\HintException If the test file can't get written.
*/
public function isHtaccessWorking(string $dataDir) {
$config = Server::get(IConfig::class);

if (\OC::$CLI || !$config->getSystemValueBool('check_for_working_htaccess', true)) {
return true;
}

$testContent = $this->createHtaccessTestFile($dataDir);
if ($testContent === false) {
return false;
}

$fileName = '/htaccesstest.txt';
$testFile = $dataDir . '/' . $fileName;

// accessing the file via http
$url = Server::get(IURLGenerator::class)->getAbsoluteURL(\OC::$WEBROOT . '/data' . $fileName);
try {
$content = Server::get(IClientService::class)->newClient()->get($url)->getBody();
} catch (\Exception $e) {
$content = false;
}

if (str_starts_with($url, 'https:')) {
$url = 'http:' . substr($url, 6);
} else {
$url = 'https:' . substr($url, 5);
}

try {
$fallbackContent = Server::get(IClientService::class)->newClient()->get($url)->getBody();
} catch (\Exception $e) {
$fallbackContent = false;
}

// cleanup
@unlink($testFile);

/*
* If the content is not equal to test content our .htaccess
* is working as required
*/
return $content !== $testContent && $fallbackContent !== $testContent;
}

/**
* @return array<string|array> errors
*/
Expand Down
9 changes: 2 additions & 7 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1965,14 +1965,9 @@ public function currentUserCanEnumerateTargetUser(?IUser $currentUser, IUser $ta
}

/**
* Copied from \OC_Util::isSharingDisabledForUser
*
* TODO: Deprecate function from OC_Util
*
* @param string $userId
* @return bool
* Check if sharing is disabled for the current user
*/
public function sharingDisabledForUser($userId) {
public function sharingDisabledForUser(?string $userId): bool {
return $this->shareDisableChecker->sharingDisabledForUser($userId);
}

Expand Down
7 changes: 1 addition & 6 deletions lib/private/Share20/ShareDisableChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ public function __construct(
$this->sharingDisabledForUsersCache = new CappedMemoryCache();
}


/**
* @param ?string $userId
* @return bool
*/
public function sharingDisabledForUser(?string $userId) {
public function sharingDisabledForUser(?string $userId): bool {
if ($userId === null) {
return false;
}
Expand Down
7 changes: 5 additions & 2 deletions lib/private/Template/JSConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCP\ISession;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\Server;
use OCP\ServerVersion;
use OCP\Session\Exceptions\SessionNotAvailableException;
use OCP\Share\IManager as IShareManager;
Expand Down Expand Up @@ -161,6 +162,8 @@ public function getConfig(): string {
'enable_non-accessible_features' => $this->config->getSystemValueBool('enable_non-accessible_features', true),
];

$shareManager = Server::get(IShareManager::class);

$array = [
'_oc_debug' => $this->config->getSystemValue('debug', false) ? 'true' : 'false',
'_oc_isadmin' => $uid !== null && $this->groupManager->isAdmin($uid) ? 'true' : 'false',
Expand Down Expand Up @@ -235,11 +238,11 @@ public function getConfig(): string {
'defaultExpireDateEnforced' => $enforceDefaultExpireDate,
'enforcePasswordForPublicLink' => Util::isPublicLinkPasswordRequired(),
'enableLinkPasswordByDefault' => $enableLinkPasswordByDefault,
'sharingDisabledForUser' => Util::isSharingDisabledForUser(),
'sharingDisabledForUser' => $shareManager->sharingDisabledForUser($uid),
'resharingAllowed' => Share::isResharingAllowed(),
'remoteShareAllowed' => $outgoingServer2serverShareEnabled,
'federatedCloudShareDoc' => $this->urlGenerator->linkToDocs('user-sharing-federated'),
'allowGroupSharing' => \OC::$server->get(IShareManager::class)->allowGroupSharing(),
'allowGroupSharing' => $shareManager->allowGroupSharing(),
'defaultInternalExpireDateEnabled' => $defaultInternalExpireDateEnabled,
'defaultInternalExpireDate' => $defaultInternalExpireDate,
'defaultInternalExpireDateEnforced' => $defaultInternalExpireDateEnforced,
Expand Down
5 changes: 3 additions & 2 deletions lib/private/Template/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ function script($app, $file = null): void {
function style($app, $file = null): void {
if (is_array($file)) {
foreach ($file as $f) {
OC_Util::addStyle($app, $f);
Util::addStyle($app, $f);
}
} else {
OC_Util::addStyle($app, $file);
Util::addStyle($app, $file);
}
}

Expand All @@ -143,6 +143,7 @@ function style($app, $file = null): void {
* @param string $app the appname
* @param string|string[] $file the filename,
* if an array is given it will add all styles
* @deprecated 32.0.0
*/
function vendor_style($app, $file = null): void {
if (is_array($file)) {
Expand Down
Loading
Loading