refactor: 💡 do not scope-prefix paths by default

This commit is contained in:
Randall Morey committed 2020-09-10 19:02:53 -04:00
1 parent ab608c7544
commit 795f3f5839
32 files changed
+15 -353

No files matched your search

-46
View File
@@ -58,54 +58,8 @@ export default class ApplicationAdapter extends RESTAdapter.extend(
*/
namespace = get(config, 'api.namespace');
/**
* Whether or not to prefix the URL with the resource scope.
* @type {boolean}
*/
hasScopePrefix = true;
// =methods
/**
* Prepends a scope to the URL prefix. Precedence is given to the ID passed
* via `adapterOptions.scopeID`. If this value isn't found in
* `adapterOptions`, we look to the `scope.scope_id` field on the snapshot,
* which most resources have.
*
* Note: scopes themselves never receive a scope URL prefix.
*
* @override
* @param {string} path
* @param {string} parentURL
* @param {string} modelName
* @param {string} id
* @param {object} snapshot
* @return {string}
*/
urlPrefix(path, parentURL, modelName, id, snapshot) {
const prefix = super.urlPrefix(...arguments);
let scopePath = '';
let scopeID = '';
if (snapshot && this.hasScopePrefix) {
// Not all snapshots have `attr` (such as array snapshots),
// so we do this sort of ugly check.
if (snapshot.attr) {
const parentScope = snapshot.attr('scope');
if (parentScope) scopeID = parentScope.attr('scope_id');
}
// Attempt to get scopeID from adapterOptions and fallback on its current
// value if it wasn't passed through options.
scopeID = getWithDefault(snapshot, 'adapterOptions.scopeID', scopeID);
}
// Only non-scope resources need a scope path, since scope resources
// aren't technically "scoped" the same way.
// Ensure a slash is added between prefix + scope path if needed.
if (scopeID && prefix.charAt(prefix.length - 1) !== '/') {
scopePath = `/scopes/${scopeID}`;
}
return `${prefix}${scopePath}`;
}
/**
* Appends a custom method after a colon, if a method is passed via the
* snapshot's `adapterOptions.method` field.
-13
View File
@@ -1,13 +0,0 @@
import ApplicationAdapter from './application';
export default class AuthMethodAdapter extends ApplicationAdapter {
// =attributes
/**
* Auth methods use the new, unprefixed pathing style.
* @override
*/
hasScopePrefix = false;
}
-13
View File
@@ -1,13 +0,0 @@
import ApplicationAdapter from './application';
export default class GroupAdapter extends ApplicationAdapter {
// =attributes
/**
* Groups use the new, unprefixed pathing style.
* @override
*/
hasScopePrefix = false;
}
-13
View File
@@ -1,13 +0,0 @@
import ApplicationAdapter from './application';
export default class HostCatalogAdapter extends ApplicationAdapter {
// =attributes
/**
* Host catalogs use the new, unprefixed pathing style.
* @override
*/
hasScopePrefix = false;
}
-18
View File
@@ -1,18 +0,0 @@
import ApplicationAdapter from './application';
import { inject as service } from '@ember/service';
export default class HostSetAdapter extends ApplicationAdapter {
// =services
@service store;
// =attributes
/**
* Host sets use the new, unprefixed pathing style.
* @override
*/
hasScopePrefix = false;
}
-18
View File
@@ -1,18 +0,0 @@
import ApplicationAdapter from './application';
import { inject as service } from '@ember/service';
export default class HostAdapter extends ApplicationAdapter {
// =services
@service store;
// =attributes
/**
* Hosts use the new, unprefixed pathing style.
* @override
*/
hasScopePrefix = false;
}
-13
View File
@@ -1,13 +0,0 @@
import ApplicationAdapter from './application';
export default class RoleAdapter extends ApplicationAdapter {
// =attributes
/**
* Roles use the new, unprefixed pathing style.
* @override
*/
hasScopePrefix = false;
}
-13
View File
@@ -1,13 +0,0 @@
import ApplicationAdapter from './application';
export default class ScopeAdapter extends ApplicationAdapter {
// =attributes
/**
* Scopes do not include a scope prefix.
* @override
*/
hasScopePrefix = false;
}
-13
View File
@@ -1,13 +0,0 @@
import ApplicationAdapter from './application';
export default class TargetAdapter extends ApplicationAdapter {
// =attributes
/**
* Targets use the new, unprefixed pathing style.
* @override
*/
hasScopePrefix = false;
}
-13
View File
@@ -1,13 +0,0 @@
import ApplicationAdapter from './application';
export default class UserAdapter extends ApplicationAdapter {
// =attributes
/**
* Users use the new, unprefixed pathing style.
* @override
*/
hasScopePrefix = false;
}