Merge branch 'main' into 19069-workflow-launching
[arvados.git] / cypress / integration / group-manage.spec.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 describe('Group manage tests', function() {
6     let activeUser;
7     let adminUser;
8     let otherUser;
9     let userThree;
10     const groupName = `Test group (${Math.floor(999999 * Math.random())})`;
11
12     before(function() {
13         // Only set up common users once. These aren't set up as aliases because
14         // aliases are cleaned up after every test. Also it doesn't make sense
15         // to set the same users on beforeEach() over and over again, so we
16         // separate a little from Cypress' 'Best Practices' here.
17         cy.getUser('admin', 'Admin', 'User', true, true)
18             .as('adminUser').then(function() {
19                 adminUser = this.adminUser;
20             }
21         );
22         cy.getUser('user', 'Active', 'User', false, true)
23             .as('activeUser').then(function() {
24                 activeUser = this.activeUser;
25             }
26         );
27         cy.getUser('otheruser', 'Other', 'User', false, true)
28             .as('otherUser').then(function() {
29                 otherUser = this.otherUser;
30             }
31         );
32         cy.getUser('userThree', 'User', 'Three', false, true)
33             .as('userThree').then(function() {
34                 userThree = this.userThree;
35             }
36         );
37     });
38
39     it('creates a new group', function() {
40         cy.loginAs(activeUser);
41
42         // Navigate to Groups
43         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
44
45         // Create new group
46         cy.get('[data-cy=groups-panel-new-group]').click();
47         cy.get('[data-cy=form-dialog]')
48             .should('contain', 'New Group')
49             .within(() => {
50                 cy.get('input[name=name]').type(groupName);
51                 cy.get('[data-cy=users-field] input').type("three");
52             });
53         cy.get('[role=tooltip]').click();
54         cy.get('[data-cy=form-dialog]').within(() => {
55             cy.get('[data-cy=form-submit-btn]').click();
56         })
57
58         // Check that the group was created
59         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
60         cy.get('[data-cy=group-members-data-explorer]').contains(activeUser.user.full_name);
61         cy.get('[data-cy=group-members-data-explorer]').contains(userThree.user.full_name);
62     });
63
64     it('adds users to the group', function() {
65         // Add other user to the group
66         cy.get('[data-cy=group-member-add]').click();
67         cy.get('.sharing-dialog')
68             .should('contain', 'Sharing settings')
69             .within(() => {
70                 cy.get('[data-cy=invite-people-field] input').type("other");
71             });
72         cy.get('[role=tooltip]').click();
73         cy.get('.sharing-dialog').contains('Save').click();
74
75         // Check that both users are present with appropriate permissions
76         cy.get('[data-cy=group-members-data-explorer]')
77             .contains(otherUser.user.full_name)
78             .parents('tr')
79             .within(() => {
80                 cy.contains('Read');
81             });
82         cy.get('[data-cy=group-members-data-explorer] tr')
83             .contains(activeUser.user.full_name)
84             .parents('tr')
85             .within(() => {
86                 cy.contains('Manage');
87             });
88     });
89
90     it('changes permission level of a member', function() {
91         // Test change permission level
92         cy.get('[data-cy=group-members-data-explorer]')
93             .contains(otherUser.user.full_name)
94             .parents('tr')
95             .within(() => {
96                 cy.contains('Read')
97                     .parents('td')
98                     .within(() => {
99                         cy.get('button').click();
100                     });
101             });
102         cy.get('[data-cy=context-menu]')
103             .contains('Write')
104             .click();
105         cy.get('[data-cy=group-members-data-explorer]')
106             .contains(otherUser.user.full_name)
107             .parents('tr')
108             .within(() => {
109                 cy.contains('Write');
110             });
111     });
112
113     it('can unhide and re-hide users', function() {
114         // Must use admin user to have manage permission on user
115         cy.loginAs(adminUser);
116         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
117         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
118
119         // Check that other user is hidden
120         cy.get('[data-cy=group-details-permissions-tab]').click();
121         cy.get('[data-cy=group-permissions-data-explorer]')
122             .should('not.contain', otherUser.user.full_name)
123         cy.get('[data-cy=group-details-members-tab]').click();
124
125         // Test unhide
126         cy.get('[data-cy=group-members-data-explorer]')
127             .contains(otherUser.user.full_name)
128             .parents('tr')
129             .within(() => {
130                 cy.get('[data-cy=user-visible-checkbox]').click();
131             });
132         // Check that other user is visible
133         cy.get('[data-cy=group-details-permissions-tab]').click();
134         cy.get('[data-cy=group-permissions-data-explorer]')
135             .contains(otherUser.user.full_name)
136             .parents('tr')
137             .within(() => {
138                 cy.contains('Read');
139             });
140         // Test re-hide
141         cy.get('[data-cy=group-details-members-tab]').click();
142         cy.get('[data-cy=group-members-data-explorer]')
143             .contains(otherUser.user.full_name)
144             .parents('tr')
145             .within(() => {
146                 cy.get('[data-cy=user-visible-checkbox]').click();
147             });
148         // Check that other user is hidden
149         cy.get('[data-cy=group-details-permissions-tab]').click();
150         cy.get('[data-cy=group-permissions-data-explorer]')
151             .should('not.contain', otherUser.user.full_name)
152     });
153
154     it('displays resources shared with the group', function() {
155         // Switch to activeUser
156         cy.loginAs(activeUser);
157         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
158
159         // Get groupUuid and create shared project
160         cy.get('[data-cy=groups-panel-data-explorer]')
161             .contains(groupName)
162             .parents('tr')
163             .find('[data-cy=uuid]')
164             .invoke('text')
165             .as('groupUuid')
166             .then((groupUuid) => {
167                 cy.createProject({
168                     owningUser: activeUser,
169                     projectName: 'test-project',
170                 }).as('testProject').then((testProject) => {
171                     cy.shareWith(activeUser.token, groupUuid, testProject.uuid, 'can_read');
172                 });
173             });
174
175         // Check that the project is listed in permissions
176         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
177         cy.get('[data-cy=group-details-permissions-tab]').click();
178         cy.get('[data-cy=group-permissions-data-explorer]')
179             .contains('test-project')
180             .parents('tr')
181             .within(() => {
182                 cy.contains('Read');
183             });
184     });
185
186     it('removes users from the group', function() {
187         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
188         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
189
190         // Remove other user
191         cy.get('[data-cy=group-members-data-explorer]')
192             .contains(otherUser.user.full_name)
193             .parents('tr')
194             .within(() => {
195                 cy.get('[data-cy=resource-delete-button]').click();
196             });
197         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
198         cy.get('[data-cy=group-members-data-explorer]')
199             .should('not.contain', otherUser.user.full_name);
200
201         // Remove user three
202         cy.get('[data-cy=group-members-data-explorer]')
203             .contains(userThree.user.full_name)
204             .parents('tr')
205             .within(() => {
206                 cy.get('[data-cy=resource-delete-button]').click();
207             });
208         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
209         cy.get('[data-cy=group-members-data-explorer]')
210             .should('not.contain', userThree.user.full_name);
211     });
212
213     it('renames the group', function() {
214         // Navigate to Groups
215         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
216
217         // Open rename dialog
218         cy.get('[data-cy=groups-panel-data-explorer]')
219             .contains(groupName)
220             .rightclick();
221         cy.get('[data-cy=context-menu]')
222             .contains('Rename')
223             .click();
224
225         // Rename the group
226         cy.get('[data-cy=form-dialog]')
227             .should('contain', 'Edit Group')
228             .within(() => {
229                 cy.get('input[name=name]').clear().type(groupName + ' (renamed)');
230                 cy.get('button').contains('Save').click();
231             });
232
233         // Check that the group was renamed
234         cy.get('[data-cy=groups-panel-data-explorer]')
235             .contains(groupName + ' (renamed)');
236     });
237
238     it('deletes the group', function() {
239         // Navigate to Groups
240         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
241
242         // Delete the group
243         cy.get('[data-cy=groups-panel-data-explorer]')
244             .contains(groupName + ' (renamed)')
245             .rightclick();
246         cy.get('[data-cy=context-menu]')
247             .contains('Remove')
248             .click();
249         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
250
251         // Check that the group was deleted
252         cy.get('[data-cy=groups-panel-data-explorer]')
253             .should('not.contain', groupName + ' (renamed)');
254     });
255
256     it('disables group-related controls for built-in groups', function() {
257         cy.loginAs(adminUser);
258
259         ['All users', 'Anonymous users', 'System group'].forEach((builtInGroup) => {
260             cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
261             cy.get('[data-cy=groups-panel-data-explorer]').contains(builtInGroup).click();
262
263             // Check group member actions
264             cy.get('[data-cy=group-members-data-explorer]')
265                 .within(() => {
266                     cy.get('[data-cy=group-member-add]').should('not.exist');
267                     cy.get('[data-cy=user-visible-checkbox] input').should('be.disabled');
268                     cy.get('[data-cy=resource-delete-button]').should('be.disabled');
269                     cy.get('[data-cy=edit-permission-button]').should('not.exist');
270                 });
271
272             // Check permissions actions
273             cy.get('[data-cy=group-details-permissions-tab]').click();
274             cy.get('[data-cy=group-permissions-data-explorer]').within(() => {
275                 cy.get('[data-cy=resource-delete-button]').should('be.disabled');
276                 cy.get('[data-cy=edit-permission-button]').should('not.exist');
277             });
278         });
279     });
280
281 });