1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 describe('Sharing tests', function () {
10 // Only set up common users once. These aren't set up as aliases because
11 // aliases are cleaned up after every test. Also it doesn't make sense
12 // to set the same users on beforeEach() over and over again, so we
13 // separate a little from Cypress' 'Best Practices' here.
14 cy.getUser('admin', 'Admin', 'User', true, true)
15 .as('adminUser').then(function () {
16 adminUser = this.adminUser;
18 cy.getUser('collectionuser1', 'Collection', 'User', false, true)
19 .as('activeUser').then(function () {
20 activeUser = this.activeUser;
24 beforeEach(function () {
26 cy.clearLocalStorage()
29 it('can create and delete sharing URLs on collections', () => {
30 const collName = 'shared-collection ' + new Date().getTime();
31 cy.createCollection(adminUser.token, {
33 owner_uuid: adminUser.uuid,
34 }).as('sharedCollection').then(function (sharedCollection) {
35 cy.loginAs(adminUser);
37 cy.get('main').contains(sharedCollection.name).rightclick();
38 cy.get('[data-cy=context-menu]').within(() => {
39 cy.contains('Share').click();
41 cy.get('.sharing-dialog').within(() => {
42 cy.contains('Sharing URLs').click();
43 cy.contains('Create sharing URL');
44 cy.contains('No sharing URLs');
45 cy.should('not.contain', 'Token');
46 cy.should('not.contain', 'expiring at:');
48 cy.contains('Create sharing URL').click();
49 cy.should('not.contain', 'No sharing URLs');
51 cy.contains('expiring at:');
53 cy.get('[data-cy=remove-url-btn]').find('button').click();
54 cy.contains('No sharing URLs');
55 cy.should('not.contain', 'Token');
56 cy.should('not.contain', 'expiring at:');
61 it('can share projects to other users', () => {
62 cy.loginAs(adminUser);
64 cy.createGroup(adminUser.token, {
65 name: `my-shared-writable-project ${Math.floor(Math.random() * 999999)}`,
66 group_class: 'project',
67 }).as('mySharedWritableProject').then(function (mySharedWritableProject) {
68 cy.contains('Refresh').click();
69 cy.get('main').contains(mySharedWritableProject.name).rightclick();
70 cy.get('[data-cy=context-menu]').within(() => {
71 cy.contains('Share').click();
73 cy.get('[id="select-permissions"]').as('selectPermissions');
74 cy.get('@selectPermissions').click();
75 cy.contains('Write').click();
76 cy.get('.sharing-dialog').as('sharingDialog');
77 cy.get('[data-cy=invite-people-field]').find('input').type(activeUser.user.email);
78 cy.get('[role=tooltip]').click();
79 cy.get('@sharingDialog').within(() => {
80 cy.get('[data-cy=add-invited-people]').click();
81 cy.contains('Close').click();
85 cy.createGroup(adminUser.token, {
86 name: `my-shared-readonly-project ${Math.floor(Math.random() * 999999)}`,
87 group_class: 'project',
88 }).as('mySharedReadonlyProject').then(function (mySharedReadonlyProject) {
89 cy.contains('Refresh').click();
90 cy.get('main').contains(mySharedReadonlyProject.name).rightclick();
91 cy.get('[data-cy=context-menu]').within(() => {
92 cy.contains('Share').click();
94 cy.get('.sharing-dialog').as('sharingDialog');
95 cy.get('[data-cy=invite-people-field]').find('input').type(activeUser.user.email);
96 cy.get('[role=tooltip]').click();
97 cy.get('@sharingDialog').within(() => {
98 cy.get('[data-cy=add-invited-people]').click();
99 cy.contains('Close').click();
103 cy.getAll('@mySharedWritableProject', '@mySharedReadonlyProject')
104 .then(function ([mySharedWritableProject, mySharedReadonlyProject]) {
105 cy.loginAs(activeUser);
107 cy.contains('Shared with me').click();
109 cy.get('main').contains(mySharedWritableProject.name).rightclick();
110 cy.get('[data-cy=context-menu]').should('contain', 'Move to trash');
111 cy.get('[data-cy=context-menu]').contains('Move to trash').click();
113 // GUARD: Let's wait for the above removed project to disappear
114 // before continuing, to avoid intermittent failures.
115 cy.get('main').should('not.contain', mySharedWritableProject.name);
117 cy.get('main').contains(mySharedReadonlyProject.name).rightclick();
118 cy.get('[data-cy=context-menu]').should('not.contain', 'Move to trash');
122 it('can edit project in shared with me', () => {
124 owningUser: adminUser,
125 targetUser: activeUser,
126 projectName: 'mySharedWritableProject',
131 cy.getAll('@mySharedWritableProject')
132 .then(function ([mySharedWritableProject]) {
133 cy.loginAs(activeUser);
135 cy.get('[data-cy=side-panel-tree]').contains('Shared with me').click();
137 const newProjectName = `New project name ${mySharedWritableProject.name}`;
138 const newProjectDescription = `New project description ${mySharedWritableProject.name}`;
140 cy.testEditProjectOrCollection('main', mySharedWritableProject.name, newProjectName, newProjectDescription);
144 it('can share only when target users are present', () => {
145 const collName = `mySharedCollectionForUsers-${new Date().getTime()}`;
146 cy.createCollection(adminUser.token, {
148 owner_uuid: adminUser.uuid,
149 }).as('mySharedCollectionForUsers')
151 cy.getAll('@mySharedCollectionForUsers')
152 .then(function ([]) {
153 cy.loginAs(adminUser);
154 cy.get('[data-cy=project-panel]').contains(collName).rightclick();
155 cy.get('[data-cy=context-menu]').contains('Share').click();
156 cy.get('button').get('[data-cy=add-invited-people]').should('be.disabled');
157 cy.get('[data-cy=invite-people-field] input').type('Anonymous');
158 cy.get('div[role=tooltip]').contains('anonymous').click();
159 cy.get('button').get('[data-cy=add-invited-people]').should('not.be.disabled');
160 cy.get('[data-cy=invite-people-field] div[role=button]').contains('anonymous').parent().find('svg').click();
161 cy.get('button').get('[data-cy=add-invited-people]').should('be.disabled');