Skip to content

Commit

Permalink
Merge pull request #478 from nextcloud/backport/472
Browse files Browse the repository at this point in the history
[Backport/472] Add capabilities
  • Loading branch information
SwikritiT committed Aug 31, 2023
2 parents 4d27c18 + 87ac06e commit f456f12
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Closure;
use OCA\Files\Event\LoadSidebar;
use OCA\OpenProject\Capabilities;
use OCA\OpenProject\Listener\BeforeNodeInsideOpenProjectGroupfilderChangedListener;
use OCA\OpenProject\Listener\BeforeUserDeletedListener;
use OCA\OpenProject\Listener\BeforeGroupDeletedListener;
Expand Down Expand Up @@ -65,6 +66,7 @@ public function __construct(array $urlParams = []) {
}

public function register(IRegistrationContext $context): void {
$context->registerCapability(Capabilities::class);
$context->registerDashboardWidget(OpenProjectWidget::class);
$context->registerSearchProvider(OpenProjectSearchProvider::class);

Expand Down
37 changes: 37 additions & 0 deletions lib/Capabilities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace OCA\OpenProject;

use OCA\OpenProject\AppInfo\Application;
use OCP\App\IAppManager;
use OCP\Capabilities\IPublicCapability;

class Capabilities implements IPublicCapability {

/** @var IAppManager */
private $appManager;

public function __construct(
IAppManager $appManager
) {
$this->appManager = $appManager;
}

/**
* @return array<string, array<string, bool|string>>
*/
public function getCapabilities(): array {
$appVersion = $this->appManager->getAppVersion(Application::APP_ID);
$groupfoldersVersion = $this->appManager->getAppVersion('groupfolders');
$groupfoldersEnabled = $this->appManager->isEnabledForUser('groupfolders');
return [
Application::APP_ID => [
'app_version' => $appVersion,
'groupfolder_version' => $groupfoldersVersion,
'groupfolders_enabled' => $groupfoldersEnabled,
],
];
}
}
48 changes: 48 additions & 0 deletions tests/acceptance/features/api/capabilities.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Feature: get capabilities of the app

Scenario: Get capabilities when group folder app is enabled
When the administrator requests the nextcloud capabilities
Then the HTTP status code should be "200"
And the ocs data of the response should match
""""
{
"type": "object",
"required": [
"capabilities"
],
"properties": {
"capabilities": {
"type": "object",
"required": [
"integration_openproject"
],
"properties": {
"integration_openproject": {
"type": "object",
"required": [
"app_version",
"groupfolder_version",
"groupfolders_enabled"
],
"properties": {
"app_version": {
"type": "string",
"pattern": "^\\d+\\.\\d+\\.\\d+$"
},
"groupfolder_version": {
"type": "string",
"pattern": "^\\d+\\.\\d+\\.\\d+(\\-\\w+)?$"
},
"groupfolders_enabled": {
"type": "boolean",
"enum": [
true
]
}
}
}
}
}
}
}
"""
10 changes: 10 additions & 0 deletions tests/acceptance/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,16 @@ public function theUserSendsARequestToTheEndpoint(
);
}

/**
* @When the administrator requests the nextcloud capabilities
*
* @return void
*/
public function theAdministratorRequestsCapabilities(): void {
$this->response = $this->sendOCSRequest(
'/cloud/capabilities', 'GET', $this->getAdminUsername()
);
}

/**
* @Then /^the content of file at "([^"]*)" for user "([^"]*)" should be "([^"]*)"$/
Expand Down

0 comments on commit f456f12

Please sign in to comment.