diff --git a/ui-v2/app/helpers/token/is-legacy.js b/ui-v2/app/helpers/token/is-legacy.js index d21144a3e..427ad11df 100644 --- a/ui-v2/app/helpers/token/is-legacy.js +++ b/ui-v2/app/helpers/token/is-legacy.js @@ -2,8 +2,17 @@ import { helper } from '@ember/component/helper'; import { get } from '@ember/object'; const _isLegacy = function(token) { + // Empty Rules take priority over a Legacy: true + // in order to make this decision const rules = get(token, 'Rules'); - return get(token, 'Legacy') || (rules != null && rules.trim() != ''); + if (rules != null) { + return rules.trim() !== ''; + } + const legacy = get(token, 'Legacy'); + if (typeof legacy !== 'undefined') { + return legacy; + } + return false; }; export function isLegacy(params, hash) { const token = params[0]; diff --git a/ui-v2/tests/unit/helpers/token/is-legacy-test.js b/ui-v2/tests/unit/helpers/token/is-legacy-test.js index f80282902..8e7a86355 100644 --- a/ui-v2/tests/unit/helpers/token/is-legacy-test.js +++ b/ui-v2/tests/unit/helpers/token/is-legacy-test.js @@ -19,7 +19,7 @@ test('it returns false if the token has Rules but those rules are empty', functi const actual = isLegacy([{ Rules: '' }]); assert.notOk(actual); }); -test('it returns false if the token has Rules but those rules are empty', function(assert) { +test('it returns false if the token has Rules but those rules is null', function(assert) { const actual = isLegacy([{ Rules: null }]); assert.notOk(actual); }); @@ -44,3 +44,10 @@ test('it returns false if tokens have no Rules, or has Rules but those rules are const actual = isLegacy([[{}, { Rules: '' }]]); assert.notOk(actual); }); +test('it returns false if a token is marked as legacy, has Rules but those rules are empty', function(assert) { + // this may seem strange, but empty Rules should override Legacy, this only happens + // when a legacy token that has already been loaded has its rules wiped out + // WITHOUT then the ui refreshing + const actual = isLegacy([{ Legacy: true, Rules: '' }]); + assert.notOk(actual); +});