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