Merge branch '22203-dunglam2k-s3-path-style'
[arvados.git] / services / workbench2 / cypress / e2e / group-manage.cy.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, add users to it and changes permission level', 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         // Add other user to the group
64         cy.get('[data-cy=group-member-add]').click();
65         cy.get('.sharing-dialog')
66             .should('contain', 'Sharing settings')
67             .within(() => {
68                 cy.get('[data-cy=invite-people-field] input').type("other");
69             });
70         cy.get('[data-cy="loading-spinner"]').should('not.exist');
71         cy.get('[data-cy="users-tab-label"]').click();
72         cy.get('[data-cy=sharing-suggestion]').click();
73         // Add admin to the group
74         cy.get('.sharing-dialog')
75             .should('contain', 'Sharing settings')
76             .within(() => {
77                 cy.get('[data-cy=invite-people-field] input').clear().type("admin");
78             });
79         cy.get('[data-cy="loading-spinner"]').should('not.exist');
80         cy.wait(1000);
81         cy.get('[data-cy="users-tab-label"]').click();
82         cy.get('[data-cy=sharing-suggestion]').click();
83         cy.get('.sharing-dialog').get('[data-cy=add-invited-people]').click();
84         cy.get('.sharing-dialog').contains('Close').click();
85
86         // Check that both users are present with appropriate permissions
87         cy.get('[data-cy=group-members-data-explorer]')
88             .contains(otherUser.user.full_name)
89             .parents('tr')
90             .within(() => {
91                 cy.contains('Read');
92             });
93         cy.get('[data-cy=group-members-data-explorer] tr')
94             .contains(activeUser.user.full_name)
95             .parents('tr')
96             .within(() => {
97                 cy.contains('Manage');
98             });
99
100         // Test change permission level
101         cy.get('[data-cy=group-members-data-explorer]')
102             .contains(otherUser.user.full_name)
103             .parents('tr')
104             .within(() => {
105                 cy.contains('Read')
106                     .parents('td')
107                     .within(() => {
108                         cy.get('button').click();
109                     });
110             });
111         cy.get('[data-cy=context-menu]')
112             .contains('Write')
113             .click();
114         cy.get('[data-cy=group-members-data-explorer]')
115             .contains(otherUser.user.full_name)
116             .parents('tr')
117             .within(() => {
118                 cy.contains('Write');
119             });
120
121         // Change admin to manage
122         cy.get('[data-cy=group-members-data-explorer]')
123             .contains(adminUser.user.full_name)
124             .parents('tr')
125             .within(() => {
126                 cy.contains('Read')
127                     .parents('td')
128                     .within(() => {
129                         cy.get('button').click();
130                     });
131             });
132         cy.get('[data-cy=context-menu]')
133             .contains('Manage')
134             .click();
135         cy.get('[data-cy=group-members-data-explorer]')
136             .contains(adminUser.user.full_name)
137             .parents('tr')
138             .within(() => {
139                 cy.contains('Manage');
140             });
141     });
142
143     it('can unhide and re-hide users', function() {
144         // Must use admin user to have manage permission on user
145         cy.loginAs(adminUser);
146         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
147         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
148
149         // Check that other user is hidden
150         cy.get('[data-cy=group-details-permissions-tab]').click();
151         cy.get('[data-cy=group-permissions-data-explorer]')
152             .should('not.contain', otherUser.user.full_name)
153         cy.get('[data-cy=group-details-members-tab]').click();
154
155         // Test unhide
156         cy.get('[data-cy=group-members-data-explorer]')
157             .contains(otherUser.user.full_name)
158             .parents('tr')
159             .within(() => {
160                 cy.get('[data-cy=user-visible-checkbox]').click();
161             });
162         // Check that other user is visible
163         cy.get('[data-cy=group-details-permissions-tab]').click();
164         cy.get('[data-cy=group-permissions-data-explorer]')
165             .contains(otherUser.user.full_name)
166             .parents('tr')
167             .within(() => {
168                 cy.contains('Read');
169             });
170         // Test re-hide
171         cy.get('[data-cy=group-details-members-tab]').click();
172         cy.get('[data-cy=group-members-data-explorer]')
173             .contains(otherUser.user.full_name)
174             .parents('tr')
175             .within(() => {
176                 cy.get('[data-cy=user-visible-checkbox]').click();
177             });
178         // Check that other user is hidden
179         cy.get('[data-cy=group-details-permissions-tab]').click();
180         cy.get('[data-cy=group-permissions-data-explorer]')
181             .should('not.contain', otherUser.user.full_name)
182     });
183
184     it('displays resources shared with the group', function() {
185         // Switch to activeUser
186         cy.loginAs(activeUser);
187         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
188
189         // Get groupUuid and create shared project
190         cy.get('[data-cy=groups-panel-data-explorer]')
191             .contains(groupName)
192             .parents('tr')
193             .find('[data-cy=uuid]')
194             .invoke('text')
195             .as('groupUuid')
196             .then((groupUuid) => {
197                 cy.createProject({
198                     owningUser: activeUser,
199                     projectName: 'test-project',
200                 }).as('testProject').then((testProject) => {
201                     cy.shareWith(activeUser.token, groupUuid, testProject.uuid, 'can_read');
202                 });
203             });
204
205         // Check that the project is listed in permissions
206         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
207         cy.get('[data-cy=group-details-permissions-tab]').click();
208         cy.get('[data-cy=group-permissions-data-explorer]')
209             .contains('test-project')
210             .parents('tr')
211             .within(() => {
212                 cy.contains('Read');
213             });
214     });
215
216     it('removes users from the group', function() {
217         cy.loginAs(activeUser);
218
219         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
220         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
221
222         // Remove other user
223         cy.get('[data-cy=group-members-data-explorer]')
224             .contains(otherUser.user.full_name)
225             .parents('tr')
226             .within(() => {
227                 cy.get('[data-cy=resource-delete-button]').click();
228             });
229         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
230         cy.get('[data-cy=group-members-data-explorer]')
231             .should('not.contain', otherUser.user.full_name);
232
233         // Remove user three
234         cy.get('[data-cy=group-members-data-explorer]')
235             .contains(userThree.user.full_name)
236             .parents('tr')
237             .within(() => {
238                 cy.get('[data-cy=resource-delete-button]').click();
239             });
240         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
241         cy.get('[data-cy=group-members-data-explorer]')
242             .should('not.contain', userThree.user.full_name);
243     });
244
245     it('renames the group', function() {
246         cy.loginAs(adminUser);
247         // Navigate to Groups
248         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
249
250         // Open rename dialog
251         cy.get('[data-cy=groups-panel-data-explorer]')
252             .contains(groupName)
253             .rightclick();
254         cy.get('[data-cy=context-menu]')
255             .contains('Rename')
256             .click();
257
258         // Rename the group
259         cy.get('[data-cy=form-dialog]')
260             .should('contain', 'Edit Group')
261             .within(() => {
262                 cy.get('input[name=name]').clear().type(groupName + ' (renamed)');
263                 cy.get('button').contains('Save').click();
264             });
265
266         // Check that the group was renamed
267         cy.get('[data-cy=groups-panel-data-explorer]')
268             .contains(groupName + ' (renamed)');
269     });
270
271     it('deletes the group', function() {
272         cy.loginAs(adminUser);
273
274         // Navigate to Groups
275         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
276
277         // Delete the group
278         cy.get('[data-cy=groups-panel-data-explorer]')
279             .contains(groupName + ' (renamed)')
280             .rightclick();
281         cy.get('[data-cy=context-menu]')
282             .contains('Remove')
283             .click();
284         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
285
286         // Check that the group was deleted
287         cy.get('[data-cy=groups-panel-data-explorer]')
288             .should('not.contain', groupName + ' (renamed)');
289     });
290
291     it('disables group-related controls for built-in groups', function() {
292         cy.loginAs(adminUser);
293
294         ['All users', 'Anonymous users', 'System group'].forEach((builtInGroup) => {
295             cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
296             cy.get('[data-cy=groups-panel-data-explorer]').contains(builtInGroup).click();
297
298             // Check group member actions
299             cy.get('[data-cy=group-members-data-explorer]')
300                 .within(() => {
301                     cy.get('[data-cy=group-member-add]').should('not.exist');
302                     cy.get('[data-cy=user-visible-checkbox] input').should('be.disabled');
303                     cy.get('[data-cy=resource-delete-button]').should('be.disabled');
304                     cy.get('[data-cy=edit-permission-button]').should('not.exist');
305                 });
306
307             // Check permissions actions
308             cy.get('[data-cy=group-details-permissions-tab]').click();
309             cy.get('[data-cy=group-permissions-data-explorer]').within(() => {
310                 cy.get('[data-cy=resource-delete-button]').should('be.disabled');
311                 cy.get('[data-cy=edit-permission-button]').should('not.exist');
312             });
313         });
314     });
315
316 });