apluslms / a-plus

A+ frontend portal - A+ LMS documentation:
https://apluslms.github.io/
Other
64 stars 72 forks source link

Fix course instance editor breaking when using "instances" as URL. #1345

Closed sayravai closed 4 months ago

sayravai commented 4 months ago

Fixes #782

Description

What?

When editing a course instance, if one used 'instances' as the URL, it did not get saved into the database due to being a reserved word, but the returned HTML still contained the broken path for all links on the page.

Why?

The URL was only checked for disallowed strings on the model level, which is only run after the URL validation process. This caused the links in the returned HTML to contain the broken URL, as no ValidationErrors were raised.

How?

A test similar to the one on the model level was added to the URL validation (CourseInstanceForm -> clean_url). Also a static class variable RESERVED_URLS was added to the CourseInstance class, so the forbidden strings list can be referenced from the CourseInstanceForm class without being redeclared in multiple files.

Fixes #782

Testing

What type of test did you run?

[ADD A DESCRIPTION ABOUT WHAT YOU TESTED MANUALLY]

Did you test the changes in

It's unlikely that this PR would be browser-dependent in any way.

Translation

I did not add a new translation string, but reused the ERROR_URL_ALREADY_TAKEN.

Programming style

No new functions were added in this PR.

Have you updated the README or other relevant documentation?

This PR does not create any new functionality that should be documented.

Is it Done?

Clean up your git commit history before submitting the pull request!