Skip to content

Commit

Permalink
review address
Browse files Browse the repository at this point in the history
Signed-off-by: nabim777 <[email protected]>
  • Loading branch information
nabim777 committed Oct 3, 2024
1 parent 9654f47 commit 3939420
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 310 deletions.
438 changes: 216 additions & 222 deletions .github/workflows/shared_workflow.yml

Large diffs are not rendered by default.

14 changes: 2 additions & 12 deletions lib/Listener/LoadAdditionalScriptsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\OpenProject\AppInfo\Application;
use OCA\OpenProject\VersionUtil;
use OCA\OpenProject\ServerVersionHelper;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Util;
Expand All @@ -13,22 +13,12 @@
* @template-implements IEventListener<Event>
*/
class LoadAdditionalScriptsListener implements IEventListener {
/**
* @var VersionUtil
*/
private $versionUtil;

public function __construct(
VersionUtil $versionUtil
) {
$this->versionUtil = $versionUtil;
}

public function handle(Event $event): void {
if (!$event instanceof LoadAdditionalScriptsEvent) {
return;
}
$nextcloudVersion = $this->versionUtil->getNextcloudVersion();
$nextcloudVersion = ServerVersionHelper::getNextcloudVersion();
if (version_compare($nextcloudVersion, '28') < 0) {
Util::addScript(Application::APP_ID, Application::APP_ID . '-fileActions');
Util::addScript(Application::APP_ID, Application::APP_ID . '-filesPluginLessThan28', 'files');
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();
}
}
14 changes: 3 additions & 11 deletions lib/Service/OauthService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use OCA\OAuth2\Db\Client;
use OCA\OAuth2\Db\ClientMapper;
use OCA\OAuth2\Exceptions\ClientNotFoundException;
use OCA\OpenProject\VersionUtil;
use OCA\OpenProject\ServerVersionHelper;
use OCP\Security\ICrypto;
use OCP\Security\ISecureRandom;

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

/**
* @var VersionUtil
*/
private $versionUtil;

/**
* @var ICrypto
*/
Expand All @@ -45,13 +39,11 @@ class OauthService {
*/
public function __construct(ClientMapper $clientMapper,
ISecureRandom $secureRandom,
ICrypto $crypto,
VersionUtil $versionUtil
ICrypto $crypto
) {
$this->secureRandom = $secureRandom;
$this->clientMapper = $clientMapper;
$this->crypto = $crypto;
$this->versionUtil = $versionUtil;
}

/**
Expand Down Expand Up @@ -88,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 = $this->versionUtil->getNextcloudVersion();
$nextcloudVersion = ServerVersionHelper::getNextcloudVersion();
$client->setSecret($this->hashOrEncryptSecretBasedOnNextcloudVersion($secret, $nextcloudVersion));
$client->setClientIdentifier($clientId);
$client = $this->clientMapper->insert($client);
Expand Down
37 changes: 0 additions & 37 deletions lib/VersionUtil.php

This file was deleted.

41 changes: 20 additions & 21 deletions tests/acceptance/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,7 @@ public function verifyTableNodeRows(TableNode $table, array $requiredRows = [],
* @param BeforeScenarioScope $scope
*
* @return void
* @throws Exception
*/
public function before(BeforeScenarioScope $scope):void {
setlocale(LC_ALL, 'C.utf8');
Expand All @@ -1174,35 +1175,17 @@ public function before(BeforeScenarioScope $scope):void {
$this->sharingContext = $environment->getContext('SharingContext');
$this->directUploadContext = $environment->getContext('DirectUploadContext');
}
}

/**
* @AfterScenario
*
* @return void
* @throws Exception
*/
public function after():void {
foreach ($this->createdUsers as $userData) {
$this->theAdministratorDeletesTheUser($userData['userid']);
}
foreach ($this->createdgroups as $groups) {
$this->theAdministratorDeletesTheGroup($groups);
}
$this->createdAppPasswords = [];
$this->setGroupfolderDavPath();
}

/**
* This will run before EVERY scenario.
* It will set the group folder dev path
*
* @BeforeScenario
* It will set the group folder DAV path
*
* @param BeforeScenarioScope $scope
* @return void
* @throws Exception
*/
final public function setgroupfolderDavPath(BeforeScenarioScope $scope): void {
private function setGroupfolderDavPath(): void {
// groupfolder with version greater then 19.0.0 uses "ocs/v2.php/" endpoint
$capabilitiesResponse = $this->sendOCSRequest(
'/cloud/capabilities', 'GET', $this->getAdminUsername()
Expand All @@ -1216,4 +1199,20 @@ final public function setgroupfolderDavPath(BeforeScenarioScope $scope): void {
$this->groupFolderDavPath = "ocs/v2.php/";
}
}

/**
* @AfterScenario
*
* @return void
* @throws Exception
*/
public function after():void {
foreach ($this->createdUsers as $userData) {
$this->theAdministratorDeletesTheUser($userData['userid']);
}
foreach ($this->createdgroups as $groups) {
$this->theAdministratorDeletesTheGroup($groups);
}
$this->createdAppPasswords = [];
}
}
7 changes: 0 additions & 7 deletions tests/lib/Service/OauthSeviceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
namespace OCA\OpenProject\Service;

use OCA\OAuth2\Db\ClientMapper;
use OCA\OpenProject\VersionUtil;
use OCP\Security\ICrypto;
use OCP\Security\ISecureRandom;
use PHPUnit\Framework\TestCase;
Expand All @@ -34,7 +33,6 @@ protected function getOauthServiceMock(
$clientMapperMock = null,
$iSecureRandomMock = null,
$iCryptoMock = null,
$versionUtil = null,
): OauthService {

if ($clientMapperMock === null) {
Expand All @@ -46,15 +44,10 @@ protected function getOauthServiceMock(
if ($iCryptoMock === null) {
$iCryptoMock = $this->getMockBuilder(ICrypto::class)->getMock();
}
if ($versionUtil === null) {
$versionUtil = $this->getMockBuilder(VersionUtil::class)->disableOriginalConstructor()->getMock();
}

return new OauthService(
$clientMapperMock,
$iSecureRandomMock,
$iCryptoMock,
$versionUtil
);
}

Expand Down

0 comments on commit 3939420

Please sign in to comment.