Skip to content

Commit

Permalink
Merge pull request #35013 from dimagi/rc/link-previous-builds
Browse files Browse the repository at this point in the history
use primary/canonical app id for web apps url param appId
  • Loading branch information
Robert-Costello authored Aug 28, 2024
2 parents 35efecc + ee7dd82 commit 0d78fd3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
31 changes: 22 additions & 9 deletions corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 0d78fd3

Please sign in to comment.