diff --git a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/apps/api.js b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/apps/api.js index 2bbe4aac018f..c1ee0e77fae8 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/apps/api.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/apps/api.js @@ -59,7 +59,12 @@ hqDefine("cloudcare/js/formplayer/apps/api", [ return null; } var appCollection = Collections(apps); - return appCollection.get(id); + let fetchedApp = appCollection.get(id); + if (!fetchedApp) { + fetchedApp = appCollection.models.find(currApp => currApp.get("copy_of") === id); + } + + return fetchedApp; }, }; diff --git a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/apps/views.js b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/apps/views.js index 993601bd7bc8..d032a17d106b 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/apps/views.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/apps/views.js @@ -29,7 +29,7 @@ hqDefine("cloudcare/js/formplayer/apps/views", [ rowClick: function (e) { e.preventDefault(); - FormplayerFrontend.trigger("app:select", this.model.get('_id')); + FormplayerFrontend.trigger("app:select", this.model.get('copy_of')); }, rowKeyAction: function (e) { diff --git a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/api.js b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/api.js index 129a94804a5f..73ac467415b7 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/api.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/api.js @@ -48,16 +48,22 @@ hqDefine("cloudcare/js/formplayer/menus/api", [ menus; $.when(AppsAPI.getAppEntities()).done(function (appCollection) { + const app = appCollection.find(function (app) { + const currPrimaryAppId = app.get('copy_of'); + // Prevents breaking if a web apps session spans pre and post deploy. Can remove post deploy. + if (app.id && app.id === params.appId) { + return app; + } + if (currPrimaryAppId && currPrimaryAppId === params.appId) { + return app; + } + if (currPrimaryAppId && (currPrimaryAppId === params.copyOf)) { + return app; + } + }); if (!params.preview) { // Make sure the user has access to the app - if (!appCollection.find(function (app) { - if (app.id && app.id === params.appId) { - return true; - } - if (app.get('copy_of') && app.get('copy_of') === params.copyOf) { - return true; - } - })) { + if (!app) { FormplayerFrontend.trigger( 'showError', gettext('The application could not be found') @@ -67,6 +73,13 @@ hqDefine("cloudcare/js/formplayer/menus/api", [ return; } } + let appId = params.appId; + if (!params.preview) { + const copyOf = app.get('copy_of'); + if (copyOf && copyOf === params.appId) { + appId = app.id; + } + } FormplayerFrontend.permitIntervalSync = true; options = { success: function (parsedMenus, response) { @@ -164,7 +177,7 @@ hqDefine("cloudcare/js/formplayer/menus/api", [ "username": user.username, "restoreAs": user.restoreAs, "domain": user.domain, - "app_id": params.appId, + "app_id": appId, "endpoint_id": params.endpointId, "endpoint_args": params.endpointArgs, "locale": params.changeLang || displayOptions.language,