-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix #5466: Added check to enforce that all name of controllers end with "Handler" or "Page" #5878
Conversation
Hi @lilithxxx, FYI the travis build is still failing. Could you please investigate? Also please include a reference in this PR to the other PR (and close one of them so that there's just a single point of focus ). Thanks! |
Codecov Report
@@ Coverage Diff @@
## develop #5878 +/- ##
========================================
Coverage 45.53% 45.53%
========================================
Files 517 517
Lines 30335 30335
Branches 4562 4562
========================================
Hits 13812 13812
Misses 16523 16523 Continue to review full report at Codecov.
|
@seanlip made the changes, PTAL |
core/controllers/base_test.py
Outdated
""" | ||
def get(self): | ||
"""Handles GET requests.""" | ||
text = 'example' |
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.
text
is vague -- consider file_contents instead.
@@ -107,8 +107,8 @@ def test_editable_collection_handler_get(self): | |||
response = self.testapp.get( | |||
'%s/%s' % ( | |||
feconf.COLLECTION_EDITOR_DATA_URL_PREFIX, | |||
self.COLLECTION_ID)) | |||
self.assertEqual(response.status_int, 302) | |||
self.COLLECTION_ID), expect_errors=True) |
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 don't understand why your PR is causing the underlying behaviour here to change. Conceptually this PR is supposed to be just a renaming, so this looks like an unintended consequence.
Can you dig into this and find out why it changed? Tests are supposed to protect against this sort of thing; when a test fails, it may be due to an error in the newly-introduced code.
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.
@seanlip Isn't this an expected behaviour? This test checks that non-editors cannot access the editor data handler due to them not being whitelisted. Hence if we dont add expect_errors
there's an app error of not being authorised.
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.
But why did your PR in particular cause this behaviour to change?
(I think 302 typically represents a redirect to the login page. So it's not necessarily wrong. But the more pertinent question is the one above.)
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.
It seems the error occurs when modifying EditableCollectionDataHandler
in collection_editor
by adding GET_HANDLER_ERROR_RETURN_TYPE
. There seems to be some kind of authorisation problem.
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.
OK, that's a good start. Can you continue digging into this and tracing what exactly happens, then explaining that in this comment? It's important that we understand what exactly we are modifying, especially with something so crucial as rights management -- we need to get that right.
So, perhaps explain what the flow was like before, and then explain what the flow is now after your modification.
Thanks!
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.
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.
Ah, ok, thanks for checking! That's a good find.
Looking at that part of the code, I think the logic is not quite correct. Could we modify it so that we return the HTML error page response only if the request is GET and the handler type is HTML, otherwise we return the JSON response?
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.
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 agree that 401 errors make sense in both these cases. But they should be JSON responses, right? I'm not sure how this conceptually conflicts with the last comment I made.... could you please explain?
(Note that my last comment talks about the form of the response -- HTML vs JSON -- and does not suggest any changes to the response status codes.)
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.
done
Hi @lilithxxx. Due to recent changes in the "develop" branch, this PR now has a merge conflict. Please follow this link if you need help resolving the conflict, so that the PR can be merged. Thanks! |
Hi @lilithxxx. Due to recent changes in the "develop" branch, this PR now has a merge conflict. Please follow this link if you need help resolving the conflict, so that the PR can be merged. Thanks! |
@seanlip made changes. PTAL |
core/controllers/base.py
Outdated
elif return_type == feconf.HANDLER_TYPE_HTML: | ||
method = self.request.environ['REQUEST_METHOD'] | ||
|
||
if(return_type == feconf.HANDLER_TYPE_HTML and |
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.
Missing space before '('
@apb7 -- shouldn't the linter catch this?
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.
done
core/controllers/base.py
Outdated
self.values.update(values) | ||
if 'iframed' in self.values and self.values['iframed']: | ||
self.render_template( | ||
'pages/error/error_iframed.html', iframe_restriction=None) | ||
else: | ||
self.render_template('pages/error/error.html') | ||
else: | ||
logging.warning('Not a recognized return type: ' | ||
'defaulting to render JSON.') | ||
if return_type != feconf.HANDLER_TYPE_JSON: |
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.
What if the return type is DOWNLOADABLE (say)?
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.
done
core/controllers/base_test.py
Outdated
file_contents = 'example' | ||
self.render_downloadable_file( | ||
file_contents, 'example.pdf', | ||
'text/plain') |
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.
Move to end of previous line.
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.
done
@seanlip made changes. PTAL |
@lilithxxx, why are you force pushing? Please don't do that. It messes up the history and makes it harder to review things. Otherwise, the PR LGTM, and I have no further comments. Thanks! |
Actually there were conflicts so I had to force push. I won't do that again |
Thanks for explaining! For future reference, see notes in step 5 here for how to merge code -- you should address the conflicts directly when you're doing the merge, by searching for "<<< HEAD" say. See https://help.github.com/articles/resolving-a-merge-conflict-using-the-command-line/ for more details. (And yep, never force-push again, please. Thanks!) |
Fixes #5466
This PR adds a function to check all controller's name end with 'Handler' or 'Page'.
The controllers that are sub-classes of the base class which did not end with the words are changed accordingly.
This PR is a duplicate of #5641
Explanation
Checklist
python scripts/pre_commit_linter.py
andbash scripts/run_frontend_tests.sh
.