mirror of https://github.com/status-im/consul.git
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:
parent
971f3fb433
commit
7ddafc45d9
|
@ -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];
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue