Skip to content

Commit

Permalink
#34 | Make script run using node 18
Browse files Browse the repository at this point in the history
  • Loading branch information
himeshr committed Nov 27, 2024
1 parent 5eb9e8e commit 825c888
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 53 deletions.
186 changes: 151 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
},
"license": "AGPL-3.0",
"scripts": {},
"dependencies": {},
"dependencies": {
"node-fetch": "^3.3.2"
},
"type": "module",
"devDependencies": {
"amazon-cognito-identity-js": "1.28.0"
}
Expand Down
1 change: 1 addition & 0 deletions reportingSystem/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
25 changes: 10 additions & 15 deletions reportingSystem/superset/assets/RoleUpgrade.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const username = ""; // add admin username

const password = ""; // add password
import fetch from 'node-fetch';

const roleIds = []; // add roles

Expand All @@ -13,16 +11,14 @@ let auth_token = null;

const login = async () => {

const request = new Request(`${baseurl}/api/v1/security/login`,{
const response = await fetch(`${baseurl}/api/v1/security/login`,{
method : "POST",
headers:{
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({"username":username, "password":password, "provider": "db", "refresh": true})
});

const response = await fetch(request).then((response)=>{
}).then((response)=>{
if(response.status === 200 && response.headers.get("content-type").includes("application/json")) {
return response.json();
}
Expand Down Expand Up @@ -53,14 +49,13 @@ const addPermissionInRole = async (roleId,permissionSet,newPermission) => {
"Authorization":`Bearer ${auth_token}`
},
body: JSON.stringify({
"permission_view_menu_ids": permissionSet
"permission_view_menu_ids": [...permissionSet]
})
}).then((response)=>{
if(response.status === 200) {
return response.json();
}
else{
console.log("Not updated");
} else{
console.log("Not updated", response);
process.exit(0);
}
}).catch((error)=>{
Expand Down Expand Up @@ -103,10 +98,10 @@ const getPermissionSet = async(roleId)=>{

const doTask = async () => {
await login();
for(role of roleIds){
for(permission of permissionIdList) {
const permissionList = await getPermissionSet(role);
await addPermissionInRole(role, permissionList, permission);
for(var role of roleIds){
for(var permission of permissionIdList) {
const permissionSet = await getPermissionSet(role);
await addPermissionInRole(role, permissionSet, permission);
}
}
};
Expand Down
11 changes: 9 additions & 2 deletions reportingSystem/superset_db_sqllite_to_postgres.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,12 @@ exit
docker restart avnisuperset_4.0.1
```

2. Add permissions to role. First take ids from file [/assets/role_permission_upgrade.sql](https://github.com/avniproject/avni-infra/blob/superset/reportingSystem/superset/assets/role_permission_upgrade.sql). put iy into [/assets/RoleUpgrade.js](https://github.com/avniproject/avni-infra/blob/superset/reportingSystem/superset/assets/RoleUpgrade.js)
and run scripts.
2. Add permissions to role. First take ids from file [/assets/role_permission_upgrade.sql](https://github.com/avniproject/avni-infra/blob/superset/reportingSystem/superset/assets/role_permission_upgrade.sql). put it into [/assets/RoleUpgrade.js](https://github.com/avniproject/avni-infra/blob/superset/reportingSystem/superset/assets/RoleUpgrade.js)
and run scripts.

```bash
nvm use;
npm install
node superset/assets/RoleUpgrade.js
```

0 comments on commit 825c888

Please sign in to comment.