Let me get it running first
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
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
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
Nice, works 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 So thatās enough to not have to worry (for now)
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