-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add admin functions for wiping a version #5140
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
ericholscher
merged 11 commits into
readthedocs:master
from
dojutsu-user:admin-action-for-version
Feb 26, 2019
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fd32096
add custom admin action
dojutsu-user 906c404
Merge branch 'master' into admin-action-for-version
dojutsu-user 27e648b
remove imports from __future__
dojutsu-user e21176c
Merge branch 'master' into admin-action-for-version
dojutsu-user 45c75d3
add improvements
dojutsu-user 93000cf
update test
dojutsu-user 2f1abee
Merge branch 'master' into admin-action-for-version
dojutsu-user 7fcc7c9
Merge branch 'master' into admin-action-for-version
dojutsu-user 1795bb0
import the missing os
dojutsu-user a0659c5
Merge branch 'master' into admin-action-for-version
dojutsu-user b206c70
add more tests
dojutsu-user File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
|
||
from django.shortcuts import get_object_or_404 | ||
|
||
from readthedocs.core.utils import broadcast | ||
from readthedocs.projects.tasks import remove_dirs | ||
from readthedocs.builds.models import Version | ||
|
||
|
||
def wipe_version_via_slug(version_slug): | ||
"""Wipes the given version.""" | ||
version = get_object_or_404(Version, slug=version_slug) | ||
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_dirs, args=[(del_dir,)]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
60 changes: 60 additions & 0 deletions
60
readthedocs/rtd_tests/tests/versions/test_admin_actions.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
import mock | ||
|
||
from mock import call | ||
import django_dynamic_fixture as fixture | ||
from django.test import TestCase | ||
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME | ||
from django.contrib.auth.models import User | ||
from django import urls | ||
|
||
from readthedocs.builds.models import Version | ||
from readthedocs.core.models import UserProfile | ||
from readthedocs.projects.models import Project | ||
from readthedocs.projects.tasks import remove_dirs | ||
|
||
|
||
class VersionAdminActionsTest(TestCase): | ||
|
||
@classmethod | ||
def setUpTestData(cls): | ||
cls.owner = fixture.get(User) | ||
cls.profile = fixture.get(UserProfile, user=cls.owner, banned=False) | ||
cls.admin = fixture.get(User, is_staff=True, is_superuser=True) | ||
cls.project = fixture.get( | ||
Project, | ||
main_language_project=None, | ||
users=[cls.owner], | ||
) | ||
cls.version = fixture.get(Version, project=cls.project) | ||
|
||
def setUp(self): | ||
self.client.force_login(self.admin) | ||
|
||
@mock.patch('readthedocs.core.utils.general.broadcast') | ||
def test_wipe_selected_version(self, mock_broadcast): | ||
action_data = { | ||
ACTION_CHECKBOX_NAME: [self.version.pk], | ||
'action': 'wipe_selected_versions', | ||
'post': 'yes', | ||
} | ||
resp = self.client.post( | ||
urls.reverse('admin:builds_version_changelist'), | ||
action_data | ||
) | ||
expected_del_dirs = [ | ||
os.path.join(self.version.project.doc_path, 'checkouts', self.version.slug), | ||
os.path.join(self.version.project.doc_path, 'envs', self.version.slug), | ||
os.path.join(self.version.project.doc_path, 'conda', self.version.slug), | ||
] | ||
|
||
mock_broadcast.assert_has_calls( | ||
[ | ||
call(type='build', task=remove_dirs, args=[(expected_del_dirs[0],)]), | ||
call(type='build', task=remove_dirs, args=[(expected_del_dirs[1],)]), | ||
call(type='build', task=remove_dirs, args=[(expected_del_dirs[2],)]), | ||
], | ||
any_order=False | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be filtering by a project, not just a version slug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
I have pushed the changes.