Skip to content

This merges all the bugfix PR's I had into one. #2754

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

Merged
merged 13 commits into from
Mar 30, 2017
Merged
16 changes: 9 additions & 7 deletions media/javascript/rtd.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
}
);

checkVersion(slug, version);
// This is a deprecated API and file, so removing this to reduce errors
// on our servers.
// checkVersion(slug, version);
getVersions(slug, version);

/*
Expand All @@ -78,12 +80,12 @@
*/


$.ajax({
url: "https://api.grokthedocs.com/static/javascript/bundle-client.js",
crossDomain: true,
dataType: "script",
cache: true,
});
// $.ajax({
// url: "https://api.grokthedocs.com/static/javascript/bundle-client.js",
// crossDomain: true,
// dataType: "script",
// cache: true,
// });



Expand Down
10 changes: 5 additions & 5 deletions readthedocs/core/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ def base_resolve_path(self, project_slug, filename, version_slug=None,
# Only support `/docs/project' URLs outside our normal environment. Normally
# the path should always have a subdomain or CNAME domain
if subdomain or cname or (self._use_subdomain()):
url = '/'
url = u'/'
else:
url = '/docs/{project_slug}/'
url = u'/docs/{project_slug}/'

if subproject_slug:
url += 'projects/{subproject_slug}/'
url += u'projects/{subproject_slug}/'

if single_version:
url += '{filename}'
url += u'{filename}'
else:
url += '{language}/{version_slug}/{filename}'
url += u'{language}/{version_slug}/{filename}'

return url.format(
project_slug=project_slug, filename=filename,
Expand Down
2 changes: 2 additions & 0 deletions readthedocs/core/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def decide_if_cors(sender, request, **kwargs):

Returns True when a request should be given CORS access.
"""
if 'HTTP_ORIGIN' not in request.META:
return False
host = urlparse(request.META['HTTP_ORIGIN']).netloc.split(':')[0]
valid_url = False
for url in WHITELIST_URLS:
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/oauth/services/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,5 @@ def setup_webhook(self, project):
log.error('Bitbucket webhook creation failed for project: %s',
project)
log.debug('Bitbucket webhook creation failure response: %s',
dict(resp))
resp.content)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resp.json() is more correct. Also, feel free to drop this, I have a fix in my branch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That only works for JSON content, and most of the issues here are the responses aren't valid JSON.

return (False, resp)
2 changes: 1 addition & 1 deletion readthedocs/oauth/services/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def setup_webhook(self, project):
log.error('GitHub webhook creation failed for project: %s',
project)
log.debug('GitHub webhook creation failure response: %s',
dict(resp))
resp.content)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

return (False, resp)

@classmethod
Expand Down
5 changes: 3 additions & 2 deletions readthedocs/projects/version_handling.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Project version handling"""

import unicodedata
from collections import defaultdict
from packaging.version import Version
from packaging.version import InvalidVersion
Expand Down Expand Up @@ -107,8 +108,8 @@ def version_windows(versions, major=1, minor=1, point=1):

def parse_version_failsafe(version_string):
try:
return Version(version_string)
except InvalidVersion:
return Version(unicodedata.normalize('NFKD', version_string).encode('ascii', 'ignore'))
except (UnicodeError, InvalidVersion):
return None


Expand Down
38 changes: 17 additions & 21 deletions readthedocs/restapi/views/model_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,27 +132,23 @@ def sync_versions(self, request, **kwargs):
log.exception("Sync Versions Error: %s" % e.message)
return Response({'error': e.message}, status=status.HTTP_400_BAD_REQUEST)

try:
old_stable = project.get_stable_version()
promoted_version = project.update_stable_version()
if promoted_version:
new_stable = project.get_stable_version()
log.info(
"Triggering new stable build: {project}:{version}".format(
project=project.slug,
version=new_stable.identifier))
trigger_build(project=project, version=new_stable)

# Marking the tag that is considered the new stable version as
# active and building it if it was just added.
if (
activate_new_stable and
promoted_version.slug in added_versions):
promoted_version.active = True
promoted_version.save()
trigger_build(project=project, version=promoted_version)
except:
log.exception("Stable Version Failure", exc_info=True)
promoted_version = project.update_stable_version()
if promoted_version:
new_stable = project.get_stable_version()
log.info(
"Triggering new stable build: {project}:{version}".format(
project=project.slug,
version=new_stable.identifier))
trigger_build(project=project, version=new_stable)

# Marking the tag that is considered the new stable version as
# active and building it if it was just added.
if (
activate_new_stable and
promoted_version.slug in added_versions):
promoted_version.active = True
promoted_version.save()
trigger_build(project=project, version=promoted_version)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removed get_stable_version call, what was the problem there? Any side effects on this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't used, so I figured not, it seemed like a weird thing to have side effects, but didn't check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No side effects, just dead code.


return Response({
'added_versions': added_versions,
Expand Down
17 changes: 17 additions & 0 deletions readthedocs/rtd_tests/tests/test_sync_versions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

import json

from django.test import TestCase
Expand Down Expand Up @@ -344,3 +346,18 @@ def test_update_inactive_stable_version(self):
version_stable = Version.objects.get(slug=STABLE)
self.assertFalse(version_stable.active)
self.assertEqual(version_stable.identifier, '1.0.0')

def test_unicode(self):
version_post_data = {
'branches': [],
'tags': [
{'identifier': 'foo-£', 'verbose_name': 'foo-£'},
]
}

resp = self.client.post(
'/api/v2/project/%s/sync_versions/' % self.pip.pk,
data=json.dumps(version_post_data),
content_type='application/json',
)
self.assertEqual(resp.status_code, 200)
21 changes: 20 additions & 1 deletion readthedocs/search/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def process_mkdocs_json(version, build_dir=True):
html_files.append(os.path.join(root, filename))
page_list = []
for filename in html_files:
if not valid_mkdocs_json(file_path=filename):
continue
relative_path = parse_path_from_file(documentation_type='mkdocs', file_path=filename)
html = parse_content_from_file(documentation_type='mkdocs', file_path=filename)
headers = parse_headers_from_file(documentation_type='mkdocs', file_path=filename)
Expand All @@ -50,12 +52,29 @@ def recurse_while_none(element):
return element.text


def valid_mkdocs_json(file_path):
try:
with codecs.open(file_path, encoding='utf-8', mode='r') as f:
content = f.read()
except IOError as e:
log.warning('(Search Index) Unable to index file: %s, error: %s' % (file_path, e))
return None

page_json = json.loads(content)
for to_check in ['url', 'content']:
if to_check not in page_json:
log.warning('(Search Index) Unable to index file: %s error: Invalid JSON' % (file_path))
return None

return True


def parse_path_from_file(documentation_type, file_path):
try:
with codecs.open(file_path, encoding='utf-8', mode='r') as f:
content = f.read()
except IOError as e:
log.info('(Search Index) Unable to index file: %s, error :%s' % (file_path, e))
log.warning('(Search Index) Unable to index file: %s, error: %s' % (file_path, e))
return ''

page_json = json.loads(content)
Expand Down