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 beforeEach(function() {
41 cy.clearLocalStorage();
44 it('creates a new group', function() {
45 cy.loginAs(activeUser);
48 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
51 cy.get('[data-cy=groups-panel-new-group]').click();
52 cy.get('[data-cy=form-dialog]')
53 .should('contain', 'Create Group')
55 cy.get('input[name=name]').type(groupName);
56 cy.get('[data-cy=users-field] input').type("three");
58 cy.get('[role=tooltip]').click();
59 cy.get('[data-cy=form-dialog] button[type=submit]').click();
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);
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')
73 cy.get('[data-cy=invite-people-field] input').type("other");
75 cy.get('[role=tooltip]').click();
76 cy.get('.sharing-dialog').contains('Save').click();
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)
85 cy.get('[data-cy=group-members-data-explorer] tr')
86 .contains(activeUser.user.full_name)
89 cy.contains('Manage');
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)
102 cy.get('button').click();
105 cy.get('[data-cy=context-menu]')
108 cy.get('[data-cy=group-members-data-explorer]')
109 .contains(otherUser.user.full_name)
112 cy.contains('Write');
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();
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();
129 cy.get('[data-cy=group-members-data-explorer]')
130 .contains(otherUser.user.full_name)
133 cy.get('[data-cy=user-visible-checkbox]').click();
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)
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)
149 cy.get('[data-cy=user-visible-checkbox]').click();
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)
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();
162 // Get groupUuid and create shared project
163 cy.get('[data-cy=groups-panel-data-explorer]')
166 .find('[data-cy=uuid]')
169 .then((groupUuid) => {
171 owningUser: activeUser,
172 projectName: 'test-project',
173 }).as('testProject').then((testProject) => {
174 cy.shareWith(activeUser.token, groupUuid, testProject.uuid, 'can_read');
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')
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();
194 cy.get('[data-cy=group-members-data-explorer]')
195 .contains(otherUser.user.full_name)
198 cy.get('[data-cy=resource-delete-button]').click();
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);
205 cy.get('[data-cy=group-members-data-explorer]')
206 .contains(userThree.user.full_name)
209 cy.get('[data-cy=resource-delete-button]').click();
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);
216 it('renames the group', function() {
217 // Navigate to Groups
218 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
220 // Open rename dialog
221 cy.get('[data-cy=groups-panel-data-explorer]')
224 cy.get('[data-cy=context-menu]')
229 cy.get('[data-cy=form-dialog]')
230 .should('contain', 'Edit Group')
232 cy.get('input[name=name]').clear().type(groupName + ' (renamed)');
233 cy.get('button[type=submit]').click();
236 // Check that the group was renamed
237 cy.get('[data-cy=groups-panel-data-explorer]')
238 .contains(groupName + ' (renamed)');
241 it('deletes the group', function() {
242 // Navigate to Groups
243 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
246 cy.get('[data-cy=groups-panel-data-explorer]')
247 .contains(groupName + ' (renamed)')
249 cy.get('[data-cy=context-menu]')
252 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
254 // Check that the group was deleted
255 cy.get('[data-cy=groups-panel-data-explorer]')
256 .should('not.contain', groupName + ' (renamed)');
259 it('disables group-related controls for built-in groups', function() {
260 cy.loginAs(adminUser);
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();
266 // Check group member actions
267 cy.get('[data-cy=group-members-data-explorer]')
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');
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');