-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add some basic spam removal features to admin #3131
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
Changes from 1 commit
Commits
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
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 |
---|---|---|
|
@@ -200,3 +200,8 @@ def make_api_project(project_data): | |
project = Project(**project_data) | ||
project.save = _new_save | ||
return project | ||
|
||
|
||
def delete_project(project): | ||
broadcast(type='app', task=tasks.remove_dir, args=[project.doc_path]) | ||
project.delete() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems redundant. Isn't this already called on project.delete()? If not, it should be. |
Empty file.
80 changes: 80 additions & 0 deletions
80
readthedocs/rtd_tests/tests/projects/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,80 @@ | ||
import mock | ||
import django_dynamic_fixture as fixture | ||
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME | ||
from django.contrib.auth.models import User | ||
from django.core import urlresolvers | ||
from django.test import TestCase | ||
|
||
from readthedocs.core.models import UserProfile | ||
from readthedocs.projects.models import Project | ||
|
||
|
||
class ProjectAdminActionsTest(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], | ||
) | ||
|
||
def setUp(self): | ||
self.client.force_login(self.admin) | ||
|
||
def test_project_ban_owner(self): | ||
self.assertFalse(self.owner.profile.banned) | ||
action_data = { | ||
ACTION_CHECKBOX_NAME: [self.project.pk], | ||
'action': 'ban_owner', | ||
'index': 0, | ||
} | ||
resp = self.client.post( | ||
urlresolvers.reverse('admin:projects_project_changelist'), | ||
action_data | ||
) | ||
self.assertTrue(self.project.users.filter(profile__banned=True).exists()) | ||
self.assertFalse(self.project.users.filter(profile__banned=False).exists()) | ||
|
||
def test_project_ban_multiple_owners(self): | ||
owner_b = fixture.get(User) | ||
profile_b = fixture.get(UserProfile, user=owner_b, banned=False) | ||
self.project.users.add(owner_b) | ||
self.assertFalse(self.owner.profile.banned) | ||
self.assertFalse(owner_b.profile.banned) | ||
action_data = { | ||
ACTION_CHECKBOX_NAME: [self.project.pk], | ||
'action': 'ban_owner', | ||
'index': 0, | ||
} | ||
resp = self.client.post( | ||
urlresolvers.reverse('admin:projects_project_changelist'), | ||
action_data | ||
) | ||
self.assertFalse(self.project.users.filter(profile__banned=True).exists()) | ||
self.assertEqual(self.project.users.filter(profile__banned=False).count(), 2) | ||
|
||
@mock.patch('readthedocs.projects.admin.remove_dir') | ||
def test_project_delete(self, remove_dir): | ||
"""Test project and artifacts are removed""" | ||
action_data = { | ||
ACTION_CHECKBOX_NAME: [self.project.pk], | ||
'action': 'delete_selected', | ||
'index': 0, | ||
'post': 'yes', | ||
} | ||
resp = self.client.post( | ||
urlresolvers.reverse('admin:projects_project_changelist'), | ||
action_data | ||
) | ||
self.assertFalse(Project.objects.filter(pk=self.project.pk).exists()) | ||
remove_dir.apply_async.assert_has_calls([ | ||
mock.call( | ||
kwargs={}, | ||
queue='celery', | ||
args=[self.project.doc_path] | ||
), | ||
]) |
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.
Would be good to add a docstring about why we're doing this. To clean up left over stuff from build servers? We could also just call .delete() directly, which should trigger the logic that does this, instead of special casing this one cleanup task.
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.
The admin calls
.delete()
on theProject
queryset, bulking the operations, this was to avoid messing with any of the logic there.Project
also doesn't have a delete method that does this currently, because we need to make a decision on whether a user deleting a project should remove the files from webs.