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) {
}
function isScopedToUri(group, uri) {
// If the group has scope info, the scoping is enforced,
// and the uri patterns don't include this page's uri
// the group is not selectable, otherwise it is.
if (group.scopes && group.scopes.enforced) {
// Groups with no scopes or groups with no uri_patterns defined
// are considered in scope.
if (group.scopes && group.scopes.uri_patterns.length > 0) {
return uriMatchesScopes(uri, group.scopes.uri_patterns);
}
return true;
......
......@@ -102,14 +102,14 @@ describe('sidebar.util.groups', () => {
{
description: 'sets `isScopedToUri` to true if `scopes` is missing',
scopes: undefined,
shouldBeSelectable: true,
isScopedToUri: true,
uri: 'https://foo.com/bar',
},
{
description:
'sets `isScopedToUri` to true if `scopes.enforced` is false',
scopes: { enforced: false },
shouldBeSelectable: true,
'sets `isScopedToUri` to true if `scopes.uri_patterns` is empty',
scopes: { uri_patterns: [] },
isScopedToUri: true,
uri: 'https://foo.com/bar',
},
{
......@@ -119,20 +119,20 @@ describe('sidebar.util.groups', () => {
enforced: true,
uri_patterns: ['http://foo.com*', 'https://foo.com*'],
},
shouldBeSelectable: true,
isScopedToUri: true,
uri: 'https://foo.com/bar',
},
{
description:
'sets `isScopedToUri` to false if `scopes.uri_patterns` do not match the uri',
scopes: { enforced: true, uri_patterns: ['http://foo.com*'] },
shouldBeSelectable: false,
isScopedToUri: false,
uri: 'https://foo.com/bar',
},
{
description: 'it permits multiple *s in the scopes uri pattern',
scopes: { enforced: true, uri_patterns: ['https://foo.com*bar*'] },
shouldBeSelectable: true,
isScopedToUri: true,
uri: 'https://foo.com/boo/bar/baz',
},
{
......@@ -141,17 +141,17 @@ describe('sidebar.util.groups', () => {
enforced: true,
uri_patterns: ['https://foo.com?bar=foo$[^]($){mu}+&boo=*'],
},
shouldBeSelectable: true,
isScopedToUri: true,
uri: 'https://foo.com?bar=foo$[^]($){mu}+&boo=foo',
},
].forEach(({ description, scopes, shouldBeSelectable, uri }) => {
].forEach(({ description, scopes, isScopedToUri, uri }) => {
it(description, () => {
const userGroups = [{ id: 'groupa', name: 'GroupA', scopes: scopes }];
const featuredGroups = [];
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