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 cy.get('.sharing-dialog').contains('Save').click();
74 cy.get('.sharing-dialog').contains('Close').click();
76 // Check that both users are present with appropriate permissions
77 cy.get('[data-cy=group-members-data-explorer]')
78 .contains(otherUser.user.full_name)
83 cy.get('[data-cy=group-members-data-explorer] tr')
84 .contains(activeUser.user.full_name)
87 cy.contains('Manage');
91 it('changes permission level of a member', function() {
92 // Test change permission level
93 cy.get('[data-cy=group-members-data-explorer]')
94 .contains(otherUser.user.full_name)
100 cy.get('button').click();
103 cy.get('[data-cy=context-menu]')
106 cy.get('[data-cy=group-members-data-explorer]')
107 .contains(otherUser.user.full_name)
110 cy.contains('Write');
114 it('can unhide and re-hide users', function() {
115 // Must use admin user to have manage permission on user
116 cy.loginAs(adminUser);
117 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
118 cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
120 // Check that other user is hidden
121 cy.get('[data-cy=group-details-permissions-tab]').click();
122 cy.get('[data-cy=group-permissions-data-explorer]')
123 .should('not.contain', otherUser.user.full_name)
124 cy.get('[data-cy=group-details-members-tab]').click();
127 cy.get('[data-cy=group-members-data-explorer]')
128 .contains(otherUser.user.full_name)
131 cy.get('[data-cy=user-visible-checkbox]').click();
133 // Check that other user is visible
134 cy.get('[data-cy=group-details-permissions-tab]').click();
135 cy.get('[data-cy=group-permissions-data-explorer]')
136 .contains(otherUser.user.full_name)
142 cy.get('[data-cy=group-details-members-tab]').click();
143 cy.get('[data-cy=group-members-data-explorer]')
144 .contains(otherUser.user.full_name)
147 cy.get('[data-cy=user-visible-checkbox]').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)
155 it('displays resources shared with the group', function() {
156 // Switch to activeUser
157 cy.loginAs(activeUser);
158 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
160 // Get groupUuid and create shared project
161 cy.get('[data-cy=groups-panel-data-explorer]')
164 .find('[data-cy=uuid]')
167 .then((groupUuid) => {
169 owningUser: activeUser,
170 projectName: 'test-project',
171 }).as('testProject').then((testProject) => {
172 cy.shareWith(activeUser.token, groupUuid, testProject.uuid, 'can_read');
176 // Check that the project is listed in permissions
177 cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
178 cy.get('[data-cy=group-details-permissions-tab]').click();
179 cy.get('[data-cy=group-permissions-data-explorer]')
180 .contains('test-project')
187 it('removes users from the group', function() {
188 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
189 cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
192 cy.get('[data-cy=group-members-data-explorer]')
193 .contains(otherUser.user.full_name)
196 cy.get('[data-cy=resource-delete-button]').click();
198 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
199 cy.get('[data-cy=group-members-data-explorer]')
200 .should('not.contain', otherUser.user.full_name);
203 cy.get('[data-cy=group-members-data-explorer]')
204 .contains(userThree.user.full_name)
207 cy.get('[data-cy=resource-delete-button]').click();
209 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
210 cy.get('[data-cy=group-members-data-explorer]')
211 .should('not.contain', userThree.user.full_name);
214 it('renames the group', function() {
215 // Navigate to Groups
216 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
218 // Open rename dialog
219 cy.get('[data-cy=groups-panel-data-explorer]')
222 cy.get('[data-cy=context-menu]')
227 cy.get('[data-cy=form-dialog]')
228 .should('contain', 'Edit Group')
230 cy.get('input[name=name]').clear().type(groupName + ' (renamed)');
231 cy.get('button').contains('Save').click();
234 // Check that the group was renamed
235 cy.get('[data-cy=groups-panel-data-explorer]')
236 .contains(groupName + ' (renamed)');
239 it('deletes the group', function() {
240 // Navigate to Groups
241 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
244 cy.get('[data-cy=groups-panel-data-explorer]')
245 .contains(groupName + ' (renamed)')
247 cy.get('[data-cy=context-menu]')
250 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
252 // Check that the group was deleted
253 cy.get('[data-cy=groups-panel-data-explorer]')
254 .should('not.contain', groupName + ' (renamed)');
257 it('disables group-related controls for built-in groups', function() {
258 cy.loginAs(adminUser);
260 ['All users', 'Anonymous users', 'System group'].forEach((builtInGroup) => {
261 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
262 cy.get('[data-cy=groups-panel-data-explorer]').contains(builtInGroup).click();
264 // Check group member actions
265 cy.get('[data-cy=group-members-data-explorer]')
267 cy.get('[data-cy=group-member-add]').should('not.exist');
268 cy.get('[data-cy=user-visible-checkbox] input').should('be.disabled');
269 cy.get('[data-cy=resource-delete-button]').should('be.disabled');
270 cy.get('[data-cy=edit-permission-button]').should('not.exist');
273 // Check permissions actions
274 cy.get('[data-cy=group-details-permissions-tab]').click();
275 cy.get('[data-cy=group-permissions-data-explorer]').within(() => {
276 cy.get('[data-cy=resource-delete-button]').should('be.disabled');
277 cy.get('[data-cy=edit-permission-button]').should('not.exist');