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('[role=tooltip]').click();
71 // Add admin to the group
72 cy.get('.sharing-dialog')
73 .should('contain', 'Sharing settings')
75 cy.get('[data-cy=invite-people-field] input').type("admin");
77 cy.get('[role=tooltip]').click();
78 cy.get('.sharing-dialog').get('[data-cy=add-invited-people]').click();
79 cy.get('.sharing-dialog').contains('Close').click();
81 // Check that both users are present with appropriate permissions
82 cy.get('[data-cy=group-members-data-explorer]')
83 .contains(otherUser.user.full_name)
88 cy.get('[data-cy=group-members-data-explorer] tr')
89 .contains(activeUser.user.full_name)
92 cy.contains('Manage');
95 // Test change permission level
96 cy.get('[data-cy=group-members-data-explorer]')
97 .contains(otherUser.user.full_name)
103 cy.get('button').click();
106 cy.get('[data-cy=context-menu]')
109 cy.get('[data-cy=group-members-data-explorer]')
110 .contains(otherUser.user.full_name)
113 cy.contains('Write');
116 // Change admin to manage
117 cy.get('[data-cy=group-members-data-explorer]')
118 .contains(adminUser.user.full_name)
124 cy.get('button').click();
127 cy.get('[data-cy=context-menu]')
130 cy.get('[data-cy=group-members-data-explorer]')
131 .contains(adminUser.user.full_name)
134 cy.contains('Manage');
138 it('can unhide and re-hide users', function() {
139 // Must use admin user to have manage permission on user
140 cy.loginAs(adminUser);
141 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
142 cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
144 // Check that other user is hidden
145 cy.get('[data-cy=group-details-permissions-tab]').click();
146 cy.get('[data-cy=group-permissions-data-explorer]')
147 .should('not.contain', otherUser.user.full_name)
148 cy.get('[data-cy=group-details-members-tab]').click();
151 cy.get('[data-cy=group-members-data-explorer]')
152 .contains(otherUser.user.full_name)
155 cy.get('[data-cy=user-visible-checkbox]').click();
157 // Check that other user is visible
158 cy.get('[data-cy=group-details-permissions-tab]').click();
159 cy.get('[data-cy=group-permissions-data-explorer]')
160 .contains(otherUser.user.full_name)
166 cy.get('[data-cy=group-details-members-tab]').click();
167 cy.get('[data-cy=group-members-data-explorer]')
168 .contains(otherUser.user.full_name)
171 cy.get('[data-cy=user-visible-checkbox]').click();
173 // Check that other user is hidden
174 cy.get('[data-cy=group-details-permissions-tab]').click();
175 cy.get('[data-cy=group-permissions-data-explorer]')
176 .should('not.contain', otherUser.user.full_name)
179 it('displays resources shared with the group', function() {
180 // Switch to activeUser
181 cy.loginAs(activeUser);
182 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
184 // Get groupUuid and create shared project
185 cy.get('[data-cy=groups-panel-data-explorer]')
188 .find('[data-cy=uuid]')
191 .then((groupUuid) => {
193 owningUser: activeUser,
194 projectName: 'test-project',
195 }).as('testProject').then((testProject) => {
196 cy.shareWith(activeUser.token, groupUuid, testProject.uuid, 'can_read');
200 // Check that the project is listed in permissions
201 cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
202 cy.get('[data-cy=group-details-permissions-tab]').click();
203 cy.get('[data-cy=group-permissions-data-explorer]')
204 .contains('test-project')
211 it('removes users from the group', function() {
212 cy.loginAs(activeUser);
214 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
215 cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
218 cy.get('[data-cy=group-members-data-explorer]')
219 .contains(otherUser.user.full_name)
222 cy.get('[data-cy=resource-delete-button]').click();
224 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
225 cy.get('[data-cy=group-members-data-explorer]')
226 .should('not.contain', otherUser.user.full_name);
229 cy.get('[data-cy=group-members-data-explorer]')
230 .contains(userThree.user.full_name)
233 cy.get('[data-cy=resource-delete-button]').click();
235 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
236 cy.get('[data-cy=group-members-data-explorer]')
237 .should('not.contain', userThree.user.full_name);
240 it('renames the group', function() {
241 cy.loginAs(adminUser);
242 // Navigate to Groups
243 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
245 // Open rename dialog
246 cy.get('[data-cy=groups-panel-data-explorer]')
249 cy.get('[data-cy=context-menu]')
254 cy.get('[data-cy=form-dialog]')
255 .should('contain', 'Edit Group')
257 cy.get('input[name=name]').clear().type(groupName + ' (renamed)');
258 cy.get('button').contains('Save').click();
261 // Check that the group was renamed
262 cy.get('[data-cy=groups-panel-data-explorer]')
263 .contains(groupName + ' (renamed)');
266 it('deletes the group', function() {
267 cy.loginAs(adminUser);
269 // Navigate to Groups
270 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
273 cy.get('[data-cy=groups-panel-data-explorer]')
274 .contains(groupName + ' (renamed)')
276 cy.get('[data-cy=context-menu]')
279 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
281 // Check that the group was deleted
282 cy.get('[data-cy=groups-panel-data-explorer]')
283 .should('not.contain', groupName + ' (renamed)');
286 it('disables group-related controls for built-in groups', function() {
287 cy.loginAs(adminUser);
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();
293 // Check group member actions
294 cy.get('[data-cy=group-members-data-explorer]')
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');
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');