mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-31 22:54:11 +00:00
optimize code
This commit is contained in:
@@ -15,6 +15,7 @@ from seahub.api2.permissions import IsProVersion
|
||||
|
||||
from seahub.onlyoffice.models import RepoExtraConfig, REPO_OFFICE_CONFIG
|
||||
from seahub.settings import OFFICE_SUITE_LIST
|
||||
from seahub.utils.repo import get_repo_owner
|
||||
|
||||
class OfficeSuiteConfig(APIView):
|
||||
|
||||
@@ -23,7 +24,7 @@ class OfficeSuiteConfig(APIView):
|
||||
throttle_classes = (UserRateThrottle,)
|
||||
|
||||
def get(self, request, repo_id):
|
||||
if not request.user.permissions.can_use_office_suite:
|
||||
if not request.user.permissions.can_choose_office_suite:
|
||||
error_msg = 'Permission denied.'
|
||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||
|
||||
@@ -31,7 +32,12 @@ class OfficeSuiteConfig(APIView):
|
||||
if not repo:
|
||||
error_msg = 'Library %s not found.' % repo_id
|
||||
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
|
||||
|
||||
|
||||
repo_owner = get_repo_owner(request, repo_id)
|
||||
if '@seafile_group' in repo_owner:
|
||||
error_msg = 'Department repo can not use this feature.'
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||
|
||||
current_suite = RepoExtraConfig.objects.filter(repo_id=repo_id, config_type=REPO_OFFICE_CONFIG).first()
|
||||
suites_info = []
|
||||
for office_suite in OFFICE_SUITE_LIST:
|
||||
@@ -56,7 +62,7 @@ class OfficeSuiteConfig(APIView):
|
||||
error_msg = 'suite_id invalid.'
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||
|
||||
if not request.user.permissions.can_use_office_suite:
|
||||
if not request.user.permissions.can_choose_office_suite:
|
||||
error_msg = 'Permission denied.'
|
||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||
|
||||
@@ -66,6 +72,11 @@ class OfficeSuiteConfig(APIView):
|
||||
error_msg = 'Library %s not found.' % repo_id
|
||||
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
|
||||
|
||||
repo_owner = get_repo_owner(request, repo_id)
|
||||
if '@seafile_group' in repo_owner:
|
||||
error_msg = 'Department repo can not use this feature.'
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||
|
||||
config_details = {
|
||||
'office_suite': {
|
||||
'suite_id': suite_id
|
||||
|
@@ -447,10 +447,10 @@ class UserPermissions(object):
|
||||
|
||||
return self._get_perm_by_roles('can_publish_repo')
|
||||
|
||||
def can_use_office_suite(self):
|
||||
def can_choose_office_suite(self):
|
||||
if not settings.ENABLE_MULTIPLE_OFFICE_SUITE:
|
||||
return False
|
||||
return self._get_perm_by_roles('can_use_office_suite')
|
||||
return self._get_perm_by_roles('can_choose_office_suite')
|
||||
|
||||
|
||||
class AdminPermissions(object):
|
||||
|
@@ -46,7 +46,7 @@ DEFAULT_ENABLED_ROLE_PERMISSIONS = {
|
||||
'can_publish_repo': True,
|
||||
'upload_rate_limit': 0,
|
||||
'download_rate_limit': 0,
|
||||
'can_use_office_suite': False,
|
||||
'can_choose_office_suite': True,
|
||||
},
|
||||
GUEST_USER: {
|
||||
'can_add_repo': False,
|
||||
@@ -69,7 +69,7 @@ DEFAULT_ENABLED_ROLE_PERMISSIONS = {
|
||||
'can_publish_repo': False,
|
||||
'upload_rate_limit': 0,
|
||||
'download_rate_limit': 0,
|
||||
'can_use_office_suite': False,
|
||||
'can_choose_office_suite': False,
|
||||
},
|
||||
}
|
||||
|
||||
|
@@ -150,7 +150,7 @@
|
||||
canSetExProps: {% if can_set_ex_props %} true {% else %} false {% endif %},
|
||||
enableSeaTableIntegration: {% if enable_seatable_integration %} true {% else %} false {% endif %},
|
||||
isOrgContext: {% if org is not None %} true {% else %} false {% endif %},
|
||||
enableMultipleOfficeSuite: {% if user.permissions.can_use_office_suite %} true {% else %} false {% endif %},
|
||||
enableMultipleOfficeSuite: {% if user.permissions.can_choose_office_suite %} true {% else %} false {% endif %},
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
@@ -91,8 +91,8 @@ from seahub.settings import FILE_ENCODING_LIST, FILE_PREVIEW_MAX_SIZE, \
|
||||
FILE_ENCODING_TRY_LIST, MEDIA_URL, SEAFILE_COLLAB_SERVER, ENABLE_WATERMARK, \
|
||||
SHARE_LINK_EXPIRE_DAYS_MIN, SHARE_LINK_EXPIRE_DAYS_MAX, SHARE_LINK_PASSWORD_MIN_LENGTH, \
|
||||
SHARE_LINK_FORCE_USE_PASSWORD, SHARE_LINK_PASSWORD_STRENGTH_LEVEL, \
|
||||
SHARE_LINK_EXPIRE_DAYS_DEFAULT, ENABLE_SHARE_LINK_REPORT_ABUSE, SEADOC_SERVER_URL, ENABLE_MULTIPLE_OFFICE_SUITE, \
|
||||
OFFICE_SUITE_LIST
|
||||
SHARE_LINK_EXPIRE_DAYS_DEFAULT, ENABLE_SHARE_LINK_REPORT_ABUSE, SEADOC_SERVER_URL, \
|
||||
ENABLE_MULTIPLE_OFFICE_SUITE, OFFICE_SUITE_LIST
|
||||
|
||||
|
||||
# wopi
|
||||
|
Reference in New Issue
Block a user