Skip to content

Commit 123f687

Browse files
authored
Merge pull request #1372 from nextcloud/carl/port-deprecated
Fix some deprecations
2 parents b26e927 + ba4d3db commit 123f687

4 files changed

Lines changed: 18 additions & 6 deletions

File tree

lib/Controller/Id4meController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use OCP\Security\ICrypto;
4545
use OCP\Security\ISecureRandom;
4646

47+
use OCP\ServerVersion;
4748
use OCP\Util;
4849
use Psr\Log\LoggerInterface;
4950

@@ -71,6 +72,7 @@ public function __construct(
7172
private ID4MeService $id4MeService,
7273
private LoggerInterface $logger,
7374
private ICrypto $crypto,
75+
private ServerVersion $serverVersion,
7476
) {
7577
parent::__construct($request, $config, $l10n);
7678

@@ -322,6 +324,6 @@ public function code(string $state = '', string $code = '', string $scope = '')
322324
// Set last password confirm to the future as we don't have passwords to confirm against with SSO
323325
$this->session->set('last-password-confirm', strtotime('+4 year', time()));
324326

325-
return new RedirectResponse(\OC_Util::getDefaultPageUrl());
327+
return new RedirectResponse($this->serverVersion->getMajorVersion() >= 32 ? $this->urlGenerator->linkToDefaultPageUrl() : \OC_Util::getDefaultPageUrl());
326328
}
327329
}

lib/Controller/LoginController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
use OCP\IUserSession;
5959
use OCP\Security\ICrypto;
6060
use OCP\Security\ISecureRandom;
61+
use OCP\ServerVersion;
6162
use OCP\Session\Exceptions\SessionNotAvailableException;
6263
use OCP\User\Events\BeforeUserLoggedInEvent;
6364
use OCP\User\Events\UserCreatedEvent;
@@ -99,6 +100,7 @@ public function __construct(
99100
private ICrypto $crypto,
100101
private TokenService $tokenService,
101102
private OidcService $oidcService,
103+
private ServerVersion $serverVersion,
102104
) {
103105
parent::__construct($request, $config, $l10n);
104106
}
@@ -696,7 +698,7 @@ public function code(string $state = '', string $code = '', string $scope = '',
696698
return $this->getRedirectResponse($redirectUrl);
697699
}
698700

699-
return new RedirectResponse(\OC_Util::getDefaultPageUrl());
701+
return new RedirectResponse($this->serverVersion->getMajorVersion() >= 32 ? $this->urlGenerator->linkToDefaultPageUrl() : \OC_Util::getDefaultPageUrl());
700702
}
701703

702704
/**

lib/User/Backend.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
use OCP\DB\Exception;
2727
use OCP\EventDispatcher\GenericEvent;
2828
use OCP\EventDispatcher\IEventDispatcher;
29+
use OCP\Files\IRootFolder;
30+
use OCP\Files\ISetupManager;
2931
use OCP\Files\NotFoundException;
3032
use OCP\Files\NotPermittedException;
3133
use OCP\IConfig;
@@ -35,11 +37,13 @@
3537
use OCP\IUser;
3638
use OCP\IUserManager;
3739
use OCP\Server;
40+
use OCP\ServerVersion;
3841
use OCP\User\Backend\ABackend;
3942
use OCP\User\Backend\ICountUsersBackend;
4043
use OCP\User\Backend\ICustomLogout;
4144
use OCP\User\Backend\IGetDisplayNameBackend;
4245
use OCP\User\Backend\IPasswordConfirmationBackend;
46+
use OCP\User\Events\UserFirstTimeLoggedInEvent;
4347
use Psr\Log\LoggerInterface;
4448
use Throwable;
4549

@@ -63,6 +67,7 @@ public function __construct(
6367
private ProvisioningService $provisioningService,
6468
private LdapService $ldapService,
6569
private IUserManager $userManager,
70+
private ServerVersion $serverVersion,
6671
) {
6772
}
6873

@@ -391,9 +396,9 @@ private function checkFirstLogin(string $userId): bool {
391396

392397
$firstLogin = $user->getLastLogin() === 0;
393398
if ($firstLogin) {
394-
\OC_Util::setupFS($userId);
399+
$this->serverVersion->getMajorVersion() >= 34 ? Server::get(ISetupManager::class)->setupForUser($user) : \OC_Util::setupFS($userId);
395400
// trigger creation of user home and /files folder
396-
$userFolder = \OC::$server->getUserFolder($userId);
401+
$userFolder = Server::get(IRootFolder::class)->getUserFolder($userId);
397402
try {
398403
// copy skeleton
399404
\OC_Util::copySkeleton($userId, $userFolder);
@@ -403,8 +408,7 @@ private function checkFirstLogin(string $userId): bool {
403408

404409
// trigger any other initialization
405410
$this->eventDispatcher->dispatch(IUser::class . '::firstLogin', new GenericEvent($user));
406-
// TODO add this when user_oidc min NC version is >= 28
407-
// $this->eventDispatcher->dispatchTyped(new UserFirstTimeLoggedInEvent($user));
411+
$this->eventDispatcher->dispatchTyped(new UserFirstTimeLoggedInEvent($user));
408412
}
409413
$user->updateLastLoginTimestamp();
410414
return $firstLogin;

psalm.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
<referencedClass name="Symfony\Component\Console\Question\ConfirmationQuestion" />
4747
<referencedClass name="OC\Accounts\AccountManager" />
4848
<referencedClass name="OCA\OIDCIdentityProvider\AppInfo\Application" />
49+
<referencedClass name="OCP\ServerVersion" />
50+
<referencedClass name="OCP\Files\ISetupManager" />
51+
<referencedClass name="OCP\User\Events\UserFirstTimeLoggedInEvent" />
4952
</errorLevel>
5053
</UndefinedClass>
5154
<UndefinedDocblockClass>
@@ -59,6 +62,7 @@
5962
<referencedClass name="OCA\User_LDAP\User_Proxy" />
6063
<referencedClass name="OCA\User_LDAP\User\DeletedUsersIndex" />
6164
<referencedClass name="Doctrine\DBAL\Schema\SchemaException" />
65+
<referencedClass name="OCP\Files\ISetupManager" />
6266
</errorLevel>
6367
</UndefinedDocblockClass>
6468
</issueHandlers>

0 commit comments

Comments
 (0)