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

Support multiple roles on a contact type #86

Merged
merged 16 commits into from
Mar 19, 2024

Conversation

paulpascal
Copy link
Contributor

@paulpascal paulpascal commented Mar 11, 2024

Fix #69

  • change user_role to string[]
  • have a config function to generate userRoleProperty anytime we may need it (default property_name, type,... and only passing the user_role as parameter)
  • implement changes in Place and PlaceFactory to process the new property
  • add ValidatorRole to handle check selected roles against user_role (behaving as allowed roles when having more than one item)
  • update in UserPayload (to only use role and no more type)
  • update concerned templates
  • update doc

Copy link
Member

@kennsippell kennsippell left a comment

Choose a reason for hiding this comment

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

Nice work, buddy! Really really nice start on this work.

src/public/place/create_form.html Outdated Show resolved Hide resolved
src/public/place/bulk_create_form.html Outdated Show resolved Hide resolved
src/public/place/create_form.html Outdated Show resolved Hide resolved
test/services/upload-manager.spec.ts Show resolved Hide resolved
README.md Outdated
@@ -44,6 +44,7 @@ Property | Type | Description
`contact_types.replacement_property` | Property | Defines how this `contact_type` is described when being replaced. The `property_name` is always `replacement`. See [ConfigProperty](#ConfigProperty).
`contact_types.place_properties` | Array<ConfigProperty> | Defines the attributes which are collected and set on the user's created place. See [ConfigProperty](#ConfigProperty).
`contact_types.contact_properties` | Array<ConfigProperty> | Defines the attributes which are collected and set on the user's primary contact doc. See [ConfigProperty](#ConfigProperty).
`contact_types.user_roles_property` | ConfigProperty | Defines the property used for specifying user role(s) when creating users of this contact type. Add flexibility to choose role(s) when there are multiple roles available at this level of your hierarchy. See [ConfigProperty](#ConfigProperty).
Copy link
Member

Choose a reason for hiding this comment

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

I think it is important that we somehow capture the "allowed roles" at each level. Currently, this feature supports free-text input but what if somebody uses the wrong case? What if they use a CHW role for a supervisor user (this can actually result in quite serious bugs)? What if there are trailing spaces on the role, which is super common when working with CSVs?

Ideally, I think the best user experience for this feature would be a set of checkboxes like in the CHT today (see screenshot). You don't need to implement that UI here in this PR, we can start with free-text; but if we capture the "allowed roles" and validate them, I think that's a good start.

image

There are probably a few ways to approach this. But you'll want to validate this propery like the other property types. You'll probably end up with something like argument: ["role1", "role2"].

Copy link
Member

@kennsippell kennsippell Mar 12, 2024

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried to use it, but since select_multiple only accept parameter to be object for the moment (not simple array).

Got a simple role validator that can do the job, maybe the time to complete select_multiple feature.

src/config/index.ts Outdated Show resolved Hide resolved
src/services/user-payload.ts Outdated Show resolved Hide resolved
@paulpascal
Copy link
Contributor Author

Hi @kennsippell, thank you for your thorough review - I have worked on them.
Whenever you have the time, could you please take another look? I appreciate your feedback.
Thanks!

@kennsippell kennsippell self-requested a review March 12, 2024 18:33
Copy link
Member

@kennsippell kennsippell left a comment

Choose a reason for hiding this comment

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

Great progress @paulpascal !

src/lib/validation.ts Outdated Show resolved Hide resolved
src/lib/validation.ts Outdated Show resolved Hide resolved
src/lib/validation.ts Outdated Show resolved Hide resolved
src/liquid/place/bulk_create_form.html Outdated Show resolved Hide resolved
src/config/index.ts Show resolved Hide resolved
test/services/place.spec.ts Outdated Show resolved Hide resolved
test/mocks.ts Outdated Show resolved Hide resolved
src/liquid/place/bulk_create_form.html Outdated Show resolved Hide resolved
test/lib/validation.spec.ts Show resolved Hide resolved
src/liquid/place/list.html Outdated Show resolved Hide resolved
@paulpascal
Copy link
Contributor Author

Hello @kennsippell, had some work after our discussion, and made changes accordingly.
Would you please review it back ?

Many thanks

Copy link
Member

@kennsippell kennsippell left a comment

Choose a reason for hiding this comment

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

Nice. Feels very close!

import { ContactProperty } from '../config';
import { IValidator } from './validation';

export default class ValidatorRole implements IValidator {
Copy link
Member

@kennsippell kennsippell Mar 18, 2024

Choose a reason for hiding this comment

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

can this be repalced with @inromualdo 's select_multiple? or are you planning to keep this?

i assumed you're going to delete this; so i didn't review this file. let me know if this is incorrect

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes @kennsippell , of course. Was waiting for his work to be validated to rebase.
But I can rebase right now it is okay with you.

Copy link
Member

Choose a reason for hiding this comment

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

ideally i think we would set Ro's work to be the base branch for this work. then we would merge Ro's PR first.

given the circumstances, i'm fine with pushing this change forward as-is and we can ensure we delete it in Ro's PR

src/liquid/place/bulk_create_form.html Outdated Show resolved Hide resolved
src/services/place-factory.ts Outdated Show resolved Hide resolved
test/mocks.ts Outdated Show resolved Hide resolved
test/services/upload-manager.spec.ts Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@paulpascal
Copy link
Contributor Author

Nice. Feels very close!

Thanks @kennsippell , feedback addressed

Copy link
Member

@kennsippell kennsippell left a comment

Choose a reason for hiding this comment

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

Very well done, sir

src/config/index.ts Outdated Show resolved Hide resolved
import { ContactProperty } from '../config';
import { IValidator } from './validation';

export default class ValidatorRole implements IValidator {
Copy link
Member

Choose a reason for hiding this comment

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

ideally i think we would set Ro's work to be the base branch for this work. then we would merge Ro's PR first.

given the circumstances, i'm fine with pushing this change forward as-is and we can ensure we delete it in Ro's PR

<tr>
<td>{{ userRoleProperty.friendly_name }}</td>
<td>{{ userRoleProperty.required }}</td>
<td>Role of the user. Specify multiple roles with <i>space</i>. Allowed roles are <i>{{ contactType.user_role | join: ', ' }}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<td>Role of the user. Specify multiple roles with <i>space</i>. Allowed roles are <i>{{ contactType.user_role | join: ', ' }}
<td>Role of the user. Separate multiple roles with a <i>space</i>. Allowed roles are <i>{{ contactType.user_role | join: ', ' }}

Can you have a space in a valid CouchDB role? If so, we should change to ,.

src/services/place.ts Outdated Show resolved Hide resolved
test/services/place.spec.ts Outdated Show resolved Hide resolved
test/services/place.spec.ts Show resolved Hide resolved
@paulpascal paulpascal merged commit b110678 into main Mar 19, 2024
1 check passed
@paulpascal paulpascal deleted the 69-support-multiple-level-roles branch March 27, 2024 06:25
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.

Support for two user_roles (togo chw and rcom) at village level
2 participants