mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-16 06:03:35 +00:00
pro version can use search (#6636)
This commit is contained in:
parent
b6b5997643
commit
e1e524ecbc
@ -10,6 +10,7 @@ from seaserv import seafile_api
|
|||||||
|
|
||||||
from seahub.api2.authentication import TokenAuthentication
|
from seahub.api2.authentication import TokenAuthentication
|
||||||
from seahub.api2.throttling import UserRateThrottle
|
from seahub.api2.throttling import UserRateThrottle
|
||||||
|
from seahub.api2.permissions import IsProVersion
|
||||||
from seahub.api2.utils import api_error
|
from seahub.api2.utils import api_error
|
||||||
from seahub.utils.repo import is_valid_repo_id_format
|
from seahub.utils.repo import is_valid_repo_id_format
|
||||||
from seahub.utils import HAS_FILE_SEARCH, HAS_FILE_SEASEARCH
|
from seahub.utils import HAS_FILE_SEARCH, HAS_FILE_SEASEARCH
|
||||||
@ -25,7 +26,7 @@ class PublishedRepoSearchView(APIView):
|
|||||||
""" Search public repos
|
""" Search public repos
|
||||||
"""
|
"""
|
||||||
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
||||||
permission_classes = (IsAuthenticatedOrReadOnly,)
|
permission_classes = (IsAuthenticatedOrReadOnly, IsProVersion)
|
||||||
throttle_classes = (UserRateThrottle, )
|
throttle_classes = (UserRateThrottle, )
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
|
@ -36,6 +36,7 @@ from .serializers import AuthTokenSerializer
|
|||||||
from .utils import get_diff_details, to_python_boolean, \
|
from .utils import get_diff_details, to_python_boolean, \
|
||||||
api_error, get_file_size, prepare_starred_files, is_web_request, \
|
api_error, get_file_size, prepare_starred_files, is_web_request, \
|
||||||
get_groups, api_group_check, get_timestamp, json_response
|
get_groups, api_group_check, get_timestamp, json_response
|
||||||
|
from seahub.api2.permissions import IsProVersion
|
||||||
from seahub.wopi.utils import get_wopi_dict
|
from seahub.wopi.utils import get_wopi_dict
|
||||||
from seahub.api2.base import APIView
|
from seahub.api2.base import APIView
|
||||||
from seahub.api2.models import TokenV2, DESKTOP_PLATFORMS
|
from seahub.api2.models import TokenV2, DESKTOP_PLATFORMS
|
||||||
@ -443,7 +444,7 @@ class Search(APIView):
|
|||||||
""" Search all the repos
|
""" Search all the repos
|
||||||
"""
|
"""
|
||||||
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
||||||
permission_classes = (IsAuthenticated,)
|
permission_classes = (IsAuthenticated, IsProVersion)
|
||||||
throttle_classes = (UserRateThrottle, )
|
throttle_classes = (UserRateThrottle, )
|
||||||
|
|
||||||
def get(self, request, format=None):
|
def get(self, request, format=None):
|
||||||
|
@ -27,6 +27,7 @@ from seaserv import seafile_api, check_quota, get_org_id_by_repo_id
|
|||||||
|
|
||||||
from seahub.views import check_folder_permission
|
from seahub.views import check_folder_permission
|
||||||
from seahub.api2.authentication import TokenAuthentication, SdocJWTTokenAuthentication
|
from seahub.api2.authentication import TokenAuthentication, SdocJWTTokenAuthentication
|
||||||
|
from seahub.api2.permissions import IsProVersion
|
||||||
from seahub.api2.utils import api_error, user_to_dict, to_python_boolean, get_user_common_info
|
from seahub.api2.utils import api_error, user_to_dict, to_python_boolean, get_user_common_info
|
||||||
from seahub.api2.throttling import UserRateThrottle
|
from seahub.api2.throttling import UserRateThrottle
|
||||||
from seahub.seadoc.utils import is_valid_seadoc_access_token, get_seadoc_upload_link, \
|
from seahub.seadoc.utils import is_valid_seadoc_access_token, get_seadoc_upload_link, \
|
||||||
@ -2900,6 +2901,7 @@ class SeadocEditorCallBack(APIView):
|
|||||||
class SeadocSearchFilenameView(APIView):
|
class SeadocSearchFilenameView(APIView):
|
||||||
|
|
||||||
authentication_classes = (SdocJWTTokenAuthentication, TokenAuthentication, SessionAuthentication)
|
authentication_classes = (SdocJWTTokenAuthentication, TokenAuthentication, SessionAuthentication)
|
||||||
|
permission_classes = (IsProVersion, )
|
||||||
throttle_classes = (UserRateThrottle,)
|
throttle_classes = (UserRateThrottle,)
|
||||||
|
|
||||||
def get(self, request, file_uuid):
|
def get(self, request, file_uuid):
|
||||||
|
@ -8,6 +8,11 @@ from seahub.test_utils import BaseTestCase, TRAVIS
|
|||||||
|
|
||||||
from seaserv import seafile_api
|
from seaserv import seafile_api
|
||||||
|
|
||||||
|
try:
|
||||||
|
from seahub.settings import LOCAL_PRO_DEV_ENV
|
||||||
|
except ImportError:
|
||||||
|
LOCAL_PRO_DEV_ENV = False
|
||||||
|
|
||||||
|
|
||||||
class SearchTest(BaseTestCase):
|
class SearchTest(BaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -35,8 +40,13 @@ class SearchTest(BaseTestCase):
|
|||||||
|
|
||||||
@patch('seahub.api2.views.HAS_FILE_SEARCH', True)
|
@patch('seahub.api2.views.HAS_FILE_SEARCH', True)
|
||||||
@patch('seahub.api2.views.search_files')
|
@patch('seahub.api2.views.search_files')
|
||||||
|
@patch('seahub.api2.views.is_pro_version')
|
||||||
@pytest.mark.skipif(TRAVIS, reason="")
|
@pytest.mark.skipif(TRAVIS, reason="")
|
||||||
def test_can_search_file(self, mock_search_files):
|
def test_can_search_file(self, mock_search_files, mock_is_pro_version):
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
|
mock_is_pro_version.return_value = True
|
||||||
mock_search_files.return_value = self.mock_results, \
|
mock_search_files.return_value = self.mock_results, \
|
||||||
self.mock_total
|
self.mock_total
|
||||||
|
|
||||||
@ -50,22 +60,37 @@ class SearchTest(BaseTestCase):
|
|||||||
assert json_resp['results'][0]['repo_id'] == self.mock_results[0]['repo_id']
|
assert json_resp['results'][0]['repo_id'] == self.mock_results[0]['repo_id']
|
||||||
|
|
||||||
@patch('seahub.api2.views.HAS_FILE_SEARCH', True)
|
@patch('seahub.api2.views.HAS_FILE_SEARCH', True)
|
||||||
def test_can_not_search_with_invalid_repo_permission(self):
|
@patch('seahub.api2.views.is_pro_version')
|
||||||
|
def test_can_not_search_with_invalid_repo_permission(self, mock_is_pro_version):
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
|
mock_is_pro_version.return_value = True
|
||||||
self.login_as(self.admin)
|
self.login_as(self.admin)
|
||||||
resp = self.client.get(self.url + '?q=lian&search_repo=%s' %
|
resp = self.client.get(self.url + '?q=lian&search_repo=%s' %
|
||||||
self.repo_id)
|
self.repo_id)
|
||||||
self.assertEqual(403, resp.status_code)
|
self.assertEqual(403, resp.status_code)
|
||||||
|
|
||||||
@patch('seahub.api2.views.HAS_FILE_SEARCH', True)
|
@patch('seahub.api2.views.HAS_FILE_SEARCH', True)
|
||||||
def test_can_not_search_without_q_parameter(self):
|
@patch('seahub.api2.views.is_pro_version')
|
||||||
|
def test_can_not_search_without_q_parameter(self, mock_is_pro_version):
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
|
mock_is_pro_version.return_value = True
|
||||||
self.login_as(self.user)
|
self.login_as(self.user)
|
||||||
resp = self.client.get(self.url)
|
resp = self.client.get(self.url)
|
||||||
self.assertEqual(400, resp.status_code)
|
self.assertEqual(400, resp.status_code)
|
||||||
|
|
||||||
@patch('seahub.api2.views.HAS_FILE_SEARCH', True)
|
@patch('seahub.api2.views.HAS_FILE_SEARCH', True)
|
||||||
@patch('seahub.api2.views.search_files')
|
@patch('seahub.api2.views.search_files')
|
||||||
|
@patch('seahub.api2.views.is_pro_version')
|
||||||
@pytest.mark.skipif(TRAVIS, reason="")
|
@pytest.mark.skipif(TRAVIS, reason="")
|
||||||
def test_can_search_with_search_path(self, mock_search_files):
|
def test_can_search_with_search_path(self, mock_search_files, mock_is_pro_version):
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
|
mock_is_pro_version.return_value = True
|
||||||
mock_search_files.return_value = self.mock_results, \
|
mock_search_files.return_value = self.mock_results, \
|
||||||
self.mock_total
|
self.mock_total
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user