Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: configuration shouldn't check for enabled if audit is enabledByDefault #675

Merged
merged 2 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,24 @@ class Configuration extends BaseModel {
const siteId = site.getId();
const orgId = site.getOrganizationId();

if (handler.disabled) {
const sites = handler.disabled.sites || [];
const orgs = handler.disabled.orgs || [];
if (sites.includes(siteId) || orgs.includes(orgId)) {
Copy link
Member

@solaris007 solaris007 Apr 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a direct return

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@solaris007
If we return directly, like earlier

return !(sites.includes(siteId) || orgs.includes(orgId));

we'll be returning just based on disabled only. If the site isn't disabled, or disabled is empty, we'll end up returning true. That's why I'm explicitly returning only if its specifically disabled or enabled or enabledByDefault.

return false;
}
}

if (handler.enabledByDefault) {
return true;
}
if (handler.enabled) {
const sites = handler.enabled.sites || [];
const orgs = handler.enabled.orgs || [];
return sites.includes(siteId) || orgs.includes(orgId);
}

if (handler.disabled) {
const sites = handler.disabled.sites || [];
const orgs = handler.disabled.orgs || [];
return !(sites.includes(siteId) || orgs.includes(orgId));
}

return handler.enabledByDefault;
return false;
}

isHandlerEnabledForOrg(type, org) {
Expand All @@ -101,15 +106,19 @@ class Configuration extends BaseModel {

const orgId = org.getId();

if (handler.enabled) {
return handler.enabled.orgs?.includes(orgId);
if (handler.disabled && handler.disabled.orgs?.includes(orgId)) {
return false;
}

if (handler.disabled) {
return !handler.disabled.orgs?.includes(orgId);
if (handler.enabledByDefault) {
return true;
}

if (handler.enabled) {
return handler.enabled.orgs?.includes(orgId);
}

return handler.enabledByDefault;
return false;
}

#updatedHandler(type, entityId, enabled, entityKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ const configurations = [
orgs: ['757ceb98-05c8-4e07-bb23-bc722115b2b0'],
},
},
sitemap: {
enabledByDefault: true,
enabled: {
sites: [],
orgs: [],
},
disabled: {
sites: [],
orgs: [],
},
},
'lhs-mobile': {
enabledByDefault: false,
enabled: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ describe('ConfigurationModel', () => {
expect(instance.isHandlerEnabledForOrg('404', org)).to.be.true;
});

it('returns true when enabled is there and the handler is enabled by default', () => {
console.log('starting test');
expect(instance.isHandlerEnabledForSite('sitemap', site)).to.be.true;
expect(instance.isHandlerEnabledForOrg('sitemap', org)).to.be.true;
});

it('returns false if a handler is not enabled by default', () => {
expect(instance.isHandlerEnabledForSite('organic-keywords', site)).to.be.false;
expect(instance.isHandlerEnabledForOrg('organic-keywords', org)).to.be.false;
Expand Down Expand Up @@ -148,7 +154,7 @@ describe('ConfigurationModel', () => {

it('gets all enabled audits for a site', () => {
expect(Object.keys(instance.getHandlers() || {})
.filter((handler) => instance.isHandlerEnabledForSite(handler, site))).to.deep.equal(['404', 'rum-ingest', 'lhs-mobile']);
.filter((handler) => instance.isHandlerEnabledForSite(handler, site))).to.deep.equal(['404', 'rum-ingest', 'sitemap', 'lhs-mobile']);
expect(instance.getEnabledAuditsForSite(site)).to.deep.equal(['lhs-mobile', '404']);
});
});
Expand Down