Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upDocument link refactor #2683
Conversation
seanh
added some commits
Oct 27, 2015
seanh
referenced this pull request
Oct 27, 2015
Merged
Trello 144 add a list of most recently annotated by the group urls to the group page #2667
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
seanh
Oct 27, 2015
Contributor
TODO:
-
Fix patchers, see Nick's comment - A couple of comments from Nick about tests: https://github.com/hypothesis/h/pull/2667/files#r43128239, https://github.com/hypothesis/h/pull/2667/files#r43128472
- Add 10px padding to the
.group-formdiv - Test on more production data.
- It's almost certainly possible to make this code crash by throwing random types of junk into our API
|
TODO:
|
seanh
added some commits
Oct 27, 2015
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
seanh
added some commits
Oct 28, 2015
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
seanh
Oct 28, 2015
Contributor
One thing I've noticed is that since the text in the <input> on the group page is automatically selected to make copying easier, and the text is at the bottom of the page, the browser window will scroll to the bottom of the page on page load. This only really matters if the list of documents is long enough to make a scrollbar appear of course, but with our current length (max 25 documents) it can be.
|
One thing I've noticed is that since the text in the |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
seanh
Oct 28, 2015
Contributor
Ok, I've refactored this, and done some more work to make it more bullet proof against unexpected data.
@nickstenning I'll do the patcher thing in a separate pr, since we have that patcher problem all over our code
|
Ok, I've refactored this, and done some more work to make it more bullet proof against unexpected data. @nickstenning I'll do the patcher thing in a separate pr, since we have that patcher problem all over our code |
nickstenning
reviewed
Oct 29, 2015
| link = ('<a href="{href}" title="{title}">{link_text}</a> ' | ||
| '({hostname})'.format(href=href, title=title, | ||
| link_text=link_text, hostname=hostname)) | ||
| elif hostname and not href: |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nickstenning
Oct 29, 2015
Contributor
The second half of these conditionals isn't needed... it's implied by the fact we're in an elif clause and we'd never of got here if it weren't true.
nickstenning
Oct 29, 2015
Contributor
The second half of these conditionals isn't needed... it's implied by the fact we're in an elif clause and we'd never of got here if it weren't true.
nickstenning
reviewed
Oct 29, 2015
| else: | ||
| link = '<a title="{title}">{link_text}</a>'.format( | ||
| title=title, link_text=link_text) | ||
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nickstenning
Oct 29, 2015
Contributor
This whole function would be a fair bit clearer if you just assigned the format strings and did the .format once at the end:
if href and hostname:
tpl = '<a href="{href}" title="{title}">{link_text}</a> ({hostname})'
elif hostname:
tpl = '...'
elif href:
...
link = tpl.format(href=href, title=title, link_text=link_text, hostname=hostname)
return jinja2.Markup(link)
nickstenning
Oct 29, 2015
Contributor
This whole function would be a fair bit clearer if you just assigned the format strings and did the .format once at the end:
if href and hostname:
tpl = '<a href="{href}" title="{title}">{link_text}</a> ({hostname})'
elif hostname:
tpl = '...'
elif href:
...
link = tpl.format(href=href, title=title, link_text=link_text, hostname=hostname)
return jinja2.Markup(link)
nickstenning
reviewed
Oct 29, 2015
| """ | ||
| if self.uri.lower().startswith("file:///"): | ||
| # self.uri is already escaped so we don't need to escape it again |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nickstenning
Oct 29, 2015
Contributor
There's a bunch of places you've got comments like this. I don't think this is the right approach. The entire point of a taintedness approach to string escaping is that you don't need to examine the whole call stack to understand if what you're doing is safe. If this function returns something that needs to be escaped, it should escape it. Using jinja2.escape(self.uri.split('/')[-1]) will not double escape anything.
nickstenning
Oct 29, 2015
Contributor
There's a bunch of places you've got comments like this. I don't think this is the right approach. The entire point of a taintedness approach to string escaping is that you don't need to examine the whole call stack to understand if what you're doing is safe. If this function returns something that needs to be escaped, it should escape it. Using jinja2.escape(self.uri.split('/')[-1]) will not double escape anything.
nickstenning
reviewed
Oct 29, 2015
| groups = [g for g in groups | ||
| if not g == self.request.authenticated_userid] | ||
| principals = [p for p in principals | ||
| if not p == self.request.authenticated_userid] |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nickstenning
reviewed
Oct 29, 2015
| assert isinstance(models.Annotation(uri=uri).uri, unicode) | ||
| @patch("h.api.models.Annotation.uri", new_callable=PropertyMock) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nickstenning
Oct 29, 2015
Contributor
As I mentioned the other day, there's really no need to use PropertyMock here. @patch.object(models.Annotation, 'uri', 'http://example.com/example.html') would work just fine and would be less to understand.
nickstenning
Oct 29, 2015
Contributor
As I mentioned the other day, there's really no need to use PropertyMock here. @patch.object(models.Annotation, 'uri', 'http://example.com/example.html') would work just fine and would be less to understand.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nickstenning
Oct 29, 2015
Contributor
I have a bunch of comments, but none of them are blockers to merging. Take a chance to read them over and feel free to either submit PRs addressing the comments or roll that work into whatever else we do with this later.
|
I have a bunch of comments, but none of them are blockers to merging. Take a chance to read them over and feel free to either submit PRs addressing the comments or roll that work into whatever else we do with this later. |
seanh commentedOct 27, 2015
No description provided.