Skip to content
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

Merged
merged 3 commits into from
Nov 2, 2018
Merged

Support for masquerade #17

merged 3 commits into from
Nov 2, 2018

Conversation

Ivanca
Copy link
Contributor

@Ivanca Ivanca commented Oct 25, 2018

image

@Ivanca
Copy link
Contributor Author

Ivanca commented Nov 1, 2018

@felipemontoya review needed.

Copy link
Member

@felipemontoya felipemontoya left a 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
Copy link
Member

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 Show resolved Hide resolved
active_comps = get_enabled_permission_classes()
for permission in active_comps:
if masquerade and masquerade.role != 'staff' and permission == AlwaysAllowStaff:
Copy link
Member

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

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
Copy link
Member

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?

Copy link
Contributor Author

@Ivanca Ivanca Nov 1, 2018

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.


return None

def supports_preview_menu(self, request):
""" if request view support preview_menu or not (not fully accurate) """
Copy link
Member

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.

Suggested change
""" 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"""

'staff_access': request.user.is_staff,
'masquerade': masquerade,
}
js_reposition = render_to_string('seb-reposition-wrapper-preview-menu.html', {})
Copy link
Member

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

'masquerade': masquerade,
}
js_reposition = render_to_string('seb-reposition-wrapper-preview-menu.html', {})
masquerade_html = render_to_string('preview_menu.html', context) + js_reposition
Copy link
Member

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

@@ -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)
Copy link
Member

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

@Ivanca Ivanca force-pushed the icc/support-for-masquerade branch 3 times, most recently from 7704f22 to 66f576e Compare November 2, 2018 15:33
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':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: comment

Copy link
Member

@felipemontoya felipemontoya left a 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 👍

@Ivanca Ivanca merged commit 1853369 into master Nov 2, 2018
@felipemontoya felipemontoya deleted the icc/support-for-masquerade branch April 11, 2019 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants