mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-02 15:38:15 +00:00
Illegal report by react (#3415)
* illegal report 1, add illegal report at shared file page 2, list all illegal reports at admin page * add ENABLE_SHARE_LINK_REPORT_ILLEGAL setting * UserRateThrottle -> AnonRateThrottle * use to_python_boolean * frontend by React * remove illegal report dialog in shared dir view * add migrations dir * add illegal_reports migrations * rename illegal to abuse in api * rename illegal to abuse in test * rename illegal to abuse in share file view * rename illegal to abuse in react * rename illegal to abuse in Backbone * add enableShareLinkReportAbuse in templates * add ReportAbuse * update ReportAbuse * update ReportAbuse urls * update ReportAbuse api-js * sysadmin_react_app.html * sysadmin.py * fix * fix * fix * can not abuse own file * Contact Information is required. * fix review * remove repo icon
This commit is contained in:
102
tests/api/endpoints/test_abuse_reports.py
Normal file
102
tests/api/endpoints/test_abuse_reports.py
Normal file
@@ -0,0 +1,102 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import json
|
||||
|
||||
from mock import patch, MagicMock
|
||||
from django.core.urlresolvers import reverse
|
||||
from seahub.test_utils import BaseTestCase
|
||||
from seahub.share.models import FileShare
|
||||
|
||||
|
||||
class AbuseReportsTest(BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.repo_id = self.repo.id
|
||||
self.file_path = self.file
|
||||
self.folder_path = self.folder
|
||||
self.url = reverse('api-v2.1-abuse-reports')
|
||||
self.inner_file_path = self.create_file(
|
||||
repo_id=self.repo.id,
|
||||
parent_dir='/folder/',
|
||||
filename='inner.txt',
|
||||
username='test@test.com')
|
||||
|
||||
def tearDown(self):
|
||||
self.remove_repo()
|
||||
|
||||
def _add_file_share_link(self):
|
||||
fs = FileShare.objects.create_file_link(
|
||||
self.user.username, self.repo.id, self.file, None, None)
|
||||
|
||||
return fs.token
|
||||
|
||||
def _add_dir_share_link(self):
|
||||
fs = FileShare.objects.create_dir_link(
|
||||
self.user.username, self.repo.id, self.folder, None, None)
|
||||
|
||||
return fs.token
|
||||
|
||||
def _remove_share_link(self, token):
|
||||
link = FileShare.objects.get(token=token)
|
||||
link.delete()
|
||||
|
||||
@patch('seahub.api2.endpoints.abuse_reports.ENABLE_SHARE_LINK_REPORT_ABUSE', MagicMock(return_value=True))
|
||||
def test_file_share_link_can_report(self):
|
||||
self.login_as(self.user)
|
||||
shared_token = self._add_file_share_link()
|
||||
|
||||
data = {
|
||||
'share_link_token': shared_token,
|
||||
'abuse_type': 'copyright',
|
||||
'description': '',
|
||||
'reporter': '',
|
||||
'file_path': self.file_path,
|
||||
}
|
||||
|
||||
resp = self.client.post(self.url, data)
|
||||
self.assertEqual(200, resp.status_code)
|
||||
|
||||
json_resp = json.loads(resp.content)
|
||||
assert json_resp['handled'] is not None
|
||||
assert json_resp['id'] is not None
|
||||
assert json_resp['file_name'] is not None
|
||||
assert json_resp['repo_id'] is not None
|
||||
assert json_resp['repo_name'] is not None
|
||||
assert json_resp['time'] is not None
|
||||
|
||||
assert data['file_path'] == json_resp['file_path']
|
||||
assert data['reporter'] == json_resp['reporter']
|
||||
assert data['description'] == json_resp['description']
|
||||
assert data['abuse_type'] == json_resp['abuse_type']
|
||||
|
||||
self._remove_share_link(shared_token)
|
||||
|
||||
@patch('seahub.api2.endpoints.abuse_reports.ENABLE_SHARE_LINK_REPORT_ABUSE', MagicMock(return_value=True))
|
||||
def test_dir_share_link_can_report(self):
|
||||
self.login_as(self.user)
|
||||
shared_token = self._add_file_share_link()
|
||||
|
||||
data = {
|
||||
'share_link_token': shared_token,
|
||||
'abuse_type': 'copyright',
|
||||
'description': '',
|
||||
'reporter': '',
|
||||
'file_path': self.inner_file_path,
|
||||
}
|
||||
|
||||
resp = self.client.post(self.url, data)
|
||||
self.assertEqual(200, resp.status_code)
|
||||
|
||||
json_resp = json.loads(resp.content)
|
||||
assert json_resp['handled'] is not None
|
||||
assert json_resp['id'] is not None
|
||||
assert json_resp['file_name'] is not None
|
||||
assert json_resp['repo_id'] is not None
|
||||
assert json_resp['repo_name'] is not None
|
||||
assert json_resp['time'] is not None
|
||||
assert json_resp['file_path'] is not None
|
||||
|
||||
assert data['reporter'] == json_resp['reporter']
|
||||
assert data['description'] == json_resp['description']
|
||||
assert data['abuse_type'] == json_resp['abuse_type']
|
||||
|
||||
self._remove_share_link(shared_token)
|
Reference in New Issue
Block a user