forked from openedx/openedx-platform
-
Notifications
You must be signed in to change notification settings - Fork 15
feat: decouple enterprise from courseware view redirects #338
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
Merged
pwnage101
merged 1 commit into
release-ulmo
from
pwnage101/ENT-11544-edx-CoursewareViewStarted
Jun 17, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| """ | ||
| Decorators for courseware views. | ||
| """ | ||
| import functools | ||
|
|
||
| from django.shortcuts import redirect | ||
| from opaque_keys import InvalidKeyError | ||
| from opaque_keys.edx.keys import CourseKey | ||
| from openedx_filters.learning.filters import CoursewareViewStarted | ||
|
|
||
|
|
||
| def courseware_view_hooks(view_func): | ||
| """ | ||
| Decorator that calls the CoursewareViewStarted filter before rendering a courseware view. | ||
|
|
||
| If any pipeline step raises ``CoursewareViewStarted.RedirectToUrl``, the user is | ||
| redirected to that URL. Otherwise, the original view is rendered normally. | ||
|
|
||
| Usage:: | ||
|
|
||
| @courseware_view_hooks | ||
| def my_view(request, course_id, ...): | ||
| ... | ||
|
|
||
| Works with both function-based views and ``method_decorator``-wrapped class-based views. | ||
| The wrapped view must accept ``course_id`` as its first argument after ``request``, which | ||
| binds whether callers pass it positionally or as a URL keyword argument. | ||
| """ | ||
| @functools.wraps(view_func) | ||
| def _wrapper(request, course_id, *args, **kwargs): | ||
| try: | ||
| course_key = CourseKey.from_string(course_id) | ||
| except InvalidKeyError: | ||
| # Skip bad request which contains a malformed course_id; let the view logic raise an error. | ||
| return view_func(request, course_id, *args, **kwargs) | ||
|
|
||
| try: | ||
| view_name = getattr(view_func, '__name__', '') | ||
| CoursewareViewStarted.run_filter(course_key=course_key, view_name=view_name) | ||
|
pwnage101 marked this conversation as resolved.
|
||
| except CoursewareViewStarted.RedirectToUrl as exc: | ||
| # One of the pipeline steps wants us to block view execution and redirect to a specific URL. | ||
| return redirect(exc.redirect_to) | ||
|
|
||
| return view_func(request, course_id, *args, **kwargs) | ||
|
|
||
| return _wrapper | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.