20318: Remove redundant WriteTo case already handled by io.Copy.
[arvados.git] / services / workbench2 / 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         // 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').type("admin");
78             });
79         cy.get('[role=tooltip]').click();
80         cy.get('.sharing-dialog').get('[data-cy=add-invited-people]').click();
81         cy.get('.sharing-dialog').contains('Close').click();
82
83         // Check that both users are present with appropriate permissions
84         cy.get('[data-cy=group-members-data-explorer]')
85             .contains(otherUser.user.full_name)
86             .parents('tr')
87             .within(() => {
88                 cy.contains('Read');
89             });
90         cy.get('[data-cy=group-members-data-explorer] tr')
91             .contains(activeUser.user.full_name)
92             .parents('tr')
93             .within(() => {
94                 cy.contains('Manage');
95             });
96     });
97
98     it('changes permission level of a member', function() {
99         // Test change permission level
100         cy.get('[data-cy=group-members-data-explorer]')
101             .contains(otherUser.user.full_name)
102             .parents('tr')
103             .within(() => {
104                 cy.contains('Read')
105                     .parents('td')
106                     .within(() => {
107                         cy.get('button').click();
108                     });
109             });
110         cy.get('[data-cy=context-menu]')
111             .contains('Write')
112             .click();
113         cy.get('[data-cy=group-members-data-explorer]')
114             .contains(otherUser.user.full_name)
115             .parents('tr')
116             .within(() => {
117                 cy.contains('Write');
118             });
119
120         // Change admin to manage
121         cy.get('[data-cy=group-members-data-explorer]')
122             .contains(adminUser.user.full_name)
123             .parents('tr')
124             .within(() => {
125                 cy.contains('Read')
126                     .parents('td')
127                     .within(() => {
128                         cy.get('button').click();
129                     });
130             });
131         cy.get('[data-cy=context-menu]')
132             .contains('Manage')
133             .click();
134         cy.get('[data-cy=group-members-data-explorer]')
135             .contains(adminUser.user.full_name)
136             .parents('tr')
137             .within(() => {
138                 cy.contains('Manage');
139             });
140     });
141
142     it('can unhide and re-hide users', function() {
143         // Must use admin user to have manage permission on user
144         cy.loginAs(adminUser);
145         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
146         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).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         cy.get('[data-cy=group-details-members-tab]').click();
153
154         // Test unhide
155         cy.get('[data-cy=group-members-data-explorer]')
156             .contains(otherUser.user.full_name)
157             .parents('tr')
158             .within(() => {
159                 cy.get('[data-cy=user-visible-checkbox]').click();
160             });
161         // Check that other user is visible
162         cy.get('[data-cy=group-details-permissions-tab]').click();
163         cy.get('[data-cy=group-permissions-data-explorer]')
164             .contains(otherUser.user.full_name)
165             .parents('tr')
166             .within(() => {
167                 cy.contains('Read');
168             });
169         // Test re-hide
170         cy.get('[data-cy=group-details-members-tab]').click();
171         cy.get('[data-cy=group-members-data-explorer]')
172             .contains(otherUser.user.full_name)
173             .parents('tr')
174             .within(() => {
175                 cy.get('[data-cy=user-visible-checkbox]').click();
176             });
177         // Check that other user is hidden
178         cy.get('[data-cy=group-details-permissions-tab]').click();
179         cy.get('[data-cy=group-permissions-data-explorer]')
180             .should('not.contain', otherUser.user.full_name)
181     });
182
183     it('displays resources shared with the group', function() {
184         // Switch to activeUser
185         cy.loginAs(activeUser);
186         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
187
188         // Get groupUuid and create shared project
189         cy.get('[data-cy=groups-panel-data-explorer]')
190             .contains(groupName)
191             .parents('tr')
192             .find('[data-cy=uuid]')
193             .invoke('text')
194             .as('groupUuid')
195             .then((groupUuid) => {
196                 cy.createProject({
197                     owningUser: activeUser,
198                     projectName: 'test-project',
199                 }).as('testProject').then((testProject) => {
200                     cy.shareWith(activeUser.token, groupUuid, testProject.uuid, 'can_read');
201                 });
202             });
203
204         // Check that the project is listed in permissions
205         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
206         cy.get('[data-cy=group-details-permissions-tab]').click();
207         cy.get('[data-cy=group-permissions-data-explorer]')
208             .contains('test-project')
209             .parents('tr')
210             .within(() => {
211                 cy.contains('Read');
212             });
213     });
214
215     it('removes users from the group', function() {
216         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
217         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
218
219         // Remove other user
220         cy.get('[data-cy=group-members-data-explorer]')
221             .contains(otherUser.user.full_name)
222             .parents('tr')
223             .within(() => {
224                 cy.get('[data-cy=resource-delete-button]').click();
225             });
226         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
227         cy.get('[data-cy=group-members-data-explorer]')
228             .should('not.contain', otherUser.user.full_name);
229
230         // Remove user three
231         cy.get('[data-cy=group-members-data-explorer]')
232             .contains(userThree.user.full_name)
233             .parents('tr')
234             .within(() => {
235                 cy.get('[data-cy=resource-delete-button]').click();
236             });
237         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
238         cy.get('[data-cy=group-members-data-explorer]')
239             .should('not.contain', userThree.user.full_name);
240     });
241
242     it('renames the group', function() {
243         cy.loginAs(adminUser);
244         // Navigate to Groups
245         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
246
247         // Open rename dialog
248         cy.get('[data-cy=groups-panel-data-explorer]')
249             .contains(groupName)
250             .rightclick();
251         cy.get('[data-cy=context-menu]')
252             .contains('Rename')
253             .click();
254
255         // Rename the group
256         cy.get('[data-cy=form-dialog]')
257             .should('contain', 'Edit Group')
258             .within(() => {
259                 cy.get('input[name=name]').clear().type(groupName + ' (renamed)');
260                 cy.get('button').contains('Save').click();
261             });
262
263         // Check that the group was renamed
264         cy.get('[data-cy=groups-panel-data-explorer]')
265             .contains(groupName + ' (renamed)');
266     });
267
268     it('deletes the group', function() {
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 });