Skip to content

Commit 691a0a6

Browse files
committed
fix(delegation): hide notification options when no delegation rights
1 parent 5d35d6f commit 691a0a6

File tree

2 files changed

+80
-122
lines changed

2 files changed

+80
-122
lines changed

templates/components/helpdesk_forms/delegation_alert.html.twig

+73-89
Original file line numberDiff line numberDiff line change
@@ -39,97 +39,81 @@
3939
{% endif %}
4040

4141
{% set users = get_current_user().getUsersFromDelegatedGroups() %}
42-
{% set user_dropdown_html %}
43-
{{ fields.dropdownArrayField(
44-
'delegation_users_id',
45-
selected_user.getID(),
46-
users,
47-
'',
48-
{
49-
'no_label' : true,
50-
'width' : 'auto',
51-
'field_class' : '',
52-
'mb' : '',
53-
'aria_label' : __('Select the user to delegate'),
54-
'wrapper_class' : 'd-inline-block',
55-
}
56-
) }}
57-
{% endset %}
42+
{% if users|length > 1 %}
43+
{% set user_dropdown_html %}
44+
{{ fields.dropdownArrayField(
45+
'delegation_users_id',
46+
selected_user.getID(),
47+
users,
48+
'',
49+
{
50+
'no_label' : true,
51+
'width' : 'auto',
52+
'field_class' : '',
53+
'mb' : '',
54+
'aria_label' : __('Select the user to delegate'),
55+
'wrapper_class' : 'd-inline-block',
56+
}
57+
) }}
58+
{% endset %}
5859

59-
{% set notification_part_html %}
60-
<span class="input-group d-inline-flex w-auto">
61-
{% if selected_user.getID() == get_current_user().getID() %}
62-
{{ fields.dropdownArrayField(
63-
'delegation_use_notification',
64-
'1',
65-
{
66-
'0': __('I don\'t want'),
67-
'1': __('I want'),
68-
},
69-
'',
70-
{
71-
'no_label' : true,
72-
'width' : 'auto',
73-
'field_class' : '',
74-
'mb' : '',
75-
'aria_label' : __('Do you want to be notified of future events of this ticket'),
76-
'wrapper_class' : 'd-inline-block',
77-
}
78-
) }}
79-
{% else %}
80-
{{ fields.dropdownArrayField(
81-
'delegation_use_notification',
82-
'1',
83-
{
84-
'0': __('He doesn\'t want'),
85-
'1': __('He wants'),
86-
},
87-
'',
88-
{
89-
'no_label' : true,
90-
'width' : 'auto',
91-
'field_class' : '',
92-
'mb' : '',
93-
'aria_label' : __('Do you want to be notified of future events of this ticket'),
94-
'wrapper_class' : 'd-inline-block',
95-
}
96-
) }}
97-
{% endif %}
98-
<button
99-
type="button"
100-
class="btn btn-icon rounded-end"
101-
data-bs-toggle="dropdown"
102-
data-bs-auto-close="outside"
103-
aria-expanded="false"
104-
aria-label="{{ __('Address to send the notification') }}"
105-
>
106-
<i class="ti ti-mail-cog"></i>
107-
</button>
108-
<div class="dropdown-menu p-3 pt-1 rounded-3" style="width: 250px">
109-
{{ fields.textField(
110-
'delegation_alternative_email',
111-
selected_user.getDefaultEmail(),
112-
__('Address to send the notification'),
113-
{
114-
'is_horizontal': false,
115-
'field_class' : '',
116-
'mb' : '',
117-
}
118-
) }}
119-
</div>
120-
</span>
121-
{% endset %}
60+
{% if selected_user.getID() != get_current_user().getID() %}
61+
{% set notification_part_html %}
62+
<span class="input-group d-inline-flex w-auto">
63+
{{ fields.dropdownArrayField(
64+
'delegation_use_notification',
65+
'1',
66+
{
67+
'0': __('He doesn\'t want'),
68+
'1': __('He wants'),
69+
},
70+
'',
71+
{
72+
'no_label' : true,
73+
'width' : 'auto',
74+
'field_class' : '',
75+
'mb' : '',
76+
'aria_label' : __('Do you want to be notified of future events of this ticket'),
77+
'wrapper_class' : 'd-inline-block',
78+
}
79+
) }}
80+
<button
81+
type="button"
82+
class="btn btn-icon rounded-end"
83+
data-bs-toggle="dropdown"
84+
data-bs-auto-close="outside"
85+
aria-expanded="false"
86+
aria-label="{{ __('Address to send the notification') }}"
87+
>
88+
<i class="ti ti-mail-cog"></i>
89+
</button>
90+
<div class="dropdown-menu p-3 pt-1 rounded-3" style="width: 250px">
91+
{{ fields.textField(
92+
'delegation_alternative_email',
93+
selected_user.getDefaultEmail(),
94+
__('Address to send the notification'),
95+
{
96+
'is_horizontal': false,
97+
'field_class' : '',
98+
'mb' : '',
99+
}
100+
) }}
101+
</div>
102+
</span>
103+
{% endset %}
122104

123-
<div class="alert d-flex align-items-center justify-content-start flex-wrap">
124-
{% if users|length > 1 %}
125-
{{ __('This ticket is for %1$s and %2$s to be notified of future events of this ticket.')|format(
126-
'<span class="mx-2">' ~ user_dropdown_html|raw ~ '</span>',
127-
'<span class="mx-2">' ~ notification_part_html|raw ~ '</span>'
128-
)|raw }}
105+
<div class="alert d-flex align-items-center justify-content-start flex-wrap">
106+
{{ __('This ticket is for %1$s and %2$s to be notified of future events of this ticket.')|format(
107+
'<span class="mx-2">' ~ user_dropdown_html|raw ~ '</span>',
108+
'<span class="mx-2">' ~ notification_part_html|raw ~ '</span>'
109+
)|raw }}
110+
</div>
129111
{% else %}
130-
{{ __('%1$s to be notified of future events of this ticket.')|format(
131-
'<span class="mx-2">' ~ notification_part_html|raw ~ '</span>'
132-
)|raw }}
112+
<div class="alert d-flex align-items-center justify-content-start flex-wrap">
113+
{{ __('This ticket is for %1$s')|format(
114+
'<span class="mx-2">' ~ user_dropdown_html|raw ~ '</span>'
115+
)|raw }}
116+
</div>
133117
{% endif %}
134-
</div>
118+
{% endif %}
135119
{% endif %}

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

+7-33
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,10 @@ describe('Form delegation', () => {
3737
uuid = new Date().getTime();
3838
});
3939

40-
it('can choice my notifications preferences', () => {
40+
it("can't view delegation section when no delegation rights", () => {
4141
createFormAndRenderIt();
42-
43-
// Check values
44-
cy.getDropdownByLabelText('Do you want to be notified of future events of this ticket').should('have.text', 'I want');
45-
cy.getDropdownByLabelText('Do you want to be notified of future events of this ticket').click();
46-
cy.get('.select2-results__options').contains('I don\'t want');
47-
48-
// Define email address
49-
cy.findByRole('button', { name: 'Address to send the notification' }).click();
50-
cy.findByRole('textbox', { name: 'Address to send the notification' }).clear();
51-
cy.findByRole('textbox', { name: 'Address to send the notification' }).type('[email protected]');
52-
53-
// Fill form
54-
cy.findByRole('textbox', { name: 'Name' }).type('Test');
55-
56-
// Submit form
57-
cy.findByRole('button', { name: 'Submit' }).click();
58-
59-
// Go to the created ticket
60-
cy.findByRole('link', { name: `My test form - ${uuid}` }).click();
61-
62-
cy.findByRole('region', { name: 'Actors' }).within(() => {
63-
cy.findByRole('listitem', { name: 'E2E Tests' }).should('exist');
64-
cy.findByRole('button', { name: 'Email followup' }).click();
65-
cy.findByRole('checkbox', { name: 'Email followup' }).should('be.checked');
66-
cy.findByRole('textbox', { name: 'Email address' }).should('have.value', '[email protected]');
67-
});
42+
cy.getDropdownByLabelText('Select the user to delegate').should('not.exist');
43+
cy.getDropdownByLabelText('Do you want to be notified of future events of this ticket').should('not.exist');
6844
});
6945

7046
it('can delegate', () => {
@@ -75,10 +51,9 @@ describe('Form delegation', () => {
7551
cy.getDropdownByLabelText('Select the user to delegate').should('have.text', 'Myself');
7652
cy.getDropdownByLabelText('Select the user to delegate').click();
7753
cy.get('.select2-results__options').contains(`Test user - ${uuid}`);
54+
cy.getDropdownByLabelText('Select the user to delegate').click();
7855

79-
cy.getDropdownByLabelText('Do you want to be notified of future events of this ticket').should('have.text', 'I want');
80-
cy.getDropdownByLabelText('Do you want to be notified of future events of this ticket').click();
81-
cy.get('.select2-results__options').contains('I don\'t want');
56+
cy.getDropdownByLabelText('Do you want to be notified of future events of this ticket').should('not.exist');
8257

8358
// Select user to delegate
8459
cy.getDropdownByLabelText('Select the user to delegate').selectDropdownValue(`Test user - ${uuid}`);
@@ -120,10 +95,9 @@ describe('Form delegation', () => {
12095
cy.getDropdownByLabelText('Select the user to delegate').should('have.text', 'Myself');
12196
cy.getDropdownByLabelText('Select the user to delegate').click();
12297
cy.get('.select2-results__options').contains(`Test user - ${uuid}`);
98+
cy.getDropdownByLabelText('Select the user to delegate').click();
12399

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');
100+
cy.getDropdownByLabelText('Do you want to be notified of future events of this ticket').should('not.exist');
127101

128102
// Select user to delegate
129103
cy.getDropdownByLabelText('Select the user to delegate').selectDropdownValue(`Test user - ${uuid}`);

0 commit comments

Comments
 (0)