Commit c76faf4b authored by Hannah Stepanek's avatar Hannah Stepanek

Remove scopes.enforced dependency in isScopedToUri

Previously, if the scope was not enforced, isScopedToUri would always
return true. Now, isScopedToUri is true only when the scopes.uri_patterns
match.
parent 3c9d3448
...@@ -35,10 +35,9 @@ function combineGroups(userGroups, featuredGroups, uri) { ...@@ -35,10 +35,9 @@ function combineGroups(userGroups, featuredGroups, uri) {
} }
function isScopedToUri(group, uri) { function isScopedToUri(group, uri) {
// If the group has scope info, the scoping is enforced, // Groups with no scopes or groups with no uri_patterns defined
// and the uri patterns don't include this page's uri // are considered in scope.
// the group is not selectable, otherwise it is. if (group.scopes && group.scopes.uri_patterns.length > 0) {
if (group.scopes && group.scopes.enforced) {
return uriMatchesScopes(uri, group.scopes.uri_patterns); return uriMatchesScopes(uri, group.scopes.uri_patterns);
} }
return true; return true;
......
...@@ -102,14 +102,14 @@ describe('sidebar.util.groups', () => { ...@@ -102,14 +102,14 @@ describe('sidebar.util.groups', () => {
{ {
description: 'sets `isScopedToUri` to true if `scopes` is missing', description: 'sets `isScopedToUri` to true if `scopes` is missing',
scopes: undefined, scopes: undefined,
shouldBeSelectable: true, isScopedToUri: true,
uri: 'https://foo.com/bar', uri: 'https://foo.com/bar',
}, },
{ {
description: description:
'sets `isScopedToUri` to true if `scopes.enforced` is false', 'sets `isScopedToUri` to true if `scopes.uri_patterns` is empty',
scopes: { enforced: false }, scopes: { uri_patterns: [] },
shouldBeSelectable: true, isScopedToUri: true,
uri: 'https://foo.com/bar', uri: 'https://foo.com/bar',
}, },
{ {
...@@ -119,20 +119,20 @@ describe('sidebar.util.groups', () => { ...@@ -119,20 +119,20 @@ describe('sidebar.util.groups', () => {
enforced: true, enforced: true,
uri_patterns: ['http://foo.com*', 'https://foo.com*'], uri_patterns: ['http://foo.com*', 'https://foo.com*'],
}, },
shouldBeSelectable: true, isScopedToUri: true,
uri: 'https://foo.com/bar', uri: 'https://foo.com/bar',
}, },
{ {
description: description:
'sets `isScopedToUri` to false if `scopes.uri_patterns` do not match the uri', 'sets `isScopedToUri` to false if `scopes.uri_patterns` do not match the uri',
scopes: { enforced: true, uri_patterns: ['http://foo.com*'] }, scopes: { enforced: true, uri_patterns: ['http://foo.com*'] },
shouldBeSelectable: false, isScopedToUri: false,
uri: 'https://foo.com/bar', uri: 'https://foo.com/bar',
}, },
{ {
description: 'it permits multiple *s in the scopes uri pattern', description: 'it permits multiple *s in the scopes uri pattern',
scopes: { enforced: true, uri_patterns: ['https://foo.com*bar*'] }, scopes: { enforced: true, uri_patterns: ['https://foo.com*bar*'] },
shouldBeSelectable: true, isScopedToUri: true,
uri: 'https://foo.com/boo/bar/baz', uri: 'https://foo.com/boo/bar/baz',
}, },
{ {
...@@ -141,17 +141,17 @@ describe('sidebar.util.groups', () => { ...@@ -141,17 +141,17 @@ describe('sidebar.util.groups', () => {
enforced: true, enforced: true,
uri_patterns: ['https://foo.com?bar=foo$[^]($){mu}+&boo=*'], uri_patterns: ['https://foo.com?bar=foo$[^]($){mu}+&boo=*'],
}, },
shouldBeSelectable: true, isScopedToUri: true,
uri: 'https://foo.com?bar=foo$[^]($){mu}+&boo=foo', uri: 'https://foo.com?bar=foo$[^]($){mu}+&boo=foo',
}, },
].forEach(({ description, scopes, shouldBeSelectable, uri }) => { ].forEach(({ description, scopes, isScopedToUri, uri }) => {
it(description, () => { it(description, () => {
const userGroups = [{ id: 'groupa', name: 'GroupA', scopes: scopes }]; const userGroups = [{ id: 'groupa', name: 'GroupA', scopes: scopes }];
const featuredGroups = []; const featuredGroups = [];
const groups = combineGroups(userGroups, featuredGroups, uri); const groups = combineGroups(userGroups, featuredGroups, uri);
groups.forEach(g => assert.equal(g.isScopedToUri, shouldBeSelectable)); groups.forEach(g => assert.equal(g.isScopedToUri, isScopedToUri));
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment