Overhaul The User Management Dashboard

Let me get it running first :slight_smile:

I adjusted your import:

import UserSchema from '../../../../models/user';

UserSchema.find().exec(function(err, users) {
  console.log(users);
});

Now I got this:

ERROR in ./app/models/user.js
Module build failed: Error: Couldn't find preset "es2015" relative to directory "/home/rob/openmrs/openmrs-contrib-id/app/models"
    at /home/rob/openmrs/openmrs-contrib-id/app/user-modules/openmrs-contrib-id-user-management-dashboard/node_modules/babel-core/lib/transformation/file/options/option
-manager.js:395:17                                                                                                                                                     
    at Array.map (native)
    at OptionManager.resolvePresets (/home/rob/openmrs/openmrs-contrib-id/app/user-modules/openmrs-contrib-id-user-management-dashboard/node_modules/babel-core/lib/tran
sformation/file/options/option-manager.js:387:20)                                                                                                                      
    at OptionManager.mergePresets (/home/rob/openmrs/openmrs-contrib-id/app/user-modules/openmrs-contrib-id-user-management-dashboard/node_modules/babel-core/lib/transf
ormation/file/options/option-manager.js:370:10)                                                                                                                        
    at OptionManager.mergeOptions (/home/rob/openmrs/openmrs-contrib-id/app/user-modules/openmrs-contrib-id-user-management-dashboard/node_modules/babel-core/lib/transf
ormation/file/options/option-manager.js:330:14)                                                                                                                        
    at OptionManager.init (/home/rob/openmrs/openmrs-contrib-id/app/user-modules/openmrs-contrib-id-user-management-dashboard/node_modules/babel-core/lib/transformation
/file/options/option-manager.js:488:10)                                                                                                                                
    at File.initOptions (/home/rob/openmrs/openmrs-contrib-id/app/user-modules/openmrs-contrib-id-user-management-dashboard/node_modules/babel-core/lib/transformation/f
ile/index.js:223:65)                                                                                                                                                   
    at new File (/home/rob/openmrs/openmrs-contrib-id/app/user-modules/openmrs-contrib-id-user-management-dashboard/node_modules/babel-core/lib/transformation/file/inde
x.js:140:24)                                                                                                                                                           
    at Pipeline.transform (/home/rob/openmrs/openmrs-contrib-id/app/user-modules/openmrs-contrib-id-user-management-dashboard/node_modules/babel-core/lib/transformation
/pipeline.js:46:16)                                                                                                                                                    
    at transpile (/home/rob/openmrs/openmrs-contrib-id/app/user-modules/openmrs-contrib-id-user-management-dashboard/node_modules/babel-loader/index.js:14:22)
 @ ./app/user-modules/openmrs-contrib-id-user-management-dashboard/app/lib/Api.js 3:12-46

I think I can resolve that error ā€“ hold on

to fix that, just do from the openmrs-id root:

npm i babel-preset-es2015 babel-preset-react babel-preset-stage-0

Iā€™m gonna add that to the package.json ā€“ Really dislike this ā€“ a lot.

this is just a hotfix, I believe, it also can be configured in the webpack config

That fixed that error but got a boatload of othersā€¦

Yes, its that Iā€™m talking about. And the solution - is to update webpack config

Go ahead and do that ā€“ Iā€™m gonna go to bed ā€“ I should be up in about 6-7 hours.

If we will not find the solution, the other idea - is to make simple REST API, and make API calls instead of importing libraries.

this REST API can be implemented inside user-dashboard module, i will try, if it will work

Thereā€™s probably a way, @pascal ā€“ do you have any insight?

Even if weā€™ll find a way to fix webpack config, it will compile all code from id-dashboard into huge file, (because we will make imports inside user-dashboard), will be better to isolate that code, and make a REST API

1 Like

Did you see this? Thereā€™s a way to tell it to just parse files we need.

Can you help me, how to make authorized request to OpenMRS ID?

I added route /api/users, for gettting list of users, but when I am calling it, the response is 'Unauthorized". I must set authorization credentials in headers, or just make ā€˜/loginā€™ request before calling my REST API endpoint? Thanks

So we store the current authenticated user in the sessionā€¦so this should work. You shouldnā€™t be using another endpoint ā€“ we donā€™t expose an API for this. So you control everything. Just import the UserSchema in the index.js file.

Please have your mounted URL hang off of /admin/user-management-dashboard

Actually @dmytro.trifonov , utillize the middleware function implemented here. It should just say youā€™re not allowed to see this. Feel free to implement a middleware function that exposes the response as JSON, or submit a PR to check thatā€¦

Please also be sure to do app.admin.addPage('Data Management', '/admin/user-management-dashboard'); So that it appears on the admin dashboard :slight_smile:

1 Like

How did your day go @dmytro.trifonov?

I am trying to use ID Dashboard REST API, but even I make login request,and then request for a data, there are always ā€œUnauthorizedā€ responseā€¦ I donā€™t know why session not workingā€¦ I make requests using native fetch method.

When Iā€™ll setup connection between React components, and ID Dashboard API, I can go ahead and implement features for working with user data

Okay so this works. do it off of /admin and you get the role checks for free ā€“ if somebody tries to make a request and theyā€™re not an admin. Similarly for the main user management dashboard

app.get('/admin/api/users', (req,res) => { 
    UserSchema.find().exec((err, users)=>{
      if(err) res.json(err);
      res.json({users});
    });
});

However you wanna name it ā€“ donā€™t do it off of /api/ ā€“ not sure where thatā€™s used, but it is. One thing we need to figure out how to deal with is the fact that the password and other sensitive pieces of information are not sent when we use JSON: https://github.com/openmrs/openmrs-contrib-id/blob/master/app/models/user.js#L304

1 Like

Nice, works :slight_smile: Ok, letā€™s focus on functionality for now, and then we will add user credentials check.

This works for now ā€“ so long as you hang off of /admin ā€“ we have role checks :slight_smile: So thatā€™s enough to not have to worry (for now) :slight_smile: You need to figure out a way to allow the User object to export the sensitive details (we care about this ā€“ itā€™s vital) ā€“ do a pull request to dashboard itself if you need to and Iā€™ll review it as fast as I can :slight_smile: