From 5e548daa7b2aa0abe16240402475295097b0747b Mon Sep 17 00:00:00 2001 From: noah Date: Sun, 14 Dec 2025 18:19:49 +0000 Subject: [PATCH 1/2] added a exclude disabled option to last seen Signed-off-by: noah --- core/Command/User/LastSeen.php | 12 ++- tests/Core/Command/User/LastSeenTest.php | 94 ++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) diff --git a/core/Command/User/LastSeen.php b/core/Command/User/LastSeen.php index 514396f9f5283..8c58f17940ae3 100644 --- a/core/Command/User/LastSeen.php +++ b/core/Command/User/LastSeen.php @@ -38,6 +38,12 @@ protected function configure(): void { InputOption::VALUE_NONE, 'shows a list of when all users were last logged in' ) + ->addOption( + 'exclude-disabled', + null, + InputOption::VALUE_NONE, + 'exclude disabled users from the list (only works with --all)' + ) ; } @@ -68,7 +74,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 1; } - $this->userManager->callForAllUsers(static function (IUser $user) use ($output): void { + $excludeDisabled = $input->getOption('exclude-disabled'); + $this->userManager->callForAllUsers(static function (IUser $user) use ($output, $excludeDisabled): void { + if ($excludeDisabled && !$user->isEnabled()) { + return; + } $lastLogin = $user->getLastLogin(); if ($lastLogin === 0) { $output->writeln($user->getUID() . ' has never logged in.'); diff --git a/tests/Core/Command/User/LastSeenTest.php b/tests/Core/Command/User/LastSeenTest.php index 64c710eacc59f..fd1d57431f069 100644 --- a/tests/Core/Command/User/LastSeenTest.php +++ b/tests/Core/Command/User/LastSeenTest.php @@ -92,4 +92,98 @@ public function testInvalidUser(): void { self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); } + + public function testAllUsersWithoutExcludeDisabled(): void { + $enabledUser = $this->getMockBuilder(IUser::class)->getMock(); + $enabledUser->expects($this->once()) + ->method('getLastLogin') + ->willReturn(time()); + $enabledUser->expects($this->once()) + ->method('getUID') + ->willReturn('enabled_user'); + $enabledUser->expects($this->never()) + ->method('isEnabled'); + + $disabledUser = $this->getMockBuilder(IUser::class)->getMock(); + $disabledUser->expects($this->once()) + ->method('getLastLogin') + ->willReturn(time()); + $disabledUser->expects($this->once()) + ->method('getUID') + ->willReturn('disabled_user'); + $disabledUser->expects($this->never()) + ->method('isEnabled'); + + $this->consoleInput->expects($this->once()) + ->method('getArgument') + ->with('uid') + ->willReturn(null); + + $this->consoleInput->expects($this->exactly(2)) + ->method('getOption') + ->willReturnMap([ + ['all', true], + ['exclude-disabled', false], + ]); + + $this->userManager->expects($this->once()) + ->method('callForAllUsers') + ->willReturnCallback(function ($callback) use ($enabledUser, $disabledUser) { + $callback($enabledUser); + $callback($disabledUser); + }); + + $this->consoleOutput->expects($this->exactly(2)) + ->method('writeln') + ->with($this->stringContains("'s last login:")); + + self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); + } + + public function testAllUsersWithExcludeDisabled(): void { + $enabledUser = $this->getMockBuilder(IUser::class)->getMock(); + $enabledUser->expects($this->once()) + ->method('getLastLogin') + ->willReturn(time()); + $enabledUser->expects($this->once()) + ->method('getUID') + ->willReturn('enabled_user'); + $enabledUser->expects($this->once()) + ->method('isEnabled') + ->willReturn(true); + + $disabledUser = $this->getMockBuilder(IUser::class)->getMock(); + $disabledUser->expects($this->never()) + ->method('getLastLogin'); + $disabledUser->expects($this->never()) + ->method('getUID'); + $disabledUser->expects($this->once()) + ->method('isEnabled') + ->willReturn(false); + + $this->consoleInput->expects($this->once()) + ->method('getArgument') + ->with('uid') + ->willReturn(null); + + $this->consoleInput->expects($this->exactly(2)) + ->method('getOption') + ->willReturnMap([ + ['all', true], + ['exclude-disabled', true], + ]); + + $this->userManager->expects($this->once()) + ->method('callForAllUsers') + ->willReturnCallback(function ($callback) use ($enabledUser, $disabledUser) { + $callback($enabledUser); + $callback($disabledUser); + }); + + $this->consoleOutput->expects($this->once()) + ->method('writeln') + ->with($this->stringContains("'s last login:")); + + self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); + } } From c82fb9603234ca6adbc6f68f34364394aa0083ab Mon Sep 17 00:00:00 2001 From: Noah <99681487+NoahOksuz@users.noreply.github.com> Date: Mon, 15 Dec 2025 11:31:06 +0000 Subject: [PATCH 2/2] Update LastSeenTest.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> Signed-off-by: Noah <99681487+NoahOksuz@users.noreply.github.com> --- tests/Core/Command/User/LastSeenTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Core/Command/User/LastSeenTest.php b/tests/Core/Command/User/LastSeenTest.php index fd1d57431f069..6afcf40c8033e 100644 --- a/tests/Core/Command/User/LastSeenTest.php +++ b/tests/Core/Command/User/LastSeenTest.php @@ -182,7 +182,7 @@ public function testAllUsersWithExcludeDisabled(): void { $this->consoleOutput->expects($this->once()) ->method('writeln') - ->with($this->stringContains("'s last login:")); + ->with($this->stringContains("enabled_user's last login:")); self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); }