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

M2-6042: Validate Params from Admin to Web App #438

Merged
merged 26 commits into from
Apr 25, 2024

Conversation

sultanofcardio
Copy link
Contributor

@sultanofcardio sultanofcardio commented Apr 18, 2024

📝 Description

🔗 Jira Ticket M2-6042

This PR builds on #431 and introduces validation of the following query parameters:

  • startActivityOrFlow - An activity or Flow ID
  • respondentId - The respondent taking the assessment
  • subjectId - The subject who the assessment is about

If one of these parameter is omitted, then no validation takes place and the app behaves as it does today with one exception: the activity or flow is not started. Starting the activity/flow automatically now requires the provision of all three parameters.

If they are all provided, then the following validation is performed:

  • startActivityOrFlow identifies a valid activity
  • respondentId matches the currently authenticated user
  • subjectId corresponds to a real subject
  • The currently authenticated user has one of these roles in the applet
    • Super Admin
    • Owner
    • Manager

If all the validation passes, then the activity/flow is started automatically and the context is stored in a multi-informant redux store.

📸 Screenshots

There isn't really anything to show, besides error banners I guess 🤷

🪤 Peer Testing

Note

You'll need to test this change locally, as it depends on backend changes that haven't yet been deployed. Use the feature/multiinformant-metapod branch for your API

Note

This feature depends on the enableMultiInformant feature flag. If it it not already enabled, you can manually enable it here like so:

features.enableMultiInformant = true;

There are quite a few scenarios that need to be tested, so buckle up. For this test, you'll need the following set up in your workspace:

  • An owner
  • A manager
  • An editor
  • A reviewer
  • A limited account participant

You will also need at least one applet with at least one activity.

Make note of the user ID and subject ID for each of the users above, as well as the applet ID and activity ID then using the following URL template:

https://localhost:5173/protected/applets/{appletId}/?startActivityOrFlow={activityId}&respondentId={sourceUserId}&subjectId={targetSubjectId}

Substitute for each of following scenarios, and validate the outcome:

Scenario Source (user ID) Target (subject ID) Outcome
Owner, Manager Limited account participant Activity is started
Editor, Reviewer, Coordinator Limited account participant Activities page
Owner,Manager Any team member Activity is started
Editor, Reviewer, Coordinator Themself Activities page
Respondent Limited account participant Activities page
Respondent Themself Activities page

Note

Also, be sure to validate the scenarios mentioned in the description above regarding the query parameter combinations

✏️ Notes

N/A

@sultanofcardio sultanofcardio self-assigned this Apr 18, 2024
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-438.d15zn9do8xbzga.amplifyapp.com

@sultanofcardio
Copy link
Contributor Author

sultanofcardio commented Apr 19, 2024

The acceptance criteria for this ticket lists coordinator as one of the roles that should be able to perform this flow. However, I've removed this ability pre-emptively in anticipation of M2-6348

@sultanofcardio sultanofcardio marked this pull request as ready for review April 22, 2024 16:27
Copy link
Contributor

@farmerpaul farmerpaul left a comment

Choose a reason for hiding this comment

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

Hey @sultanofcardio, great work on this! Must have been quite a slog having to take into account all of that nuanced validation logic…

I had just a couple minor suggestions, see what you think, happy to hear your thoughts there.

I did run through the peer testing, and I discovered a couple issues. First, here's what I found:

Source Subject Outcome
owner Limited account ❌ Doesn't start activity (no error message)
manager Limited account ✅ Starts activity
coordinator Limited account 🤔 You are not authorized to complete this assessment on behalf of this subject.
editor Limited account 🤔 This subject does not exist
reviewer Limited account 🤔 This subject does not exist
owner Team member ❌ Doesn't start activity (no error message)
manager Team member ✅ Starts activity
coordinator Themself 🤔 You are not authorized to complete this assessment on behalf of this subject.
editor Themself 🤔 This subject does not exist
reviewer Themself 🤔 This subject does not exist
respondent Limited account 🤔 This subject does not exist
respondent Themself 🤔 This subject does not exist

My main concern:

  • When I try to use Take Now as the owner, it always takes me to the Activity List, rather than initiate the activity. And there's no error message. I'm wondering if I've got my applet configured wrong, or do you experience the same thing?

Lesser concern:

  • I'm not sure what the error message is supposed to be – but I would guess that it's supposed to be the same for all of the error cases above? Mainly, it doesn't make a whole lot of sense to me for the "This subject does not exist" error to appear most of the time.

src/features/TakeNow/ui/ValidateTakeNowParams.tsx Outdated Show resolved Hide resolved
src/features/TakeNow/ui/ValidateTakeNowParams.tsx Outdated Show resolved Hide resolved
src/features/TakeNow/ui/ValidateTakeNowParams.tsx Outdated Show resolved Hide resolved
@sultanofcardio sultanofcardio force-pushed the feature/M2-6042-validate-take-now-params branch from 455e1a8 to 20d4334 Compare April 23, 2024 21:35
@sultanofcardio
Copy link
Contributor Author

Thanks for the thorough review as usual @farmerpaul. I implemented all of your suggestions!

About the outcome of your testing, your table should look like the one I included in the PR description. That means something is amiss somewhere.

When I try to use Take Now as the owner, it always takes me to the Activity List, rather than initiate the activity. And there's no error message. I'm wondering if I've got my applet configured wrong, or do you experience the same thing?

No, the owner (and manager) should be able to start the activity for any other user. The only cases where the activity list is rendered without an error message is when we are unable to fetch the subject ID for the current user. If you created your workspace and users before multi-informant, your owner user may be missing a subject. Check the console for this error message

Unable to fetch subject ID for current user

P.S. I've noticed that I was unable to submit activities in the respondent web app with the owner user since starting work on multi-informant, until I recreated the workspace. If this is indeed the case (I haven't tested robustly) then there may be something wrong with the way pre-MI data is being migrated, and we should create a ticket for it.

I'm not sure what the error message is supposed to be – but I would guess that it's supposed to be the same for all of the error cases above? Mainly, it doesn't make a whole lot of sense to me for the "This subject does not exist" error to appear most of the time.

The coordinator scenario is correct: They are unable to start take now according to the list of allowed roles. For the other ones, the error message should be the same as for the coordinator scenario. If you have multiple applets, be sure that you're using the subject ID corresponding to the applet that you're testing with (subjects exist in the context of an applet).

Copy link
Contributor

@farmerpaul farmerpaul left a comment

Choose a reason for hiding this comment

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

Thanks for making those updates! Code looks great.

Take now as owner issue

I re-ran tests, following your suggestion of creating a new workspace, with a new applet and activity. This first issue is now resolved – the owner is now considered a subject on the BE, and can now act as a respondent on behalf of another user. Thanks for the suggestion!

  • One of us should create a ticket detailing this issue. I would characterize it as a data integrity issue, what do you think? Either the subject records should be created in bulk for existing workspaces, or perhaps done on-demand (i.e. an endpoint request expecting the subject to exist should ensure it's created if found to be missing).
  • In the meantime, until that ticket is completed, would it still be prudent to handle this scenario in Take Now flow with a helpful error message?

"This subject does not exist" issue

This one is still happening even with this newly created workspace, applet, participants and team members. I've only ever been using the subjectId for each participant as returned in the response to the respondents query on the applet's Participants screen, so that shouldn't be the issue.

Here's what I see in the JS console when the Take Now page request loads, and I've added a debug statement to output isSubjectError and subjectData:

Screenshot 2024-04-24 at 11 33 47 AM

Looks to me like there's an issue fetching the workspace ID, and resulting in several malformed requests. Let me know if you'd like me to troubleshoot further.

src/features/TakeNow/lib/useTakeNowValidation.tsx Outdated Show resolved Hide resolved
@farmerpaul farmerpaul self-requested a review April 24, 2024 14:46
@sultanofcardio
Copy link
Contributor Author

One of us should create a ticket detailing this issue. I would characterize it as a data integrity issue, what do you think? Either the subject records should be created in bulk for existing workspaces, or perhaps done on-demand (i.e. an endpoint request expecting the subject to exist should ensure it's created if found to be missing).

I'm happy to create this ticket, but I would like to investigate further. For now I'll raise it in Slack

Looks to me like there's an issue fetching the workspace ID, and resulting in several malformed requests. Let me know if you'd like me to troubleshoot further.

I'm not sure this is it. The workspace ID is present in the applet data. The malformed requests you're seeing are a result of the nature of hooks. The hooks have to run even before the proper data is present, so some of them will be malformed at first. Let me do some investigation to see what this could be

@sultanofcardio sultanofcardio force-pushed the feature/M2-6042-validate-take-now-params branch from 8d1e034 to c96de7f Compare April 24, 2024 15:56
@sultanofcardio
Copy link
Contributor Author

@farmerpaul Thanks for catching this. I've made a small patch to account for the permissions of the get subject endpoint. After patching it, I ran these happy path tests:

Source Target Outcome Expected Outcome ✅/❌
Owner Owner (self) Able to complete the flow Able to complete the flow
Owner Manager Able to complete the flow Able to complete the flow
Owner Coordinator Able to complete the flow Able to complete the flow
Owner Editor Able to complete the flow Able to complete the flow
Owner Reviewer Able to complete the flow Able to complete the flow
Owner Full Account Able to complete the flow Able to complete the flow
Owner Limited account Able to complete the flow Able to complete the flow
Manager Owner Able to complete the flow Able to complete the flow
Manager Manager (self) Able to complete the flow Able to complete the flow
Manager Coordinator Able to complete the flow Able to complete the flow
Manager Editor Able to complete the flow Able to complete the flow
Manager Reviewer Able to complete the flow Able to complete the flow
Manager Full Account Able to complete the flow Able to complete the flow
Manager Limited account Able to complete the flow Able to complete the flow
Coordinator Owner Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Coordinator Manager Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Coordinator Coordinator (self) Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Coordinator Editor Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Coordinator Reviewer Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Coordinator Full Account Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Coordinator Limited account Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Editor Owner Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Editor Manager Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Editor Coordinator Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Editor Editor (self) Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Editor Reviewer Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Editor Full Account Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Editor Limited account Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Reviewer Owner Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Reviewer Manager Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Reviewer Coordinator Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Reviewer Editor Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Reviewer Reviewer (self) Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Reviewer Full Account Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Reviewer Limited account Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Full Account Owner Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Full Account Manager Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Full Account Coordinator Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Full Account Editor Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Full Account Reviewer Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Full Account Full Account (self) Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.
Full Account Limited account Receive error message: You are not authorized to complete this assessment on behalf of this subject. Receive error message: You are not authorized to complete this assessment on behalf of this subject.

Can you retest and see if you get the expected outcomes?

@ChaconC
Copy link
Contributor

ChaconC commented Apr 24, 2024

Just went through all tests and got the expected results as per your table.

Source Subject Submit Notes
owner owner (self) OK
owner coordinator OK
owner editor OK
owner manager OK
owner reviewer OK
owner Full account OK
owner Limited account OK
manager owner OK
manager coordinator OK
manager editor OK
manager manager (self) OK
manager reviewer OK
manager Full account OK
manager Limited Account OK
coordinator owner Not Authorized
coordinator coordinator (self) Not Authorized
coordinator editor Not Authorized
coordinator manager Not Authorized
coordinator reviewer Not Authorized
coordinator Full account Not Authorized
coordinator Limited Account Not Authorized
editor owner Not Authorized
editor coordinator Not Authorized
editor editor (self) Not Authorized
editor manager Not Authorized
editor reviewer Not Authorized
editor Full account Not Authorized
editor Limited Account Not Authorized
reviewer owner Not Authorized
reviewer coordinator Not Authorized
reviewer editor Not Authorized
reviewer manager Not Authorized
reviewer reviewer (self) Not Authorized
reviewer Full account Not Authorized
reviewer Limited Account Not Authorized
Full account owner Not Authorized
Full account coordinator Not Authorized
Full account editor Not Authorized
Full account manager Not Authorized
Full account reviewer Not Authorized
Full account Full account (self) Not Authorized
Full account Limited account Not Authorized
Test Expected Result Error Message
Missing Activity ID No error
Missing Subject ID No error
Missing Respondent ID No error
Invalid Activity ID Activity does not exist
Invalid Subject ID Subject does not exist
Invalid Respondent ID Not Authorized
Invalid Applet ID Assessment is no longer accepting respondents

@sultanofcardio sultanofcardio requested a review from ChaconC April 25, 2024 05:20
Copy link
Contributor

@ChaconC ChaconC left a comment

Choose a reason for hiding this comment

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

🚀

Copy link
Contributor

@farmerpaul farmerpaul left a comment

Choose a reason for hiding this comment

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

I didn't do as exhaustive testing as @ChaconC (kudos, man!), but I did run through all my previous scenarios, and everything is now tickety-boo! Thanks @sultanofcardio, awesome work.

Source Subject Outcome
owner Limited account ✅ Starts activity
manager Limited account ✅ Starts activity
coordinator Limited account You are not authorized to complete this assessment on behalf of this subject.
editor Limited account You are not authorized to complete this assessment on behalf of this subject.
reviewer Limited account You are not authorized to complete this assessment on behalf of this subject.
owner Team member ✅ Starts activity
manager Team member ✅ Starts activity
coordinator Themself You are not authorized to complete this assessment on behalf of this subject.
editor Themself You are not authorized to complete this assessment on behalf of this subject.
reviewer Themself You are not authorized to complete this assessment on behalf of this subject.
respondent Limited account You are not authorized to complete this assessment on behalf of this subject.
respondent Themself You are not authorized to complete this assessment on behalf of this subject.

@sultanofcardio sultanofcardio merged commit 94c9e8b into dev Apr 25, 2024
6 checks passed
@sultanofcardio sultanofcardio deleted the feature/M2-6042-validate-take-now-params branch April 25, 2024 18:04
sultanofcardio added a commit to ChildMindInstitute/mindlogger-admin that referenced this pull request May 6, 2024
This is a one-liner to remove `Coordinator` from the list of roles with access to the Take Now menu item in the activity context menu. Other roles remain unaffected.

This does not prevent a coordinator from initiating take now using a manually constructed URL. That scenario is handled in the [respondent web app](ChildMindInstitute/mindlogger-web-refactor#438)
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.

3 participants