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

Changes for superset bulk user create in Uganda #1

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

KicaRonaldOkello
Copy link

This PR makes changes for superset bulk user creation for MoH Uganda dashboards

src/index.ts Outdated

const DASHBOARD_VIEWER_ROLE_ID = 9;
const DASHBOARD_VIEWER_ROLE_ID = 7;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to get this ID from superset dynamically

@KicaRonaldOkello KicaRonaldOkello force-pushed the superset-bulk-user-creation-uganda branch from 3dfc136 to a702cff Compare February 1, 2024 11:26
SUPERSET_PASSWORD = "admin"
SUPERSET_BASE_URL = "http://localhost:8088"
SUPERSET_API_PATH = "/api/v1"
CHA_TABLES = [1,2,3]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to load the datasets dynamically and also be able to update the rowlevel security with the newly added datasets

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can safely be ignored.

Copy link
Collaborator

@alexosugo alexosugo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall. I'm keen about running tests of the readAndParse function where some of the method calls fail. Are the errors being handled gracefully or do they run optimistically, expecting the previous method to have completed successfully?

We could explore chaining then method calls and handling the errors in one place.

SUPERSET_PASSWORD = "admin"
SUPERSET_BASE_URL = "http://localhost:8088"
SUPERSET_API_PATH = "/api/v1"
CHA_TABLES = [1,2,3]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can safely be ignored.


export const getAvailableRowlevelSecurityFromSuperset = async (
authorizationHeaders: any,
): Promise<any> => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're using Typescript, let's utilize it's full capability. Define the return type to make your code more predictable.

`/security/roles/`,
JSON.stringify(role),
);
return { id: createdRole.id, name: createdRole.result.name };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used defined objects instead of destructuring. It'll be easier to identify errors. Also this method assumes a success scenario. The postRequest function checks to see if the request fails but doesn't handle the error.


if (!dasboardViewerRole) {
// Number got directly from Superset, could change
dasboardViewerRole = { id: 7, name: DASHBOARD_VIEWER };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's handle the scenario of when the user does not exist and return that as an output or error to the user. This can have unintended consequences if ones don't know that this was hardcoded here.

src/index.ts Outdated
console.log(`Processed ${users.length} successfully`);

users.forEach(async (user) => {
let userRole: { id: number; name: string };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interface SupersetRole is already defined. Let's use that to improve readability.

src/index.ts Outdated

const generatedRole = generateRole(user.role, user.place);

const roleExists = rolesAvailableOnSuperset.find(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The const name roleExists implies a boolean. Perhaps rename it to something more descriptive.

@alexosugo
Copy link
Collaborator

Please consider extracting the implementation of the readAndParse function into a separate file since it's custom to UG. I'll do the same for KE since the flows are different. The country being serviced can be defined in the env variables.

@paulpascal paulpascal marked this pull request as ready for review February 9, 2024 22:52
@paulpascal paulpascal marked this pull request as draft February 9, 2024 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants