ui: Make empty Rules ('') take priority over a `Legacy: true` (#4899)

Even if an old style token has a Legacy of true, yet it has an empty set
of Rules, treat the token as a new style token, as its essentially the
same
This commit is contained in:
John Cowen 2018-11-06 18:08:10 +00:00 committed by GitHub
parent e4be60b25c
commit d7e969f513
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -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];

View File

@ -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);
});