Skip to content

Commit

Permalink
Merge pull request #1433 from Scifabric/issue-1396-help-privacy
Browse files Browse the repository at this point in the history
give json result for privacy
  • Loading branch information
therealmarv committed Jan 26, 2017
2 parents 7a379e6 + 684004d commit 68c3a48
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
25 changes: 24 additions & 1 deletion doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2086,4 +2086,27 @@ If a project is already unfeatured:
{
"status_code": 415,
"error": "Project.id 1069 is not featured"
}
}
Help privacy
~~~~~~~~~~~~
**Endpoint: /help/privacy**
*Allowed methods*: **GET**
**GET**
Gives you the privacy policy for your PYBOSSA
* **content**: Simplified HTML of rendered privacy policy.
* **template**: The Jinja2 template that could be rendered.
* **title**: the title for the endpoint.
**Example output**
.. code-block:: python
{
"content": "<html><body><p>privacy policy here</p></body></html>"
"template": "help/privacy.html",
"title": "Privacy Policy"
}
12 changes: 9 additions & 3 deletions pybossa/view/help.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf8 -*-
# This file is part of PYBOSSA.
#
# Copyright (C) 2015 Scifabric LTD.
# Copyright (C) 2017 Scifabric LTD.
#
# PYBOSSA is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
Expand All @@ -18,9 +18,11 @@
"""Help view for PYBOSSA."""
from flask import Blueprint
from flask import render_template
from pybossa.util import handle_content_type
from pybossa.cache import projects as cached_projects
from pybossa.cache import categories as cached_cat
from random import choice
from readability.readability import Document

blueprint = Blueprint('help', __name__)

Expand Down Expand Up @@ -60,5 +62,9 @@ def cookies_policy():
@blueprint.route('/privacy')
def privacy():
"""Render help/privacy policy page."""
return render_template('help/privacy.html',
title='Help: Cookies Policy')
# use readability to remove styling and headers
cleaned_up_content = Document(render_template('help/privacy.html')).summary()
response = dict(template='help/privacy.html',
content=cleaned_up_content,
title='Privacy Policy')
return handle_content_type(response)
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"pyjwt",
"flask_json_multidict",
"flask-cors>=3.0.2, <3.0.3",
"webassets>=0.12.1, <0.12.2"
"webassets>=0.12.1, <0.12.2",
"readability-lxml>=0.6.2, <1.0"
]

setup(
Expand Down
15 changes: 15 additions & 0 deletions test/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from factories import ProjectFactory, CategoryFactory, TaskFactory, TaskRunFactory, UserFactory
from unidecode import unidecode
from werkzeug.utils import secure_filename
from nose.tools import assert_raises


class TestWeb(web.Helper):
Expand Down Expand Up @@ -4221,6 +4222,20 @@ def test_59_help_privacy(self):
res = self.app.get(url, follow_redirects=True)
err_msg = "There should be a privacy policy page"
assert "Privacy" in res.data, err_msg
assert_raises(ValueError, json.loads, res.data)

@with_context
def test_60_help_privacy_json(self):
"""Test privacy json endpoint"""
url = "/help/privacy"
res = self.app_get_json(url)
data = json.loads(res.data)
err_msg = 'Template wrong'
assert data['template'] == 'help/privacy.html', err_msg
err_msg = 'Title wrong'
assert data['title'] == 'Privacy Policy', err_msg
err_msg = "There should be HTML content"
assert '<body' in data['content'], err_msg

@with_context
def test_69_allow_anonymous_contributors(self):
Expand Down

0 comments on commit 68c3a48

Please sign in to comment.