Skip to content

Commit

Permalink
Merge pull request #513 from nextcloud/bugfix/495/must-be-of-type-arr…
Browse files Browse the repository at this point in the history
…ay-int-given

Release for 26 and Prevent "must be of type array, int given" for max()
  • Loading branch information
nickvergessen authored Feb 17, 2023
2 parents f856961 + 7624ef4 commit e923ed7
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpunit-sqlite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

strategy:
matrix:
php-versions: ['8.0', '8.1']
php-versions: ['8.0', '8.1', '8.2']
server-versions: ['master']
include:
- php-versions: '7.4'
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog
All notable changes to this project will be documented in this file.

## 1.9.0 – 2023-02-17
### Changed
- Compatibility with Nextcloud 26

### Fixed
- Prevent "must be of type array, int given" for max()

## 1.8.1 – 2022-11-18
### Added
- Allow to send an email reminder before deleting users
Expand Down
4 changes: 2 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* ⛔ Exclude accounts based on group memberships (default: admin group)
* 🔑 Exclude accounts that never logged in (default: enabled)
]]></description>
<version>1.8.1</version>
<version>1.9.0</version>
<licence>agpl</licence>
<author>Joas Schilling</author>
<namespace>UserRetention</namespace>
Expand All @@ -27,7 +27,7 @@
<screenshot>https://raw.githubusercontent.com/nextcloud/user_retention/master/docs/screenshot.png</screenshot>

<dependencies>
<nextcloud min-version="25" max-version="25" />
<nextcloud min-version="25" max-version="26" />
</dependencies>

<background-jobs>
Expand Down
4 changes: 4 additions & 0 deletions lib/Service/RetentionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ protected function getAuthTokensLastActivity(IUser $user): ?int {
return null;
}

if (count($lastActivities) === 1) {
return array_pop($lastActivities);
}

return max(...$lastActivities);
}

Expand Down
45 changes: 45 additions & 0 deletions tests/Service/RetentionServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/
namespace OCA\UserRetention\Tests;

use OC\Authentication\Token\Manager;
use OC\Authentication\Token\PublicKeyToken;
use OCA\UserRetention\BackgroundJob\ExpireUsers;
use OCA\UserRetention\Service\RetentionService;
use OCA\UserRetention\SkipUserException;
Expand Down Expand Up @@ -254,4 +256,47 @@ public function testSkipUserBasedOnProtectedGroupMembership(array $excludedGroup
$this->assertTrue(true);
}
}

public function dataGetAuthTokensLastActivity(): array {
return [
[[], null],
[[1], 1],
[[1, 2], 2],
[[4, 2], 4],
];
}

/**
* @dataProvider dataGetAuthTokensLastActivity
* @param int[] $tokenActivities
* @param ?int $expected
*/
public function testGetAuthTokensLastActivity(array $tokenActivities, ?int $expected): void {
$service = $this->createService();

$tokens = [];
foreach ($tokenActivities as $lastActivity) {
$token = PublicKeyToken::fromParams([
'lastActivity' => $lastActivity,
]);

$tokens[] = $token;
}

$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn('uid');

$manager = $this->createMock(Manager::class);
$manager->method('getTokenByUser')
->with('uid')
->willReturn($tokens);

$this->container->method('get')
->with(Manager::class)
->willReturn($manager);

$actual = self::invokePrivate($service, 'getAuthTokensLastActivity', [$user]);
$this->assertSame($expected, $actual);
}
}

0 comments on commit e923ed7

Please sign in to comment.