Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions lib/AppConfigOverwrite.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand All @@ -11,22 +12,17 @@
use OC\AppConfig;

class AppConfigOverwrite extends AppConfig {

/** @var string[][] */
private array $overWrite = [];

/**
* @param string[][] $overwrite
*/
public function setOverwrite(array $overwrite): void {
$this->overWrite = $overwrite;
}


/**
* @param $app
* @param $key
* @param $default
* @return string
*/
public function getValue($app, $key, $default = '') {
public function getValue($app, $key, $default = ''): string {
Comment thread
solracsf marked this conversation as resolved.
if (isset($this->overWrite[$app]) && isset($this->overWrite[$app][$key])) {
return $this->overWrite[$app][$key];
}
Expand Down
12 changes: 7 additions & 5 deletions lib/AppWhitelist.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2017 ownCloud GmbH
Expand Down Expand Up @@ -29,9 +31,6 @@ class AppWhitelist {

public const DEFAULT_WHITELIST = 'files_trashbin,files_versions,files_sharing,files_texteditor,text,activity,firstrunwizard,photos,notifications,dashboard,user_status,weather_status';

/**
* AppWhitelist constructor.
*/
public function __construct(
IURLGenerator $urlGenerator,
private readonly Config $config,
Expand Down Expand Up @@ -70,9 +69,9 @@ public function isUrlAllowed(IUser $user, string|false $url): bool {
$this->logger->notice("Blocking access to non-whitelisted app ($app) for guest", ['app' => 'guests']);
return false;
}
} else {
return true;
}

return true;
}

public function verifyAccess(IUser $user, IRequest $request): void {
Expand Down Expand Up @@ -130,6 +129,9 @@ private function getRequestedApp(string|false $url): string {
return 'core';
}

/**
* @return list<string>
*/
public function getWhitelistAbleApps(): array {
return array_values(array_diff(
$this->appManager->getInstalledApps(),
Expand Down
9 changes: 6 additions & 3 deletions lib/BackgroundJob/TransferJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ private function notifyFailure(Transfer $transfer): void {
'source' => $transfer->getSource(),
'target' => $transfer->getTarget(),
]);

$this->notificationManager->notify($notification);
}

Expand All @@ -63,13 +64,14 @@ private function notifySuccess(Transfer $transfer): void {
'source' => $transfer->getSource(),
'target' => $transfer->getTarget(),
]);

$this->notificationManager->notify($notification);
}

private function fail(Transfer $transfer, ?IUser $targetUser = null): void {
$this->notifyFailure($transfer);
$this->transferMapper->delete($transfer);
if (!($targetUser instanceof IUser)) {
if (!$targetUser instanceof IUser) {
return;
}
$result = $targetUser->delete(); // Rollback created user
Expand All @@ -90,7 +92,7 @@ public function run($argument): void {
$target = $transfer->getTarget();

$sourceUser = $this->userManager->get($source);
if (!($sourceUser instanceof IUser)) {
if (!$sourceUser instanceof IUser) {
$this->logger->error('Failed to transfer missing guest user: ' . $source);
$this->fail($transfer);
return;
Expand All @@ -107,7 +109,7 @@ public function run($argument): void {
$this->secureRandom->generate(20), // Password hash will be copied to target user from source user
);

if (!($targetUser instanceof IUser)) {
if (!$targetUser instanceof IUser) {
$this->logger->error('Failed to create new user: ' . $target);
$this->fail($transfer);
return;
Expand Down Expand Up @@ -141,6 +143,7 @@ public function run($argument): void {
if (!$result) {
$this->logger->error('Failed to delete guest user', ['user' => $sourceUser->getUID()]);
}

$this->notifySuccess($transfer);
$this->transferMapper->delete($transfer);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/Capabilities.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand Down
1 change: 1 addition & 0 deletions lib/Command/AddCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand Down
28 changes: 8 additions & 20 deletions lib/Config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand Down Expand Up @@ -28,21 +29,15 @@ public function allowExternalStorage(): bool {
return $this->appConfig->getAppValueBool('allow_external_storage', false);
}

/**
* @param string|bool $allow
*/
public function setAllowExternalStorage($allow): void {
public function setAllowExternalStorage(string|bool $allow): void {
$this->appConfig->setAppValueBool('allow_external_storage', $allow === true || $allow === 'true') ;
}

public function hideOtherUsers(): bool {
return $this->appConfig->getAppValueBool('hide_users', true);
}

/**
* @param string|bool $hide
*/
public function setHideOtherUsers($hide): void {
public function setHideOtherUsers(string|bool $hide): void {
$this->appConfig->setAppValueBool('hide_users', $hide === true || $hide === 'true') ;
}

Expand All @@ -54,25 +49,19 @@ public function useWhitelist(): bool {
return $this->appConfig->getAppValueBool('usewhitelist', true);
}

/**
* @param string|bool $use
*/
public function setUseWhitelist($use): void {
public function setUseWhitelist(string|bool $use): void {
$this->appConfig->setAppValueBool('usewhitelist', $use === true || $use === 'true') ;
}

/**
* @return string[]
* @return list<string>
*/
public function getAppWhitelist(): array {
Comment thread
CarlSchwan marked this conversation as resolved.
$whitelist = $this->appConfig->getAppValueString('whitelist', AppWhitelist::DEFAULT_WHITELIST);
return explode(',', $whitelist);
}

/**
* @param array|string $whitelist
*/
public function setAppWhitelist($whitelist): void {
public function setAppWhitelist(array|string $whitelist): void {
if (is_array($whitelist)) {
$whitelist = implode(',', $whitelist);
}
Expand Down Expand Up @@ -106,12 +95,11 @@ public function canCreateGuests(): bool {
}
}


return !$this->isSharingRestrictedToGroup();
}

/**
* @return string[]
* @return list<string>
*/
public function getCreateRestrictedToGroup(): array {
Comment thread
CarlSchwan marked this conversation as resolved.
$groups = $this->appConfig->getAppValueArray('create_restricted_to_group', []);
Expand All @@ -127,7 +115,7 @@ public function getCreateRestrictedToGroup(): array {
}

/**
* @param string[] $groups
* @param list<string> $groups
*/
public function setCreateRestrictedToGroup(array $groups): void {
$this->appConfig->setAppValueArray('create_restricted_to_group', $groups);
Comment thread
CarlSchwan marked this conversation as resolved.
Expand Down
7 changes: 4 additions & 3 deletions lib/Controller/APIController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand Down Expand Up @@ -44,7 +45,7 @@ public function languages(): DataResponse {
$l = $this->l10nFactory->get('lib', $lang);
// TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version
$potentialName = $l->t('__language_name__');
if ($l->getLanguageCode() === $lang && $potentialName[0] !== '_') {//first check if the language name is in the translation file
if ($l->getLanguageCode() === $lang && $potentialName[0] !== '_') { // first check if the language name is in the translation file
$ln = [
'code' => $lang,
'name' => $potentialName,
Expand All @@ -54,14 +55,14 @@ public function languages(): DataResponse {
'code' => $lang,
'name' => 'English (US)',
];
} else {//fallback to language code
} else { // fallback to language code
$ln = [
'code' => $lang,
'name' => $lang,
];
}

// put appropriate languages into appropriate arrays, to print them sorted
// Put appropriate languages into appropriate arrays, to print them sorted
// common languages -> divider -> other languages
if (in_array($lang, Factory::COMMON_LANGUAGE_CODES)) {
$commonLanguages[array_search($lang, Factory::COMMON_LANGUAGE_CODES)] = $ln;
Expand Down
12 changes: 8 additions & 4 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2017 ownCloud GmbH
Expand Down Expand Up @@ -41,6 +43,7 @@ public function getConfig(): DataResponse {
$allowExternalStorage = $this->config->allowExternalStorage();
$hideUsers = $this->config->hideOtherUsers();
$whitelist = $this->config->getAppWhitelist();

return new DataResponse([
'useWhitelist' => $useWhitelist,
'whitelist' => $whitelist,
Expand All @@ -53,21 +56,20 @@ public function getConfig(): DataResponse {
}

/**
* @param $useWhitelist bool
* @param $whitelist string[]
* @param $allowExternalStorage bool
* @param $hideUsers bool
* @param list<string> $whitelist
*/
public function setConfig(bool $useWhitelist, array $whitelist, bool $allowExternalStorage, bool $hideUsers, array $createRestrictedToGroup): DataResponse {
$newWhitelist = [];
foreach ($whitelist as $app) {
$newWhitelist[] = trim((string)$app);
}

$this->config->setUseWhitelist($useWhitelist);
$this->config->setAppWhitelist($newWhitelist);
$this->config->setAllowExternalStorage($allowExternalStorage);
$this->config->setHideOtherUsers($hideUsers);
$this->config->setCreateRestrictedToGroup($createRestrictedToGroup);

return new DataResponse();
}

Expand All @@ -81,6 +83,7 @@ public function setConfig(bool $useWhitelist, array $whitelist, bool $allowExter
public function getWhitelist(): DataResponse {
$useWhitelist = $this->config->useWhitelist();
$whitelist = $this->config->getAppWhitelist();

return new DataResponse([
'useWhitelist' => $useWhitelist,
'whitelist' => $whitelist,
Expand All @@ -94,6 +97,7 @@ public function getWhitelist(): DataResponse {
*/
public function resetWhitelist(): DataResponse {
$this->config->setAppWhitelist(AppWhitelist::DEFAULT_WHITELIST);

return new DataResponse([
'whitelist' => explode(',', AppWhitelist::DEFAULT_WHITELIST),
]);
Expand Down
1 change: 1 addition & 0 deletions lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public function transfer(string $guestUserId, string $targetUserId): DataRespons
}

$this->transferService->addTransferJob($author, $sourceUser, $targetUserId);

return new DataResponse([], Http::STATUS_CREATED);
}
}
3 changes: 3 additions & 0 deletions lib/Db/Transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ class Transfer extends Entity {

/** @var string */
protected $author;

/** @var string */
protected $source;

/** @var string */
protected $target;

/** @var string */
protected $status;

Expand Down
2 changes: 2 additions & 0 deletions lib/FilteredNavigationManager.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand Down
2 changes: 2 additions & 0 deletions lib/FilteredSettingsManager.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand Down
Loading
Loading