From 278b8499c687fb7ccf72ba491ff71a81a8ae7a78 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Thu, 14 May 2020 14:36:38 -0700 Subject: [PATCH 1/2] Protect against making watch requests using adapters that don't extend Watchable --- ui/app/utils/properties/watch.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ui/app/utils/properties/watch.js b/ui/app/utils/properties/watch.js index f447144ca..209b42746 100644 --- a/ui/app/utils/properties/watch.js +++ b/ui/app/utils/properties/watch.js @@ -1,8 +1,10 @@ import Ember from 'ember'; import { get } from '@ember/object'; +import { assert } from '@ember/debug'; import RSVP from 'rsvp'; import { task } from 'ember-concurrency'; import wait from 'nomad-ui/utils/wait'; +import Watchable from 'nomad-ui/adapters/watchable'; import XHRToken from 'nomad-ui/utils/classes/xhr-token'; import config from 'nomad-ui/config/environment'; @@ -10,6 +12,10 @@ const isEnabled = config.APP.blockingQueries !== false; export function watchRecord(modelName) { return task(function*(id, throttle = 2000) { + assert( + 'To watch a record, the record adapter MUST extend Watchable', + this.store.adapterFor(modelName) instanceof Watchable + ); const token = new XHRToken(); if (typeof id === 'object') { id = get(id, 'id'); @@ -35,6 +41,10 @@ export function watchRecord(modelName) { export function watchRelationship(relationshipName) { return task(function*(model, throttle = 2000) { + assert( + 'To watch a relationship, the adapter of the model provided to the watchRelationship task MUST extend Watchable', + this.store.adapterFor(model.constructor.modelName) instanceof Watchable + ); const token = new XHRToken(); while (isEnabled && !Ember.testing) { try { @@ -56,6 +66,10 @@ export function watchRelationship(relationshipName) { export function watchAll(modelName) { return task(function*(throttle = 2000) { + assert( + 'To watch all, the respective adapter MUST extend Watchable', + this.store.adapterFor(modelName) instanceof Watchable + ); const token = new XHRToken(); while (isEnabled && !Ember.testing) { try { @@ -78,6 +92,10 @@ export function watchAll(modelName) { export function watchQuery(modelName) { return task(function*(params, throttle = 10000) { + assert( + 'To watch a query, the adapter for the type being queried MUST extend Watchable', + this.store.adapterFor(modelName) instanceof Watchable + ); const token = new XHRToken(); while (isEnabled && !Ember.testing) { try { From 3fcd5edd41bbd696ddc38e2f745ebca90c09e685 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Thu, 14 May 2020 14:37:07 -0700 Subject: [PATCH 2/2] Make the Plugin adapter extend Watchable --- ui/app/adapters/plugin.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 ui/app/adapters/plugin.js diff --git a/ui/app/adapters/plugin.js b/ui/app/adapters/plugin.js new file mode 100644 index 000000000..c89779543 --- /dev/null +++ b/ui/app/adapters/plugin.js @@ -0,0 +1,7 @@ +import Watchable from './watchable'; + +export default Watchable.extend({ + queryParamsToAttrs: { + type: 'type', + }, +});