Skip to content

bugfix remove course pre requisite only if is not entrance exam - #22529

Merged
mariajgrimaldi merged 3 commits into
openedx:masterfrom
appsembler:maxi/fix-entrance-exam-course-details
Nov 17, 2022
Merged

bugfix remove course pre requisite only if is not entrance exam#22529
mariajgrimaldi merged 3 commits into
openedx:masterfrom
appsembler:maxi/fix-entrance-exam-course-details

Conversation

@melvinsoft

Copy link
Copy Markdown
Contributor

This is a bug fix for Entrance Exams management in Schedule & Details page.

The error is easy to reproduce:
You need to make sure that the following FEATURES flags are enabled:

"FEATURES":
    "MILESTONES_APP": true,
    "ENABLE_PREREQUISITE_COURSES": true,
    "ENTRANCE_EXAMS": true
  • Go to or create a new course, then go to "Schedule and Details" , enable an entrance exam for the course, you can leave the default score or change it.
  • Go to Content -> Outline and fill the entrance exam with a couple of courses, then create a normal unit in the course.
  • Go to the LMS and Enroll in the course with a new learner (without any staff privilege). You will only be able to see the entrance exam.
  • Go to Studio again, same course and then "Schedule and Details" change the enrollment date or any other data and save.

When you go back to the LMS, you will find out that the entrance exam is disabled now, and you can see all the course content, but in the "Schedule and Details" is still active.

What happens in the background, is that there is a bug in the settings handlers that is there is any pre requisite course set, iterates over all pre requisites and deletes them, but the problem is Entrance Exams are a type of pre requisite since they belong to the milestones app, and is getting deleted too.

The fix check the milestone namespace, and if it's an Entrance Exam skips it.

Co-Authored-By: Omar Al-Ithawi i@omardo.com

@openedx-webhooks

openedx-webhooks commented Dec 13, 2019

Copy link
Copy Markdown

Thanks for the pull request, @melvinsoft! 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 as you can:

  • 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 Dec 13, 2019
@natabene

Copy link
Copy Markdown
Contributor

jenkins run all

@natabene

Copy link
Copy Markdown
Contributor

@melvinsoft Thank you for your contribution, please let me know once all tests are green.

@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 Dec 13, 2019

@OmarIthawi OmarIthawi left a comment

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.

Thanks Maxi! I've added some minor changes. Please let me know whenever this is ready for review again.

Comment thread cms/djangoapps/contentstore/tests/test_course_settings.py Outdated
Comment thread cms/djangoapps/contentstore/tests/test_course_settings.py
Comment thread cms/djangoapps/contentstore/tests/test_course_settings.py
Comment thread cms/djangoapps/contentstore/tests/test_course_settings.py Outdated
Comment thread cms/djangoapps/contentstore/tests/test_course_settings.py Outdated
Comment thread cms/djangoapps/contentstore/tests/test_course_settings.py Outdated
Comment thread cms/djangoapps/contentstore/tests/test_course_settings.py Outdated
Comment thread cms/djangoapps/contentstore/tests/test_course_settings.py Outdated
Comment thread cms/djangoapps/contentstore/views/course.py Outdated
course_milestones = milestones_api.get_course_milestones(course_key=course_key, relationship="requires")
for milestone in course_milestones:
remove_prerequisite_course(course_key, milestone)
ee_milestone_namespace = generate_milestone_namespace(

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.

ee is not immediately clear. Please refactor as suggested below 👇

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.

Done

@melvinsoft

Copy link
Copy Markdown
Contributor Author

jenkins run all

3 similar comments
@natabene

Copy link
Copy Markdown
Contributor

jenkins run all

@natabene

natabene commented Jan 2, 2020

Copy link
Copy Markdown
Contributor

jenkins run all

@natabene

natabene commented Jan 7, 2020

Copy link
Copy Markdown
Contributor

jenkins run all

@melvinsoft
melvinsoft force-pushed the maxi/fix-entrance-exam-course-details branch from 529907a to 01fa77f Compare January 10, 2020 22:39
@melvinsoft

Copy link
Copy Markdown
Contributor Author

jenkins run all

1 similar comment
@natabene

Copy link
Copy Markdown
Contributor

jenkins run all

@natabene

Copy link
Copy Markdown
Contributor

@melvinsoft Can you please check the failing tests?

@OmarIthawi
OmarIthawi force-pushed the maxi/fix-entrance-exam-course-details branch from 01fa77f to fcffb2e Compare February 19, 2020 07:56
@OmarIthawi

Copy link
Copy Markdown
Member

Thanks Natalia for the ping. @melvinsoft I've rebased the branch meanwhile hoping the Jenkins tests will be a bit better,

@melvinsoft

Copy link
Copy Markdown
Contributor Author

@natabene Thanks for reaching out, and thanks @OmarIthawi I hope test are better now after the rebase, if not we'll take care of the errors.

@natabene

Copy link
Copy Markdown
Contributor

jenkins run all

@OmarIthawi

Copy link
Copy Markdown
Member

@melvinsoft I've fixed all of the quality checks that I can fix, please check the second commit to see what I have done.

There's only one that I couldn't fix quickly, which is pylint complaining about the if statement we added, too many nested if statements are not acceptable by pylint.

@natabene We could use the reviewer advice on how to refactor the code to avoid nested if statements. Could you please move this to Engineering Review?

@natabene

Copy link
Copy Markdown
Contributor

@OmarIthawi Sure, I will line this up.

@openedx-webhooks openedx-webhooks added engineering review and removed waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. labels Feb 19, 2020
@melvinsoft

Copy link
Copy Markdown
Contributor Author

@OmarIthawi Thank you for the changes, and thanks for helping moving this PR along.

@natabene

natabene commented Mar 3, 2020

Copy link
Copy Markdown
Contributor

jenkins run all

@melvinsoft

Copy link
Copy Markdown
Contributor Author

@natabene Looks like all checks have passed now!

@OmarIthawi Thanks for pylint fixes!

@OmarIthawi OmarIthawi left a comment

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.

...

@natabene natabene changed the title bugfix remove course pre requisite only if is not entrance exam bugfix remove course pre requisite only if is not entrance exam Sep 1, 2022
@natabene natabene changed the title bugfix remove course pre requisite only if is not entrance exam bugfix remove course pre requisite only if is not entrance exam Sep 1, 2022
@natabene

natabene commented Sep 1, 2022

Copy link
Copy Markdown
Contributor

@melvinsoft Sorry for delay, this is good to go now from CLA perspective. The check is green.

@natabene

natabene commented Sep 1, 2022

Copy link
Copy Markdown
Contributor

Who can take it over the finish line and merge (once ready)?

@mariajgrimaldi

Copy link
Copy Markdown
Member

I can review @natabene

@OmarIthawi

Copy link
Copy Markdown
Member

Thanks @mariajgrimaldi and @natabene. The PR should be ready for review and merge.

@shadinaif would you mind confirm that?

@mariajgrimaldi

Copy link
Copy Markdown
Member

Let me know! @shadinaif @OmarIthawi

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.

Agreed. It'd more clear if you use entrance_exam_namespace or something similar. Also, can you add a substantial comment explaining why you're adding this change? In case there's a similar issue in the future

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.

And that makes me wonder, do you think there are other milestones that this piece of code could remove? or just entrance exam?

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.

Suggested change
if not milestone["namespace"] == ee_milestone_namespace:
if milestone["namespace"] != ee_milestone_namespace:

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.

Done

@mariajgrimaldi

Copy link
Copy Markdown
Member

Hello! Any updates here?

@shadinaif
shadinaif force-pushed the maxi/fix-entrance-exam-course-details branch 2 times, most recently from 6193915 to 4ce975c Compare October 8, 2022 01:34
@shadinaif

Copy link
Copy Markdown
Contributor

Thanks @mariajgrimaldi for the reminder

@shadinaif
shadinaif force-pushed the maxi/fix-entrance-exam-course-details branch from 4ce975c to 76e724c Compare October 8, 2022 01:57
Comment on lines +527 to +544
assert milestones_helpers.any_unfulfilled_milestones(self.course.id, self.user.id), \
'The entrance exam should be required.'

data_date = {
'entrance_exam_enabled': 'true',
'entrance_exam_minimum_score_pct': '60',
'syllabus': 'none',
'short_description': 'empty',
'overview': '',
'effort': '',
'intro_video': '',
'start_date': '2018-01-01',
'end_date': '{year}-12-31'.format(year=datetime.datetime.now().year + 4),
}
response = self.client.post(
settings_details_url,
data=json.dumps(data_date),
content_type='application/json',
HTTP_ACCEPT='application/json'
)
assert response.status_code == 200
assert milestones_helpers.any_unfulfilled_milestones(self.course.id, self.user.id), \
'The entrance exam should be required.'

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.

Is this test duplicated? What changes from the 1st post call to the 2nd one? If it's just the date:
so we don't have to duplicate this, we could use the ddt library, something like this:

@ddt.data(
     first_dict,
     second_dict
)
def test_entrance_after_changing_other_setting(self, edit_course_data):

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.

Thank you for the review! it's not duplicated, we need to verify that saving new settings will not delete the entrance exam we set before. I've adjusted the code to show that

@mariajgrimaldi mariajgrimaldi left a comment

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.

Hello! I tested a before & after (attached here), and this is working as you described. Thank you so much. I'm happy with this but consider making the tests shorter as I mentioned in the comment (if this makes sense to you folks).

After creating a course, enabling the entrance exam and then updating the date in the course:

After doing the same but with the fix:

I have a question: How can people fix this without creating a new course? For me, it worked to turn off and on again the entrance exam.

@mariajgrimaldi

mariajgrimaldi commented Oct 19, 2022

Copy link
Copy Markdown
Member

@shadinaif: hello! Do these recommendations make sense to you? If not, please leave a comment explaining and I'll merge it since the implementation looks good to me.

@mariajgrimaldi

Copy link
Copy Markdown
Member

@shadinaif hello again! Please, refer to my previous comment so we can merge :)

@shadinaif
shadinaif force-pushed the maxi/fix-entrance-exam-course-details branch from 76e724c to ef93b2e Compare November 16, 2022 13:15
melvinsoft and others added 3 commits November 16, 2022 16:17
See details in the related PR

Update cms/djangoapps/contentstore/tests/test_course_settings.py

Co-Authored-By: Omar Al-Ithawi <i@omardo.com>

Update cms/djangoapps/contentstore/tests/test_course_settings.py

Co-Authored-By: Omar Al-Ithawi <i@omardo.com>
Reformatting for an old code, no harm done
We've made a change in an old code. Pylint is not happy about that old code
we don't need to refactor it now, lets just disable the error message for it
@shadinaif
shadinaif force-pushed the maxi/fix-entrance-exam-course-details branch from ef93b2e to e68af88 Compare November 16, 2022 13:19
@mariajgrimaldi
mariajgrimaldi merged commit 5fa0528 into openedx:master Nov 17, 2022
@openedx-webhooks

Copy link
Copy Markdown

@melvinsoft 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

@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.

@OmarIthawi
OmarIthawi deleted the maxi/fix-entrance-exam-course-details branch November 17, 2022 14:02
@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

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

@OmarIthawi

Copy link
Copy Markdown
Member

@mariajgrimaldi @natabene @shadinaif and @melvinsoft. Thank you so much for closing this bug fix!

It's been a while since this was opened. Thanks for making it to the end 🎉 🎉 🎉

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

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

10 participants