Skip to content

Commit

Permalink
Merge pull request #220 from google/gimite-zero-rating2
Browse files Browse the repository at this point in the history
Make ToS page a proxy to the actual ToS page, to make it zero-rating mode friendly. #7
  • Loading branch information
gimite committed Nov 30, 2015
2 parents 9a928bf + fd55dc1 commit 738db00
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ def post(self):
responses.append(
'All data entered in Person Finder is available to the public '
'and usable by anyone. Google does not review or verify the '
'accuracy of this data google.org/personfinder/global/tos.html')
'accuracy of this data google.org/personfinder/global/tos')
elif self.config.enable_sms_record_input and add_self_m:
name_string = add_self_m.group(1).strip()
person = Person.create_original(
Expand Down
2 changes: 2 additions & 0 deletions app/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ handlers:
libraries:
- name: django
version: "1.2"
- name: lxml
version: "2.3"
1 change: 1 addition & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
'admin/resources',
'admin/review',
'css',
'tos',
])

# Exceptional cases where the module name doesn't match the URL.
Expand Down
1 change: 0 additions & 1 deletion app/resources/admin.html.template
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,6 @@
<ul>
<li>Photos attached to person records or notes, if the author has specified a URL of the photo instead of uploading it. (<a target="_blank" href="https://github.com/google/personfinder/issues/218">Issue</a>)</li>
<li>reCAPTCHA</li>
<li><a target="_blank" href="https://google.org/personfinder/global/tos.html">Terms of Services</a></li>
</ul>

<div class="option">
Expand Down
2 changes: 1 addition & 1 deletion app/resources/base.html.template
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
{{env.target_attr|safe}}>{% trans "Developers" %}</a>
<span class="link-separator">&#xb7;</span>
{% endif %}
<a href="{{env.global_url}}/tos.html" {{env.target_attr|safe}}
<a href="{{env.global_url}}/tos" {{env.target_attr|safe}}
>{% trans "Terms of Service" %}</a>
{% endblock footer %}
</div>
Expand Down
46 changes: 36 additions & 10 deletions app/resources/tos.html.template
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
{# Terms of Service page for a new site. Fill in content below. #}
{# Copyright 2015 Google Inc. Licensed under the Apache License, Version #}
{# 2.0 (the "License"); you may not use this file except in compliance with #}
{# the License. You may obtain a copy of the License at: #}
{# http://www.apache.org/licenses/LICENSE-2.0 #}
{# Unless required by applicable law or agreed to in writing, software #}
{# distributed under the License is distributed on an "AS IS" BASIS, #}
{# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #}
{# See the License for the specific language governing permissions and #}
{# limitations under the License. #}

{# Template for the Terms of Service page. #}

{% extends "static-base.html.template" %}
{% load i18n %}

{% block content %}
<h1>Terms of Service</h1>

<p>
(This page has not been filled in by the site owner.
It is recommended that site owners specify their Terms of Service
when launching a Person Finder site. Site owners should see the
<a href="https://github.com/google/personfinder">project page</a>
for instructions on filling in the content of this page.)
{% endblock content %}

{% if article_html %}

{{article_html|safe}}

{% else %}{% if tos_url %}

<h1>Terms of Service</h1>

{# In case we fail to fetch/parse the ToS page (e.g., the page has #}
{# changed its layout), we fall back to show a link to the page instead. #}
<p><a href="{{tos_url}}">Click here to see the terms of service (external site)</a></p>

{% else %}

<h1>Terms of Service</h1>

<p>The term of service is not specified by the site owner.</p>

<p>If you are the site owner, you can specify the URL of the terms of service to "tos_url" config. See <a href="https://github.com/google/personfinder/wiki/DeveloperFaq#how-to-readwrite-config-values">here</a> to learn how to update configs.</p>

{% endif %}{% endif %}

{% endblock %}
68 changes: 68 additions & 0 deletions app/tos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/python2.7
# Copyright 2015 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Terms of Services page."""

__author__ = 'ichikawa@google.com (Hiroshi Ichikawa)'

import logging
import traceback
import urllib2
import urlparse

import lxml.etree

import utils


class Handler(utils.BaseHandler):

repo_required = False

def get(self):
article_html = None

# Fetches the ToS page and embed it in the page. We do this instead of
# just redirecting to the ToS page because we need to host the content
# in our domain in zero-rating mode. See "Zero-rating" section of the
# admin page (app/resources/admin.html.template) for details of
# zero-rating mode.
try:
if self.config.tos_url:
res = urllib2.urlopen(self.config.tos_url)
tos_html = res.read()
doc = lxml.etree.HTML(tos_html)
articles = doc.xpath("//div[@class='maia-article']")
if articles:
article = articles[0]
for anchor in article.xpath('.//a'):
href = anchor.attrib.get('href')
if href and anchor.text:
# Converts relative URLs to absolute URLs.
anchor.attrib['href'] = urlparse.urljoin(
res.geturl(), href)
anchor.text += ' (external site)'
article_html = lxml.etree.tostring(article, method='html')

except:
logging.error(
'Error during fetching/parsing the ToS page from %s\n%s',
self.config.tos_url,
traceback.format_exc())

self.render(
'tos.html',
article_html=article_html,
tos_url=self.config.tos_url)
4 changes: 2 additions & 2 deletions tests/server_test_cases/person_note_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2562,7 +2562,7 @@ def test_sms_api(self):
'More at: google.org/personfinder/haiti?ui=light ## '
'All data entered in Person Finder is available to the public '
'and usable by anyone. Google does not review or verify the '
'accuracy of this data google.org/personfinder/global/tos.html'
'accuracy of this data google.org/personfinder/global/tos'
'</message_text>\n'
'</response>\n')
assert expected == doc.content, text_diff(expected, doc.content)
Expand All @@ -2579,7 +2579,7 @@ def test_sms_api(self):
'More at: google.org/personfinder/haiti?ui=light ## '
'All data entered in Person Finder is available to the public '
'and usable by anyone. Google does not review or verify the '
'accuracy of this data google.org/personfinder/global/tos.html'
'accuracy of this data google.org/personfinder/global/tos'
'</message_text>\n'
'</response>\n')
assert expected == doc.content, text_diff(expected, doc.content)
Expand Down

0 comments on commit 738db00

Please sign in to comment.