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

Document link refactor #2683

Merged
merged 8 commits into from Oct 29, 2015

Conversation

Projects
None yet
2 participants
@seanh
Contributor

seanh commented Oct 27, 2015

No description provided.

seanh added some commits Oct 27, 2015

Refactor document link rendering
Separate pulling values out of annotations and escaping them if
necessary; and formatting those values into a link.
@seanh

This comment has been minimized.

Show comment
Hide comment
@seanh

seanh Oct 27, 2015

Contributor

TODO:

Contributor

seanh commented Oct 27, 2015

TODO:

seanh added some commits Oct 27, 2015

@seanh

This comment has been minimized.

Show comment
Hide comment
@seanh

This comment has been minimized.

Show comment
Hide comment
@seanh

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.

Contributor

seanh commented Oct 28, 2015

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.

@seanh

This comment has been minimized.

Show comment
Hide comment
@seanh

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

Contributor

seanh commented Oct 28, 2015

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

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.

@nickstenning

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

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.

else:
link = '<a title="{title}">{link_text}</a>'.format(
title=title, link_text=link_text)

This comment has been minimized.

@nickstenning

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

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)
"""
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.

@nickstenning

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

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.

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.

@nickstenning

nickstenning Oct 29, 2015

Contributor

s/not p ==/p !=/

@nickstenning

nickstenning Oct 29, 2015

Contributor

s/not p ==/p !=/

assert isinstance(models.Annotation(uri=uri).uri, unicode)
@patch("h.api.models.Annotation.uri", new_callable=PropertyMock)

This comment has been minimized.

@nickstenning

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

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

This comment has been minimized.

Show comment
Hide comment
@nickstenning

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.

Contributor

nickstenning commented Oct 29, 2015

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.

nickstenning added a commit that referenced this pull request Oct 29, 2015

@nickstenning nickstenning merged commit aa653ad into master Oct 29, 2015

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@nickstenning nickstenning deleted the document_link_refactor branch Oct 29, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment