Skip to content

Commit e356aef

Browse files
committed
display error if groupfolders app not supported
Signed-off-by: nabim777 <[email protected]>
1 parent 1643e0a commit e356aef

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 = '7.0.0';
7071
public const MIN_SUPPORTED_OIDC_APP_VERSION = '1.4.0';
7172
public const NEXTCLOUD_HUB_PROVIDER = "nextcloud_hub";
@@ -1072,6 +1073,9 @@ public function isSystemReadyForProjectFolderSetUp(): bool {
10721073
if (!$this->isGroupfoldersAppEnabled()) {
10731074
throw new \Exception('The "Group folders" app is not installed');
10741075
}
1076+
if (!$this->isGroupfoldersSupported()) {
1077+
throw new \Exception('The "Group folders" app is not supported');
1078+
}
10751079
}
10761080
if ($this->userManager->userExists(Application::OPEN_PROJECT_ENTITIES_NAME)) {
10771081
throw new OpenprojectGroupfolderSetupConflictException('The user "'. Application::OPEN_PROJECT_ENTITIES_NAME .'" already exists');
@@ -1100,7 +1104,8 @@ public function isProjectFoldersSetupComplete(): bool {
11001104
$this->groupManager->groupExists(Application::OPEN_PROJECT_ENTITIES_NAME) &&
11011105
$this->isUserPartOfAndAdminOfGroup() &&
11021106
$this->isGroupfoldersAppEnabled() &&
1103-
$this->isGroupfolderAppCorrectlySetup()
1107+
$this->isGroupfolderAppCorrectlySetup() &&
1108+
$this->isGroupfoldersSupported()
11041109
);
11051110
}
11061111

@@ -1174,14 +1179,22 @@ public function isOpenProjectGroupfolderCreated(): bool {
11741179
public function isGroupfoldersAppEnabled(): bool {
11751180
$user = $this->userManager->get(Application::OPEN_PROJECT_ENTITIES_NAME);
11761181
return (
1177-
class_exists('\OCA\GroupFolders\Folder\FolderManager') &&
11781182
$this->appManager->isEnabledForUser(
11791183
'groupfolders',
11801184
$user
11811185
)
11821186
);
11831187
}
11841188

1189+
public function isGroupfoldersSupported(): bool {
1190+
$groupfoldersVersion = $this->appManager->getAppVersion('groupfolders');
1191+
return (
1192+
$this->isGroupfoldersAppEnabled() &&
1193+
class_exists('\OCA\GroupFolders\Folder\FolderManager') &&
1194+
version_compare($groupfoldersVersion, self::MIN_SUPPORTED_GROUP_FOLDERS_APP_VERSION) >= 0
1195+
);
1196+
}
1197+
11851198
/**
11861199
* @param $auditLogMessage
11871200
* @return void

src/components/AdminSettings.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,8 @@ export default {
10671067
const url = generateUrl('settings/apps/files/groupfolders')
10681068
const htmlLink = `<a class="link" href="${url}" target="_blank" title="${linkText}">${linkText}</a>`
10691069
switch (errorKey) {
1070+
case 'The "Group folders" app is not supported' :
1071+
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 })
10701072
case 'The "Group folders" app is not installed' :
10711073
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 })
10721074
default:

tests/lib/Service/OpenProjectAPIServiceTest.php

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

22762276
$service = $this->getOpenProjectAPIServiceMock(
2277-
['getGroupFolderManager'],
2277+
['getGroupFolderManager', 'isGroupfoldersSupported'],
22782278
[
22792279
'userManager' => $userManagerMock,
22802280
'groupManager' => $groupManagerMock,
@@ -2285,6 +2285,8 @@ public function testIsProjectFoldersSetupComplete(): void {
22852285
$folderManagerMock = $this->getFolderManagerMock();
22862286
$service->method('getGroupFolderManager')
22872287
->willReturn($folderManagerMock);
2288+
$service->method('isGroupfoldersSupported')
2289+
->willReturn(true);
22882290
$this->assertTrue($service->isProjectFoldersSetupComplete());
22892291
}
22902292

@@ -2476,7 +2478,7 @@ public function testIsSystemReadyForProjectFolderSetUp(): void {
24762478
->with('groupfolders', $userMock)
24772479
->willReturn(true);
24782480
$service = $this->getOpenProjectAPIServiceMock(
2479-
['getGroupFolderManager'],
2481+
['getGroupFolderManager', 'isGroupfoldersSupported'],
24802482
[
24812483
'userManager' => $userManagerMock,
24822484
'groupManager' => $groupManagerMock,
@@ -2491,6 +2493,8 @@ public function testIsSystemReadyForProjectFolderSetUp(): void {
24912493
]]);
24922494
$service->method('getGroupFolderManager')
24932495
->willReturn($folderManagerMock);
2496+
$service->method('isGroupfoldersSupported')
2497+
->willReturn(true);
24942498
$result = $service->isSystemReadyForProjectFolderSetUp();
24952499
$this->assertTrue($result);
24962500
}
@@ -2500,18 +2504,20 @@ public function testIsSystemReadyForProjectFolderSetUp(): void {
25002504
*/
25012505
public function isSystemReadyForGroupFolderSetUpUserOrGroupExistsExceptionDataProvider(): array {
25022506
return [
2503-
[true, true, false, false,'The "Group folders" app is not installed'],
2504-
[true, false, false, false,'The user "'. Application::OPEN_PROJECT_ENTITIES_NAME .'" already exists'],
2505-
[false, true, false, false,'The group "'. Application::OPEN_PROJECT_ENTITIES_NAME .'" already exists'],
2506-
[false, false, false, false,'The "Group folders" app is not installed'],
2507-
[false, false, true, true,'The group folder name "'. Application::OPEN_PROJECT_ENTITIES_NAME .'" already exists'],
2507+
[true, true, false, true, false,'The "Group folders" app is not installed'],
2508+
[true, true, true, false, false,'The "Group folders" app is not supported'],
2509+
[true, false, false, true, false,'The user "'. Application::OPEN_PROJECT_ENTITIES_NAME .'" already exists'],
2510+
[false, true, false, true, false,'The group "'. Application::OPEN_PROJECT_ENTITIES_NAME .'" already exists'],
2511+
[false, false, false, true,false,'The "Group folders" app is not installed'],
2512+
[false, false, true, true, true,'The group folder name "'. Application::OPEN_PROJECT_ENTITIES_NAME .'" already exists'],
25082513
];
25092514
}
25102515

25112516
/**
25122517
* @param bool $userExists
25132518
* @param bool $groupExists
25142519
* @param bool $appEnabled
2520+
* @param bool $appSupported
25152521
* @param bool $groupFolderExists
25162522
* @param string $exception
25172523
* @return void
@@ -2521,6 +2527,7 @@ public function testIsSystemReadyForGroupFolderSetUpUserOrGroupExistsException(
25212527
bool $userExists,
25222528
bool $groupExists,
25232529
bool $appEnabled,
2530+
bool $appSupported,
25242531
bool $groupFolderExists,
25252532
string $exception
25262533
): void {
@@ -2548,7 +2555,7 @@ public function testIsSystemReadyForGroupFolderSetUpUserOrGroupExistsException(
25482555
->with('groupfolders', $userMock)
25492556
->willReturn($appEnabled);
25502557
$service = $this->getOpenProjectAPIServiceMock(
2551-
['getGroupFolderManager'],
2558+
['getGroupFolderManager', 'isGroupfoldersSupported'],
25522559
[
25532560
'userManager' => $userManagerMock,
25542561
'groupManager' => $groupManagerMock,
@@ -2558,6 +2565,8 @@ public function testIsSystemReadyForGroupFolderSetUpUserOrGroupExistsException(
25582565
$folderManagerMock = $this->getFolderManagerMock();
25592566
$service->method('getGroupFolderManager')
25602567
->willReturn($folderManagerMock);
2568+
$service->method('isGroupfoldersSupported')
2569+
->willReturn($appSupported);
25612570
$this->expectException(\Exception::class);
25622571
$this->expectExceptionMessage($exception);
25632572
$service->isSystemReadyForProjectFolderSetUp();
@@ -4421,4 +4430,63 @@ public function testIsOIDCAppSupported($appEnabled, $version, $expected): void {
44214430
$actualResult = $service->isOIDCAppSupported();
44224431
$this->assertEquals($expected, $actualResult);
44234432
}
4433+
4434+
/**
4435+
* Data provider for testIsGroupfoldersSupported
4436+
*/
4437+
public function dataProviderForIsGroupfoldersSupported(): array {
4438+
return [
4439+
'has installed supported groupfolders apps and class exist' => [
4440+
'appInstalledAndEnabled' => true,
4441+
'classesExist' => true,
4442+
'version' => '1.0.0',
4443+
'expected' => true,
4444+
],
4445+
'has supported groupfolders apps installed but class does not exist' => [
4446+
'appInstalledAndEnabled' => true,
4447+
'classesExist' => false,
4448+
'version' => '1.0.0',
4449+
'expected' => false,
4450+
],
4451+
'has groupfolders apps not installed' => [
4452+
'appInstalledAndEnabled' => false,
4453+
'classesExist' => true,
4454+
'version' => '1.0.0',
4455+
'expected' => false,
4456+
],
4457+
'has installed unsupported groupfolders apps version' => [
4458+
'appInstalledAndEnabled' => true,
4459+
'classesExist' => true,
4460+
'version' => '0',
4461+
'expected' => false,
4462+
],
4463+
'has installed groupfolders apps higher version and all classes exist' => [
4464+
'appInstalledAndEnabled' => true,
4465+
'classesExist' => true,
4466+
'version' => '4.0.0',
4467+
'expected' => true,
4468+
]
4469+
];
4470+
}
4471+
4472+
/**
4473+
* @dataProvider dataProviderForIsGroupfoldersSupported
4474+
*/
4475+
public function testIsGroupfoldersSupported($appInstalledAndEnabled, $classesExist, $version, $expected): void {
4476+
$mock = $this->getFunctionMock(__NAMESPACE__, "class_exists");
4477+
$mock->expects($this->any())->willReturn($classesExist);
4478+
4479+
$iAppManagerMock = $this->getMockBuilder(IAppManager::class)->getMock();
4480+
$iAppManagerMock->method('getAppVersion')->with('groupfolders')->willReturn($version);
4481+
4482+
$service = $this->getOpenProjectAPIServiceMock(
4483+
['isGroupfoldersAppEnabled'],
4484+
[
4485+
'appManager' => $iAppManagerMock,
4486+
],
4487+
);
4488+
$service->method('isGroupfoldersAppEnabled')->willReturn($appInstalledAndEnabled);
4489+
$actualResult = $service->isGroupfoldersSupported();
4490+
$this->assertEquals($expected, $actualResult);
4491+
}
44244492
}

0 commit comments

Comments
 (0)