Create script to make PNID a dev

This commit is contained in:
Matthew Lopez 2023-12-21 20:18:32 -05:00
parent 4ef90ce2bb
commit c45b574f13
No known key found for this signature in database
GPG Key ID: 302A6EE3D63B7E0E
2 changed files with 42 additions and 3 deletions

View File

@ -0,0 +1,37 @@
// This should run in the account container
const mongoose = require("mongoose");
const { connect } = require("./dist/database");
const { PNID } = require("./dist/models/pnid");
async function runAsync() {
await connect();
if (process.env.PNID) {
const pnid = await PNID.findOne({
usernameLower: process.env.PNID.toLowerCase(),
});
if (pnid) {
await updatePnidAccessLevel(pnid, 3, "dev");
} else {
console.log(`No PNID found for username ${process.env.PNID}.`);
}
} else {
console.log("No username given, skipping update.");
}
await mongoose.connection.close();
}
runAsync().then(() => {
console.log("Done updating PNID access levels.");
process.exit(0);
});
async function updatePnidAccessLevel(pnid, access_level, server_access_level) {
pnid.access_level = access_level;
pnid.server_access_level = server_access_level;
console.log(`Saving dev PNID: ${pnid.username} (${pnid.pid})`);
await pnid.save();
}

View File

@ -10,6 +10,7 @@ done
git_base=$(git rev-parse --show-toplevel)
create_server_script=$(cat "$git_base/scripts/run-in-container/create-server-in-database.js")
create_endpoint_script=$(cat "$git_base/scripts/run-in-container/create-endpoint-in-database.js")
update_pnid_access_level_script=$(cat "$git_base/scripts/run-in-container/update-pnid-access-level-in-database.js")
necessary_environment="friends miiverse-api wiiu-chat"
. "$git_base/environment/system.local.env"
@ -27,9 +28,10 @@ docker compose exec -e COMPUTER_IP="$COMPUTER_IP" \
-e WIIU_CHAT_PORT="$PN_WIIU_CHAT_AUTHENTICATION_SERVER_PORT" \
account node -e "$create_server_script"
printf "Enter the PNID you want to give dev access to: "
read -r dev_pnid
docker compose exec -e PNID="$dev_pnid" account node -e "$update_pnid_access_level_script"
docker compose up -d miiverse-api
docker compose exec miiverse-api node -e "$create_endpoint_script"
# TODO: Script should a PNID's access_level to 3 and server_access_level to dev
# so users can access the servers