apluslms / mooc-grader

Automatic assessment framework compatible with A-plus LMS.
14 stars 30 forks source link

Hardcoded /login URLs do not work with FORCE_SCRIPT_NAME #136

Closed markkuriekkinen closed 1 year ago

markkuriekkinen commented 2 years ago

When the mooc-grader installation uses the FORCE_SCRIPT_NAME Django setting to serve all mooc-grader views behind a common URL prefix, then the system breaks down due to the hardcoded /login URL in a couple of places. The code should use the Django URL resolvers to form the URLs instead of hardcoding the URL strings.

This affects Tampere University since they use FORCE_SCRIPT_NAME. Their graders are supposed to be served from URL paths starting /graderA, on another server /graderE and so on. The prefix should affect all URLs of the MOOC-Grader. The URL path prefix is needed when the URL domain name is shared between multiple servers.

Hardcoded /login is used here:

https://github.com/apluslms/mooc-grader/blob/1f5b16365930f5b18de4c39e427ce2be7e0884d6/util/auth.py#L11 When Tampere hardcodes login_required_base(redirect_url="/graderA/login?referer={url}") there, it works. Note that reverse() doesn't seem to work in the module-level code since Django has not set up everything when the module is loaded and the module-level code is executed. https://docs.djangoproject.com/en/3.2/ref/urlresolvers/#reverse

https://github.com/apluslms/mooc-grader/blob/1f5b16365930f5b18de4c39e427ce2be7e0884d6/access/templates/access/login.html#L20

Aalto internal ticket: https://rt.cs.aalto.fi/Ticket/Display.html?id=21827

markkuriekkinen commented 2 years ago

At least, fixing the template should be trivial since it can use the normal url template tag: https://github.com/apluslms/mooc-grader/blob/1f5b16365930f5b18de4c39e427ce2be7e0884d6/access/templates/access/login.html#L20

https://docs.djangoproject.com/en/3.2/ref/templates/builtins/#url