Merge pull request #55278 from nextcloud/backport/55177/stable31
Some checks are pending
Integration sqlite / changes (push) Waiting to run
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, --tags ~@large files_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, capabilities_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, collaboration_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, comments_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, dav_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, federation_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, file_conversions) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, files_reminders) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, filesdrop_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, ldap_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, openldap_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, openldap_numerical_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, remoteapi_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, setup_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, sharees_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, sharing_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, theming_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (stable31, 8.1, stable31, videoverification_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite-summary (push) Blocked by required conditions
Psalm static code analysis / static-code-analysis (push) Waiting to run
Psalm static code analysis / static-code-analysis-security (push) Waiting to run
Psalm static code analysis / static-code-analysis-ocp (push) Waiting to run
Psalm static code analysis / static-code-analysis-ncu (push) Waiting to run

[stable31] fix(systemtags): Provide initial state for admin restriction setting
This commit is contained in:
Andy Scherzinger 2025-12-04 08:24:37 +01:00 committed by GitHub
commit 847ae2be3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 48 additions and 1 deletions

View file

@ -5,16 +5,28 @@
*/
namespace OCA\SystemTags\Settings;
use OCA\SystemTags\AppInfo\Application;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\IAppConfig;
use OCP\Settings\ISettings;
use OCP\Util;
class Admin implements ISettings {
public function __construct(
private IAppConfig $appConfig,
private IInitialState $initialStateService,
) {
}
/**
* @return TemplateResponse
*/
public function getForm() {
$restrictSystemTagsCreationToAdmin = $this->appConfig->getValueBool(Application::APP_ID, 'restrict_creation_to_admin', false);
$this->initialStateService->provideInitialState('restrictSystemTagsCreationToAdmin', $restrictSystemTagsCreationToAdmin);
Util::addScript('systemtags', 'admin');
return new TemplateResponse('systemtags', 'admin', [], '');
}

View file

@ -7,19 +7,54 @@ namespace OCA\SystemTags\Tests\Settings;
use OCA\SystemTags\Settings\Admin;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\IAppConfig;
use Test\TestCase;
class AdminTest extends TestCase {
/** @var Admin */
private $admin;
/** @var IAppConfig|\PHPUnit\Framework\MockObject\MockObject */
private $appConfig;
/** @var IInitialState|\PHPUnit\Framework\MockObject\MockObject */
private $initialState;
protected function setUp(): void {
parent::setUp();
$this->admin = new Admin();
$this->appConfig = $this->createMock(IAppConfig::class);
$this->initialState = $this->createMock(IInitialState::class);
$this->admin = new Admin(
$this->appConfig,
$this->initialState
);
}
public function testGetForm(): void {
$this->appConfig->expects($this->once())
->method('getValueBool')
->with('systemtags', 'restrict_creation_to_admin', false)
->willReturn(false);
$this->initialState->expects($this->once())
->method('provideInitialState')
->with('restrictSystemTagsCreationToAdmin', false);
$expected = new TemplateResponse('systemtags', 'admin', [], '');
$this->assertEquals($expected, $this->admin->getForm());
}
public function testGetFormWithRestrictedCreation(): void {
$this->appConfig->expects($this->once())
->method('getValueBool')
->with('systemtags', 'restrict_creation_to_admin', false)
->willReturn(true);
$this->initialState->expects($this->once())
->method('provideInitialState')
->with('restrictSystemTagsCreationToAdmin', true);
$expected = new TemplateResponse('systemtags', 'admin', [], '');
$this->assertEquals($expected, $this->admin->getForm());
}