Skip to content

Commit

Permalink
update user output and have it work with mongodb 4
Browse files Browse the repository at this point in the history
  • Loading branch information
fitztrev committed Nov 7, 2023
1 parent 4f80bf6 commit b340bed
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ services:
restart: unless-stopped
networks:
- lila-network
volumes:
- ./repos/lila:/lila
- ./scripts:/scripts

redis:
image: redis:7.2.3-alpine3.18
Expand Down
6 changes: 3 additions & 3 deletions lila-docker
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ setup_database() {

echo "Adding test data..."

docker compose run --rm -v $(pwd)/repos/lila:/lila mongodb bash -c \
docker compose run --rm mongodb bash -c \
"mongo --host mongodb lichess /lila/bin/mongodb/indexes.js"

docker compose run --rm python bash -c \
"python /lila-db-seed/spamdb/spamdb.py --uri=mongodb://mongodb/lichess --password=$PASSWORD --su-password=$SU_PASSWORD --es --es-host=elasticsearch:9200"

docker compose run --rm -v $(pwd)/scripts:/scripts mongodb bash -c \
"mongosh --host mongodb lichess --file /scripts/mongodb/users.js"
docker compose run --rm mongodb bash -c \
"mongo --quiet --host mongodb lichess /scripts/mongodb/users.js"
}

run_formatter() {
Expand Down
44 changes: 31 additions & 13 deletions scripts/mongodb/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,41 @@
let users = db.user4
.find()
.toArray()
.filter((user) => user._id !== 'lichess') // `lichess` user login is disabled
.filter((user) => user._id !== "lichess") // `lichess` user login is disabled
.map((user) => {
return {
username: user._id,
roles: user.roles.join(', '),
title: user.title || '',
marks: user.marks.join(', '),
}
})
roles: user.roles.join(", "),
title: user.title || "",
marks: user.marks.join(", "),
};
});

console.log('Special User Accounts')
console.table(users.filter((user) => user.roles))
function printUsers(users) {
print(users.map((user) => user.username).join(", "));
print();
}

console.log('Marked Accounts')
console.table(users.filter((user) => user.marks))
print("==========================================");
print(" Test User Accounts ");
print("==========================================");

console.log('Regular Accounts')
console.table(users.filter((user) => !user.roles && !user.marks))
print("Special User Accounts");
print("---------------------");
printUsers(users.filter((user) => user.roles));

console.log('You can log in with any of the above user accounts.')
print("Marked Accounts");
print("---------------");
printUsers(users.filter((user) => user.marks));

print("BOT Accounts");
print("------------");
printUsers(users.filter((user) => user.title === "BOT"));

print("Regular Accounts");
print("----------------");
printUsers(
users.filter((user) => !user.roles && !user.marks && user.title !== "BOT"),
);

print("You can log in with any of the above user accounts.");

0 comments on commit b340bed

Please sign in to comment.