diff --git a/.gitignore b/.gitignore index 119bbf7..62e3dcf 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,5 @@ npm-debug.log* yarn-debug.log* yarn-error.log* -# will be added upon deployment as it is located on separate repo. Will store user roles. -# see https://github.com/WATonomous/infra-config/tree/master/directory/users/data -/backend/data \ No newline at end of file +# will be mounted on deployment. Will store user roles. For local development, create one in the shape specified in README.md +/backend/user_directory.json \ No newline at end of file diff --git a/README.md b/README.md index 85e834c..82c350c 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,24 @@ cd backend nodemon start ``` -## Generating seeding data +### Permissions + +Create a file `/backend/user_directory.json` that has the following shape. This will determine your approval levels. If for some reason you have multiple accounts, simply add more elements to the array. +In the production environment this file is mounted automatically based on https://github.com/WATonomous/infra-config/tree/master/directory/users/data + +``` +[ + { + finance_system: { + email: + enabled: true + membership: 'Administrator' | 'Member' + } + } + ] +``` + +### Generating seeding data To generate seed data, in the terminal in the backend directory, run: diff --git a/backend/utils/getSheetData.js b/backend/utils/getSheetData.js index c18d50a..1ddcfa2 100644 --- a/backend/utils/getSheetData.js +++ b/backend/utils/getSheetData.js @@ -1,31 +1,25 @@ const fs = require('fs') -const yaml = require('js-yaml') -require('dotenv').config() const { updateGoogleGroups } = require('../service/googlegroup.service') -const readUserGroups = async () => { - // check if ./data exists - if (!fs.existsSync('./data')) { - console.log('No user role data to be found.') +const readUserGroupsv2 = async () => { + if (!fs.existsSync('./user_directory.json')) { return [] } - const yamlFiles = await fs.promises.readdir('./data') + const data = JSON.parse( + await fs.promises.readFile('./user_directory.json', 'utf8') + ) const userGroups = [] - const promises = yamlFiles.map(async (yamlFile) => { - const doc = yaml.load( - await fs.promises.readFile(`./data/${yamlFile}`, 'utf8') - ) - if (doc?.finance_system?.enabled) { - userGroups.push(doc.finance_system) + for (const userInfo of data) { + if (userInfo.finance_system?.enabled) { + userGroups.push(userInfo.finance_system) } - }) - await Promise.all(promises) + } return userGroups } const updateGroup = async () => { - const users = await readUserGroups() + const users = await readUserGroupsv2() try { await updateGoogleGroups(users) console.log('Updated google groups')