Skip to content

add admin functions for wiping a version #3728

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from __future__ import (
absolute_import, division, print_function, unicode_literals)
import os

from builtins import object
from random import choice
Expand All @@ -18,7 +19,8 @@
from textclassifier.validators import ClassifierValidator

from readthedocs.builds.constants import TAG
from readthedocs.core.utils import slugify, trigger_build
from readthedocs.core.utils import slugify, trigger_build, broadcast
from readthedocs.projects.tasks import remove_dir
from readthedocs.integrations.models import Integration
from readthedocs.oauth.models import RemoteRepository
from readthedocs.projects import constants
Expand Down Expand Up @@ -323,6 +325,7 @@ def save(self):
versions = self.project.versions.all()
for version in versions:
self.save_version(version)
self.wipe_build_environment(version)
default_version = self.cleaned_data.get('default-version', None)
if default_version:
self.project.default_version = default_version
Expand All @@ -347,6 +350,20 @@ def save_version(self, version):
if version.active and not version.built and not version.uploaded:
trigger_build(project=self.project, version=version)

def wipe_build_environment(self, version):
wipe_action = self.cleaned_data.get(
'wipe-{}'.format(version.slug),
False,
)
if wipe_action:
del_dirs = [
os.path.join(version.project.doc_path, 'checkouts', version.slug),
os.path.join(version.project.doc_path, 'envs', version.slug),
os.path.join(version.project.doc_path, 'conda', version.slug),
]
for del_dir in del_dirs:
broadcast(type='build', task=remove_dir, args=[del_dir])


def build_versions_form(project):
"""Versions form with a list of versions and version privacy levels."""
Expand All @@ -365,6 +382,7 @@ def build_versions_form(project):
for version in versions_qs:
field_name = 'version-{}'.format(version.slug)
privacy_name = 'privacy-{}'.format(version.slug)
wipe_name = 'wipe-{}'.format(version.slug)
if version.type == TAG:
label = '{} ({})'.format(
version.verbose_name,
Expand All @@ -378,6 +396,12 @@ def build_versions_form(project):
initial=version.active,
required=False,
)
attrs[wipe_name] = forms.BooleanField(
# This isn't a real label, but just a slug for the template
label='wipe',
widget=forms.CheckboxInput,
required=False
)
attrs[privacy_name] = forms.ChoiceField(
# This isn't a real label, but just a slug for the template
label='privacy',
Expand Down
5 changes: 4 additions & 1 deletion readthedocs/templates/projects/project_versions.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ <h2> {% trans "Choose Active Versions" %} </h2>
{% trans "Tags" %}: {{ field }}
{% endcomment %}

{% elif field.label == 'wipe' %}
{% trans "Wipe" %} {{ field }}

{% else %}
{# This is a custom field with a label of the version, and a value of a checkbox denoting if it is active #}
<h3>{{ field.label}}</h3>
<h3>{{ field.label }}</h3>
{% trans "Active" %} {{ field }}
{% endif %}
{% endif %}
Expand Down