Skip to content

Commit

Permalink
Merge c9e98da into 91ddbf5
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayur Dhamanwala committed Oct 2, 2018
2 parents 91ddbf5 + c9e98da commit 72541da
Show file tree
Hide file tree
Showing 6 changed files with 310 additions and 65 deletions.
45 changes: 26 additions & 19 deletions client/validators/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {get, set, isEmpty, isEqual} from 'lodash';
import {gettext, eventUtils} from '../utils';
import * as selectors from '../selectors';
import {formProfile} from './profile';
import {PRIVILEGES} from '../constants';
import {PRIVILEGES, EVENTS} from '../constants';

const validateRequiredDates = ({value, errors, messages}) => {
if (!get(value, 'start')) {
Expand Down Expand Up @@ -139,6 +139,7 @@ const validateDates = ({getState, value, errors, messages}) => {
}

const newErrors = {};
const modalProps = selectors.general.modalProps(getState());

self.validateRequiredDates({
value: value,
Expand All @@ -150,24 +151,30 @@ const validateDates = ({getState, value, errors, messages}) => {
errors: newErrors,
messages: messages,
});
self.validateDateInPast({
getState: getState,
value: value,
errors: newErrors,
messages: messages,
});
self.validateRecurringRules({
getState: getState,
value: value,
errors: newErrors,
messages: messages,
});
self.validateMultiDayDuration({
value: value,
getState: getState,
errors: newErrors,
messages: messages,
});

// we don't have to validate all recurring form update time action
// as only time is modified. we could be modifying a event that schedule
// after until or difference could be greater than multi day duration
if (get(modalProps, 'actionType', '') !== EVENTS.ITEM_ACTIONS.UPDATE_TIME.label) {
self.validateDateInPast({
getState: getState,
value: value,
errors: newErrors,
messages: messages,
});
self.validateRecurringRules({
getState: getState,
value: value,
errors: newErrors,
messages: messages,
});
self.validateMultiDayDuration({
value: value,
getState: getState,
errors: newErrors,
messages: messages,
});
}

if (!isEqual(newErrors, {})) {
errors.dates = newErrors;
Expand Down
12 changes: 12 additions & 0 deletions server/planning/events/events_base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,15 @@ def _set_events_planning(events):
if '_plans' not in event:
event['_plans'] = []
event['_plans'].append(plan)

@staticmethod
def remove_fields(new_event, extra_fields=None):
"""Remove fields not required by new event"""
for f in {'_id', 'guid', 'unique_name', 'unique_id', 'lock_user', 'lock_time',
'lock_session', 'lock_action', '_created', '_updated', '_etag', 'pubstatus',
'reason', 'duplicate_to', 'duplicate_from', 'reschedule_to'}:
new_event.pop(f, None)

if extra_fields:
for f in extra_fields:
new_event.pop(f, None)
9 changes: 5 additions & 4 deletions server/planning/events/events_reschedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def update_single_event(self, updates, original):
if has_plannings:
self._reschedule_event_plannings(original, reason)

self.set_planning_schedule(updates)

@staticmethod
def _mark_event_rescheduled(updates, original, reason, keep_dates=False):
updates['state'] = WORKFLOW_STATE.RESCHEDULED
Expand Down Expand Up @@ -114,17 +116,16 @@ def _duplicate_event(updates, original, events_service):
new_event = deepcopy(original)
new_event.update(updates)

for f in {'_id', 'guid', 'unique_name', 'unique_id', 'lock_user', 'lock_time',
'lock_session', 'lock_action', '_created', '_updated', '_etag', 'pubstatus',
'reason', 'duplicate_to', 'duplicate_from', 'reschedule_to'}:
new_event.pop(f, None)
# Remove fields not required by new events
EventsRescheduleService.remove_fields(new_event)

new_event[ITEM_STATE] = WORKFLOW_STATE.DRAFT
new_event['guid'] = generate_guid(type=GUID_NEWSML)
new_event['_id'] = new_event['guid']
new_event['reschedule_from'] = original[config.ID_FIELD]
new_event['_reschedule_from_schedule'] = original['dates']['start']
set_original_creator(new_event)
EventsRescheduleService.set_planning_schedule(new_event)

created_event = events_service.create([new_event])[0]
history_service = get_resource_service('events_history')
Expand Down

0 comments on commit 72541da

Please sign in to comment.