Skip to content

Commit

Permalink
fixes issue with apiPath not updating for generated items after remov…
Browse files Browse the repository at this point in the history
…ing ember data query
  • Loading branch information
zofskeez committed Feb 14, 2025
1 parent 1c90025 commit 1773fdf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
13 changes: 11 additions & 2 deletions ui/app/routes/vault/cluster/access/method/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@ import { singularize } from 'ember-inflector';

export default Route.extend({
pathHelp: service('path-help'),
store: service(),

beforeModel() {
async beforeModel() {
const { apiPath, type, authMethodPath, itemType } = this.getMethodAndModelInfo();
const modelType = `generated-${singularize(itemType)}-${type}`;
return this.pathHelp.getNewModel(modelType, authMethodPath, apiPath, itemType);
await this.pathHelp.getNewModel(modelType, authMethodPath, apiPath, itemType);
// getNewModel also creates an adapter if one does not exist and sets the apiPath value initially
// this value will not change when routing between auth methods of the same type
// in the generated-item-list adapter there is a short circuit to update the apiPath value on query({ list: true })
// since we have removed that request to test the generated client it breaks the workflow
// example -> navigate to userpass1, then userpass2, create a user and they will be created in userpass1
// the apiPath value should be kept in sync at all times but since this will all be removed eventually -- hack it!
const adapter = this.store.adapterFor(modelType);
adapter.apiPath = apiPath;
},

getMethodAndModelInfo() {
Expand Down
8 changes: 1 addition & 7 deletions ui/app/routes/vault/cluster/access/method/item/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,8 @@ export default Route.extend(ListRoute, {

setupController(controller) {
this._super(...arguments);
const { apiPath, authMethodPath, itemType, methodModel } = this.getMethodAndModelInfo();
const { itemType, methodModel } = this.getMethodAndModelInfo();
controller.set('itemType', itemType);
controller.set('methodModel', methodModel);
this.pathHelp.getPaths(apiPath, authMethodPath, itemType).then((paths) => {
controller.set(
'paths',
paths.paths.filter((path) => path.navigation && path.itemType.includes(itemType))
);
});
},
});

0 comments on commit 1773fdf

Please sign in to comment.