fix: normalize embedded scope IDs and ensure scope resources do not receive scope-prefixed URLs like other resources do

This commit is contained in:
Randall Morey committed 2020-07-23 10:34:31 -04:00
1 parent c743cc1716
commit b7996f6271
4 files changed
+47 -12

No files matched your search

+10 -4
View File
@@ -71,10 +71,16 @@ export default class ApplicationAdapter extends RESTAdapter.extend(
*/
urlPrefix(path, parentURL, modelName, id, snapshot={}) {
const prefix = super.urlPrefix(...arguments);
let scopePath = getWithDefault(snapshot, 'adapterOptions.scopeID', '');
// Ensure a slash is added between prefix + scope path if needed.
if (scopePath && prefix.charAt(prefix.length - 1) !== '/') {
scopePath = `/scopes/${scopePath}`;
const isScope = modelName === 'scope';
let scopePath = '';
// Only non-scope resources need a scope path, since scope resources
// aren't technically "scoped" the same way.
if (!isScope) {
scopePath = getWithDefault(snapshot, 'adapterOptions.scopeID', '');
// Ensure a slash is added between prefix + scope path if needed.
if (scopePath && prefix.charAt(prefix.length - 1) !== '/') {
scopePath = `/scopes/${scopePath}`;
}
}
return `${prefix}${scopePath}`;
}