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

feat: adds a certificate template modifier #34042

Conversation

deborahgu
Copy link
Member

@deborahgu deborahgu commented Jan 11, 2024

Description

Adds a management command to modify certificate templates, with a dry run option.

Notes:

Inherently unsafe; just as a search and replace on the first string match, because you can't use HTML/lxml-style parsing on HTML blended with django templating instructions. For the same reason, doesn't do any sanity checking on the contents of the string match, except for the safety checking that's inherent on the template itself. Help/usage text stresses that it should be always run with --dry-run first.

FIXES: APER-2851

adds a management command to modify certificate templates, with a dry
run option. Inherently unsafe; just as a search and replace on the first
string match.

TODO:
* unit tests
* make sure the multi-line string replacements work via django admin

FIXES: APER-2851
undid my auto formatters reordering of the includes, because I'm
assuming that's what the lint-amnesty directives are there for. Best
practice would have a human-written comment explaining why they need to
stay there, but I'm just going have to assume it's correct, Because no
such human-written comment exists.

FIXES: APER-2851
fixing a long line problem

FIXES: APER-2851
adding the migration for  the ability to manage these command configs
via django admin

FIXES: APER-2851
pep8

FIXES: APER-2851
still needs mocks for all tests to work

FIXES: APER-2851
Re-factored to make the code more testable, and added some more tests,
also improved dry run logging

FIXES: APER-2851
@deborahgu deborahgu marked this pull request as ready for review January 17, 2024 21:51
@deborahgu deborahgu requested a review from justinhynes January 17, 2024 21:51
class Meta:
model = GeneratedCertificate

course_id = None
status = CertificateStatuses.unavailable
mode = GeneratedCertificate.MODES.honor
name = ''
name = ""
Copy link
Member Author

Choose a reason for hiding this comment

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

Quote style changed to our approved doublequotes on saving the file.


generate_course_certificate(user=student, course_key=course_key, status=status, enrollment_mode=enrollment_mode,
course_grade=course_grade, generation_mode=generation_mode)
student = User.objects.get(id=kwargs.pop("student"))
Copy link
Member Author

Choose a reason for hiding this comment

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

changed to standard style on file save.

not sure why the manual linter didn't complain

FIXES: APER-2851
Fixing a linter air

FIXES: APER-2851
Comment on lines +23 to +31
This is DANGEROUS.
* This uses string replacement to modify HTML-like templates, because the presence of
Django Templating makes it impossible to do true parsing.
* This isn't parameterizing the replacement text, for the same reason. It has
no way of knowing what is template language and what is HTML.
Do not trust that this will get the conversion right without verification,
and absolutely do not accepted untrusted user input for the replacement text. This is
to be run by trusted users only.
Always run this with dry-run or in a reliable test environment.
Copy link
Contributor

Choose a reason for hiding this comment

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

Kudos 👍. Thanks for pointing out that this is a potentially dangerous and destructive action.

class Command(BaseCommand):
"""Management command to modify certificate templates.
Example usage:
./manage.py lms modify_cert_template --old-text
Copy link
Contributor

@justinhynes justinhynes Jan 18, 2024

Choose a reason for hiding this comment

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

The example seems incomplete at a first glance. Should this also have an example of --old-text and how to use the other options (like --new_text {blah})? I'd love to see an example of how to specify the templates too.

Copy link
Contributor

@justinhynes justinhynes left a comment

Choose a reason for hiding this comment

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

This looks slick! Other than a request to expand on the example command in the docstring, I think this looks good to me!

improving a comment

FIXES: APER-2851
@deborahgu deborahgu merged commit 611e3cc into master Jan 22, 2024
62 of 63 checks passed
@deborahgu deborahgu deleted the dkaplan1/APER-2851_replicate-share-certificate-in-facebook-improvements-for-edx.org branch January 22, 2024 14:23
@edx-pipeline-bot
Copy link
Contributor

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

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

1 similar comment
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

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