mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
feat(tools): allow seed script to set user flags (#55534)
This commit is contained in:
committed by
GitHub
parent
13828c6a3f
commit
d626997c51
@@ -1,3 +1,5 @@
|
||||
const { parseArgs } = require('node:util');
|
||||
|
||||
const path = require('path');
|
||||
const debug = require('debug');
|
||||
const { MongoClient } = require('mongodb');
|
||||
@@ -11,23 +13,15 @@ const {
|
||||
userIds
|
||||
} = require('./user-data');
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
const options = {
|
||||
'set-true': { type: 'string', multiple: true },
|
||||
'top-contributor': { type: 'boolean' },
|
||||
'set-false': { type: 'string', multiple: true },
|
||||
'seed-trophy-challenges': { type: 'boolean' },
|
||||
'certified-user': { type: 'boolean' }
|
||||
};
|
||||
|
||||
const allowedArgs = [
|
||||
'--donor',
|
||||
'--top-contributor',
|
||||
'--unset-privacy-terms',
|
||||
'--seed-trophy-challenges',
|
||||
'certified-user'
|
||||
];
|
||||
|
||||
// Check for invalid arguments
|
||||
args.forEach(arg => {
|
||||
if (!allowedArgs.includes(arg))
|
||||
throw new Error(
|
||||
`Invalid argument ${arg}. Allowed arguments are ${allowedArgs.join(', ')}`
|
||||
);
|
||||
});
|
||||
const { values: argValues } = parseArgs({ options });
|
||||
|
||||
const log = debug('fcc:tools:seedLocalAuthUser');
|
||||
const { MONGOHQ_URL } = process.env;
|
||||
@@ -87,16 +81,16 @@ const trophyChallenges = [
|
||||
];
|
||||
|
||||
[demoUser, blankUser, fullyCertifiedUser].forEach(user => {
|
||||
if (args.includes('--donor')) {
|
||||
user.isDonating = true;
|
||||
}
|
||||
if (args.includes('--top-contributor')) {
|
||||
if (argValues['top-contributor']) {
|
||||
user.yearsTopContributor = ['2017', '2018', '2019'];
|
||||
}
|
||||
if (args.includes('--unset-privacy-terms')) {
|
||||
user.acceptedPrivacyTerms = false;
|
||||
for (const key of argValues['set-false'] || []) {
|
||||
user[key] = false;
|
||||
}
|
||||
if (args.includes('--seed-trophy-challenges')) {
|
||||
for (const key of argValues['set-true'] || []) {
|
||||
user[key] = true;
|
||||
}
|
||||
if (argValues['--seed-trophy-challenges']) {
|
||||
user.completedChallenges = trophyChallenges;
|
||||
}
|
||||
});
|
||||
@@ -128,7 +122,7 @@ const run = async () => {
|
||||
|
||||
await dropUserTokens();
|
||||
await dropUsers();
|
||||
if (args.includes('certified-user')) {
|
||||
if (argValues['certified-user']) {
|
||||
await user.insertOne(fullyCertifiedUser);
|
||||
await user.insertOne(blankUser);
|
||||
await user.insertOne(publicUser);
|
||||
|
||||
Reference in New Issue
Block a user