Skip to content

Extension point to customize certificate views - #21147

Merged
bradenmacdonald merged 1 commit into
openedx:masterfrom
open-craft:josh/upstream/BB-1388
May 28, 2021
Merged

Extension point to customize certificate views#21147
bradenmacdonald merged 1 commit into
openedx:masterfrom
open-craft:josh/upstream/BB-1388

Conversation

@kaizoku

@kaizoku kaizoku commented Jul 17, 2019

Copy link
Copy Markdown
Contributor

We'd like to optionally require logins for viewing and downloading certificates.
This PR adds an extension point using a new feature added in openedx/edx-django-utils#64 to allow modifying the webview for certificates.

JIRA tickets: Implements BB-1388.

Dependencies: None

Sandbox URL: https://pr20957.sandbox.opencraft.hosting/

Testing instructions:

  1. Generate a certificate to test with.
    /edx/bin/{python,manage}.edxapp lms --settings=devstack_docker generate_fake_cert verified course-v1:edX+DemoX+Demo_Course
    
  2. Check the certificate renders normally with no login required in an logged-out browser: http://localhost:18000/certificates/user/8/course/course-v1:edX+DemoX+Demo_Course
  3. Add the following to lms/envs/private.py in the devstack
    OVERRIDE_RENDER_CERTIFICATE_VIEW = "lms.envs.private.certificate_render_html_view_override"
    from django.contrib.auth.decorators import login_required
    def certificate_render_html_view_override(prev_fn, request, user_id, course_id):
        return login_required(prev_fn)(request, user_id, course_id)
    
  4. Check the certificate page again and ensure it requires login now.

Author notes and concerns: None

Reviewers

@kaizoku
kaizoku requested a review from a team July 17, 2019 08:32
@openedx-webhooks

openedx-webhooks commented Jul 17, 2019

Copy link
Copy Markdown

Thanks for the pull request, @kaizoku! I've created OSPR-3752 to keep track of it in JIRA, where we prioritize reviews. Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

@openedx-webhooks openedx-webhooks added needs triage open-source-contribution PR author is not from Axim or 2U labels Jul 17, 2019
@kaizoku
kaizoku force-pushed the josh/upstream/BB-1388 branch 2 times, most recently from 787e196 to 6bd84e6 Compare July 17, 2019 10:08
@natabene

Copy link
Copy Markdown
Contributor

@kaizoku Thank you for your contribution. Please let me know once tests are green and this is ready for our review.

@openedx-webhooks openedx-webhooks added waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. and removed needs triage labels Jul 18, 2019
@kaizoku

kaizoku commented Jul 20, 2019

Copy link
Copy Markdown
Contributor Author

@natabene , I think that test failure was a fluke, it's an HTTP Connection error from selenium, and doesn't come from any components changed in this PR. The test works successfully on this branch in my devstack. I'll see if I can get jenkins to re-run it.

@kaizoku

kaizoku commented Jul 20, 2019

Copy link
Copy Markdown
Contributor Author

jenkins run bokchoy

@kaizoku kaizoku changed the title [WIP] Optionally require logins for certificate views Optionally require logins for certificate views Jul 21, 2019

@giovannicimolin giovannicimolin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

  • I tested this:
  1. Checked out this branch.
  2. Generated fake certificate for user.
  3. Checked that the certificate was publicly accessible ✔️
  4. Switched certificates.require_login on
  5. Checked that the certificate page required login to be accessible, and the redirect pointed back to the correct page. ✔️
  • I read through the code
  • Includes documentation ⚠️
  • I checked for accessibility issues NA

@kaizoku Nice work! Very simple and clean implementation. 😁

I have a question: isn't it better for this feature to be enabled/disabled per course instead of instance wide?

And a comment about your notes:

Should we create a waffle configuration in a new file for the certificates application?

This is not really required, but you could add a namespace variable to the top of the file where the switch is being used and use that, like this:

CERTIFICATES_NAMESPACE = 'certificates'
WaffleSwitch(CERTIFICATES_NAMESPACE, 'require_login').is_enabled()

There's not that many examples in the codebase related to that, and it's not a blocker for merging.

@kaizoku

kaizoku commented Jul 23, 2019

Copy link
Copy Markdown
Contributor Author

Thanks @giovannicimolin!

Hm, perhaps we should use a CourseWaffleFlag, that would provide more fine grained control.

My worry there is that course authors would have to create a new waffle flag for every course they create, and authentication wouldn't be enforced if they hadn't gotten the memo about creating waffle flags for their course. Whereas an organization who wants authentication for their certificates would likely want them for all courses, so missing this on one course would maybe be a kind of breach.

Also for the documentation note, I'm not sure where waffle flags are typically documented.
I did see a post today about documentation of waffle flags, which references OEP-17, but that OEP mostly describes when and why to create a waffle flag, but not much of how or where to document it.

@kaizoku

kaizoku commented Jul 24, 2019

Copy link
Copy Markdown
Contributor Author

@giovannicimolin, I've switched this around to using a CourseWaffleFlag, since it defers to WaffleFlag, so we can still set a global, but have overrides for each course as needed.

@giovannicimolin

Copy link
Copy Markdown
Contributor

@kaizoku Nice work here! I tested it again and it works perfectly.

👍

  • I tested this:
  1. Ran the same tests as before, but switching to a flag instead of a switch.
  2. Checked that viewing certificates can require login either on a per course basis or instance wide using the certificates.require_login. ✔️
  • I read through the code
  • Includes documentation ⚠️
  • I checked for accessibility issues NA

@giovannicimolin

Copy link
Copy Markdown
Contributor

@natabene This is ready for edX review.

@natabene

Copy link
Copy Markdown
Contributor

@ormsbee This is ready for your review, when you have a chance.

@openedx-webhooks openedx-webhooks added awaiting prioritization and removed waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. labels Jul 25, 2019
@natabene

Copy link
Copy Markdown
Contributor

@marcotuts Do you want to review this before it goes to engineering?

@natabene
natabene requested a review from marcotuts July 29, 2019 20:45
@openedx-webhooks openedx-webhooks added product review PR requires product review before merging and removed awaiting prioritization labels Jul 29, 2019
@kaizoku

kaizoku commented Aug 20, 2019

Copy link
Copy Markdown
Contributor Author

@marcotuts, @ormsbee any chance you've been able to check this out?

@natabene

Copy link
Copy Markdown
Contributor

@kaizoku Sorry for delay, we will try to look at this this week.

@kaizoku

kaizoku commented Aug 22, 2019

Copy link
Copy Markdown
Contributor Author

No problem @natabene , thanks for the response :)

@kaizoku

kaizoku commented Sep 20, 2019

Copy link
Copy Markdown
Contributor Author

@natabene, any chance you've been able to look at this PR?

@natabene

Copy link
Copy Markdown
Contributor

@kaizoku Sorry, not yet. We will try today.

@kaizoku

kaizoku commented Oct 21, 2019

Copy link
Copy Markdown
Contributor Author

@natabene has this come up for review yet?

@openedx-webhooks openedx-webhooks added the blocked by other work PR cannot be finished until other work is complete label Nov 17, 2020
@pomegranited

Copy link
Copy Markdown
Contributor

@kaizoku CC @bradenmacdonald

We are working to change the implementation here to a plugin approach so that there is no increase in code complexity to the core platform.

So can we close this OSPR?

@kaizoku

kaizoku commented Mar 11, 2021

Copy link
Copy Markdown
Contributor Author

@pomegranited, we'll still need to add one line to enable the plugin point after https://github.com/edx/edx-platform/pull/21433 is merged.
This PR currently has most of the contents from that PR for testing.
Once it's merged though, I'll cut it down to the decorator which creates the pluggability point: @pluggable_override('RENDER_CERTIFICATE_VIEW_IMPL')

@pomegranited

Copy link
Copy Markdown
Contributor

No worries, thanks for the update @kaizoku !

@kaizoku
kaizoku force-pushed the josh/upstream/BB-1388 branch 2 times, most recently from b2aca9e to a8d295c Compare May 3, 2021 16:55

@Agrendalath Agrendalath May 3, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@kaizoku, I see that the docstring, from which this has been copied, was not updated after the reworks. I'll fix this in #27466. Please use the prefix OVERRIDE_ for this, as described here (e.g. OVERRIDE_GET_UNIT_ICON), to keep it consistent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing that out. I've updated the variable name here to match.

@kaizoku
kaizoku force-pushed the josh/upstream/BB-1388 branch 2 times, most recently from 0e69769 to d4b6ec6 Compare May 15, 2021 11:26
@kaizoku

kaizoku commented May 17, 2021

Copy link
Copy Markdown
Contributor Author

This PR is ready for upstream review.

@bradenmacdonald bradenmacdonald left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@kaizoku Code looks good to me 👍🏻

Can you please: (1) Update the PR description to match the final approach taken here, and (2) rebase+squash to one commit with a conventional commit prefix?

@openedx-webhooks openedx-webhooks added changes requested and removed blocked by other work PR cannot be finished until other work is complete labels May 24, 2021
@kaizoku
kaizoku force-pushed the josh/upstream/BB-1388 branch from d39efcc to 43c332b Compare May 28, 2021 07:31
@kaizoku

kaizoku commented May 28, 2021

Copy link
Copy Markdown
Contributor Author

Thanks for the review @bradenmacdonald. I've squashed the PR, updated the commit message, and updated the PR description here. This should be ready now.

@bradenmacdonald

Copy link
Copy Markdown
Contributor

jenkins run js

@edx-status-bot

Copy link
Copy Markdown

Your PR has finished running tests. There were no failures.

@bradenmacdonald bradenmacdonald changed the title Optionally require logins for certificate views Extension point to customize certificate views May 28, 2021
@bradenmacdonald
bradenmacdonald merged commit 2650d59 into openedx:master May 28, 2021
@openedx-webhooks

Copy link
Copy Markdown

@kaizoku 🎉 Your pull request was merged!

Please take a moment to answer a two question survey so we can improve your experience in the future.

@bradenmacdonald
bradenmacdonald deleted the josh/upstream/BB-1388 branch May 28, 2021 18:10
@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

EdX Release Notice: This PR has been deployed to the staging environment in preparation for a release to production.

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

EdX Release Notice: This PR has been deployed to the production environment.

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

EdX Release Notice: This PR has been deployed to the staging environment in preparation for a release to production.

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

EdX Release Notice: This PR has been deployed to the production environment.

@kaizoku

kaizoku commented May 29, 2021

Copy link
Copy Markdown
Contributor Author

Thanks for the review @bradenmacdonald !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants