Skip to content

Conversation

@shanbady
Copy link
Contributor

@shanbady shanbady commented Mar 11, 2024

What are the relevant tickets?

Closes #555

Description (What does it do?)

This PR implements a shareable program letter view for users who have earned a program certificate in micromasters.
The the flow for this is:

  1. User receives program certificate in micromasters upon which it is recorded in MM database
  2. MM program certificate table is pulled into data lake ultimately ends up in program certificate data mart
  3. Data mart is synced directly to a ProgramCertificates table in MIT-Open
  4. User visits dashboard in Open and see's link to view program letter if they have an entry in ProgramCertificates for the program dashboard they are looking at.
  5. that link points to an "intercept view" which:
    • generates a "program letter" object which will have a uuid that is used in the shareable url
    • makes an api call to the micromasters cms to fetch the template content for the program letter
    • forwards the user to the program letter view which renders the letter and is shareable

Main Changes

The changes in this PR can be grouped into 3 main parts:
1 - An api route added to create a program letter object and fetch template data from micromasters
2 - Autogenerated api schema for above route
3 - fronted react view to render the program letter

How can this be tested?

  1. in your .env file, set MICROMASTERS_CMS_API_URL=https://micromasters-rc.odl.mit.edu/api/v0/wagtail/
  2. get into a django shell via docker-compose exec web python manage.py shell
  3. We are going to create 2 program certificates for your user. On production this would exist as a result of the data sync but we will simulate these records here. Make sure you replace the email here with whatever user you will be logging in with:

from profiles.models import ProgramCertificate
ProgramCertificate.objects.get_or_create(user_full_name='john doe',user_email='your@email.here', micromasters_program_id=1, program_title='Supply Chain Management')
ProgramCertificate.objects.get_or_create(user_full_name='john doe',user_email='your@email.here', micromasters_program_id=18, program_title='Statistics and Data Science')
ProgramCertificate.objects.get_or_create(user_full_name='john doe',user_email='your@email.here', micromasters_program_id=2, program_title='Data, Economics, and Development Policy')
  1. login as the user with email from above.
  2. visit http://localhost:8063/program_letter/1/ and http://localhost:8063/program_letter/18/ - you should be redirected to shareable (viewable in incognito mode while logged out) program letter views. The urls should have uuids in them.

@codecov
Copy link

codecov bot commented Mar 11, 2024

Codecov Report

Attention: Patch coverage is 78.91566% with 35 lines in your changes are missing coverage. Please review.

Project coverage is 76.52%. Comparing base (4093245) to head (533eab0).
Report is 18 commits behind head on main.

Files Patch % Lines
frontends/api/src/generated/api.ts 12.50% 28 Missing ⚠️
...nds/api/src/test-utils/factories/programLetters.ts 33.33% 2 Missing ⚠️
profiles/utils.py 87.50% 0 Missing and 2 partials ⚠️
frontends/api/src/clients.ts 83.33% 1 Missing ⚠️
frontends/api/src/test-utils/urls.ts 66.66% 1 Missing ⚠️
.../src/pages/ProgramLetterPage/ProgramLetterPage.tsx 95.23% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #605      +/-   ##
==========================================
+ Coverage   76.50%   76.52%   +0.02%     
==========================================
  Files         242      244       +2     
  Lines       10141    10296     +155     
  Branches     1721     1738      +17     
==========================================
+ Hits         7758     7879     +121     
- Misses       2217     2248      +31     
- Partials      166      169       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@shanbady shanbady changed the title Shanbady/programletter react reference implementation Program Letter View Mar 11, 2024
@shanbady shanbady added the Needs Review An open Pull Request that is ready for review label Mar 12, 2024
@shanbady shanbady marked this pull request as ready for review March 12, 2024 02:40
@mbertrand mbertrand self-assigned this Mar 12, 2024
Copy link
Member

@mbertrand mbertrand left a comment

Choose a reason for hiding this comment

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

Overall works great! Just noticed a couple things:

  • Some docstrings are wrong or missing.
  • If I enter the wrong uuid in the letter url, I would expect to get a 404 page but instead I get an error message if it is a valid but wrong uuid, or a mostly blank letter on the frontend and a backend 'not a valid UUID' ValidationError if it isn't a valid uuid:

Screenshot 2024-03-12 at 10 29 03 AM

Screenshot 2024-03-12 at 10 22 14 AM

@mbertrand mbertrand added Waiting on author and removed Needs Review An open Pull Request that is ready for review labels Mar 12, 2024
@ChristopherChudzicki
Copy link
Contributor

ChristopherChudzicki commented Mar 12, 2024

@mbertrand Re

If I enter the wrong uuid in the letter url, I would expect to get a 404 page but instead I get an error message

You're actually seeing a 404 page covered up by a dev-mode error overlay. In production, you'd only get the 404 page. The error overlay has a little X in upper right corner that you can click to get rid of it.

I find the error overlay annoying / confusing for 404 and 403 errors, too. IIRC the error overlay is pretty easy to disable entirely, but I don't think I found a way to disable it just for the 404/403/401 errors that we handle with NotFound and Forbidden pages.

Although, the error overlay only shows for synchronous errors—which doesn't include the 500 API response. (It does include the 401, 403, 404 b/c we intentionally monitor for those asynchronous errors and re-throw them so a handler can show the forbidden or not-found pages). And in my experience synchronous errors don't happen too often, so maybe disabling it would be best.

or a mostly blank letter on the frontend and a backend 'not a valid UUID' ValidationError if it isn't a valid uuid:

I see that issue, too.

@shanbady
Copy link
Contributor Author

@mbertrand I resolved the blank page issue by checking for valid uuids and 404'ing server side if invalid which will trigger the 404 on the frontend.

@shanbady shanbady added Needs Review An open Pull Request that is ready for review and removed Waiting on author labels Mar 12, 2024
@shanbady shanbady requested a review from mbertrand March 12, 2024 18:20
Copy link
Member

@mbertrand mbertrand left a comment

Choose a reason for hiding this comment

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

Looks great! 👍

@mbertrand mbertrand added Waiting on author and removed Needs Review An open Pull Request that is ready for review labels Mar 12, 2024
@shanbady shanbady merged commit f125f24 into main Mar 12, 2024
@shanbady shanbady deleted the shanbady/programletter-react-reference-implementation branch March 12, 2024 18:50
This was referenced Mar 18, 2024
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.

Create shareable program letter display view

4 participants