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