Skip to content

Commit

Permalink
Limit the number of records per user
Browse files Browse the repository at this point in the history
  • Loading branch information
Genne23v committed Mar 20, 2023
1 parent a580cf1 commit 1e3cea5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ SAML_IDP_METADATA_PATH=config/idp-metadata-dev.xml
EXPIRATION_REPEAT_FREQUENCY_MS=86400000
# 7 * 24 * 60 * 60 * 1000 = 604800000 (7 days)
JOB_REMOVAL_FREQUENCY_MS=604800000

# Limit the maximum number of records per user
USER_RECORD_LIMIT=20
6 changes: 6 additions & 0 deletions app/models/record.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import type { Record } from '@prisma/client';
export const createUserRecord = async (
data: Pick<Record, 'username' | 'type' | 'subdomain' | 'value'>
) => {
if (process.env.USER_RECORD_LIMIT) {
if ((await getUserRecordCount(data.username)) >= Number(process.env.USER_RECORD_LIMIT)) {
throw new Error('User has reached the maximum number of records');
}
}

if (await doesRecordExist(data)) {
throw new Error('Record already exists');
}
Expand Down

0 comments on commit 1e3cea5

Please sign in to comment.