From d55769861eb3dadf823784b0388b1f4239200732 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Fri, 5 Oct 2012 14:45:07 -0400 Subject: [PATCH] check if 'delete metadata field' is not in the list of system metadata --- cms/djangoapps/contentstore/views.py | 9 +++++---- cms/static/js/base.js | 7 +++---- common/static/js/vendor/timepicker/datepair.js | 12 ++++++++++++ .../static/js/vendor/timepicker/jquery.timepicker.js | 2 ++ 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py index df2a6fd986..c1c3fc92d0 100644 --- a/cms/djangoapps/contentstore/views.py +++ b/cms/djangoapps/contentstore/views.py @@ -448,14 +448,15 @@ def save_item(request): # fetch original existing_item = modulestore().get_item(item_location) - logging.debug(posted_metadata) - # update existing metadata with submitted metadata (which can be partial) # IMPORTANT NOTE: if the client passed pack 'null' (None) for a piece of metadata that means 'remove it' for metadata_key in posted_metadata.keys(): - if posted_metadata[metadata_key] is None: + # NOTE: We don't want clients to be able to delete 'system metadata' which are not intended to be user + # editable + if posted_metadata[metadata_key] is None and metadata_key not in existing_item.system_metadata_fields: # remove both from passed in collection as well as the collection read in from the modulestore - del existing_item.metadata[metadata_key] + if metadata_key in existing_item.metadata: + del existing_item.metadata[metadata_key] del posted_metadata[metadata_key] # overlay the new metadata over the modulestore sourced collection to support partial updates diff --git a/cms/static/js/base.js b/cms/static/js/base.js index bc637b0075..06e8f33c92 100644 --- a/cms/static/js/base.js +++ b/cms/static/js/base.js @@ -95,11 +95,10 @@ function saveSubsection(e) { metadata[$(el).data("metadata-name")] = el.value; } - // OK, we have some metadata (namely 'Release Date' (aka 'start') and 'Due Date') which has been normalized in the UI - // we have to piece it back together. Unfortunate 'start' and 'due' use different string formatters. Rather than try to - // replicate the string formatting which is used in the backend here in JS, let's just pass back a unified format - // and let the server re-format into the expected persisted format + // Piece back together the date/time UI elements into one date/time string + // NOTE: our various "date/time" metadata elements don't always utilize the same formatting string + // so make sure we're passing back the correct format metadata['start'] = getEdxTimeFromDateTimeInputs('start_date', 'start_time'); metadata['due'] = getEdxTimeFromDateTimeInputs('due_date', 'due_time', 'MMMM dd HH:mm'); diff --git a/common/static/js/vendor/timepicker/datepair.js b/common/static/js/vendor/timepicker/datepair.js index d547925e5b..f210933593 100644 --- a/common/static/js/vendor/timepicker/datepair.js +++ b/common/static/js/vendor/timepicker/datepair.js @@ -1,3 +1,15 @@ +/************************ +datepair.js + +This is a component of the jquery-timepicker plugin + +http://jonthornton.github.com/jquery-timepicker/ + +requires jQuery 1.6+ + +version: 1.2.2 +************************/ + $(function() { $('.datepair input.date').each(function(){ diff --git a/common/static/js/vendor/timepicker/jquery.timepicker.js b/common/static/js/vendor/timepicker/jquery.timepicker.js index 506f66b5d1..3a462dd436 100755 --- a/common/static/js/vendor/timepicker/jquery.timepicker.js +++ b/common/static/js/vendor/timepicker/jquery.timepicker.js @@ -3,6 +3,8 @@ jquery-timepicker http://jonthornton.github.com/jquery-timepicker/ requires jQuery 1.6+ + +version: 1.2.2 ************************/