Skip to content

Commit

Permalink
The great whitelist removal!
Browse files Browse the repository at this point in the history
  • Loading branch information
ericholscher committed Feb 24, 2012
1 parent b572d5a commit 17db270
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 59 deletions.
37 changes: 5 additions & 32 deletions readthedocs/doc_builder/backends/sphinx.py
Expand Up @@ -91,47 +91,20 @@ def _whitelisted(self):
rtd_string = Template(RTD_CONF_ADDITIONS).render(rtd_ctx)
outfile.write(rtd_string)

def _sanitize(self):
project = self.version.project
conf_template = render_to_string('sphinx/conf.py.conf',
{'project': project,
'template_dir': TEMPLATE_DIR,
'badge': project.sponsored
})
rtd_ctx = Context({
'versions': project.ordered_active_versions(),
'current_version': self.version,
'project': project,
'settings': settings,
'static_path': STATIC_DIR,
'template_path': TEMPLATE_DIR,
})
rtd_string = Template(RTD_CONF_ADDITIONS).render(rtd_ctx)
conf_template = conf_template + "\n" + rtd_string
safe_write(project.conf_file(self.version.slug), conf_template)

def clean(self):
try:
if self.version.project.whitelisted and self.version.project.is_imported:
print "Project whitelisted"
self._whitelisted()
else:
print "Writing conf to disk"
self._sanitize()
print "Project whitelisted"
self._whitelisted()
except (OSError, SiteProfileNotAvailable, ObjectDoesNotExist):
try:
print "Writing conf to disk on error."
self._sanitize()
except (OSError, IOError):
print "Conf file not found. Error writing to disk."
return ('', 'Conf file not found. Error writing to disk.', -1)
print "Conf file not found. Error writing to disk."
return ('', 'Conf file not found. Error writing to disk.', -1)

@restoring_chdir
def build(self):
project = self.version.project
os.chdir(project.conf_dir(self.version.slug))
force_str = " -E " if self.force else ""
if project.use_virtualenv and project.whitelisted:
if project.use_virtualenv:
build_command = '%s %s -b html . _build/html' % (project.venv_bin(
version=self.version.slug, bin='sphinx-build'), force_str)
else:
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/doc_builder/backends/sphinx_epub.py
Expand Up @@ -14,7 +14,7 @@ class Builder(HtmlBuilder):
def build(self):
project = self.version.project
os.chdir(project.conf_dir(self.version.slug))
if project.use_virtualenv and project.whitelisted:
if project.use_virtualenv:
build_command = '%s -b epub . _build/epub' % project.venv_bin(
version=self.version.slug, bin='sphinx-build')
else:
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/doc_builder/backends/sphinx_htmldir.py
Expand Up @@ -13,7 +13,7 @@ class Builder(HtmlBuilder):
def build(self):
project = self.version.project
os.chdir(self.version.project.conf_dir(self.version.slug))
if project.use_virtualenv and project.whitelisted:
if project.use_virtualenv:
build_command = '%s -b dirhtml . _build/html' % project.venv_bin(
version=self.version.slug, bin='sphinx-build')
else:
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/doc_builder/backends/sphinx_man.py
Expand Up @@ -14,7 +14,7 @@ class Builder(ManpageBuilder):
def build(self):
project = self.version.project
os.chdir(self.version.project.conf_dir(self.version.slug))
if project.use_virtualenv and project.whitelisted:
if project.use_virtualenv:
build_command = '%s -b man -d _build/doctrees . _build/man' % project.venv_bin(
version=self.version.slug, bin='sphinx-build')
else:
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/doc_builder/backends/sphinx_pdf.py
Expand Up @@ -19,7 +19,7 @@ class Builder(BaseBuilder):
def build(self):
project = self.version.project
os.chdir(project.conf_dir(self.version.slug))
if project.use_virtualenv and project.whitelisted:
if project.use_virtualenv:
latex_results = run('%s -b latex -d _build/doctrees . _build/latex' %
project.venv_bin(version=self.version.slug, bin='sphinx-build'))
else:
Expand Down
7 changes: 2 additions & 5 deletions readthedocs/projects/models.py
Expand Up @@ -368,11 +368,8 @@ def version_from_branch_name(self, branch):

@property
def whitelisted(self):
try:
return all([user.get_profile().whitelisted for user in self.users.all()])
except ObjectDoesNotExist:
#Bare except so we don't have to import user.models.UserProfile
return False
#Hack this true for now.
return True

#File Building stuff.
#Not sure if this is used
Expand Down
29 changes: 15 additions & 14 deletions readthedocs/projects/tasks.py
Expand Up @@ -86,19 +86,20 @@ def new_save(*args, **kwargs):
version = Version(**version_data)
version.save = new_save

#Lots of course correction.
to_save = False
if not version.verbose_name:
version_data['verbose_name'] = 'latest'
to_save = True
if not version.active:
version_data['active'] = True
to_save = True
if version.identifier != branch:
version_data['identifier'] = branch
to_save = True
if to_save:
api.version(version.pk).put(version_data)
if not version_pk:
#Lots of course correction.
to_save = False
if not version.verbose_name:
version_data['verbose_name'] = 'latest'
to_save = True
if not version.active:
version_data['active'] = True
to_save = True
if version.identifier != branch:
version_data['identifier'] = branch
to_save = True
if to_save:
api.version(version.pk).put(version_data)

if record:
#Create Build Object.
Expand Down Expand Up @@ -199,7 +200,7 @@ def update_imported_docs(project, version):
raise ProjectImportError("Conf File Missing. Skipping.")

#Do Virtualenv bits:
if project.use_virtualenv and project.whitelisted:
if project.use_virtualenv:
update_docs_output['venv'] = run('{cmd} --no-site-packages {path}'.format(
cmd='virtualenv',
path=project.venv_path(version=version_slug)))
Expand Down
4 changes: 0 additions & 4 deletions readthedocs/templates/projects/project_import.html
Expand Up @@ -7,10 +7,6 @@
{% block content-header %}<h1>Import an existing project</h1>{% endblock %}

{% block content %}
{% if not request.user.get_profile.whitelisted %}
<p class="help_text"><b>Note:</b> If you are using custom extensions in your sphinx documentation, it will not work. Your project must be whitelisted, so that it can execute arbitrary code. Please <a href="mailto:readthedocs@readthedocs.org">email us</a> if you need this capability.</p>
{% endif %}

<form method="post" action=".">{% csrf_token %}
{{ form.as_p }}
<p><input type="submit" value="Create" /></p>
Expand Down

0 comments on commit 17db270

Please sign in to comment.