1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 describe('Group manage tests', function() {
10 const groupName = `Test group (${Math.floor(999999 * Math.random())})`;
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;
22 cy.getUser('user', 'Active', 'User', false, true)
23 .as('activeUser').then(function() {
24 activeUser = this.activeUser;
27 cy.getUser('otheruser', 'Other', 'User', false, true)
28 .as('otherUser').then(function() {
29 otherUser = this.otherUser;
32 cy.getUser('userThree', 'User', 'Three', false, true)
33 .as('userThree').then(function() {
34 userThree = this.userThree;
39 it('creates a new group, add users to it and changes permission level', function() {
40 cy.loginAs(activeUser);
43 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
46 cy.get('[data-cy=groups-panel-new-group]').click();
47 cy.get('[data-cy=form-dialog]')
48 .should('contain', 'New Group')
50 cy.get('input[name=name]').type(groupName);
51 cy.get('[data-cy=users-field] input').type("three");
53 cy.get('[role=tooltip]').click();
54 cy.get('[data-cy=form-dialog]').within(() => {
55 cy.get('[data-cy=form-submit-btn]').click();
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);
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')
68 cy.get('[data-cy=invite-people-field] input').type("other");
70 cy.get('[data-cy="loading-spinner"]').should('not.exist');
71 cy.get('[data-cy="users-tab-label"]').click();
72 cy.get('[data-cy=sharing-suggestion]').click();
73 // Add admin to the group
74 cy.get('.sharing-dialog')
75 .should('contain', 'Sharing settings')
77 cy.get('[data-cy=invite-people-field] input').clear().type("admin");
79 cy.get('[data-cy="loading-spinner"]').should('not.exist');
81 cy.get('[data-cy="users-tab-label"]').click();
82 cy.get('[data-cy=sharing-suggestion]').click();
83 cy.get('.sharing-dialog').get('[data-cy=add-invited-people]').click();
84 cy.get('.sharing-dialog').contains('Close').click();
86 // Check that both users are present with appropriate permissions
87 cy.get('[data-cy=group-members-data-explorer]')
88 .contains(otherUser.user.full_name)
93 cy.get('[data-cy=group-members-data-explorer] tr')
94 .contains(activeUser.user.full_name)
97 cy.contains('Manage');
100 // Test change permission level
101 cy.get('[data-cy=group-members-data-explorer]')
102 .contains(otherUser.user.full_name)
108 cy.get('button').click();
111 cy.get('[data-cy=context-menu]')
114 cy.get('[data-cy=group-members-data-explorer]')
115 .contains(otherUser.user.full_name)
118 cy.contains('Write');
121 // Change admin to manage
122 cy.get('[data-cy=group-members-data-explorer]')
123 .contains(adminUser.user.full_name)
129 cy.get('button').click();
132 cy.get('[data-cy=context-menu]')
135 cy.get('[data-cy=group-members-data-explorer]')
136 .contains(adminUser.user.full_name)
139 cy.contains('Manage');
143 it('can unhide and re-hide users', function() {
144 // Must use admin user to have manage permission on user
145 cy.loginAs(adminUser);
146 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
147 cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
149 // Check that other user is hidden
150 cy.get('[data-cy=group-details-permissions-tab]').click();
151 cy.get('[data-cy=group-permissions-data-explorer]')
152 .should('not.contain', otherUser.user.full_name)
153 cy.get('[data-cy=group-details-members-tab]').click();
156 cy.get('[data-cy=group-members-data-explorer]')
157 .contains(otherUser.user.full_name)
160 cy.get('[data-cy=user-visible-checkbox]').click();
162 // Check that other user is visible
163 cy.get('[data-cy=group-details-permissions-tab]').click();
164 cy.get('[data-cy=group-permissions-data-explorer]')
165 .contains(otherUser.user.full_name)
171 cy.get('[data-cy=group-details-members-tab]').click();
172 cy.get('[data-cy=group-members-data-explorer]')
173 .contains(otherUser.user.full_name)
176 cy.get('[data-cy=user-visible-checkbox]').click();
178 // Check that other user is hidden
179 cy.get('[data-cy=group-details-permissions-tab]').click();
180 cy.get('[data-cy=group-permissions-data-explorer]')
181 .should('not.contain', otherUser.user.full_name)
184 it('displays resources shared with the group', function() {
185 // Switch to activeUser
186 cy.loginAs(activeUser);
187 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
189 // Get groupUuid and create shared project
190 cy.get('[data-cy=groups-panel-data-explorer]')
193 .find('[data-cy=uuid]')
196 .then((groupUuid) => {
198 owningUser: activeUser,
199 projectName: 'test-project',
200 }).as('testProject').then((testProject) => {
201 cy.shareWith(activeUser.token, groupUuid, testProject.uuid, 'can_read');
205 // Check that the project is listed in permissions
206 cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
207 cy.get('[data-cy=group-details-permissions-tab]').click();
208 cy.get('[data-cy=group-permissions-data-explorer]')
209 .contains('test-project')
216 it('removes users from the group', function() {
217 cy.loginAs(activeUser);
219 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
220 cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
223 cy.get('[data-cy=group-members-data-explorer]')
224 .contains(otherUser.user.full_name)
227 cy.get('[data-cy=resource-delete-button]').click();
229 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
230 cy.get('[data-cy=group-members-data-explorer]')
231 .should('not.contain', otherUser.user.full_name);
234 cy.get('[data-cy=group-members-data-explorer]')
235 .contains(userThree.user.full_name)
238 cy.get('[data-cy=resource-delete-button]').click();
240 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
241 cy.get('[data-cy=group-members-data-explorer]')
242 .should('not.contain', userThree.user.full_name);
245 it('renames the group', function() {
246 cy.loginAs(adminUser);
247 // Navigate to Groups
248 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
250 // Open rename dialog
251 cy.get('[data-cy=groups-panel-data-explorer]')
254 cy.get('[data-cy=context-menu]')
259 cy.get('[data-cy=form-dialog]')
260 .should('contain', 'Edit Group')
262 cy.get('input[name=name]').clear().type(groupName + ' (renamed)');
263 cy.get('button').contains('Save').click();
266 // Check that the group was renamed
267 cy.get('[data-cy=groups-panel-data-explorer]')
268 .contains(groupName + ' (renamed)');
271 it('deletes the group', function() {
272 cy.loginAs(adminUser);
274 // Navigate to Groups
275 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
278 cy.get('[data-cy=groups-panel-data-explorer]')
279 .contains(groupName + ' (renamed)')
281 cy.get('[data-cy=context-menu]')
284 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
286 // Check that the group was deleted
287 cy.get('[data-cy=groups-panel-data-explorer]')
288 .should('not.contain', groupName + ' (renamed)');
291 it('disables group-related controls for built-in groups', function() {
292 cy.loginAs(adminUser);
294 ['All users', 'Anonymous users', 'System group'].forEach((builtInGroup) => {
295 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
296 cy.get('[data-cy=groups-panel-data-explorer]').contains(builtInGroup).click();
298 // Check group member actions
299 cy.get('[data-cy=group-members-data-explorer]')
301 cy.get('[data-cy=group-member-add]').should('not.exist');
302 cy.get('[data-cy=user-visible-checkbox] input').should('be.disabled');
303 cy.get('[data-cy=resource-delete-button]').should('be.disabled');
304 cy.get('[data-cy=edit-permission-button]').should('not.exist');
307 // Check permissions actions
308 cy.get('[data-cy=group-details-permissions-tab]').click();
309 cy.get('[data-cy=group-permissions-data-explorer]').within(() => {
310 cy.get('[data-cy=resource-delete-button]').should('be.disabled');
311 cy.get('[data-cy=edit-permission-button]').should('not.exist');