18123: Use sharing dialog to add users to groups
[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     const groupName = `Test group (${Math.floor(999999 * Math.random())})`;
10
11     before(function() {
12         // Only set up common users once. These aren't set up as aliases because
13         // aliases are cleaned up after every test. Also it doesn't make sense
14         // to set the same users on beforeEach() over and over again, so we
15         // separate a little from Cypress' 'Best Practices' here.
16         cy.getUser('admin', 'Admin', 'User', true, true)
17             .as('adminUser').then(function() {
18                 adminUser = this.adminUser;
19             }
20         );
21         cy.getUser('user', 'Active', 'User', false, true)
22             .as('activeUser').then(function() {
23                 activeUser = this.activeUser;
24             }
25         );
26         cy.getUser('otheruser', 'Other', 'User', false, true)
27             .as('otherUser').then(function() {
28                 otherUser = this.otherUser;
29             }
30         );
31     });
32
33     beforeEach(function() {
34         cy.clearCookies();
35         cy.clearLocalStorage();
36     });
37
38     it('creates a new group', function() {
39         cy.loginAs(activeUser);
40
41         // Navigate to Groups
42         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
43
44         // Create new group
45         cy.get('[data-cy=groups-panel-new-group]').click();
46         cy.get('[data-cy=form-dialog]')
47             .should('contain', 'Create a group')
48             .within(() => {
49                 cy.get('input[name=name]').type(groupName);
50                 cy.get('button[type=submit]').click();
51             });
52         
53         // Check that the group was created
54         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
55         cy.get('[data-cy=group-members-data-explorer]').contains('Active User');
56     });
57
58     it('adds users to the group', function() {
59         // Add other user to the group
60         cy.get('[data-cy=group-member-add]').click();
61         cy.get('.sharing-dialog')
62             .should('contain', 'Sharing settings')
63             .within(() => {
64                 cy.get('[data-cy=invite-people-field] input').type("other");
65             });
66         cy.get('[role=tooltip]').click();
67         cy.get('.sharing-dialog').contains('Save').click();
68
69         // Check that both users are present with appropriate permissions
70         cy.get('[data-cy=group-members-data-explorer]')
71             .contains('Other User')
72             .parents('tr')
73             .within(() => {
74                 cy.contains('Read');
75             });
76         cy.get('[data-cy=group-members-data-explorer] tr')
77             .contains('Active User')
78             .parents('tr')
79             .within(() => {
80                 cy.contains('Manage');
81             });
82     });
83
84     it('changes permission level of a member', function() {
85         // Test change permission level
86         cy.get('[data-cy=group-members-data-explorer]')
87             .contains('Other User')
88             .parents('tr')
89             .within(() => {
90                 cy.contains('Read')
91                     .parents('td')
92                     .within(() => {
93                         cy.get('button').click();
94                     });
95             });
96         cy.get('[data-cy=context-menu]')
97             .contains('Write')
98             .click();
99         cy.get('[data-cy=group-members-data-explorer]')
100             .contains('Other User')
101             .parents('tr')
102             .within(() => {
103                 cy.contains('Write');
104             });
105     });
106
107     it('can unhide and re-hide users', function() {
108         // Must use admin user to have manage permission on user
109         cy.loginAs(adminUser);
110         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
111         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
112
113         // Check that other user is hidden
114         cy.get('[data-cy=group-details-permissions-tab]').click();
115         cy.get('[data-cy=group-permissions-data-explorer]')
116             .should('not.contain', 'Other User')
117         cy.get('[data-cy=group-details-members-tab]').click();
118
119         // Test unhide
120         cy.get('[data-cy=group-members-data-explorer]')
121             .contains('Other User')
122             .parents('tr')
123             .within(() => {
124                 cy.get('[data-cy=user-hidden-checkbox]').click();
125             });
126         // Check that other user is visible
127         cy.get('[data-cy=group-details-permissions-tab]').click();
128         cy.get('[data-cy=group-permissions-data-explorer]')
129             .contains('Other User')
130             .parents('tr')
131             .within(() => {
132                 cy.contains('Read');
133             });
134         // Test re-hide
135         cy.get('[data-cy=group-details-members-tab]').click();
136         cy.get('[data-cy=group-members-data-explorer]')
137             .contains('Other User')
138             .parents('tr')
139             .within(() => {
140                 cy.get('[data-cy=user-hidden-checkbox]').click();
141             });
142         // Check that other user is hidden
143         cy.get('[data-cy=group-details-permissions-tab]').click();
144         cy.get('[data-cy=group-permissions-data-explorer]')
145             .should('not.contain', 'Other User')
146     });
147
148     it('displays resources shared with the group', function() {
149         // Switch to activeUser
150         cy.loginAs(activeUser);
151         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
152
153         // Get groupUuid and create shared project
154         cy.get('[data-cy=groups-panel-data-explorer]')
155             .contains(groupName)
156             .parents('tr')
157             .find('[data-cy=uuid]')
158             .invoke('text')
159             .as('groupUuid')
160             .then((groupUuid) => {
161                 cy.createProject({
162                     owningUser: activeUser,
163                     projectName: 'test-project',
164                 }).as('testProject').then((testProject) => {
165                     cy.shareWith(activeUser.token, groupUuid, testProject.uuid, 'can_read');
166                 });
167             });
168
169         // Check that the project is listed in permissions
170         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
171         cy.get('[data-cy=group-details-permissions-tab]').click();
172         cy.get('[data-cy=group-permissions-data-explorer]')
173             .contains('test-project')
174             .parents('tr')
175             .within(() => {
176                 cy.contains('Read');
177             });
178     });
179
180     it('removes users from the group', function() {
181         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
182         cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
183
184         // Remove other user
185         cy.get('[data-cy=group-members-data-explorer]')
186             .contains('Other User')
187             .parents('tr')
188             .within(() => {
189                 cy.get('[data-cy=resource-delete-button]').click();
190             });
191         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
192         cy.get('[data-cy=group-members-data-explorer]')
193             .should('not.contain', 'Other User');
194     });
195
196     it('renames the group', function() {
197         // Navigate to Groups
198         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
199
200         // Open rename dialog
201         cy.get('[data-cy=groups-panel-data-explorer]')
202             .contains(groupName)
203             .rightclick();
204         cy.get('[data-cy=context-menu]')
205             .contains('Rename')
206             .click();
207
208         // Rename the group
209         cy.get('[data-cy=form-dialog]')
210             .should('contain', 'Edit Project')
211             .within(() => {
212                 cy.get('input[name=name]').clear().type(groupName + ' (renamed)');
213                 cy.get('button[type=submit]').click();
214             });
215
216         // Check that the group was renamed
217         cy.get('[data-cy=groups-panel-data-explorer]')
218             .contains(groupName + ' (renamed)');
219     });
220
221     it('deletes the group', function() {
222         // Navigate to Groups
223         cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
224
225         // Delete the group
226         cy.get('[data-cy=groups-panel-data-explorer]')
227             .contains(groupName + ' (renamed)')
228             .rightclick();
229         cy.get('[data-cy=context-menu]')
230             .contains('Remove')
231             .click();
232         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
233
234         // Check that the group was deleted
235         cy.get('[data-cy=groups-panel-data-explorer]')
236             .should('not.contain', groupName + ' (renamed)');
237     });
238
239     it('disables group-related controls for built-in groups', function() {
240         cy.loginAs(adminUser);
241
242         ['All users', 'Anonymous users', 'System group'].forEach((builtInGroup) => {
243             cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
244             cy.get('[data-cy=groups-panel-data-explorer]').contains(builtInGroup).click();
245
246             // Check group member actions
247             cy.get('[data-cy=group-members-data-explorer]')
248                 .within(() => {
249                     cy.get('[data-cy=group-member-add]').should('not.exist');
250                     cy.get('[data-cy=user-hidden-checkbox] input').should('be.disabled');
251                     cy.get('[data-cy=resource-delete-button]').should('be.disabled');
252                     cy.get('[data-cy=edit-permission-button]').should('not.exist');
253                 });
254
255             // Check permissions actions
256             cy.get('[data-cy=group-details-permissions-tab]').click();
257             cy.get('[data-cy=group-permissions-data-explorer]').within(() => {
258                 cy.get('[data-cy=resource-delete-button]').should('be.disabled');
259                 cy.get('[data-cy=edit-permission-button]').should('not.exist');
260             });
261         });
262     });
263
264 });