AIRAVATA-2228 Fix bug when sharing update fails A bug occurs when share_settings is updated in share.js but the sharing update actually fails server side. The fix is to update a copy of share_settings (new_share_settings) and then only update share_settings when the server side update completes successfully.
Project: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/commit/4c01c628 Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/4c01c628 Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/4c01c628 Branch: refs/heads/develop Commit: 4c01c6288d0d52d48c68c4d2941daf17627c467b Parents: 83e215b Author: Marcus Christie <[email protected]> Authored: Tue Nov 22 17:48:54 2016 -0500 Committer: Marcus Christie <[email protected]> Committed: Tue Nov 22 17:48:54 2016 -0500 ---------------------------------------------------------------------- public/js/sharing/share.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/4c01c628/public/js/sharing/share.js ---------------------------------------------------------------------- diff --git a/public/js/sharing/share.js b/public/js/sharing/share.js index a25b2b9..e87598a 100755 --- a/public/js/sharing/share.js +++ b/public/js/sharing/share.js @@ -205,13 +205,15 @@ $(function() { // Save the sharing permissions of each selected user $('body').on('click', '#share-box-button', function(e) { - var data, resource_id, $share_list, $update_list; + var data, resource_id, $share_list, $update_list, new_share_settings; e.stopPropagation(); e.preventDefault(); $('#share-box-error-message').empty(); data = $("#share-box").data(); $share_list = $("#share-box-share").children(); $update_list = $('.sharing-to-update'); + // Clone current share settings + new_share_settings = JSON.parse(JSON.stringify(share_settings)); // TODO: is this used any longer? I don't see where resource_id gets // set and updateUserPrivileges doesn't seem to be defined if (data.hasOwnProperty('resource_id')) { @@ -228,17 +230,17 @@ $(function() { if (data.hasOwnProperty('currentaccess')) { newaccess = data.currentaccess; } - share_settings[data.username] = newaccess; + new_share_settings[data.username] = newaccess; }); if ($(this).data().hasOwnProperty('ajaxUpdateUrl')) { - ajaxUpdateSharing($(this).data().ajaxUpdateUrl, share_settings, function(){ - updateSharingAndCloseModal(share_settings); + ajaxUpdateSharing($(this).data().ajaxUpdateUrl, new_share_settings, function(){ + updateSharingAndCloseModal(new_share_settings); }); } else { - updateSharingAndCloseModal(share_settings); + updateSharingAndCloseModal(new_share_settings); } } else { - updateSharingAndCloseModal(share_settings); + updateSharingAndCloseModal(new_share_settings); } } return false; @@ -260,6 +262,7 @@ $(function() { data.access = new_share_settings[data.username]; }); $('#share-settings').val(JSON.stringify(new_share_settings)); + share_settings = new_share_settings; $('#shared-users').removeClass('text-align-center'); } if ($share_list.length === 0) {
