Skip to content

Commit 087dc14

Browse files
committed
display error if groupfolders app not supported
Signed-off-by: nabim777 <[email protected]>
1 parent 7e87043 commit 087dc14

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
/**
7071
* @var string
7172
*/
@@ -1063,6 +1064,9 @@ public function isSystemReadyForProjectFolderSetUp(): bool {
10631064
throw new \Exception('The "Group folders" app is not installed');
10641065
}
10651066
}
1067+
if (!$this->isGroupfoldersSupported()) {
1068+
throw new \Exception('The "Group folders" app is not supported');
1069+
}
10661070
if ($this->userManager->userExists(Application::OPEN_PROJECT_ENTITIES_NAME)) {
10671071
throw new OpenprojectGroupfolderSetupConflictException('The user "'. Application::OPEN_PROJECT_ENTITIES_NAME .'" already exists');
10681072
} elseif ($this->groupManager->groupExists(Application::OPEN_PROJECT_ENTITIES_NAME)) {
@@ -1090,7 +1094,8 @@ public function isProjectFoldersSetupComplete(): bool {
10901094
$this->groupManager->groupExists(Application::OPEN_PROJECT_ENTITIES_NAME) &&
10911095
$this->isUserPartOfAndAdminOfGroup() &&
10921096
$this->isGroupfoldersAppEnabled() &&
1093-
$this->isGroupfolderAppCorrectlySetup()
1097+
$this->isGroupfolderAppCorrectlySetup() &&
1098+
$this->isGroupfoldersSupported()
10941099
);
10951100
}
10961101

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

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

src/components/AdminSettings.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,8 @@ export default {
982982
const url = generateUrl('settings/apps/files/groupfolders')
983983
const htmlLink = `<a class="link" href="${url}" target="_blank" title="${linkText}">${linkText}</a>`
984984
switch (errorKey) {
985+
case 'The "Group Folders" app is not supported' :
986+
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 })
985987
case 'The "Group folders" app is not installed' :
986988
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 })
987989
default:

tests/lib/Service/OpenProjectAPIServiceTest.php

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

23012301
$service = $this->getOpenProjectAPIServiceMock(
2302-
['getGroupFolderManager'],
2302+
['getGroupFolderManager', 'isGroupfoldersSupported'],
23032303
[
23042304
'userManager' => $userManagerMock,
23052305
'groupManager' => $groupManagerMock,
@@ -2310,6 +2310,8 @@ public function testIsProjectFoldersSetupComplete(): void {
23102310
$folderManagerMock = $this->getFolderManagerMock();
23112311
$service->method('getGroupFolderManager')
23122312
->willReturn($folderManagerMock);
2313+
$service->method('isGroupfoldersSupported')
2314+
->willReturn(true);
23132315
$this->assertTrue($service->isProjectFoldersSetupComplete());
23142316
}
23152317

@@ -2501,7 +2503,7 @@ public function testIsSystemReadyForProjectFolderSetUp(): void {
25012503
->with('groupfolders', $userMock)
25022504
->willReturn(true);
25032505
$service = $this->getOpenProjectAPIServiceMock(
2504-
['getGroupFolderManager'],
2506+
['getGroupFolderManager', 'isGroupfoldersSupported'],
25052507
[
25062508
'userManager' => $userManagerMock,
25072509
'groupManager' => $groupManagerMock,
@@ -2516,6 +2518,8 @@ public function testIsSystemReadyForProjectFolderSetUp(): void {
25162518
]]);
25172519
$service->method('getGroupFolderManager')
25182520
->willReturn($folderManagerMock);
2521+
$service->method('isGroupfoldersSupported')
2522+
->willReturn(true);
25192523
$result = $service->isSystemReadyForProjectFolderSetUp();
25202524
$this->assertTrue($result);
25212525
}
@@ -2525,18 +2529,20 @@ public function testIsSystemReadyForProjectFolderSetUp(): void {
25252529
*/
25262530
public function isSystemReadyForGroupFolderSetUpUserOrGroupExistsExceptionDataProvider(): array {
25272531
return [
2528-
[true, true, false, false,'The "Group folders" app is not installed'],
2529-
[true, false, false, false,'The user "'. Application::OPEN_PROJECT_ENTITIES_NAME .'" already exists'],
2530-
[false, true, false, false,'The group "'. Application::OPEN_PROJECT_ENTITIES_NAME .'" already exists'],
2531-
[false, false, false, false,'The "Group folders" app is not installed'],
2532-
[false, false, true, true,'The group folder name "'. Application::OPEN_PROJECT_ENTITIES_NAME .'" already exists'],
2532+
[true, true, false, true, false,'The "Group folders" app is not installed'],
2533+
[true, true, true, false, false,'The "Group folders" app is not supported'],
2534+
[true, false, false, true, false,'The user "'. Application::OPEN_PROJECT_ENTITIES_NAME .'" already exists'],
2535+
[false, true, false, true, false,'The group "'. Application::OPEN_PROJECT_ENTITIES_NAME .'" already exists'],
2536+
[false, false, false, true,false,'The "Group folders" app is not installed'],
2537+
[false, false, true, true, true,'The group folder name "'. Application::OPEN_PROJECT_ENTITIES_NAME .'" already exists'],
25332538
];
25342539
}
25352540

25362541
/**
25372542
* @param bool $userExists
25382543
* @param bool $groupExists
25392544
* @param bool $appEnabled
2545+
* @param bool $appSupported
25402546
* @param bool $groupFolderExists
25412547
* @param string $exception
25422548
* @return void
@@ -2546,6 +2552,7 @@ public function testIsSystemReadyForGroupFolderSetUpUserOrGroupExistsException(
25462552
bool $userExists,
25472553
bool $groupExists,
25482554
bool $appEnabled,
2555+
bool $appSupported,
25492556
bool $groupFolderExists,
25502557
string $exception
25512558
): void {
@@ -2573,7 +2580,7 @@ public function testIsSystemReadyForGroupFolderSetUpUserOrGroupExistsException(
25732580
->with('groupfolders', $userMock)
25742581
->willReturn($appEnabled);
25752582
$service = $this->getOpenProjectAPIServiceMock(
2576-
['getGroupFolderManager'],
2583+
['getGroupFolderManager', 'isGroupfoldersSupported'],
25772584
[
25782585
'userManager' => $userManagerMock,
25792586
'groupManager' => $groupManagerMock,
@@ -2583,6 +2590,8 @@ public function testIsSystemReadyForGroupFolderSetUpUserOrGroupExistsException(
25832590
$folderManagerMock = $this->getFolderManagerMock();
25842591
$service->method('getGroupFolderManager')
25852592
->willReturn($folderManagerMock);
2593+
$service->method('isGroupfoldersSupported')
2594+
->willReturn($appSupported);
25862595
$this->expectException(\Exception::class);
25872596
$this->expectExceptionMessage($exception);
25882597
$service->isSystemReadyForProjectFolderSetUp();
@@ -4316,4 +4325,63 @@ public function testIsOIDCUser($backend, $oidcUser, $expected): void {
43164325
$result = $service->isOIDCUser();
43174326
$this->assertEquals($expected, $result);
43184327
}
4328+
4329+
/**
4330+
* Data provider for testIsGroupfoldersSupported
4331+
*/
4332+
public function dataProviderForIsGroupfoldersSupported(): array {
4333+
return [
4334+
'has installed supported groupfolders apps and class exist' => [
4335+
'appInstalledAndEnabled' => true,
4336+
'classesExist' => true,
4337+
'version' => '1.0.0',
4338+
'expected' => true,
4339+
],
4340+
'has supported groupfolders apps installed but class does not exist' => [
4341+
'appInstalledAndEnabled' => true,
4342+
'classesExist' => false,
4343+
'version' => '1.0.0',
4344+
'expected' => false,
4345+
],
4346+
'has groupfolders apps not installed' => [
4347+
'appInstalledAndEnabled' => false,
4348+
'classesExist' => true,
4349+
'version' => '1.0.0',
4350+
'expected' => false,
4351+
],
4352+
'has installed unsupported groupfolders apps version' => [
4353+
'appInstalledAndEnabled' => true,
4354+
'classesExist' => true,
4355+
'version' => '0',
4356+
'expected' => false,
4357+
],
4358+
'has installed groupfolders apps higher version and all classes exist' => [
4359+
'appInstalledAndEnabled' => true,
4360+
'classesExist' => true,
4361+
'version' => '4.0.0',
4362+
'expected' => true,
4363+
]
4364+
];
4365+
}
4366+
4367+
/**
4368+
* @dataProvider dataProviderForIsGroupfoldersSupported
4369+
*/
4370+
public function testIsGroupfoldersSupported($appInstalledAndEnabled, $classesExist, $version, $expected): void {
4371+
$mock = $this->getFunctionMock(__NAMESPACE__, "class_exists");
4372+
$mock->expects($this->any())->willReturn($classesExist);
4373+
4374+
$iAppManagerMock = $this->getMockBuilder(IAppManager::class)->getMock();
4375+
$iAppManagerMock->method('getAppVersion')->with('groupfolders')->willReturn($version);
4376+
4377+
$service = $this->getOpenProjectAPIServiceMock(
4378+
['isGroupfoldersAppEnabled'],
4379+
[
4380+
'appManager' => $iAppManagerMock,
4381+
],
4382+
);
4383+
$service->method('isGroupfoldersAppEnabled')->willReturn($appInstalledAndEnabled);
4384+
$actualResult = $service->isGroupfoldersSupported();
4385+
$this->assertEquals($expected, $actualResult);
4386+
}
43194387
}

0 commit comments

Comments
 (0)