mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 21:45:31 +09:00
fix(api): skip the mature gate when no birth date is collected (#2582)
This commit is contained in:
1 parent
d46c8d49c6
commit
2019909a5e
4 files changed
+88
-11
No files matched your search
@@ -0,0 +1,44 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {afterEach, describe, expect, it} from 'vitest';
|
||||
import {setCachedDateOfBirthCollection} from '../instance/DateOfBirthCollectionCache';
|
||||
import {canUserAccessNsfwContent} from './AgeUtils';
|
||||
|
||||
const ADULT_DATE_OF_BIRTH = '1990-01-01';
|
||||
const MINOR_DATE_OF_BIRTH = '2020-01-01';
|
||||
|
||||
describe('canUserAccessNsfwContent', () => {
|
||||
afterEach(() => {
|
||||
setCachedDateOfBirthCollection(true);
|
||||
});
|
||||
|
||||
it('allows a bot whatever the instance collects', () => {
|
||||
setCachedDateOfBirthCollection(true);
|
||||
expect(canUserAccessNsfwContent({isBot: true, dateOfBirth: null})).toBe(true);
|
||||
});
|
||||
|
||||
it('allows an adult when the instance collects a date of birth', () => {
|
||||
setCachedDateOfBirthCollection(true);
|
||||
expect(canUserAccessNsfwContent({isBot: false, dateOfBirth: ADULT_DATE_OF_BIRTH})).toBe(true);
|
||||
});
|
||||
|
||||
it('blocks a minor when the instance collects a date of birth', () => {
|
||||
setCachedDateOfBirthCollection(true);
|
||||
expect(canUserAccessNsfwContent({isBot: false, dateOfBirth: MINOR_DATE_OF_BIRTH})).toBe(false);
|
||||
});
|
||||
|
||||
it('blocks a missing date of birth when the instance collects one', () => {
|
||||
setCachedDateOfBirthCollection(true);
|
||||
expect(canUserAccessNsfwContent({isBot: false, dateOfBirth: null})).toBe(false);
|
||||
});
|
||||
|
||||
it('allows a missing date of birth when the instance collects none', () => {
|
||||
setCachedDateOfBirthCollection(false);
|
||||
expect(canUserAccessNsfwContent({isBot: false, dateOfBirth: null})).toBe(true);
|
||||
});
|
||||
|
||||
it('allows an account with a minor date of birth when the instance collects none', () => {
|
||||
setCachedDateOfBirthCollection(false);
|
||||
expect(canUserAccessNsfwContent({isBot: false, dateOfBirth: MINOR_DATE_OF_BIRTH})).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,7 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {instanceCollectsDateOfBirth} from '../instance/DateOfBirthCollectionCache';
|
||||
|
||||
export function calculateAge(
|
||||
dateOfBirth:
|
||||
| {
|
||||
@@ -53,5 +55,8 @@ export function canUserAccessNsfwContent(user: NsfwEligibilityUser): boolean {
|
||||
if (user.isBot) {
|
||||
return true;
|
||||
}
|
||||
if (!instanceCollectsDateOfBirth()) {
|
||||
return true;
|
||||
}
|
||||
return isUserAdult(user.dateOfBirth);
|
||||
}
|
||||
Reference in new issue
Block a user