-
-
Notifications
You must be signed in to change notification settings - Fork 204
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
feat(#9116): update user place field in admin to allow setting multiple places #9128
base: master
Are you sure you want to change the base?
Conversation
a50f55f
to
94fb460
Compare
@Benmuiruri, this is just a reminder to please enable the test |
66c1166
to
7f86ea5
Compare
114252d
to
da011a6
Compare
9293711
to
c1dd63f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All AC's in the description look good to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool stuff! Great work!
I left some comments mostly about readability and reusability.
const allowedRoles = $scope.permissions.can_have_multiple_places; | ||
|
||
const userHasPermission = userRoles.some(role => allowedRoles.includes(role)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're duplicating logic that we already have in the cht script api. This should already be available in the admin app. https://github.com/medic/cht-core/blob/master/admin/src/js/services/auth.js#L65
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, the value of userCtx.roles
is admin. It ends up being a check whether current user (Admin) has the permission
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I think you have to call it like:
return chtScriptApi.v1.hasPermissions(['can_have_multiple_places'], $scope.editUserModel.role, settings.permissions);
da011a6
to
03c645a
Compare
Hi @dianabarsan I have made almost all of the requested changes. The one I could not figure out is the suggestion to use |
03c645a
to
d2abe9b
Compare
This reverts commit d9b1cff.
9c72aa4
to
43a970b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! Some minor things inline to unblock you. I'll give this a try tomorrow!
const allowedRoles = $scope.permissions.can_have_multiple_places; | ||
|
||
const userHasPermission = userRoles.some(role => allowedRoles.includes(role)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I think you have to call it like:
return chtScriptApi.v1.hasPermissions(['can_have_multiple_places'], $scope.editUserModel.role, settings.permissions);
return DB().allDocs({ keys: placeIds, include_docs: true, limit: docsFetched }) | ||
.then(result => { | ||
const places = result.rows.map(row => row.doc); | ||
const contactTypes = new Set(places.map(place => place.contact_type)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that checking the contact_type
is not enough here.
A contact can have a type
and a contact_type
as well.
Have a look at the contact type utils library: https://github.com/medic/cht-core/blob/master/shared-libs/contact-types-utils/src/index.js#L13
I think this function, that checks whether a list of contacts are of the same type can belong there, instead of here.
@@ -254,24 +277,57 @@ angular | |||
return hasPlace && hasContact; | |||
}; | |||
|
|||
const validateFacilityHierarchy = () => { | |||
const placeIds = $scope.editUserModel.place; | |||
const docsFetched = 10; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unclear why we are fetching less docs than we are actually selecting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I forgot to take it out after some experimentation.
}; | ||
|
||
const getDocs = function (ids) { | ||
const docsFetched = 10; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unclear why we are limiting to 10 documents, when we can clearly have a longer selection.
const docs = result.rows.map(row => row.doc); | ||
const docIds = docs.map(doc => doc._id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can do this in a single line:
const docs = result.rows.map(row => row.doc); | |
const docIds = docs.map(doc => doc._id); | |
const docIds = result.rows.map(row => row.doc._id); |
return resolution.then(function() { //NoSONAR | ||
$timeout(() => { //NoSONAR | ||
selectEl.trigger('change'); | ||
}, 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should figure out why this timeout is needed. I'm not comfortable with keeping this at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems what's mainly left. I will dedicate tomorrow morning to it.
selectEl.select2('data', select2Data); | ||
$timeout(() => { //NoSONAR | ||
selectEl.trigger('change'); | ||
}, 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same. We should not have delays like this, we need to figure out what is happening here.
@@ -257,6 +256,7 @@ export class ContactsComponent implements OnInit, AfterViewInit, OnDestroy { | |||
|
|||
private canViewLastVisitedDate() { | |||
if (this.sessionService.isAdmin()) { | |||
// disable UHC for DB admins |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this added accidentally?
Description
This is a continuation of #6543
Now, users can be associated with more than one facility. This PR enables the CHT's Admin app to provide a way to associate those facilities with the user.
To get the feature to work, the admin user must enable
can_have_multiple_places
to some specific roles (e.g Supervisor, community_health_assistant, etc)Whenever a new user is added:
can_have_multiple_places
Closes #9116
Code review checklist
Compose URLs
If Build CI hasn't passed, these may 404:
License
The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.