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', 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);
64 it('adds users to the group', function() {
65 // Add other user to the group
66 cy.get('[data-cy=group-member-add]').click();
67 cy.get('.sharing-dialog')
68 .should('contain', 'Sharing settings')
70 cy.get('[data-cy=invite-people-field] input').type("other");
72 cy.get('[role=tooltip]').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').type("admin");
79 cy.get('[role=tooltip]').click();
80 cy.get('.sharing-dialog').get('[data-cy=add-invited-people]').click();
81 cy.get('.sharing-dialog').contains('Close').click();
83 // Check that both users are present with appropriate permissions
84 cy.get('[data-cy=group-members-data-explorer]')
85 .contains(otherUser.user.full_name)
90 cy.get('[data-cy=group-members-data-explorer] tr')
91 .contains(activeUser.user.full_name)
94 cy.contains('Manage');
98 it('changes permission level of a member', function() {
99 // Test change permission level
100 cy.get('[data-cy=group-members-data-explorer]')
101 .contains(otherUser.user.full_name)
107 cy.get('button').click();
110 cy.get('[data-cy=context-menu]')
113 cy.get('[data-cy=group-members-data-explorer]')
114 .contains(otherUser.user.full_name)
117 cy.contains('Write');
120 // Change admin to manage
121 cy.get('[data-cy=group-members-data-explorer]')
122 .contains(adminUser.user.full_name)
128 cy.get('button').click();
131 cy.get('[data-cy=context-menu]')
134 cy.get('[data-cy=group-members-data-explorer]')
135 .contains(adminUser.user.full_name)
138 cy.contains('Manage');
142 it('can unhide and re-hide users', function() {
143 // Must use admin user to have manage permission on user
144 cy.loginAs(adminUser);
145 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
146 cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
148 // Check that other user is hidden
149 cy.get('[data-cy=group-details-permissions-tab]').click();
150 cy.get('[data-cy=group-permissions-data-explorer]')
151 .should('not.contain', otherUser.user.full_name)
152 cy.get('[data-cy=group-details-members-tab]').click();
155 cy.get('[data-cy=group-members-data-explorer]')
156 .contains(otherUser.user.full_name)
159 cy.get('[data-cy=user-visible-checkbox]').click();
161 // Check that other user is visible
162 cy.get('[data-cy=group-details-permissions-tab]').click();
163 cy.get('[data-cy=group-permissions-data-explorer]')
164 .contains(otherUser.user.full_name)
170 cy.get('[data-cy=group-details-members-tab]').click();
171 cy.get('[data-cy=group-members-data-explorer]')
172 .contains(otherUser.user.full_name)
175 cy.get('[data-cy=user-visible-checkbox]').click();
177 // Check that other user is hidden
178 cy.get('[data-cy=group-details-permissions-tab]').click();
179 cy.get('[data-cy=group-permissions-data-explorer]')
180 .should('not.contain', otherUser.user.full_name)
183 it('displays resources shared with the group', function() {
184 // Switch to activeUser
185 cy.loginAs(activeUser);
186 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
188 // Get groupUuid and create shared project
189 cy.get('[data-cy=groups-panel-data-explorer]')
192 .find('[data-cy=uuid]')
195 .then((groupUuid) => {
197 owningUser: activeUser,
198 projectName: 'test-project',
199 }).as('testProject').then((testProject) => {
200 cy.shareWith(activeUser.token, groupUuid, testProject.uuid, 'can_read');
204 // Check that the project is listed in permissions
205 cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
206 cy.get('[data-cy=group-details-permissions-tab]').click();
207 cy.get('[data-cy=group-permissions-data-explorer]')
208 .contains('test-project')
215 it('removes users from the group', function() {
216 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
217 cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
220 cy.get('[data-cy=group-members-data-explorer]')
221 .contains(otherUser.user.full_name)
224 cy.get('[data-cy=resource-delete-button]').click();
226 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
227 cy.get('[data-cy=group-members-data-explorer]')
228 .should('not.contain', otherUser.user.full_name);
231 cy.get('[data-cy=group-members-data-explorer]')
232 .contains(userThree.user.full_name)
235 cy.get('[data-cy=resource-delete-button]').click();
237 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
238 cy.get('[data-cy=group-members-data-explorer]')
239 .should('not.contain', userThree.user.full_name);
242 it('renames the group', function() {
243 cy.loginAs(adminUser);
244 // Navigate to Groups
245 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
247 // Open rename dialog
248 cy.get('[data-cy=groups-panel-data-explorer]')
251 cy.get('[data-cy=context-menu]')
256 cy.get('[data-cy=form-dialog]')
257 .should('contain', 'Edit Group')
259 cy.get('input[name=name]').clear().type(groupName + ' (renamed)');
260 cy.get('button').contains('Save').click();
263 // Check that the group was renamed
264 cy.get('[data-cy=groups-panel-data-explorer]')
265 .contains(groupName + ' (renamed)');
268 it('deletes the group', function() {
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');