Skip to content

Commit e0b8171

Browse files
authored
Merge pull request #58004 from nextcloud/backport/57533/stable32
[stable32] fix(app-settings): limit app to group initial state
2 parents dff4cf8 + ebef1f6 commit e0b8171

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

apps/settings/lib/Controller/AppSettingsController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function __construct(
6969
private CategoryFetcher $categoryFetcher,
7070
private AppFetcher $appFetcher,
7171
private IFactory $l10nFactory,
72+
private IGroupManager $groupManager,
7273
private BundleFetcher $bundleFetcher,
7374
private Installer $installer,
7475
private IURLGenerator $urlGenerator,
@@ -95,6 +96,13 @@ public function viewApps(): TemplateResponse {
9596
$this->initialState->provideInitialState('appstoreDeveloperDocs', $this->urlGenerator->linkToDocs('developer-manual'));
9697
$this->initialState->provideInitialState('appstoreUpdateCount', count($this->getAppsWithUpdates()));
9798

99+
$groups = array_map(static fn (IGroup $group): array => [
100+
'id' => $group->getGID(),
101+
'name' => $group->getDisplayName(),
102+
], $this->groupManager->search('', 5));
103+
104+
$this->initialState->provideInitialState('usersSettings', [ 'systemGroups' => $groups]);
105+
98106
if ($this->appManager->isEnabledForAnyone('app_api')) {
99107
try {
100108
Server::get(ExAppsPageService::class)->provideAppApiState($this->initialState);

apps/settings/tests/Controller/AppSettingsControllerTest.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use OCP\Files\AppData\IAppDataFactory;
2222
use OCP\Http\Client\IClientService;
2323
use OCP\IConfig;
24+
use OCP\IGroup;
25+
use OCP\IGroupManager;
2426
use OCP\IL10N;
2527
use OCP\INavigationManager;
2628
use OCP\IRequest;
@@ -46,6 +48,7 @@ class AppSettingsControllerTest extends TestCase {
4648
private CategoryFetcher&MockObject $categoryFetcher;
4749
private AppFetcher&MockObject $appFetcher;
4850
private IFactory&MockObject $l10nFactory;
51+
private IGroupManager&MockObject $groupManager;
4952
private BundleFetcher&MockObject $bundleFetcher;
5053
private Installer&MockObject $installer;
5154
private IURLGenerator&MockObject $urlGenerator;
@@ -71,6 +74,7 @@ protected function setUp(): void {
7174
$this->categoryFetcher = $this->createMock(CategoryFetcher::class);
7275
$this->appFetcher = $this->createMock(AppFetcher::class);
7376
$this->l10nFactory = $this->createMock(IFactory::class);
77+
$this->groupManager = $this->createMock(IGroupManager::class);
7478
$this->bundleFetcher = $this->createMock(BundleFetcher::class);
7579
$this->installer = $this->createMock(Installer::class);
7680
$this->urlGenerator = $this->createMock(IURLGenerator::class);
@@ -90,6 +94,7 @@ protected function setUp(): void {
9094
$this->categoryFetcher,
9195
$this->appFetcher,
9296
$this->l10nFactory,
97+
$this->groupManager,
9398
$this->bundleFetcher,
9499
$this->installer,
95100
$this->urlGenerator,
@@ -169,9 +174,16 @@ public function testViewApps(): void {
169174
->expects($this->once())
170175
->method('setActiveEntry')
171176
->with('core_apps');
177+
$this->groupManager->expects($this->once())
178+
->method('search')
179+
->with($this->equalTo(''), $this->equalTo(5))
180+
->willReturn([
181+
$this->createMock(IGroup::class),
182+
$this->createMock(IGroup::class),
183+
]);
172184

173185
$this->initialState
174-
->expects($this->exactly(4))
186+
->expects($this->exactly(5))
175187
->method('provideInitialState');
176188

177189
$policy = new ContentSecurityPolicy();
@@ -202,9 +214,16 @@ public function testViewAppsAppstoreNotEnabled(): void {
202214
->expects($this->once())
203215
->method('setActiveEntry')
204216
->with('core_apps');
217+
$this->groupManager->expects($this->once())
218+
->method('search')
219+
->with($this->equalTo(''), $this->equalTo(5))
220+
->willReturn([
221+
$this->createMock(IGroup::class),
222+
$this->createMock(IGroup::class),
223+
]);
205224

206225
$this->initialState
207-
->expects($this->exactly(4))
226+
->expects($this->exactly(5))
208227
->method('provideInitialState');
209228

210229
$policy = new ContentSecurityPolicy();

cypress/e2e/settings/apps.cy.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,34 @@ describe('Settings: App management', { testIsolation: true }, () => {
142142
cy.get('#app-sidebar-vue').contains(/Version \d+\.\d+\.\d+/).should('be.visible')
143143
})
144144

145+
it('Limit app usage to group', () => {
146+
// When I open the "Active apps" section
147+
cy.get('#app-category-enabled a')
148+
.should('contain', 'Active apps')
149+
.click({ force: true })
150+
// Then I see that the current section is "Active apps"
151+
cy.url().should('match', /settings\/apps\/enabled$/)
152+
cy.get('#app-category-enabled').find('.active').should('exist')
153+
// Then I select the app
154+
cy.get('#apps-list')
155+
.should('exist')
156+
.contains('tr', 'Dashboard', { timeout: 10000 })
157+
.click()
158+
// Then I enable "limit app to group"
159+
cy.get('[for="groups_enable_dashboard"]').click()
160+
// Then I select a group
161+
cy.get('#limitToGroups').click()
162+
cy.get('ul[role="listbox"]')
163+
.find('span')
164+
.contains('admin')
165+
.click()
166+
cy.get('span.name-parts__first')
167+
.contains('admin')
168+
.should('be.visible')
169+
// Then I disable the group limitation
170+
cy.get('button[title="Deselect admin"]').click()
171+
})
172+
145173
/*
146174
* TODO: Improve testing with app store as external API
147175
* The following scenarios require the files_antivirus and calendar app

0 commit comments

Comments
 (0)