Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ZMS-3253 ZMS-3466 ZMS-3415 ZMS-1891): Replicate frontend validation in the backend for the availability opening hours to improve data integrity and frontend validation messaging #799

Closed
Changes from 100 commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
310f536
fix(ZMS-3253): validate and block adding conflicting openingtimes
Nov 12, 2024
bbd32b1
fix(ZMS-3253): add backend validation for opening hours and improve f…
Nov 14, 2024
5543f36
fix(ZMS-3253): fix zmsentities unit test
Nov 14, 2024
03bc86e
fix(ZMS-3253): fix zmsdb unit test
Nov 14, 2024
ffcdb0a
fix(ZMS-3253): add logging to zmsapi tests
Nov 14, 2024
47565c8
fix(ZMS-3253): fix one zmsapi unit test
Nov 14, 2024
3f8030e
fix(ZMS-3253): try fix one zmsapi unit test
Nov 14, 2024
f5e08ed
fix(ZMS-3253): try fix one zmsapi unit test
Nov 14, 2024
e4b36ea
fix(ZMS-3253): try fix some unit tests
Nov 14, 2024
e5f123c
fix(ZMS-3253): try fix some unit tests
Nov 14, 2024
9528271
fix(ZMS-3253): try fix some unit tests
Nov 14, 2024
770e847
fix(ZMS-3253): try fix some unit tests
Nov 14, 2024
4a79605
fix(ZMS-3253): try fix some unit tests
Nov 14, 2024
cdd0d8c
fix(ZMS-3253): try fix some unit tests
Nov 14, 2024
8a1aa79
fix(ZMS-3253): try fix some unit tests
Nov 14, 2024
09c10fb
fix(ZMS-3253): try fix some unit tests
Nov 14, 2024
afd6d5d
fix(ZMS-3253): try fix some unit tests
Nov 14, 2024
ce5d795
fix(ZMS-3253): try fix some unit tests
Nov 14, 2024
07f74c8
Revert "fix(ZMS-3253): try fix some unit tests"
Nov 14, 2024
da65ff3
fix(ZMS-3253): try fix some unit tests
Nov 14, 2024
93b2820
fix(ZMS-3253): try fix some unit tests
Nov 14, 2024
e0d41c4
fix(ZMS-3253): try fix some unit tests
Nov 14, 2024
bde21f3
fix(ZMS-3253): try fix some unit tests
Nov 14, 2024
0cd0ad1
fix(ZMS-3253): try fix some unit tests
Nov 14, 2024
29b7cff
fix(ZMS-3253): try fix some unit tests
Nov 14, 2024
9e11157
fix(ZMS-3253): try fix some unit tests
Nov 14, 2024
c2df444
fix(ZMS-3253): try fix some unit tests
Nov 14, 2024
5faea71
fix(ZMS-3253): try fix some unit tests
Nov 14, 2024
4cd3618
fix(ZMS-3253): try fix some unit tests
Nov 14, 2024
4840338
fix(ZMS-3253): try fix some unit tests
Nov 14, 2024
c8262a0
fix(ZMS-3253): backend validation work in AvailabilityAdd
Nov 15, 2024
8281b0a
fix(ZMS-3253): correct backend validation for timeoverlaps
Nov 15, 2024
390aba7
fix(ZMS-3253): fix a validation
Nov 15, 2024
78013ea
fix(ZMS-3253): try fixing a test
Nov 15, 2024
8a07621
fix(ZMS-3253): try fixing a test
Nov 15, 2024
7892fe0
fix(ZMS-3253): try fixing a test
Nov 15, 2024
9522585
fix(ZMS-3253): try fixing a test
Nov 15, 2024
d65ccb8
fix(ZMS-3253): try fixing availability not found test
Nov 15, 2024
3fa84a1
fix(ZMS-3253): try fixing availability mockdata for testRendering
Nov 15, 2024
317d127
fix(ZMS-3253): try fixing availability mockdata for testRendering
Nov 15, 2024
c02e4e3
fix(ZMS-3253): try fixing availability mockdata for testRendering
Nov 15, 2024
c75e3c4
fix(ZMS-3253): try fixing availability mockdata for testRendering
Nov 15, 2024
2b39546
fix(ZMS-3253): try fixing availability mockdata for testRendering
Nov 15, 2024
acb62ac
fix(ZMS-3253): try fix missing scope testRendering
Nov 15, 2024
a16b2e4
fix(ZMS-3253): fix zmsadmin availabilities conflict test
Nov 15, 2024
1bd40cb
fix(ZMS-3253): show availability opening hour conflicts in the future…
Nov 15, 2024
4025319
fix(ZMS-3253): remove error_logs
Nov 15, 2024
95dcef0
fix(ZMS-3253): refactor function logic getDateTimeRangeFromList to on…
Nov 15, 2024
39ef3a6
Merge remote-tracking branch 'origin/next' into bugfix-zms-3253-valid…
Nov 15, 2024
3eb8912
fix(ZMS-3253): renable twig cache
Nov 15, 2024
46c0af9
fix(ZMS-3253): renable twig cache
Nov 15, 2024
fdd0c72
fix(ZMS-3253): fix unit test
ThomasAFink Nov 18, 2024
f319de3
fix(ZMS-3253): fix unit test
ThomasAFink Nov 18, 2024
b8fd6b6
fix(ZMS-3253): fix unit test
ThomasAFink Nov 18, 2024
a2691c1
fix(ZMS-3253): fix unit test
ThomasAFink Nov 18, 2024
fc26e13
fix(ZMS-3253): fix unit test
ThomasAFink Nov 18, 2024
bffc9fa
fix(ZMS-3253): fix unit test
ThomasAFink Nov 18, 2024
5784eb4
fix(ZMS-3253): try fix unit test
ThomasAFink Nov 18, 2024
51e25ca
fix(ZMS-3253): add unit tests for testing overlapping availability op…
ThomasAFink Nov 18, 2024
4f2a125
fix(ZMS-3253): add unit tests for testing overlapping availability op…
ThomasAFink Nov 18, 2024
e8cae55
fix(ZMS-3253): remove space
ThomasAFink Nov 18, 2024
e0f4fa6
fix(ZMS-3253): remove space
ThomasAFink Nov 18, 2024
d17ffa2
fix(ZMS-3253): add unit tests for testing overlapping availability op…
ThomasAFink Nov 18, 2024
8a41469
fix(ZMS-3253): add unit tests for testing validation availability ope…
ThomasAFink Nov 18, 2024
e230b26
fix(ZMS-3253): add unit tests for testing overlapping availability op…
ThomasAFink Nov 18, 2024
5aadb7b
fix(ZMS-3253): add unit tests for testing validation availability ope…
ThomasAFink Nov 18, 2024
246b4d1
fix(ZMS-3253): add unit tests for testing overlapping availability op…
ThomasAFink Nov 18, 2024
17dcb07
fix(ZMS-3253): add unit tests for testing overlapping availability op…
ThomasAFink Nov 18, 2024
e984774
fix(ZMS-3253): add unit tests for testing overlapping availability op…
ThomasAFink Nov 18, 2024
d5135e2
fix(ZMS-3253): add unit tests for testing overlapping availability op…
ThomasAFink Nov 18, 2024
ca99ef2
fix(ZMS-3253): add unit tests for testing validation availability ope…
ThomasAFink Nov 18, 2024
d5c6051
fix(ZMS-3253): add unit tests for testing validation availability ope…
ThomasAFink Nov 18, 2024
5527c58
fix(ZMS-3253): refactor object creation
ThomasAFink Nov 18, 2024
ad89835
fix(ZMS-3253): refactor exception messages
ThomasAFink Nov 18, 2024
2a7d978
fix(ZMS-3253): clean up commented code
ThomasAFink Nov 18, 2024
ea55b27
fix(ZMS-3253): fix grammar
ThomasAFink Nov 20, 2024
932fe5f
fix(ZMS-3253): comment error_log
ThomasAFink Nov 20, 2024
5aa9d6b
fix(ZMS-3253): Improve frontend validation for opening hours availabi…
ThomasAFink Nov 20, 2024
fb7efb7
cleanup(ZMS-3415): remove invalid text instruction for graph view ope…
ThomasAFink Nov 21, 2024
1fd8f65
fix(ZMS-1891): Add missing frontend validation for timepicker
Nov 22, 2024
f8f536f
Merge branch 'next' into bugfix-zms-3253-validation-opening-hours-of-…
Nov 22, 2024
e4981ff
fix(ZMS-1891): Improve frontend validation for time formats
Nov 22, 2024
7916a70
fix(ZMS-3253): fix frontend exclusion availability validation
ThomasAFink Dec 3, 2024
462be60
fix(ZMS-3253): fix backend exclusion availability validation
ThomasAFink Dec 4, 2024
46db273
fix(ZMS-3253): allow exclusion availability on current date
ThomasAFink Dec 4, 2024
490ddce
fix(ZMS-3253): improve validation and cleanup code
ThomasAFink Dec 4, 2024
2ce2363
fix(ZMS-3253): move js spinner
ThomasAFink Dec 4, 2024
735c579
Merge remote-tracking branch 'origin/next' into bugfix-zms-3253-valid…
ThomasAFink Dec 4, 2024
97cee9c
clean(ZMS-3253): remove console logs
ThomasAFink Dec 4, 2024
a11f7b8
Merge branch 'next' into bugfix-zms-3253-validation-opening-hours-of-…
Dec 9, 2024
b620a54
fix(ZMS-3466): fix bookable day range validation
Dec 9, 2024
e3375c1
fix(ZMS-3466): fix error accumulation
Dec 9, 2024
e646a4c
fix(ZMS-3466): improve exception handling
Dec 9, 2024
8b7a1f6
fix(ZMS-3466): improve validation prevent divide by zero
Dec 9, 2024
2a3cbb7
fix(ZMS-3466): improve validation prevent divide by zero
Dec 9, 2024
4cbe423
fix(ZMS-3466): improve validation prevent divide by zero
Dec 9, 2024
0053e60
Merge branch 'next' into bugfix-zms-3253-3466-3415-1891-validation-op…
ThomasAFink Jan 20, 2025
cab1b1d
fix(ZMS-3466): Fix to from default values in opening hours availability
ThomasAFink Jan 20, 2025
ab51699
fix(ZMS): error message
Jan 23, 2025
227e741
Merge branch 'next' into bugfix-zms-3253-3466-3415-1891-validation-op…
Jan 23, 2025
694194b
fix(ZMS-3466): fix open from and open to placeholders in form
Jan 27, 2025
d53b28e
Merge branch 'next' into bugfix-zms-3253-3466-3415-1891-validation-op…
Jan 27, 2025
088356f
fix(ZMS-3466): improve default hours
Jan 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions zmsadmin/js/page/availabilityDay/form/conflicts.js
Original file line number Diff line number Diff line change
@@ -11,26 +11,31 @@ const renderConflictList = (conflictList) => {
let conflictDatesByMessage = [];
conflictList.map(collection => {
collection.conflicts.map((conflict) => {
if (! conflictDatesByMessage[conflict.message]) {
Object.assign({}, conflictDatesByMessage[conflict.message] = []);
const existingConflict = conflictDatesByMessage.find(
item => item.message === conflict.message
);

if (existingConflict) {
existingConflict.dates.push(formatDate(collection.date));
} else {
conflictDatesByMessage.push({
message: conflict.message,
dates: [formatDate(collection.date)]
});
}
conflictDatesByMessage[conflict.message].push(formatDate(collection.date))
})
})
});
});

return (
Object.keys(conflictDatesByMessage).map((key, index) => {
return (
<div key={index}>
<div><strong>{ conflictDatesByMessage[key].join(", ") }</strong></div>
<div key={index}>- {key}</div>
</div>
)
})
)


}
conflictDatesByMessage.map((item, index) => (
<div key={index} style={{ marginBottom: '1rem' }}>
{/* Convert newlines in the message to <br /> tags */}
<div dangerouslySetInnerHTML={{ __html: item.message.replace(/\n/g, '<br />') }} />
</div>
Comment on lines +32 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Security: Replace dangerouslySetInnerHTML with safe alternative.

Using dangerouslySetInnerHTML with unsanitized content poses an XSS risk. Consider using a safe alternative.

-                {/* Convert newlines in the message to <br /> tags */}
-                <div dangerouslySetInnerHTML={{ __html: item.message.replace(/\n/g, '<br />') }} />
+                <div>
+                    {item.message.split('\n').map((line, i) => (
+                        <React.Fragment key={i}>
+                            {line}
+                            {i < item.message.split('\n').length - 1 && <br />}
+                        </React.Fragment>
+                    ))}
+                </div>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{/* Convert newlines in the message to <br /> tags */}
<div dangerouslySetInnerHTML={{ __html: item.message.replace(/\n/g, '<br />') }} />
</div>
<div>
{item.message.split('\n').map((line, i) => (
<React.Fragment key={i}>
{line}
{i < item.message.split('\n').length - 1 && <br />}
</React.Fragment>
))}
</div>
</div>
🧰 Tools
🪛 Biome (1.9.4)

[error] 33-33: Avoid passing content using the dangerouslySetInnerHTML prop.

Setting content using code can expose users to cross-site scripting (XSS) attacks

(lint/security/noDangerouslySetInnerHtml)

))
);
};


const Conflicts = (props) => {
const conflicts = Object.keys(props.conflictList).map(key => {
6 changes: 2 additions & 4 deletions zmsadmin/js/page/availabilityDay/form/content.js
Original file line number Diff line number Diff line change
@@ -140,17 +140,15 @@ const FormContent = (props) => {
<Controls>
<Label attributes={{"htmlFor": "AvDayOpenfrom", "className": "light"}}>von</Label>
<Inputs.Text name="open_from"
width="2"
value={data.open_from}
width="3"
attributes={{ placeholder: data.scope.preferences.appointment.startInDaysDefault, "id": "AvDayOpenfrom", "aria-describedby": "help_AvDayOpenfromto" }}
{...{ onChange }}
/>
</Controls>
<Controls>
<Label attributes={{"htmlFor": "AvDayOpento", "className": "light"}}>bis</Label>
<Inputs.Text name="open_to"
width="2"
value={data.open_to}
width="3"
attributes={{ placeholder: data.scope.preferences.appointment.endInDaysDefault, "id": "AvDayOpento", "aria-describedby": "help_AvDayOpenfromto" }}
{...{ onChange }}
/>
31 changes: 18 additions & 13 deletions zmsadmin/js/page/availabilityDay/form/errors.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import React from 'react'
import PropTypes from 'prop-types'
import React from 'react';
import PropTypes from 'prop-types';

const renderErrors = errors => Object.keys(errors).map(key => {
return (
const renderErrors = (errors) =>
Object.keys(errors).map(key => (
<div key={errors[key].id}>
{errors[key].itemList.map((item, index) => {
return <div key={index}>{item[0].message}</div>
})}
if (Array.isArray(item)) {
return item.map((nestedItem, nestedIndex) => (
<div key={`${index}-${nestedIndex}`}>{nestedItem.message}</div>
));
} else {
return <div key={index}>{item.message}</div>;
}
})}
</div>
)
})
));

const Errors = (props) => {
return (
@@ -18,15 +23,15 @@ const Errors = (props) => {
<h3>Folgende Fehler sind bei der Prüfung Ihrer Eingaben aufgetreten:</h3>
{renderErrors(props.errorList)}
</div> : null
)
}
);
};

Errors.defaultProps = {
errorList: []
}
};

Errors.propTypes = {
errorList: PropTypes.object
}
};

export default Errors
export default Errors;
12 changes: 5 additions & 7 deletions zmsadmin/js/page/availabilityDay/form/footerButtons.js
Original file line number Diff line number Diff line change
@@ -4,14 +4,12 @@ import PropTypes from 'prop-types'
const FooterButtons = (props) => {
const { hasConflicts, stateChanged, data, onNew, onPublish, onAbort, hasSlotCountError } = props
return (
<div className="form-actions" style={{"marginTop":"0", "padding":"0.75em"}}>
<button title="Neue Öffnungszeit anlegen und bearbeiten" className="button button--diamond button-new" onClick={onNew} disabled={(stateChanged || hasConflicts || data)}>neue Öffnungszeit</button>
<button title="Alle Änderungen werden zurückgesetzt" className="button btn" type="abort" onClick={onAbort} disabled={(!stateChanged && !hasConflicts && !data)}>Abbrechen</button>
<button title="Alle Änderungen werden gespeichert" className="button button--positive button-save" type="save" value="publish" onClick={onPublish} disabled={(!stateChanged || hasSlotCountError)}>Alle Änderungen aktivieren
</button>

<div className="form-actions" style={{ "marginTop": "0", "padding": "0.75em" }}>
<button title="Neue Öffnungszeit anlegen und bearbeiten" className="button button--diamond button-new" onClick={onNew} disabled={(stateChanged || hasConflicts || data)}>neue Öffnungszeit</button>
<button title="Alle Änderungen werden zurückgesetzt" className="button btn" type="abort" onClick={onAbort} disabled={(!stateChanged && !hasConflicts && !data)}>Abbrechen</button>
<button title="Alle Änderungen werden gespeichert" className="button button--positive button-save" type="save" value="publish" onClick={onPublish} disabled={(!stateChanged || hasSlotCountError || hasConflicts)}>Alle Änderungen aktivieren
</button>
</div>

)
}

6 changes: 3 additions & 3 deletions zmsadmin/js/page/availabilityDay/form/formButtons.js
Original file line number Diff line number Diff line change
@@ -2,8 +2,8 @@ import React from 'react'
import PropTypes from 'prop-types'

const FormButtons = (props) => {
const { data, onCopy, onExclusion, onEditInFuture, onUpdateSingle, onDelete, selectedDate, hasConflicts } = props
const disabled = ((data && (! data.id || data.__modified === true)) || hasConflicts);
const { data, onCopy, onExclusion, onEditInFuture, onUpdateSingle, onDelete, selectedDate, hasConflicts, hasSlotCountError } = props
const disabled = ((data && (! data.id || data.__modified === true)) || hasConflicts || hasSlotCountError);
return (
<div className="body">
<div className="form-actions">
@@ -21,7 +21,7 @@ const FormButtons = (props) => {
className="button button--diamond" disabled={disabled || data.startDate == selectedDate}>Ab diesem Tag ändern</button>
<button onClick={onUpdateSingle}
title="Öffnungszeit aktualisieren"
className="button button--diamond" disabled={(data && !data.id) || hasConflicts || props.isCreatingExclusion}>Aktualisieren</button>
className="button button--diamond" disabled={(data && !data.id) || hasConflicts || hasSlotCountError || props.isCreatingExclusion}>Aktualisieren</button>
</div>
</div>
)
2 changes: 2 additions & 0 deletions zmsadmin/js/page/availabilityDay/form/index.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
import FormButtons from './formButtons'
import FormContent from './content'
import { getDataValuesFromForm, cleanupFormData, getFormValuesFromData } from '../helpers'
import { hasSlotCountError } from '../form/validate';

class AvailabilityForm extends Component {
constructor(props) {
@@ -64,6 +65,7 @@ class AvailabilityForm extends Component {
onUpdateSingle={this.props.onUpdateSingle}
selectedDate={this.props.selectedDate}
hasConflicts={hasConflicts}
hasSlotCountError={hasSlotCountError(this.props)}
isCreatingExclusion={this.props.isCreatingExclusion}
/>}
</div>
Loading