Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix user groups #191

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading