Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for nextcloud master #704

Merged
merged 10 commits into from
Oct 7, 2024
Merged
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
8 changes: 7 additions & 1 deletion .github/workflows/shared_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: unit tests and linting
strategy:
matrix:
nextcloudVersion: [ stable30 ]
nextcloudVersion: [ stable30, master ]
phpVersion: [ 8.1, 8.2, 8.3 ]
include:
- nextcloudVersion: stable27
Expand All @@ -20,6 +20,8 @@ jobs:
phpVersion: 8.1
- nextcloudVersion: stable29
phpVersion: 8.1
- nextcloudVersion: master
phpVersion: 8.3
runs-on: ubuntu-20.04
steps:
- name: Checkout for nightly CI
Expand Down Expand Up @@ -202,6 +204,10 @@ jobs:
phpVersionMajor: 8
phpVersionMinor: 1
database: mysql
- nextcloudVersion: master
phpVersionMajor: 8
phpVersionMinor: 3
database: mysql
runs-on: ubuntu-20.04
container:
image: public.ecr.aws/ubuntu/ubuntu:latest
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Changed
- Add application's support for Nextcloud 31

## 2.7.0 - 2024-09-10
### Changed
Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ For more information on how to set up and use the OpenProject application, pleas
<screenshot>https://github.com/nextcloud/integration_openproject/raw/master/img/screenshot1.png</screenshot>
<screenshot>https://github.com/nextcloud/integration_openproject/raw/master/img/screenshot2.png</screenshot>
<dependencies>
<nextcloud min-version="27" max-version="30" />
<nextcloud min-version="27" max-version="31" />
</dependencies>
<background-jobs>
<job>OCA\OpenProject\BackgroundJob\RemoveExpiredDirectUploadTokens</job>
Expand Down
7 changes: 2 additions & 5 deletions lib/Listener/LoadAdditionalScriptsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace OCA\OpenProject\Listener;

use OC_Util;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\OpenProject\AppInfo\Application;
use OCA\OpenProject\ServerVersionHelper;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Util;
Expand All @@ -13,15 +13,12 @@
* @template-implements IEventListener<Event>
*/
class LoadAdditionalScriptsListener implements IEventListener {
public function __construct() {
}

public function handle(Event $event): void {
if (!$event instanceof LoadAdditionalScriptsEvent) {
return;
}

if (version_compare(OC_Util::getVersionString(), '28') < 0) {
if (version_compare(ServerVersionHelper::getNextcloudVersion(), '28') < 0) {
Util::addScript(Application::APP_ID, Application::APP_ID . '-fileActions');
Util::addScript(Application::APP_ID, Application::APP_ID . '-filesPluginLessThan28', 'files');
} else {
Expand Down
24 changes: 24 additions & 0 deletions lib/ServerVersionHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace OCA\OpenProject;

use OC_Util;

class ServerVersionHelper {
/**
* Get Nextcloud version string.
*
* @return string
*/
public static function getNextcloudVersion(): string {
// for nextcloud above 31 OC_Util::getVersionString() method does not exists
if (class_exists('OCP\ServerVersion')) {
return (new \OCP\ServerVersion())->getVersionString();
}

/** @psalm-suppress UndefinedMethod getVersionString() method is not in stable31 so making psalm not complain */
return OC_Util::getVersionString();
}
}
5 changes: 2 additions & 3 deletions lib/Service/OauthService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

namespace OCA\OpenProject\Service;

use OC_Util;
use OCA\OAuth2\Db\Client;
use OCA\OAuth2\Db\ClientMapper;
use OCA\OAuth2\Exceptions\ClientNotFoundException;
use OCA\OpenProject\ServerVersionHelper;
use OCP\Security\ICrypto;
use OCP\Security\ISecureRandom;

Expand All @@ -29,7 +29,6 @@ class OauthService {
* @var ClientMapper
*/
private $clientMapper;

/**
* @var ICrypto
*/
Expand Down Expand Up @@ -81,7 +80,7 @@ public function createNcOauthClient(string $name, string $redirectUri): array {
$client->setName($name);
$client->setRedirectUri(sprintf($redirectUri, $clientId));
$secret = $this->secureRandom->generate(64, self::validChars);
$nextcloudVersion = OC_Util::getVersionString();
$nextcloudVersion = ServerVersionHelper::getNextcloudVersion();
$client->setSecret($this->hashOrEncryptSecretBasedOnNextcloudVersion($secret, $nextcloudVersion));
$client->setClientIdentifier($clientId);
$client = $this->clientMapper->insert($client);
Expand Down
10 changes: 9 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@
<!-- these classes belong to the event app, which isn't compulsory, so might not exist while running psalm -->
<referencedClass name="OCP\App\Events\AppEnableEvent" />
<referencedClass name="OCA\AdminAudit\AuditLogger" />

<!-- this class is only in Nextcloud version 31 and does not exist while running psalm on lower version-->
<referencedClass name="OCP\ServerVersion" />
</errorLevel>
</UndefinedClass>
<UndefinedMethod>
<errorLevel type="suppress">
<referencedMethod name="OC\legacy\OC_Util::getVersionString()"/>
</errorLevel>
</UndefinedMethod>
<TooFewArguments>
<errorLevel type="suppress">
<!-- supress because constructor needs more arguments on nc version 27 > and the code has conditions to handel this for lower versions-->
Expand Down Expand Up @@ -81,6 +87,8 @@
<referencedClass name="OCA\Activity\UserSettings" />
<referencedClass name="OCA\Activity\GroupHelperDisabled" />
<referencedClass name="OCA\Activity\Data" />
<!-- this class is only in Nextcloud version 31 and does not exist while running psalm on lower version-->
<referencedClass name="OCP\ServerVersion" />
</errorLevel>
</UndefinedDocblockClass>
</issueHandlers>
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ public function theHTTPStatusCodeShouldBe(
if (\is_array($expectedStatusCode)) {
if ($message === "") {
$message = "HTTP status code $actualStatusCode is not one of the expected values " .
\implode(" or ", $expectedStatusCode);
\implode(" or ", $expectedStatusCode);
}

Assert::assertContainsEquals(
Expand Down
36 changes: 31 additions & 5 deletions tests/acceptance/features/bootstrap/GroupfoldersContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ class GroupfoldersContext implements Context {
/** @var array<mixed> */
private array $createdGroupFolders = [];

/**
* @var string|null
*/
private ?string $groupfolderDavPath = null;

/**
* @Given group folder :folderName has been created
*/
public function groupFolderHasBeenCreated(string $folderName): void {
$fullUrl = $this->featureContext->getBaseUrl() .
"index.php/apps/groupfolders/folders";

$this->getGroupfolderDavPath() . "apps/groupfolders/folders";
$headers['OCS-APIRequest'] = 'true';
$options = [
'multipart' => [
Expand Down Expand Up @@ -54,7 +57,7 @@ public function groupFolderHasBeenCreated(string $folderName): void {
public function groupHasBeenAddedToGroupFolder(string $group, string $groupfolder):void {
$groupfolderId = $this->createdGroupFolders[$groupfolder];
$fullUrl = $this->featureContext->getBaseUrl() .
"index.php/apps/groupfolders/folders/".$groupfolderId. "/groups";
$this->getGroupfolderDavPath(). "apps/groupfolders/folders/".$groupfolderId. "/groups";
$headers['OCS-APIRequest'] = 'true';
$options = [
'multipart' => [
Expand Down Expand Up @@ -158,7 +161,7 @@ private function getGroupfolderByMountpoint(string $mountpoint): array {
*/
private function getAllGroupfolders() {
$fullUrl = $this->featureContext->getBaseUrl() .
"index.php/apps/groupfolders/folders?format=json";
$this->getGroupfolderDavPath(). "apps/groupfolders/folders?format=json";

$headers['Content-Type'] = 'application/json';
$headers['OCS-APIRequest'] = 'true';
Expand All @@ -178,7 +181,7 @@ private function getAllGroupfolders() {

private function adminDeletesGroupfolder(int $id): void {
$fullUrl = $this->featureContext->getBaseUrl() .
"index.php/apps/groupfolders/folders/" . $id;
$this->getGroupfolderDavPath(). "apps/groupfolders/folders/" . $id;
$headers['OCS-APIRequest'] = 'true';
$this->featureContext->sendHttpRequest(
$fullUrl,
Expand All @@ -189,6 +192,29 @@ private function adminDeletesGroupfolder(int $id): void {
);
}

/**
* @return string
* @throws GuzzleException
*/
private function getGroupfolderDavPath(): string {
// groupfolder with version greater than or equals to 19.0.0 uses "ocs/v2.php/" endpoint
if ($this->groupfolderDavPath !== null) {
return $this->groupfolderDavPath;
}
$capabilitiesResponse = $this->featureContext->sendOCSRequest(
'/cloud/capabilities', 'GET', $this->featureContext->getAdminUsername()
);
$this->featureContext->theHTTPStatusCodeShouldBe(200, "", $capabilitiesResponse);
$responseAsJson = json_decode($capabilitiesResponse->getBody()->getContents());
$groupFolderVersion = $responseAsJson->ocs->data->capabilities->integration_openproject->groupfolder_version ?? null;
Assert::assertNotNull($groupFolderVersion, 'Group folder version not found in the response');
if (version_compare($groupFolderVersion, '19') >= 0) {
return $this->groupfolderDavPath = "ocs/v2.php/";
}
return $this->groupfolderDavPath = "index.php/";
}


/**
* This will run before EVERY scenario.
* It will set the properties for this object.
Expand Down
Loading