Skip to content

Commit

Permalink
Merge pull request #1012 from mdhaman/SDESK-3394
Browse files Browse the repository at this point in the history
[SDESK-3394] Fixing date validation for event editor form.
  • Loading branch information
Mayur Dhamanwala authored Sep 27, 2018
2 parents b8e0b65 + b78c698 commit 91ddbf5
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 8 deletions.
8 changes: 4 additions & 4 deletions client/components/Main/EditorPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ const mapDispatchToProps = (dispatch) => ({
onPost: (item) => dispatch(actions.main.post(item)),
openCancelModal: (modalProps) => dispatch(actions.main.openIgnoreCancelSaveModal(modalProps)),

onValidate: (type, item, diff, profile, errors, messages) => dispatch(validateItem({
onValidate: (type, item, diff, profile, errors, messages, ignoreDateValidation = false) => dispatch(validateItem({
profileName: type,
item: item,
diff: diff,
formProfiles: profile,
errors: errors,
messages: messages,
ignoreDateValidation: true,
ignoreDateValidation: ignoreDateValidation,
})),
loadItem: (itemId, itemType) => dispatch(actions.main.loadItem(itemId, itemType, 'edit')),
itemActions: actionUtils.getActionDispatches({dispatch: dispatch}),
Expand All @@ -79,14 +79,14 @@ const mapDispatchToPropsModal = (dispatch) => ({
onUnpost: (item) => dispatch(actions.main.unpost(item)),
onPost: (item) => dispatch(actions.main.post(item)),
openCancelModal: (modalProps) => dispatch(actions.main.openIgnoreCancelSaveModal(modalProps)),
onValidate: (type, item, diff, profile, errors, messages) => dispatch(validateItem({
onValidate: (type, item, diff, profile, errors, messages, ignoreDateValidation = false) => dispatch(validateItem({
profileName: type,
item: item,
diff: diff,
formProfiles: profile,
errors: errors,
messages: messages,
ignoreDateValidation: true,
ignoreDateValidation: ignoreDateValidation,
})),
loadItem: (itemId, itemType) => dispatch(actions.main.loadItem(itemId, itemType, 'edit')),
itemActions: actionUtils.getActionDispatches({dispatch: dispatch}),
Expand Down
6 changes: 4 additions & 2 deletions client/components/Main/ItemEditor/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ export class EditorComponent extends React.Component {
diff,
this.props.formProfiles,
errors,
errorMessages
errorMessages,
!isTemporaryId(this.props.itemId)
);

const newState = {diff, errors, errorMessages};
Expand Down Expand Up @@ -315,7 +316,8 @@ export class EditorComponent extends React.Component {
updates,
this.props.formProfiles,
errors,
errorMessages
errorMessages,
!isTemporaryId(this.props.itemId)
);

if (isEqual(errorMessages, [])) {
Expand Down
30 changes: 30 additions & 0 deletions server/features/events.feature
Original file line number Diff line number Diff line change
Expand Up @@ -928,4 +928,34 @@ Feature: Events
Then we get error 400
"""
{"_message": "Event duration is greater than 7 days.", "_status": "ERR"}
"""

@auth
Scenario: Create new event fails start date less than end date
Given config update
"""
{"MAX_MULTI_DAY_EVENT_DURATION": 7}
"""
When we post to "/events"
"""
[
{
"guid": "123",
"unique_id": "123",
"unique_name": "123 name",
"name": "event 123",
"slugline": "event-123",
"definition_short": "short value",
"definition_long": "long value",
"dates": {
"start": "2099-01-12",
"end": "2099-01-10"
},
"subject": [{"qcode": "test qcaode", "name": "test name"}]
}
]
"""
Then we get error 400
"""
{"_message": "END TIME should be after START TIME", "_status": "ERR"}
"""
2 changes: 1 addition & 1 deletion server/features/steps/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def step_impl_when_we_duplicate_event(context, event_id):

duplicate_event['duplicate_from'] = event_id
duplicate_event['dates']['start'] = "2099-01-02"
duplicate_event['dates']['start'] = "2099-01-03"
duplicate_event['dates']['end'] = "2099-01-03"
duplicate_event['unique_id'] = 456
duplicate_event['definition_short'] = 'duplicate'
duplicate_event['name'] = 'duplicate'
Expand Down
2 changes: 1 addition & 1 deletion server/planning/commands/flag_expired_items_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
}

expired = {
'event': {'dates': {'start': yesterday, 'end': yesterday - timedelta(hours=1)}},
'event': {'dates': {'start': yesterday, 'end': yesterday + timedelta(hours=1)}},
'plan': {'planning_date': yesterday},
'coverage': {'planning': {'scheduled': yesterday}}
}
Expand Down
15 changes: 15 additions & 0 deletions server/planning/events/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,21 @@ def validate_event(self, event):
@:param dict event: event created or updated
"""
self._validate_multiday_event_duration(event)
self._validate_dates(event)

def _validate_dates(self, event):
"""Validate the dates
@:param dict event:
"""
start_date = event.get('dates', {}).get('start')
end_date = event.get('dates', {}).get('end')

if not start_date or not end_date:
return

if end_date < start_date:
raise SuperdeskApiError(message="END TIME should be after START TIME")

def _validate_multiday_event_duration(self, event):
"""Validate that the multiday event duration is not greater than PLANNING_MAX_MULTI_DAY_DURATION
Expand Down

0 comments on commit 91ddbf5

Please sign in to comment.