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', 'Create 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] button[type=submit]').click();
56 // Check that the group was created
57 cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
58 cy.get('[data-cy=group-members-data-explorer]').contains(activeUser.user.full_name);
59 cy.get('[data-cy=group-members-data-explorer]').contains(userThree.user.full_name);
62 it('adds users to the group', function() {
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 cy.get('.sharing-dialog').contains('Save').click();
73 // Check that both users are present with appropriate permissions
74 cy.get('[data-cy=group-members-data-explorer]')
75 .contains(otherUser.user.full_name)
80 cy.get('[data-cy=group-members-data-explorer] tr')
81 .contains(activeUser.user.full_name)
84 cy.contains('Manage');
88 it('changes permission level of a member', function() {
89 // Test change permission level
90 cy.get('[data-cy=group-members-data-explorer]')
91 .contains(otherUser.user.full_name)
97 cy.get('button').click();
100 cy.get('[data-cy=context-menu]')
103 cy.get('[data-cy=group-members-data-explorer]')
104 .contains(otherUser.user.full_name)
107 cy.contains('Write');
111 it('can unhide and re-hide users', function() {
112 // Must use admin user to have manage permission on user
113 cy.loginAs(adminUser);
114 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
115 cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
117 // Check that other user is hidden
118 cy.get('[data-cy=group-details-permissions-tab]').click();
119 cy.get('[data-cy=group-permissions-data-explorer]')
120 .should('not.contain', otherUser.user.full_name)
121 cy.get('[data-cy=group-details-members-tab]').click();
124 cy.get('[data-cy=group-members-data-explorer]')
125 .contains(otherUser.user.full_name)
128 cy.get('[data-cy=user-visible-checkbox]').click();
130 // Check that other user is visible
131 cy.get('[data-cy=group-details-permissions-tab]').click();
132 cy.get('[data-cy=group-permissions-data-explorer]')
133 .contains(otherUser.user.full_name)
139 cy.get('[data-cy=group-details-members-tab]').click();
140 cy.get('[data-cy=group-members-data-explorer]')
141 .contains(otherUser.user.full_name)
144 cy.get('[data-cy=user-visible-checkbox]').click();
146 // Check that other user is hidden
147 cy.get('[data-cy=group-details-permissions-tab]').click();
148 cy.get('[data-cy=group-permissions-data-explorer]')
149 .should('not.contain', otherUser.user.full_name)
152 it('displays resources shared with the group', function() {
153 // Switch to activeUser
154 cy.loginAs(activeUser);
155 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
157 // Get groupUuid and create shared project
158 cy.get('[data-cy=groups-panel-data-explorer]')
161 .find('[data-cy=uuid]')
164 .then((groupUuid) => {
166 owningUser: activeUser,
167 projectName: 'test-project',
168 }).as('testProject').then((testProject) => {
169 cy.shareWith(activeUser.token, groupUuid, testProject.uuid, 'can_read');
173 // Check that the project is listed in permissions
174 cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
175 cy.get('[data-cy=group-details-permissions-tab]').click();
176 cy.get('[data-cy=group-permissions-data-explorer]')
177 .contains('test-project')
184 it('removes users from the group', function() {
185 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
186 cy.get('[data-cy=groups-panel-data-explorer]').contains(groupName).click();
189 cy.get('[data-cy=group-members-data-explorer]')
190 .contains(otherUser.user.full_name)
193 cy.get('[data-cy=resource-delete-button]').click();
195 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
196 cy.get('[data-cy=group-members-data-explorer]')
197 .should('not.contain', otherUser.user.full_name);
200 cy.get('[data-cy=group-members-data-explorer]')
201 .contains(userThree.user.full_name)
204 cy.get('[data-cy=resource-delete-button]').click();
206 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
207 cy.get('[data-cy=group-members-data-explorer]')
208 .should('not.contain', userThree.user.full_name);
211 it('renames the group', function() {
212 // Navigate to Groups
213 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
215 // Open rename dialog
216 cy.get('[data-cy=groups-panel-data-explorer]')
219 cy.get('[data-cy=context-menu]')
224 cy.get('[data-cy=form-dialog]')
225 .should('contain', 'Edit Group')
227 cy.get('input[name=name]').clear().type(groupName + ' (renamed)');
228 cy.get('button').contains('Save').click();
231 // Check that the group was renamed
232 cy.get('[data-cy=groups-panel-data-explorer]')
233 .contains(groupName + ' (renamed)');
236 it('deletes the group', function() {
237 // Navigate to Groups
238 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
241 cy.get('[data-cy=groups-panel-data-explorer]')
242 .contains(groupName + ' (renamed)')
244 cy.get('[data-cy=context-menu]')
247 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
249 // Check that the group was deleted
250 cy.get('[data-cy=groups-panel-data-explorer]')
251 .should('not.contain', groupName + ' (renamed)');
254 it('disables group-related controls for built-in groups', function() {
255 cy.loginAs(adminUser);
257 ['All users', 'Anonymous users', 'System group'].forEach((builtInGroup) => {
258 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
259 cy.get('[data-cy=groups-panel-data-explorer]').contains(builtInGroup).click();
261 // Check group member actions
262 cy.get('[data-cy=group-members-data-explorer]')
264 cy.get('[data-cy=group-member-add]').should('not.exist');
265 cy.get('[data-cy=user-visible-checkbox] input').should('be.disabled');
266 cy.get('[data-cy=resource-delete-button]').should('be.disabled');
267 cy.get('[data-cy=edit-permission-button]').should('not.exist');
270 // Check permissions actions
271 cy.get('[data-cy=group-details-permissions-tab]').click();
272 cy.get('[data-cy=group-permissions-data-explorer]').within(() => {
273 cy.get('[data-cy=resource-delete-button]').should('be.disabled');
274 cy.get('[data-cy=edit-permission-button]').should('not.exist');