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();
75 // Check that both users are present with appropriate permissions
76 cy.get('[data-cy=group-members-data-explorer]')
77 .contains(otherUser.user.full_name)
82 cy.get('[data-cy=group-members-data-explorer] tr')
83 .contains(activeUser.user.full_name)
86 cy.contains('Manage');
90 it('changes permission level of a member', function() {
91 // Test change permission level
92 cy.get('[data-cy=group-members-data-explorer]')
93 .contains(otherUser.user.full_name)
99 cy.get('button').click();
102 cy.get('[data-cy=context-menu]')
105 cy.get('[data-cy=group-members-data-explorer]')
106 .contains(otherUser.user.full_name)
109 cy.contains('Write');
113 it('can unhide and re-hide users', function() {
114 // Must use admin user to have manage permission on user
115 cy.loginAs(adminUser);
116 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
117 cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
119 // Check that other user is hidden
120 cy.get('[data-cy=group-details-permissions-tab]').click();
121 cy.get('[data-cy=group-permissions-data-explorer]')
122 .should('not.contain', otherUser.user.full_name)
123 cy.get('[data-cy=group-details-members-tab]').click();
126 cy.get('[data-cy=group-members-data-explorer]')
127 .contains(otherUser.user.full_name)
130 cy.get('[data-cy=user-visible-checkbox]').click();
132 // Check that other user is visible
133 cy.get('[data-cy=group-details-permissions-tab]').click();
134 cy.get('[data-cy=group-permissions-data-explorer]')
135 .contains(otherUser.user.full_name)
141 cy.get('[data-cy=group-details-members-tab]').click();
142 cy.get('[data-cy=group-members-data-explorer]')
143 .contains(otherUser.user.full_name)
146 cy.get('[data-cy=user-visible-checkbox]').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)
154 it('displays resources shared with the group', function() {
155 // Switch to activeUser
156 cy.loginAs(activeUser);
157 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
159 // Get groupUuid and create shared project
160 cy.get('[data-cy=groups-panel-data-explorer]')
163 .find('[data-cy=uuid]')
166 .then((groupUuid) => {
168 owningUser: activeUser,
169 projectName: 'test-project',
170 }).as('testProject').then((testProject) => {
171 cy.shareWith(activeUser.token, groupUuid, testProject.uuid, 'can_read');
175 // Check that the project is listed in permissions
176 cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
177 cy.get('[data-cy=group-details-permissions-tab]').click();
178 cy.get('[data-cy=group-permissions-data-explorer]')
179 .contains('test-project')
186 it('removes users from the group', function() {
187 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
188 cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
191 cy.get('[data-cy=group-members-data-explorer]')
192 .contains(otherUser.user.full_name)
195 cy.get('[data-cy=resource-delete-button]').click();
197 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
198 cy.get('[data-cy=group-members-data-explorer]')
199 .should('not.contain', otherUser.user.full_name);
202 cy.get('[data-cy=group-members-data-explorer]')
203 .contains(userThree.user.full_name)
206 cy.get('[data-cy=resource-delete-button]').click();
208 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
209 cy.get('[data-cy=group-members-data-explorer]')
210 .should('not.contain', userThree.user.full_name);
213 it('renames the group', function() {
214 // Navigate to Groups
215 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
217 // Open rename dialog
218 cy.get('[data-cy=groups-panel-data-explorer]')
221 cy.get('[data-cy=context-menu]')
226 cy.get('[data-cy=form-dialog]')
227 .should('contain', 'Edit Group')
229 cy.get('input[name=name]').clear().type(groupName + ' (renamed)');
230 cy.get('button').contains('Save').click();
233 // Check that the group was renamed
234 cy.get('[data-cy=groups-panel-data-explorer]')
235 .contains(groupName + ' (renamed)');
238 it('deletes the group', function() {
239 // Navigate to Groups
240 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
243 cy.get('[data-cy=groups-panel-data-explorer]')
244 .contains(groupName + ' (renamed)')
246 cy.get('[data-cy=context-menu]')
249 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
251 // Check that the group was deleted
252 cy.get('[data-cy=groups-panel-data-explorer]')
253 .should('not.contain', groupName + ' (renamed)');
256 it('disables group-related controls for built-in groups', function() {
257 cy.loginAs(adminUser);
259 ['All users', 'Anonymous users', 'System group'].forEach((builtInGroup) => {
260 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
261 cy.get('[data-cy=groups-panel-data-explorer]').contains(builtInGroup).click();
263 // Check group member actions
264 cy.get('[data-cy=group-members-data-explorer]')
266 cy.get('[data-cy=group-member-add]').should('not.exist');
267 cy.get('[data-cy=user-visible-checkbox] input').should('be.disabled');
268 cy.get('[data-cy=resource-delete-button]').should('be.disabled');
269 cy.get('[data-cy=edit-permission-button]').should('not.exist');
272 // Check permissions actions
273 cy.get('[data-cy=group-details-permissions-tab]').click();
274 cy.get('[data-cy=group-permissions-data-explorer]').within(() => {
275 cy.get('[data-cy=resource-delete-button]').should('be.disabled');
276 cy.get('[data-cy=edit-permission-button]').should('not.exist');