Skip to content

Commit 0c42be7

Browse files
committed
fix(form-delegation): Specify security strategy and improve form delegation e2e tests
1 parent b4427ca commit 0c42be7

File tree

2 files changed

+62
-4
lines changed

2 files changed

+62
-4
lines changed

src/Glpi/Controller/Form/DelegationController.php

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
use Glpi\Controller\AbstractController;
3838
use Glpi\Exception\Http\BadRequestHttpException;
3939
use Glpi\Exception\Http\NotFoundHttpException;
40+
use Glpi\Http\Firewall;
41+
use Glpi\Security\Attribute\SecurityStrategy;
4042
use Symfony\Component\HttpFoundation\Request;
4143
use Symfony\Component\HttpFoundation\Response;
4244
use Symfony\Component\Routing\Attribute\Route;
@@ -49,6 +51,7 @@ final class DelegationController extends AbstractController
4951
name: "glpi_form_delegation",
5052
methods: "GET",
5153
)]
54+
#[SecurityStrategy(Firewall::STRATEGY_AUTHENTICATED)]
5255
public function __invoke(Request $request): Response
5356
{
5457
$selected_user_id = $request->query->get('selected_user_id');

tests/cypress/e2e/form/form_delegation.cy.js

+59-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
*/
3232

3333
describe('Form delegation', () => {
34-
const uuid = new Date().getTime();
34+
let uuid = new Date().getTime();
35+
36+
beforeEach(() => {
37+
uuid = new Date().getTime();
38+
});
3539

3640
it('can choice my notifications preferences', () => {
3741
createFormAndRenderIt();
@@ -53,7 +57,7 @@ describe('Form delegation', () => {
5357
cy.findByRole('button', { name: 'Submit' }).click();
5458

5559
// Go to the created ticket
56-
cy.findByRole('link', { name: 'My test form' }).click();
60+
cy.findByRole('link', { name: `My test form - ${uuid}` }).click();
5761

5862
cy.findByRole('region', { name: 'Actors' }).within(() => {
5963
cy.findByRole('listitem', { name: 'E2E Tests' }).should('exist');
@@ -95,7 +99,55 @@ describe('Form delegation', () => {
9599
cy.findByRole('button', { name: 'Submit' }).click();
96100

97101
// Go to the created ticket
98-
cy.findByRole('link', { name: 'My test form' }).click();
102+
cy.findByRole('link', { name: `My test form - ${uuid}` }).click();
103+
104+
cy.findByRole('region', { name: 'Actors' }).within(() => {
105+
cy.findByRole('listitem', { name: `Test user - ${uuid}` }).should('exist');
106+
cy.findByRole('listitem', { name: 'E2E Tests' }).should('not.exist');
107+
cy.findByRole('button', { name: 'Email followup' }).click();
108+
cy.findByRole('checkbox', { name: 'Email followup' }).should('be.checked');
109+
cy.findByRole('textbox', { name: 'Email address' }).should('have.value', '[email protected]');
110+
});
111+
});
112+
113+
it('can delegate in self-service', () => {
114+
initDelegationWithAPI();
115+
createFormAndRenderIt();
116+
cy.changeProfile('Self-Service');
117+
cy.reload();
118+
119+
// Check values
120+
cy.getDropdownByLabelText('Select the user to delegate').should('have.text', 'Myself');
121+
cy.getDropdownByLabelText('Select the user to delegate').click();
122+
cy.get('.select2-results__options').contains(`Test user - ${uuid}`);
123+
124+
cy.getDropdownByLabelText('Do you want to be notified of future events of this ticket').should('have.text', 'I want');
125+
cy.getDropdownByLabelText('Do you want to be notified of future events of this ticket').click();
126+
cy.get('.select2-results__options').contains('I don\'t want');
127+
128+
// Select user to delegate
129+
cy.getDropdownByLabelText('Select the user to delegate').selectDropdownValue(`Test user - ${uuid}`);
130+
131+
// Check values
132+
cy.getDropdownByLabelText('Do you want to be notified of future events of this ticket').should('have.text', 'He wants');
133+
cy.getDropdownByLabelText('Do you want to be notified of future events of this ticket').click();
134+
cy.get('.select2-results__options').contains('He doesn\'t want');
135+
136+
// Define email address
137+
cy.findByRole('button', { name: 'Address to send the notification' }).click();
138+
cy.findByRole('textbox', { name: 'Address to send the notification' }).type('[email protected]');
139+
140+
// Fill form
141+
cy.findByRole('textbox', { name: 'Name' }).type('Test');
142+
143+
// Submit form
144+
cy.findByRole('button', { name: 'Submit' }).click();
145+
146+
// Change profile to view ticket properties
147+
cy.changeProfile('Super-Admin');
148+
149+
// Go to the created ticket
150+
cy.findByRole('link', { name: `My test form - ${uuid}` }).click();
99151

100152
cy.findByRole('region', { name: 'Actors' }).within(() => {
101153
cy.findByRole('listitem', { name: `Test user - ${uuid}` }).should('exist');
@@ -108,7 +160,10 @@ describe('Form delegation', () => {
108160

109161
function createFormAndRenderIt() {
110162
cy.login();
111-
cy.createFormWithAPI().as('form_id').then((form_id) => {
163+
cy.createFormWithAPI({
164+
name: `My test form - ${uuid}`,
165+
is_active: true
166+
}).as('form_id').then((form_id) => {
112167
cy.addQuestionToDefaultSectionWithAPI(
113168
form_id,
114169
'Name',

0 commit comments

Comments
 (0)