Skip to content
Draft
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
32 changes: 5 additions & 27 deletions lib/Service/CalendarInitialStateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\Talk\IBroker;
use function in_array;

class CalendarInitialStateService {
Expand All @@ -36,6 +37,7 @@
private ?IQueue $queue,
private IGroupManager $groupManager,
private IUserManager $userManager,
private IBroker $talkBroker,
) {
}

Expand Down Expand Up @@ -151,34 +153,10 @@
}

private function isTalkEnabledForUser(): bool {
$userId = $this->userId;
if ($userId === null) {
return false;
}

$talkEnabled = $this->appManager->isEnabledForUser('spreed');
$user = $this->userManager->get($userId);

if ($user === null) {
return false;
}

$userGroups = $userGroups = $this->groupManager->getUserGroupIds($user);


//groups allowed to start a conversation
$startConversation = $this->config->getAppValue('spreed', 'start_conversations', '[]');
$startConversation = json_decode($startConversation, true);

$canStartConversation = !empty(array_intersect($startConversation, $userGroups));

//groups allowed to use talk
$allowedGroups = $this->config->getAppValue('spreed', 'allowed_groups', '[]');
$allowedGroups = json_decode($allowedGroups, true);

$canUseTalk = !empty(array_intersect($allowedGroups, $userGroups));
$canStartConversation= !$this->talkBroker->isDisabledForUser();

Check failure on line 156 in lib/Service/CalendarInitialStateService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable33

UndefinedInterfaceMethod

lib/Service/CalendarInitialStateService.php:156:46: UndefinedInterfaceMethod: Method OCP\Talk\IBroker::isDisabledForUser does not exist (see https://psalm.dev/181)

Check failure on line 156 in lib/Service/CalendarInitialStateService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable32

UndefinedInterfaceMethod

lib/Service/CalendarInitialStateService.php:156:46: UndefinedInterfaceMethod: Method OCP\Talk\IBroker::isDisabledForUser does not exist (see https://psalm.dev/181)

Check failure on line 156 in lib/Service/CalendarInitialStateService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedInterfaceMethod

lib/Service/CalendarInitialStateService.php:156:46: UndefinedInterfaceMethod: Method OCP\Talk\IBroker::isDisabledForUser does not exist (see https://psalm.dev/181)
$canUseTalk= !$this->talkBroker->isNotAllowedToCreateConversations();

Check failure on line 157 in lib/Service/CalendarInitialStateService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable33

UndefinedInterfaceMethod

lib/Service/CalendarInitialStateService.php:157:37: UndefinedInterfaceMethod: Method OCP\Talk\IBroker::isNotAllowedToCreateConversations does not exist (see https://psalm.dev/181)

Check failure on line 157 in lib/Service/CalendarInitialStateService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable32

UndefinedInterfaceMethod

lib/Service/CalendarInitialStateService.php:157:37: UndefinedInterfaceMethod: Method OCP\Talk\IBroker::isNotAllowedToCreateConversations does not exist (see https://psalm.dev/181)

Check failure on line 157 in lib/Service/CalendarInitialStateService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedInterfaceMethod

lib/Service/CalendarInitialStateService.php:157:37: UndefinedInterfaceMethod: Method OCP\Talk\IBroker::isNotAllowedToCreateConversations does not exist (see https://psalm.dev/181)

return $talkEnabled && $canStartConversation && $canUseTalk;
return $canStartConversation && $canUseTalk;
}


Expand Down
30 changes: 26 additions & 4 deletions tests/php/unit/Service/CalendarInitialStateServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\Talk\IBroker;
use PHPUnit\Framework\MockObject\MockObject;

class CalendarInitialStateServiceTest extends TestCase {
Expand Down Expand Up @@ -59,6 +60,7 @@ class CalendarInitialStateServiceTest extends TestCase {

private IGroupManager&MockObject $groupManager;
private IUserManager&MockObject $userManager;
private IBroker&MockObject $talkBroker;

protected function setUp(): void {
$this->appName = 'calendar';
Expand All @@ -77,6 +79,7 @@ protected function setUp(): void {
}
$this->groupManager = $this->createMock(IGroupManager::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->talkBroker = $this->createMock(IBroker::class);
}

public function testRun(): void {
Expand All @@ -94,6 +97,7 @@ public function testRun(): void {
$this->queue,
$this->groupManager,
$this->userManager,
$this->talkBroker,
);
$this->config->expects(self::exactly(17))
->method('getAppValue')
Expand Down Expand Up @@ -137,10 +141,9 @@ public function testRun(): void {
->willReturnMap([
['dav', 'enableCalendarFederation', true, false, true],
]);
$this->appManager->expects(self::exactly(3))
$this->appManager->expects(self::exactly(2))
->method('isEnabledForUser')
->willReturnMap([
['spreed', null, true],
['tasks', null, true],
['circles', null, false],
]);
Expand All @@ -150,6 +153,12 @@ public function testRun(): void {
['spreed', true, '12.0.0'],
['circles', true, '22.0.0'],
]);
$this->talkBroker->expects(self::once())
->method('isDisabledForUser')
->willReturn(false);
$this->talkBroker->expects(self::once())
->method('isNotAllowedToCreateConversations')
->willReturn(false);
$this->appointmentContfigService->expects(self::once())
->method('getAllAppointmentConfigurations')
->with($this->userId)
Expand Down Expand Up @@ -209,6 +218,7 @@ public function testRunAnonymously(): void {
$this->queue,
$this->groupManager,
$this->userManager,
$this->talkBroker,
);
$this->config->expects(self::exactly(17))
->method('getAppValue')
Expand Down Expand Up @@ -265,6 +275,12 @@ public function testRunAnonymously(): void {
['spreed', true, '12.0.0'],
['circles', true, '22.0.0'],
]);
$this->talkBroker->expects(self::once())
->method('isDisabledForUser')
->willReturn(true);
$this->talkBroker->expects(self::once())
->method('isNotAllowedToCreateConversations')
->willReturn(true);
$this->resourceManager->expects(self::once())
->method('getBackends')
->willReturn([]);
Expand Down Expand Up @@ -326,6 +342,7 @@ public function testIndexViewFix(string $savedView, string $expectedView): void
$this->queue,
$this->groupManager,
$this->userManager,
$this->talkBroker,
);
$this->config->expects(self::exactly(17))
->method('getAppValue')
Expand Down Expand Up @@ -369,10 +386,9 @@ public function testIndexViewFix(string $savedView, string $expectedView): void
->willReturnMap([
['dav', 'enableCalendarFederation', true, false, true],
]);
$this->appManager->expects(self::exactly(3))
$this->appManager->expects(self::exactly(2))
->method('isEnabledForUser')
->willReturnMap([
['spreed', null, false],
['tasks', null, false],
['circles', null, false],
]);
Expand All @@ -382,6 +398,12 @@ public function testIndexViewFix(string $savedView, string $expectedView): void
['spreed', true, '11.3.0'],
['circles', true, '22.0.0'],
]);
$this->talkBroker->expects(self::once())
->method('isDisabledForUser')
->willReturn(true);
$this->talkBroker->expects(self::once())
->method('isNotAllowedToCreateConversations')
->willReturn(true);
$this->appointmentContfigService->expects(self::once())
->method('getAllAppointmentConfigurations')
->with($this->userId)
Expand Down
Loading