Skip to content

Commit

Permalink
fix user groups (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
victorzheng02 authored Apr 11, 2024
1 parent 77b986e commit ff204a4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
# 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
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <YOUR_WATO_EMAIL>
enabled: true
membership: 'Administrator' | 'Member'
}
}
]
```

### Generating seeding data

To generate seed data, in the terminal in the backend directory, run:

Expand Down
26 changes: 10 additions & 16 deletions backend/utils/getSheetData.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down

0 comments on commit ff204a4

Please sign in to comment.