Skip to content
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
4 changes: 2 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<name>Slack Integration</name>
<summary>Integration of Slack</summary>
<description><![CDATA[Slack integration lets you send files to Slack from Nextcloud Files.]]></description>
<version>2.1.1</version>
<version>2.1.2</version>
<licence>agpl</licence>
<author>Anupam Kumar</author>
<namespace>Slack</namespace>
Expand All @@ -17,7 +17,7 @@
<screenshot>https://raw.githubusercontent.com/nextcloud/integration_slack/main/img/screenshot1.png</screenshot>
<screenshot>https://raw.githubusercontent.com/nextcloud/integration_slack/main/img/screenshot2.png</screenshot>
<dependencies>
<nextcloud min-version="30" max-version="32"/>
<nextcloud min-version="30" max-version="33"/>
</dependencies>
<settings>
<admin>OCA\Slack\Settings\Admin</admin>
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}
],
"require": {
"php": "^8.1 || ^8.2 || ^8.3 || ^8.4",
"php": "^8.2 || ^8.3 || ^8.4",
"bamarni/composer-bin-plugin": "^1.8"
},
"scripts": {
Expand Down
28 changes: 14 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions lib/Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Services\IInitialState;
use OCP\IConfig;
use OCP\IL10N;
Expand All @@ -41,6 +42,7 @@ public function __construct(
string $appName,
IRequest $request,
private IConfig $config,
private IAppConfig $appConfig,
private IURLGenerator $urlGenerator,
private IL10N $l,
private IInitialState $initialStateService,
Expand All @@ -58,10 +60,10 @@ public function __construct(
#[NoAdminRequired]
public function isUserConnected(): DataResponse {
$token = $this->config->getUserValue($this->userId, Application::APP_ID, 'token');
$clientID = $this->config->getAppValue(Application::APP_ID, 'client_id');
$clientSecret = $this->config->getAppValue(Application::APP_ID, 'client_secret');
$clientID = $this->appConfig->getAppValueString('client_id', lazy: true);
$clientSecret = $this->appConfig->getAppValueString('client_secret', lazy: true);
$oauthPossible = $clientID !== '' && $clientSecret !== '';
$usePopup = $this->config->getAppValue(Application::APP_ID, 'use_popup', '0');
$usePopup = $this->appConfig->getAppValueString('use_popup', '0', lazy: true);

return new DataResponse([
'connected' => ($token !== ''),
Expand Down Expand Up @@ -135,7 +137,7 @@ public function setAdminConfig(array $values): DataResponse {
if (in_array($key, self::SENSITIVE_ADMIN_KEYS, true)) {
continue;
}
$this->config->setAppValue(Application::APP_ID, $key, $value);
$this->appConfig->setAppValueString($key, $value, lazy: true);
}
return new DataResponse([]);
}
Expand All @@ -157,13 +159,13 @@ public function setSensitiveAdminConfig(array $values): DataResponse {
$value = $this->crypto->encrypt($value);
}
} catch (Exception $e) {
$this->config->setAppValue(Application::APP_ID, 'client_secret', '');
$this->appConfig->setAppValueString('client_secret', '', lazy: true);
// logger takes care not to leak the secret
$this->logger->error('Could not encrypt client secret', ['exception' => $e]);
return new DataResponse(['message' => $this->l->t('Could not encrypt client secret')]);
}

$this->config->setAppValue(Application::APP_ID, $key, $value);
$this->appConfig->setAppValueString($key, $value, lazy: true);
}
return new DataResponse([]);
}
Expand Down Expand Up @@ -196,8 +198,8 @@ public function popupSuccessPage(string $user_id, string $user_displayname): Tem
*/
public function oauthRedirect(string $code = '', string $state = ''): RedirectResponse {
$configState = $this->config->getUserValue($this->userId, Application::APP_ID, 'oauth_state');
$clientID = $this->config->getAppValue(Application::APP_ID, 'client_id');
$clientSecret = $this->config->getAppValue(Application::APP_ID, 'client_secret');
$clientID = $this->appConfig->getAppValueString('client_id', lazy: true);
$clientSecret = $this->appConfig->getAppValueString('client_secret', lazy: true);

// decrypt client secret
try {
Expand Down Expand Up @@ -240,7 +242,7 @@ public function oauthRedirect(string $code = '', string $state = ''): RedirectRe
$this->config->setUserValue($this->userId, Application::APP_ID, 'refresh_token', $encryptedRefreshToken);

$userInfo = $this->storeUserInfo($result['authed_user']['id']);
$usePopup = $this->config->getAppValue(Application::APP_ID, 'use_popup', '0') === '1';
$usePopup = $this->appConfig->getAppValueString('use_popup', '0', lazy: true) === '1';

if ($usePopup) {
return new RedirectResponse(
Expand Down
49 changes: 49 additions & 0 deletions lib/Migration/Version020102Date20251125141127.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Slack\Migration;

use Closure;
use OCP\AppFramework\Services\IAppConfig;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
use Override;

class Version020102Date20251125141127 extends SimpleMigrationStep {
private static array $configKeys = [
'client_id',
'client_secret',
'use_popup',
];

public function __construct(
private IAppConfig $appConfig,
) {
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
#[Override]
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
$allSetKeys = $this->appConfig->getAppKeys();

foreach (self::$configKeys as $key) {
// skip if not already set
if (!in_array($key, $allSetKeys)) {
continue;
}
$value = $this->appConfig->getAppValueString($key);
$this->appConfig->setAppValueString($key, $value, lazy: true);
}
}
}
6 changes: 4 additions & 2 deletions lib/Service/SlackAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Exception;
use OC\User\NoUserException;
use OCA\Slack\AppInfo\Application;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Constants;
use OCP\Files\File;
use OCP\Files\Folder;
Expand Down Expand Up @@ -47,6 +48,7 @@ public function __construct(
private LoggerInterface $logger,
private IL10N $l10n,
private IConfig $config,
private IAppConfig $appConfig,
private IRootFolder $root,
private ShareManager $shareManager,
private IURLGenerator $urlGenerator,
Expand Down Expand Up @@ -440,8 +442,8 @@ private function checkTokenExpiration(string $userId): void {
* @throws \OCP\PreConditionNotMetException
*/
private function refreshToken(string $userId): bool {
$clientID = $this->config->getAppValue(Application::APP_ID, 'client_id');
$clientSecret = $this->config->getAppValue(Application::APP_ID, 'client_secret');
$clientID = $this->appConfig->getAppValueString('client_id', lazy: true);
$clientSecret = $this->appConfig->getAppValueString('client_secret', lazy: true);
$refreshToken = $this->config->getUserValue($userId, Application::APP_ID, 'refresh_token');
$refreshToken = $refreshToken === '' ? '' : $this->crypto->decrypt($refreshToken);

Expand Down
10 changes: 5 additions & 5 deletions lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
use Exception;
use OCA\Slack\AppInfo\Application;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Services\IInitialState;
use OCP\IConfig;
use OCP\Security\ICrypto;
use OCP\Settings\ISettings;
use Psr\Log\LoggerInterface;

class Admin implements ISettings {

public function __construct(
private IConfig $config,
private IAppConfig $appConfig,
private IInitialState $initialStateService,
private ICrypto $crypto,
private LoggerInterface $logger,
Expand All @@ -25,9 +25,9 @@ public function __construct(
* @return TemplateResponse
*/
public function getForm(): TemplateResponse {
$clientID = $this->config->getAppValue(Application::APP_ID, 'client_id');
$clientSecret = $this->config->getAppValue(Application::APP_ID, 'client_secret');
$usePopup = $this->config->getAppValue(Application::APP_ID, 'use_popup', '0');
$clientID = $this->appConfig->getAppValueString('client_id', lazy: true);
$clientSecret = $this->appConfig->getAppValueString('client_secret', lazy: true);
$usePopup = $this->appConfig->getAppValueString('use_popup', '0', lazy: true);

try {
if ($clientSecret !== '') {
Expand Down
8 changes: 5 additions & 3 deletions lib/Settings/Personal.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use OCA\Slack\AppInfo\Application;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Services\IInitialState;
use OCP\IConfig;
use OCP\Settings\ISettings;
Expand All @@ -12,6 +13,7 @@ class Personal implements ISettings {

public function __construct(
private IConfig $config,
private IAppConfig $appConfig,
private IInitialState $initialStateService,
private ?string $userId,
) {
Expand All @@ -27,9 +29,9 @@ public function getForm(): TemplateResponse {
$fileActionEnabled = $this->config->getUserValue($this->userId, Application::APP_ID, 'file_action_enabled', '1') === '1';

// for OAuth
$clientID = $this->config->getAppValue(Application::APP_ID, 'client_id');
$clientSecret = $this->config->getAppValue(Application::APP_ID, 'client_secret');
$usePopup = $this->config->getAppValue(Application::APP_ID, 'use_popup', '0');
$clientID = $this->appConfig->getAppValueString('client_id', lazy: true);
$clientSecret = $this->appConfig->getAppValueString('client_secret', lazy: true);
$usePopup = $this->appConfig->getAppValueString('use_popup', '0', lazy: true);

$userConfig = [
// don't need to decrypt it, just need to know if it's set
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/Service/SlackAPIServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use OCA\Slack\AppInfo\Application;
use OCA\Slack\Service\NetworkService;
use OCA\Slack\Service\SlackAPIService;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Files\IRootFolder;
use OCP\Http\Client\IClientService;
use OCP\ICacheFactory;
Expand All @@ -22,6 +23,7 @@ class SlackAPIServiceTest extends TestCase {
private LoggerInterface $logger;
private IL10N $l10n;
private IConfig $config;
private IAppConfig $appConfig;
private IRootFolder $root;
private ShareManager $shareManager;
private IURLGenerator $urlGenerator;
Expand All @@ -42,6 +44,7 @@ private function setupDummies(): void {
$this->logger = $this->createMock(LoggerInterface::class);
$this->l10n = $this->createMock(L10N::class);
$this->config = $this->createMock(IConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->root = $this->createMock(IRootFolder::class);
$this->shareManager = $this->createMock(ShareManager::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
Expand All @@ -58,6 +61,7 @@ private function setupDummies(): void {
$this->logger,
$this->l10n,
$this->config,
$this->appConfig,
$this->root,
$this->shareManager,
$this->urlGenerator,
Expand Down
2 changes: 1 addition & 1 deletion vendor-bin/php-cs-fixer/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require": {
"php": "^8.1 || ^8.2 || ^8.3 || ^8.4"
"php": "^8.2 || ^8.3 || ^8.4"
},
"require-dev": {
"nextcloud/coding-standard": "^1.1"
Expand Down
Loading
Loading