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