From b340bedf17c5006f9e006ceafd71a29d363224e8 Mon Sep 17 00:00:00 2001 From: Trevor Fitzgerald Date: Mon, 6 Nov 2023 22:03:30 -0500 Subject: [PATCH] update user output and have it work with mongodb 4 --- docker-compose.yml | 3 +++ lila-docker | 6 +++--- scripts/mongodb/users.js | 44 ++++++++++++++++++++++++++++------------ 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 70705904..d4bbadcd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/lila-docker b/lila-docker index a971059a..d9ab428f 100755 --- a/lila-docker +++ b/lila-docker @@ -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() { diff --git a/scripts/mongodb/users.js b/scripts/mongodb/users.js index 127b5768..030c0510 100644 --- a/scripts/mongodb/users.js +++ b/scripts/mongodb/users.js @@ -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.");