Skip to content

Commit b5092e5

Browse files
authored
Merge pull request #57533 from nextcloud/fix/limit-app-to-group-initial-state
fix(app-settings): limit app to group initial state
2 parents 550b15a + b7c6240 commit b5092e5

3 files changed

Lines changed: 57 additions & 2 deletions

File tree

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,
@@ -94,6 +95,13 @@ public function viewApps(): TemplateResponse {
9495
$this->initialState->provideInitialState('appstoreBundles', $this->getBundles());
9596
$this->initialState->provideInitialState('appstoreUpdateCount', count($this->getAppsWithUpdates()));
9697

98+
$groups = array_map(static fn (IGroup $group): array => [
99+
'id' => $group->getGID(),
100+
'name' => $group->getDisplayName(),
101+
], $this->groupManager->search('', 5));
102+
103+
$this->initialState->provideInitialState('usersSettings', [ 'systemGroups' => $groups]);
104+
97105
if ($this->appManager->isEnabledForAnyone('app_api')) {
98106
try {
99107
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;
@@ -45,6 +47,7 @@ class AppSettingsControllerTest extends TestCase {
4547
private CategoryFetcher&MockObject $categoryFetcher;
4648
private AppFetcher&MockObject $appFetcher;
4749
private IFactory&MockObject $l10nFactory;
50+
private IGroupManager&MockObject $groupManager;
4851
private BundleFetcher&MockObject $bundleFetcher;
4952
private Installer&MockObject $installer;
5053
private IURLGenerator&MockObject $urlGenerator;
@@ -70,6 +73,7 @@ protected function setUp(): void {
7073
$this->categoryFetcher = $this->createMock(CategoryFetcher::class);
7174
$this->appFetcher = $this->createMock(AppFetcher::class);
7275
$this->l10nFactory = $this->createMock(IFactory::class);
76+
$this->groupManager = $this->createMock(IGroupManager::class);
7377
$this->bundleFetcher = $this->createMock(BundleFetcher::class);
7478
$this->installer = $this->createMock(Installer::class);
7579
$this->urlGenerator = $this->createMock(IURLGenerator::class);
@@ -89,6 +93,7 @@ protected function setUp(): void {
8993
$this->categoryFetcher,
9094
$this->appFetcher,
9195
$this->l10nFactory,
96+
$this->groupManager,
9297
$this->bundleFetcher,
9398
$this->installer,
9499
$this->urlGenerator,
@@ -168,9 +173,16 @@ public function testViewApps(): void {
168173
->expects($this->once())
169174
->method('setActiveEntry')
170175
->with('core_apps');
176+
$this->groupManager->expects($this->once())
177+
->method('search')
178+
->with($this->equalTo(''), $this->equalTo(5))
179+
->willReturn([
180+
$this->createMock(IGroup::class),
181+
$this->createMock(IGroup::class),
182+
]);
171183

172184
$this->initialState
173-
->expects($this->exactly(3))
185+
->expects($this->exactly(4))
174186
->method('provideInitialState');
175187

176188
$policy = new ContentSecurityPolicy();
@@ -201,9 +213,16 @@ public function testViewAppsAppstoreNotEnabled(): void {
201213
->expects($this->once())
202214
->method('setActiveEntry')
203215
->with('core_apps');
216+
$this->groupManager->expects($this->once())
217+
->method('search')
218+
->with($this->equalTo(''), $this->equalTo(5))
219+
->willReturn([
220+
$this->createMock(IGroup::class),
221+
$this->createMock(IGroup::class),
222+
]);
204223

205224
$this->initialState
206-
->expects($this->exactly(3))
225+
->expects($this->exactly(4))
207226
->method('provideInitialState');
208227

209228
$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)