Skip to content

Commit 75d08be

Browse files
committed
display error if groupfolders app not supported
Signed-off-by: nabim777 <[email protected]>
1 parent 56f92f3 commit 75d08be

File tree

3 files changed

+93
-10
lines changed

3 files changed

+93
-10
lines changed

lib/Service/OpenProjectAPIService.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
class OpenProjectAPIService {
6767
public const AUTH_METHOD_OAUTH = 'oauth2';
6868
public const AUTH_METHOD_OIDC = 'oidc';
69+
public const MIN_SUPPORTED_GROUP_FOLDERS_APP_VERSION = '1.0.0';
6970
public const MIN_SUPPORTED_USER_OIDC_APP_VERSION = '6.2.0';
7071
/**
7172
* @var string
@@ -1064,6 +1065,9 @@ public function isSystemReadyForProjectFolderSetUp(): bool {
10641065
throw new \Exception('The "Group folders" app is not installed');
10651066
}
10661067
}
1068+
if (!$this->isGroupfoldersSupported()) {
1069+
throw new \Exception('The "Group folders" app is not supported');
1070+
}
10671071
if ($this->userManager->userExists(Application::OPEN_PROJECT_ENTITIES_NAME)) {
10681072
throw new OpenprojectGroupfolderSetupConflictException('The user "'. Application::OPEN_PROJECT_ENTITIES_NAME .'" already exists');
10691073
} elseif ($this->groupManager->groupExists(Application::OPEN_PROJECT_ENTITIES_NAME)) {
@@ -1091,7 +1095,8 @@ public function isProjectFoldersSetupComplete(): bool {
10911095
$this->groupManager->groupExists(Application::OPEN_PROJECT_ENTITIES_NAME) &&
10921096
$this->isUserPartOfAndAdminOfGroup() &&
10931097
$this->isGroupfoldersAppEnabled() &&
1094-
$this->isGroupfolderAppCorrectlySetup()
1098+
$this->isGroupfolderAppCorrectlySetup() &&
1099+
$this->isGroupfoldersSupported()
10951100
);
10961101
}
10971102

@@ -1165,14 +1170,22 @@ public function isOpenProjectGroupfolderCreated(): bool {
11651170
public function isGroupfoldersAppEnabled(): bool {
11661171
$user = $this->userManager->get(Application::OPEN_PROJECT_ENTITIES_NAME);
11671172
return (
1168-
class_exists('\OCA\GroupFolders\Folder\FolderManager') &&
11691173
$this->appManager->isEnabledForUser(
11701174
'groupfolders',
11711175
$user
11721176
)
11731177
);
11741178
}
11751179

1180+
public function isGroupfoldersSupported(): bool {
1181+
$groupfoldersVersion = $this->appManager->getAppVersion('groupfolders');
1182+
return (
1183+
$this->isGroupfoldersAppEnabled() &&
1184+
class_exists('\OCA\GroupFolders\Folder\FolderManager') &&
1185+
version_compare($groupfoldersVersion, self::MIN_SUPPORTED_GROUP_FOLDERS_APP_VERSION) >= 0
1186+
);
1187+
}
1188+
11761189
/**
11771190
* @param $auditLogMessage
11781191
* @return void

src/components/AdminSettings.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,8 @@ export default {
10001000
const url = generateUrl('settings/apps/files/groupfolders')
10011001
const htmlLink = `<a class="link" href="${url}" target="_blank" title="${linkText}">${linkText}</a>`
10021002
switch (errorKey) {
1003+
case 'The "Group Folders" app is not supported' :
1004+
return t('integration_openproject', 'Please update the "Group folders" app to be able to use automatically managed folders. {htmlLink}', { htmlLink }, null, { escape: false, sanitize: false })
10031005
case 'The "Group folders" app is not installed' :
10041006
return t('integration_openproject', 'Please install the "Group folders" app to be able to use automatically managed folders. {htmlLink}', { htmlLink }, null, { escape: false, sanitize: false })
10051007
default:

tests/lib/Service/OpenProjectAPIServiceTest.php

Lines changed: 76 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,7 +2303,7 @@ public function testIsProjectFoldersSetupComplete(): void {
23032303
->willReturn(true);
23042304

23052305
$service = $this->getOpenProjectAPIServiceMock(
2306-
['getGroupFolderManager'],
2306+
['getGroupFolderManager', 'isGroupfoldersSupported'],
23072307
[
23082308
'userManager' => $userManagerMock,
23092309
'groupManager' => $groupManagerMock,
@@ -2314,6 +2314,8 @@ public function testIsProjectFoldersSetupComplete(): void {
23142314
$folderManagerMock = $this->getFolderManagerMock();
23152315
$service->method('getGroupFolderManager')
23162316
->willReturn($folderManagerMock);
2317+
$service->method('isGroupfoldersSupported')
2318+
->willReturn(true);
23172319
$this->assertTrue($service->isProjectFoldersSetupComplete());
23182320
}
23192321

@@ -2505,7 +2507,7 @@ public function testIsSystemReadyForProjectFolderSetUp(): void {
25052507
->with('groupfolders', $userMock)
25062508
->willReturn(true);
25072509
$service = $this->getOpenProjectAPIServiceMock(
2508-
['getGroupFolderManager'],
2510+
['getGroupFolderManager', 'isGroupfoldersSupported'],
25092511
[
25102512
'userManager' => $userManagerMock,
25112513
'groupManager' => $groupManagerMock,
@@ -2520,6 +2522,8 @@ public function testIsSystemReadyForProjectFolderSetUp(): void {
25202522
]]);
25212523
$service->method('getGroupFolderManager')
25222524
->willReturn($folderManagerMock);
2525+
$service->method('isGroupfoldersSupported')
2526+
->willReturn(true);
25232527
$result = $service->isSystemReadyForProjectFolderSetUp();
25242528
$this->assertTrue($result);
25252529
}
@@ -2529,18 +2533,20 @@ public function testIsSystemReadyForProjectFolderSetUp(): void {
25292533
*/
25302534
public function isSystemReadyForGroupFolderSetUpUserOrGroupExistsExceptionDataProvider(): array {
25312535
return [
2532-
[true, true, false, false,'The "Group folders" app is not installed'],
2533-
[true, false, false, false,'The user "'. Application::OPEN_PROJECT_ENTITIES_NAME .'" already exists'],
2534-
[false, true, false, false,'The group "'. Application::OPEN_PROJECT_ENTITIES_NAME .'" already exists'],
2535-
[false, false, false, false,'The "Group folders" app is not installed'],
2536-
[false, false, true, true,'The group folder name "'. Application::OPEN_PROJECT_ENTITIES_NAME .'" already exists'],
2536+
[true, true, false, true, false,'The "Group folders" app is not installed'],
2537+
[true, true, true, false, false,'The "Group folders" app is not supported'],
2538+
[true, false, false, true, false,'The user "'. Application::OPEN_PROJECT_ENTITIES_NAME .'" already exists'],
2539+
[false, true, false, true, false,'The group "'. Application::OPEN_PROJECT_ENTITIES_NAME .'" already exists'],
2540+
[false, false, false, true,false,'The "Group folders" app is not installed'],
2541+
[false, false, true, true, true,'The group folder name "'. Application::OPEN_PROJECT_ENTITIES_NAME .'" already exists'],
25372542
];
25382543
}
25392544

25402545
/**
25412546
* @param bool $userExists
25422547
* @param bool $groupExists
25432548
* @param bool $appEnabled
2549+
* @param bool $appSupported
25442550
* @param bool $groupFolderExists
25452551
* @param string $exception
25462552
* @return void
@@ -2550,6 +2556,7 @@ public function testIsSystemReadyForGroupFolderSetUpUserOrGroupExistsException(
25502556
bool $userExists,
25512557
bool $groupExists,
25522558
bool $appEnabled,
2559+
bool $appSupported,
25532560
bool $groupFolderExists,
25542561
string $exception
25552562
): void {
@@ -2577,7 +2584,7 @@ public function testIsSystemReadyForGroupFolderSetUpUserOrGroupExistsException(
25772584
->with('groupfolders', $userMock)
25782585
->willReturn($appEnabled);
25792586
$service = $this->getOpenProjectAPIServiceMock(
2580-
['getGroupFolderManager'],
2587+
['getGroupFolderManager', 'isGroupfoldersSupported'],
25812588
[
25822589
'userManager' => $userManagerMock,
25832590
'groupManager' => $groupManagerMock,
@@ -2587,6 +2594,8 @@ public function testIsSystemReadyForGroupFolderSetUpUserOrGroupExistsException(
25872594
$folderManagerMock = $this->getFolderManagerMock();
25882595
$service->method('getGroupFolderManager')
25892596
->willReturn($folderManagerMock);
2597+
$service->method('isGroupfoldersSupported')
2598+
->willReturn($appSupported);
25902599
$this->expectException(\Exception::class);
25912600
$this->expectExceptionMessage($exception);
25922601
$service->isSystemReadyForProjectFolderSetUp();
@@ -4385,4 +4394,63 @@ public function testIsUserOIDCAppSupported($appInstalledAndEnabled, $classesExis
43854394
$actualResult = $service->isUserOIDCAppSupported();
43864395
$this->assertEquals($expected, $actualResult);
43874396
}
4397+
4398+
/**
4399+
* Data provider for testIsGroupfoldersSupported
4400+
*/
4401+
public function dataProviderForIsGroupfoldersSupported(): array {
4402+
return [
4403+
'has installed supported groupfolders apps and class exist' => [
4404+
'appInstalledAndEnabled' => true,
4405+
'classesExist' => true,
4406+
'version' => '1.0.0',
4407+
'expected' => true,
4408+
],
4409+
'has supported groupfolders apps installed but class does not exist' => [
4410+
'appInstalledAndEnabled' => true,
4411+
'classesExist' => false,
4412+
'version' => '1.0.0',
4413+
'expected' => false,
4414+
],
4415+
'has groupfolders apps not installed' => [
4416+
'appInstalledAndEnabled' => false,
4417+
'classesExist' => true,
4418+
'version' => '1.0.0',
4419+
'expected' => false,
4420+
],
4421+
'has installed unsupported groupfolders apps version' => [
4422+
'appInstalledAndEnabled' => true,
4423+
'classesExist' => true,
4424+
'version' => '0',
4425+
'expected' => false,
4426+
],
4427+
'has installed groupfolders apps higher version and all classes exist' => [
4428+
'appInstalledAndEnabled' => true,
4429+
'classesExist' => true,
4430+
'version' => '4.0.0',
4431+
'expected' => true,
4432+
]
4433+
];
4434+
}
4435+
4436+
/**
4437+
* @dataProvider dataProviderForIsGroupfoldersSupported
4438+
*/
4439+
public function testIsGroupfoldersSupported($appInstalledAndEnabled, $classesExist, $version, $expected): void {
4440+
$mock = $this->getFunctionMock(__NAMESPACE__, "class_exists");
4441+
$mock->expects($this->any())->willReturn($classesExist);
4442+
4443+
$iAppManagerMock = $this->getMockBuilder(IAppManager::class)->getMock();
4444+
$iAppManagerMock->method('getAppVersion')->with('groupfolders')->willReturn($version);
4445+
4446+
$service = $this->getOpenProjectAPIServiceMock(
4447+
['isGroupfoldersAppEnabled'],
4448+
[
4449+
'appManager' => $iAppManagerMock,
4450+
],
4451+
);
4452+
$service->method('isGroupfoldersAppEnabled')->willReturn($appInstalledAndEnabled);
4453+
$actualResult = $service->isGroupfoldersSupported();
4454+
$this->assertEquals($expected, $actualResult);
4455+
}
43884456
}

0 commit comments

Comments
 (0)