-
Notifications
You must be signed in to change notification settings - Fork 2
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
Support for masquerade #17
Conversation
Ivanca
commented
Oct 25, 2018
•
edited
Loading
edited
@felipemontoya review needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In terms of the support of masquerade I think we have the right solution. I did however requested many changes in the handling and rendering of responses. Also some refactoring around the permission checks
requirements.txt
Outdated
web-fragments==0.2.2 | ||
lxml==3.8.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this dependency is no longer needed
seb_openedx/middleware.py
Outdated
active_comps = get_enabled_permission_classes() | ||
for permission in active_comps: | ||
if masquerade and masquerade.role != 'staff' and permission == AlwaysAllowStaff: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is strange, we have all the logic to prevent doing things like permission == AlwaysAllowStaff
and here we are.
I propose the following, lets add an optional kwarg to the permission().check()
signature, so that we can send the masquerade object. Then we can conduct this logic in the AlwaysAllowStaff
directly
seb_openedx/middleware.py
Outdated
if access_denied: | ||
html = six.text_type(self.handle_access_denied(request, view_func, view_args, view_kwargs, course_key)) | ||
if masquerade: | ||
html += masquerade_html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we concatenating here?
Would it be possible to sent the rendering context to the handle_access_denied
function (or have it in self.context) and only add this masquerade_html
so that the renderer can put it in the correct place in the html?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@felipemontoya The renderer at SebCoursewareIndex.as_view()
is outside our control so there is no clean way to 'put it in the correct place in the html', meaning the JS positioning code is needed.
What I can do is include the "preview_menu.html" on the template in order to keep the code cleaner.
seb_openedx/middleware.py
Outdated
|
||
return None | ||
|
||
def supports_preview_menu(self, request): | ||
""" if request view support preview_menu or not (not fully accurate) """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not say this is "not fully accurate", it is more like: seb-openedx only supports masquerade on this and that views.
""" if request view support preview_menu or not (not fully accurate) """ | |
""" Calculates if request view supports the preview_menu or not in this context. Not a perfect match to openedx's internal support""" |
seb_openedx/middleware.py
Outdated
'staff_access': request.user.is_staff, | ||
'masquerade': masquerade, | ||
} | ||
js_reposition = render_to_string('seb-reposition-wrapper-preview-menu.html', {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do the context
change to the renderer, we no longer need this
seb_openedx/middleware.py
Outdated
'masquerade': masquerade, | ||
} | ||
js_reposition = render_to_string('seb-reposition-wrapper-preview-menu.html', {}) | ||
masquerade_html = render_to_string('preview_menu.html', context) + js_reposition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concatenating pieces of HTML is always strange when we have full scale renderers. This won't be necessary
seb_openedx/middleware.py
Outdated
@@ -110,7 +144,7 @@ def courseware_error_response(self, request, *view_args, **view_kwargs): | |||
html = Fragment() | |||
html.add_content(render_to_string('seb-403-error-message.html', {})) | |||
SebCoursewareIndex.set_context_fragment(html) | |||
return SebCoursewareIndex.as_view()(request, *view_args, **view_kwargs) | |||
return force_text(SebCoursewareIndex.as_view()(request, *view_args, **view_kwargs).content) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this wont be necessary after the proposed refactor
7704f22
to
66f576e
Compare
66f576e
to
4399a9c
Compare
course_key_string = view_kwargs.get('course_key_string') or view_kwargs.get('course_id') | ||
course_key = CourseKey.from_string(course_key_string) if course_key_string else None | ||
|
||
if self.get_view_path(request) == 'courseware.masquerade': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional comment inline. Other than that this LGTM 👍
fdcfe9b
to
d7eeecb
Compare