diff --git a/media/css/seahub.css b/media/css/seahub.css index 39d0b779e4..0406ac5161 100644 --- a/media/css/seahub.css +++ b/media/css/seahub.css @@ -878,7 +878,7 @@ textarea:-moz-placeholder {/* for FF */ } .nav-con-tabs-content { float:right; - width:550px; + width:564px; padding:0 1.4em 1em; min-height:150px; max-height:250px; diff --git a/seahub/api2/endpoints/admin/group_owned_libraries.py b/seahub/api2/endpoints/admin/group_owned_libraries.py index 4557e48914..78bb7682e5 100644 --- a/seahub/api2/endpoints/admin/group_owned_libraries.py +++ b/seahub/api2/endpoints/admin/group_owned_libraries.py @@ -18,7 +18,7 @@ from seahub.api2.endpoints.utils import api_check_group from seahub.signals import repo_created from seahub.utils import is_valid_dirent_name, is_org_context, \ is_pro_version -from seahub.utils.repo import get_library_storages, get_repo_owner +from seahub.utils.repo import get_library_storages, get_repo_owner, get_available_repo_perms from seahub.utils.timeutils import timestamp_to_isoformat_timestr from seahub.share.signals import share_repo_to_group_successful from seahub.constants import PERMISSION_READ, PERMISSION_READ_WRITE @@ -64,7 +64,7 @@ class AdminGroupOwnedLibraries(APIView): password = request.data.get("password", None) permission = request.data.get('permission', PERMISSION_READ_WRITE) - if permission not in [PERMISSION_READ, PERMISSION_READ_WRITE]: + if permission not in get_available_repo_perms(): error_msg = 'permission invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) diff --git a/seahub/api2/endpoints/admin/shares.py b/seahub/api2/endpoints/admin/shares.py index bbfb87815a..0d89573a5c 100644 --- a/seahub/api2/endpoints/admin/shares.py +++ b/seahub/api2/endpoints/admin/shares.py @@ -23,6 +23,7 @@ from seahub.share.signals import share_repo_to_user_successful, share_repo_to_gr from seahub.base.accounts import User from seahub.base.templatetags.seahub_tags import email2nickname from seahub.utils import is_valid_username, send_perm_audit_msg +from seahub.utils.repo import get_available_repo_perms from seahub.constants import PERMISSION_READ, PERMISSION_READ_WRITE, \ PERMISSION_ADMIN @@ -157,9 +158,7 @@ class AdminShares(APIView): # argument check permission = request.data.get('permission', None) - if not permission or permission not in (PERMISSION_READ, - PERMISSION_READ_WRITE, - PERMISSION_ADMIN): + if not permission or permission not in get_available_repo_perms(): error_msg = 'permission invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) @@ -306,9 +305,7 @@ class AdminShares(APIView): # argument check permission = request.data.get('permission', None) - if not permission or permission not in (PERMISSION_READ, - PERMISSION_READ_WRITE, - PERMISSION_ADMIN): + if not permission or permission not in get_available_repo_perms(): error_msg = 'permission invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) diff --git a/seahub/api2/endpoints/copy_move_task.py b/seahub/api2/endpoints/copy_move_task.py index 6532db7440..d64b096662 100644 --- a/seahub/api2/endpoints/copy_move_task.py +++ b/seahub/api2/endpoints/copy_move_task.py @@ -17,7 +17,7 @@ from seahub.api2.views import HTTP_443_ABOVE_QUOTA from seahub.views import check_folder_permission from seahub.utils import check_filename_with_rename -from seahub.utils.repo import get_repo_owner +from seahub.utils.repo import get_repo_owner, parse_repo_perm from seahub.utils.file_op import check_file_lock from seahub.settings import MAX_PATH @@ -193,7 +193,8 @@ class CopyMoveTaskView(APIView): if operation == 'copy': # permission check for src parent dir - if not check_folder_permission(request, src_repo_id, src_parent_dir): + if parse_repo_perm(check_folder_permission( + request, src_repo_id, src_parent_dir)).can_copy is False: error_msg = 'Permission denied.' return api_error(status.HTTP_403_FORBIDDEN, error_msg) diff --git a/seahub/api2/endpoints/dir_shared_items.py b/seahub/api2/endpoints/dir_shared_items.py index c89cd7b593..ee602a2b22 100644 --- a/seahub/api2/endpoints/dir_shared_items.py +++ b/seahub/api2/endpoints/dir_shared_items.py @@ -34,6 +34,7 @@ from seahub.utils import (is_org_context, is_valid_username, from seahub.share.signals import share_repo_to_user_successful, share_repo_to_group_successful from seahub.constants import PERMISSION_READ, PERMISSION_READ_WRITE, \ PERMISSION_ADMIN +from seahub.utils.repo import get_available_repo_perms logger = logging.getLogger(__name__) @@ -218,7 +219,7 @@ class DirSharedItemsEndpoint(APIView): return api_error(status.HTTP_404_NOT_FOUND, 'Folder %s not found.' % path) permission = request.data.get('permission', PERMISSION_READ) - if permission not in [PERMISSION_READ, PERMISSION_READ_WRITE, PERMISSION_ADMIN]: + if permission not in get_available_repo_perms(): return api_error(status.HTTP_400_BAD_REQUEST, 'permission invalid.') repo_owner = self.get_repo_owner(request, repo_id) @@ -299,7 +300,7 @@ class DirSharedItemsEndpoint(APIView): return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied.') permission = request.data.get('permission', PERMISSION_READ) - if permission not in [PERMISSION_READ, PERMISSION_READ_WRITE, PERMISSION_ADMIN]: + if permission not in get_available_repo_perms(): return api_error(status.HTTP_400_BAD_REQUEST, 'permission invalid.') result = {} diff --git a/seahub/api2/endpoints/file.py b/seahub/api2/endpoints/file.py index 91fa1c8008..94e9317d8b 100644 --- a/seahub/api2/endpoints/file.py +++ b/seahub/api2/endpoints/file.py @@ -24,6 +24,7 @@ from seahub.views import check_folder_permission from seahub.utils.file_op import check_file_lock, if_locked_by_online_office from seahub.views.file import can_preview_file, can_edit_file from seahub.constants import PERMISSION_READ_WRITE +from seahub.utils.repo import parse_repo_perm from seahub.settings import MAX_UPLOAD_FILE_NAME_LEN, \ FILE_LOCK_EXPIRATION_DAYS, OFFICE_TEMPLATE_ROOT @@ -406,7 +407,9 @@ class FileView(APIView): # permission check for source file src_repo_id = repo_id src_dir = os.path.dirname(path) - if not check_folder_permission(request, src_repo_id, src_dir): + + if parse_repo_perm(check_folder_permission( + request, src_repo_id, src_dir)).can_copy is False: error_msg = 'Permission denied.' return api_error(status.HTTP_403_FORBIDDEN, error_msg) diff --git a/seahub/api2/endpoints/group_libraries.py b/seahub/api2/endpoints/group_libraries.py index f38db226bf..27bc758f2c 100644 --- a/seahub/api2/endpoints/group_libraries.py +++ b/seahub/api2/endpoints/group_libraries.py @@ -21,7 +21,7 @@ from seahub.group.utils import is_group_member, is_group_admin from seahub.utils import is_org_context, is_valid_dirent_name, \ send_perm_audit_msg from seahub.utils.timeutils import timestamp_to_isoformat_timestr -from seahub.utils.repo import get_repo_owner +from seahub.utils.repo import get_repo_owner, get_available_repo_perms from seahub.share.models import ExtraGroupsSharePermission from seahub.share.signals import share_repo_to_group_successful from seahub.share.utils import is_repo_admin, check_group_share_in_permission, \ @@ -119,7 +119,7 @@ class GroupLibraries(APIView): return api_error(status.HTTP_403_FORBIDDEN, error_msg) permission = request.data.get('permission', PERMISSION_READ) - if permission not in [PERMISSION_READ, PERMISSION_READ_WRITE, PERMISSION_ADMIN]: + if permission not in get_available_repo_perms(): error_msg = 'permission invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) diff --git a/seahub/api2/endpoints/group_owned_libraries.py b/seahub/api2/endpoints/group_owned_libraries.py index aab6f6ef4d..9cc698625d 100644 --- a/seahub/api2/endpoints/group_owned_libraries.py +++ b/seahub/api2/endpoints/group_owned_libraries.py @@ -29,7 +29,9 @@ from seahub.group.utils import is_group_admin from seahub.utils import is_valid_dirent_name, is_org_context, \ is_pro_version, normalize_dir_path, is_valid_username, \ send_perm_audit_msg, is_valid_org_id -from seahub.utils.repo import get_library_storages, get_repo_owner +from seahub.utils.repo import ( + get_library_storages, get_repo_owner, get_available_repo_perms +) from seahub.utils.timeutils import timestamp_to_isoformat_timestr from seahub.utils.rpc import SeafileAPI from seahub.share.signals import share_repo_to_user_successful, share_repo_to_group_successful @@ -312,7 +314,7 @@ class GroupOwnedLibraryUserFolderPermission(APIView): return api_error(status.HTTP_400_BAD_REQUEST, error_msg) perm = request.data.get('permission', None) - if not perm or perm not in [PERMISSION_READ, PERMISSION_READ_WRITE]: + if not perm or perm not in get_available_repo_perms(): error_msg = 'permission invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) @@ -405,7 +407,7 @@ class GroupOwnedLibraryUserFolderPermission(APIView): return api_error(status.HTTP_400_BAD_REQUEST, error_msg) perm = request.data.get('permission', None) - if not perm or perm not in [PERMISSION_READ, PERMISSION_READ_WRITE]: + if not perm or perm not in get_available_repo_perms(): error_msg = 'permission invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) @@ -585,7 +587,7 @@ class GroupOwnedLibraryGroupFolderPermission(APIView): return api_error(status.HTTP_400_BAD_REQUEST, error_msg) perm = request.data.get('permission', None) - if not perm or perm not in [PERMISSION_READ, PERMISSION_READ_WRITE]: + if not perm or perm not in get_available_repo_perms(): error_msg = 'permission invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) @@ -673,7 +675,7 @@ class GroupOwnedLibraryGroupFolderPermission(APIView): return api_error(status.HTTP_400_BAD_REQUEST, error_msg) perm = request.data.get('permission', None) - if not perm or perm not in [PERMISSION_READ, PERMISSION_READ_WRITE]: + if not perm or perm not in get_available_repo_perms(): error_msg = 'permission invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) diff --git a/seahub/api2/endpoints/repos_batch.py b/seahub/api2/endpoints/repos_batch.py index 9a9308a22d..ad4a256a10 100644 --- a/seahub/api2/endpoints/repos_batch.py +++ b/seahub/api2/endpoints/repos_batch.py @@ -28,7 +28,8 @@ from seahub.share.signals import share_repo_to_user_successful, \ from seahub.utils import is_org_context, send_perm_audit_msg, \ normalize_dir_path, get_folder_permission_recursively, \ normalize_file_path, check_filename_with_rename -from seahub.utils.repo import get_repo_owner +from seahub.utils.repo import get_repo_owner, get_available_repo_perms, \ + parse_repo_perm from seahub.views import check_folder_permission from seahub.settings import MAX_PATH @@ -147,7 +148,7 @@ class ReposBatchView(APIView): return api_error(status.HTTP_400_BAD_REQUEST, error_msg) permission = request.data.get('permission', 'rw') - if permission not in [PERMISSION_READ, PERMISSION_READ_WRITE, PERMISSION_ADMIN]: + if permission not in get_available_repo_perms(): error_msg = 'permission invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) @@ -854,7 +855,7 @@ class ReposBatchCopyItemView(APIView): continue # src path permission check, user must has `r/rw` permission for src folder. - if check_folder_permission(request, src_repo_id, src_parent_dir) is None: + if parse_repo_perm(check_folder_permission(request, src_repo_id, src_parent_dir)).can_copy is False: error_dict = { 'error_msg': 'Permission denied.' } diff --git a/seahub/api2/endpoints/share_link_zip_task.py b/seahub/api2/endpoints/share_link_zip_task.py index 8b570a7d52..9d84123cc0 100644 --- a/seahub/api2/endpoints/share_link_zip_task.py +++ b/seahub/api2/endpoints/share_link_zip_task.py @@ -18,6 +18,7 @@ from seahub.views.file import send_file_access_msg from seahub.share.models import FileShare from seahub.utils import is_windows_operating_system, \ is_pro_version +from seahub.utils.repo import parse_repo_perm import seaserv from seaserv import seafile_api @@ -85,8 +86,8 @@ class ShareLinkZipTaskView(APIView): error_msg = 'Folder %s not found.' % real_path return api_error(status.HTTP_404_NOT_FOUND, error_msg) - if not seafile_api.check_permission_by_path(repo_id, '/', - fileshare.username): + if parse_repo_perm(seafile_api.check_permission_by_path( + repo_id, '/', fileshare.username)).can_download is False: error_msg = 'Permission denied.' return api_error(status.HTTP_403_FORBIDDEN, error_msg) diff --git a/seahub/api2/endpoints/share_links.py b/seahub/api2/endpoints/share_links.py index 7502d1daa3..ced97550e8 100644 --- a/seahub/api2/endpoints/share_links.py +++ b/seahub/api2/endpoints/share_links.py @@ -25,6 +25,7 @@ from seahub.share.models import FileShare, OrgFileShare from seahub.utils import gen_shared_link, is_org_context from seahub.views import check_folder_permission from seahub.utils.timeutils import datetime_to_isoformat_timestr +from seahub.utils.repo import parse_repo_perm from seahub.settings import SHARE_LINK_EXPIRE_DAYS_MAX, \ SHARE_LINK_EXPIRE_DAYS_MIN @@ -270,9 +271,8 @@ class ShareLinks(APIView): error_msg = 'path %s not found.' % path return api_error(status.HTTP_404_NOT_FOUND, error_msg) - - # permission check - if not check_folder_permission(request, repo_id, path): + + if parse_repo_perm(check_folder_permission(request, repo_id, path)).can_download is False: error_msg = 'Permission denied.' return api_error(status.HTTP_403_FORBIDDEN, error_msg) diff --git a/seahub/api2/endpoints/shared_repos.py b/seahub/api2/endpoints/shared_repos.py index bd6917597d..b670ea6884 100644 --- a/seahub/api2/endpoints/shared_repos.py +++ b/seahub/api2/endpoints/shared_repos.py @@ -15,9 +15,9 @@ from seahub.api2.authentication import TokenAuthentication from seahub.api2.throttling import UserRateThrottle from seahub.profile.models import Profile from seahub.utils import is_org_context, is_valid_username, send_perm_audit_msg +from seahub.utils.repo import get_available_repo_perms from seahub.base.templatetags.seahub_tags import email2nickname, email2contact_email from seahub.share.models import ExtraSharePermission, ExtraGroupsSharePermission -from seahub.constants import PERMISSION_READ, PERMISSION_READ_WRITE, PERMISSION_ADMIN from seahub.share.utils import update_user_dir_permission, update_group_dir_permission,\ check_user_share_out_permission, check_group_share_out_permission @@ -111,7 +111,7 @@ class SharedRepo(APIView): # argument check permission = request.data.get('permission', None) - if permission not in [PERMISSION_READ, PERMISSION_READ_WRITE, PERMISSION_ADMIN]: + if permission not in get_available_repo_perms(): error_msg = 'permission invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) diff --git a/seahub/api2/endpoints/zip_task.py b/seahub/api2/endpoints/zip_task.py index bc3c1d4445..f55f15cc3c 100644 --- a/seahub/api2/endpoints/zip_task.py +++ b/seahub/api2/endpoints/zip_task.py @@ -19,6 +19,7 @@ from seahub.api2.utils import api_error from seahub.views import check_folder_permission from seahub.views.file import send_file_access_msg from seahub.utils import is_windows_operating_system +from seahub.utils.repo import parse_repo_perm import seaserv from seaserv import seafile_api @@ -68,7 +69,7 @@ class ZipTaskView(APIView): return api_error(status.HTTP_404_NOT_FOUND, error_msg) # permission check - if not check_folder_permission(request, repo_id, parent_dir): + if parse_repo_perm(check_folder_permission(request, repo_id, parent_dir)).can_download is False: error_msg = 'Permission denied.' return api_error(status.HTTP_403_FORBIDDEN, error_msg) diff --git a/seahub/api2/utils.py b/seahub/api2/utils.py index c9db6785a8..a0f32c33c2 100644 --- a/seahub/api2/utils.py +++ b/seahub/api2/utils.py @@ -13,6 +13,7 @@ from functools import wraps from django.core.paginator import EmptyPage, InvalidPage from django.http import HttpResponse +from rest_framework.authentication import SessionAuthentication from rest_framework.response import Response from rest_framework import status, serializers from seaserv import seafile_api, get_personal_groups_by_user, \ @@ -435,3 +436,9 @@ def user_to_dict(email, request=None, avatar_size=AVATAR_DEFAULT_SIZE): 'user_contact_email': d['contact_email'], 'avatar_url': avatar_url, } + +def is_web_request(request): + if isinstance(request.successful_authenticator, SessionAuthentication): + return True + else: + return False diff --git a/seahub/api2/views.py b/seahub/api2/views.py index 393360f8da..de5b1075b9 100644 --- a/seahub/api2/views.py +++ b/seahub/api2/views.py @@ -33,9 +33,8 @@ from .throttling import ScopedRateThrottle, AnonRateThrottle, UserRateThrottle from .authentication import TokenAuthentication from .serializers import AuthTokenSerializer from .utils import get_diff_details, to_python_boolean, \ - api_error, get_file_size, prepare_starred_files, \ + api_error, get_file_size, prepare_starred_files, is_web_request, \ get_groups, api_group_check, get_timestamp, json_response, is_seafile_pro - from seahub.wopi.utils import get_wopi_dict from seahub.api2.base import APIView from seahub.api2.models import TokenV2, DESKTOP_PLATFORMS @@ -75,9 +74,9 @@ from seahub.utils.devices import do_unlink_device from seahub.utils.repo import get_repo_owner, get_library_storages, \ get_locked_files_by_dir, get_related_users_by_repo, \ is_valid_repo_id_format, can_set_folder_perm_by_user, \ - add_encrypted_repo_secret_key_to_database -from seahub.utils.star import star_file, unstar_file, \ - get_dir_starred_files + add_encrypted_repo_secret_key_to_database, get_available_repo_perms, \ + parse_repo_perm +from seahub.utils.star import star_file, unstar_file, get_dir_starred_files from seahub.utils.file_types import DOCUMENT from seahub.utils.file_size import get_file_size_unit from seahub.utils.file_op import check_file_lock @@ -689,6 +688,7 @@ class Repos(APIView): else: shared_repos = seafile_api.get_share_in_repo_list( email, -1, -1) + repos_with_admin_share_to = ExtraSharePermission.objects.\ get_repos_with_admin_permission(email) @@ -711,6 +711,10 @@ class Repos(APIView): library_group_id = get_group_id_by_repo_owner(r.user) library_group_name= group_id_to_name(library_group_id) + if parse_repo_perm(r.permission).can_download is False: + if not is_web_request(request): + continue + r.password_need = is_passwd_set(r.repo_id, email) repo = { "type": "srepo", @@ -766,6 +770,10 @@ class Repos(APIView): if q and q.lower() not in r.name.lower(): continue + if parse_repo_perm(r.permission).can_download is False: + if not is_web_request(request): + continue + repo = { "type": "grepo", "id": r.repo_id, @@ -2297,7 +2305,7 @@ class OpCopyView(APIView): return api_error(status.HTTP_404_NOT_FOUND, error_msg) # permission check - if check_folder_permission(request, repo_id, parent_dir) is None: + if parse_repo_perm(check_folder_permission(request, repo_id, parent_dir)).can_copy is False: return api_error(status.HTTP_403_FORBIDDEN, 'You do not have permission to copy file of this folder.') @@ -2737,7 +2745,8 @@ class FileView(APIView): return api_error(status.HTTP_400_BAD_REQUEST, 'Missing arguments.') # check src folder permission - if check_folder_permission(request, repo_id, src_dir) is None: + + if parse_repo_perm(check_folder_permission(request, repo_id, src_dir)).can_copy is False: return api_error(status.HTTP_403_FORBIDDEN, 'You do not have permission to copy file.') @@ -3075,7 +3084,10 @@ class FileHistory(APIView): error_msg = 'File %s not found.' % path return api_error(status.HTTP_404_NOT_FOUND, error_msg) - if check_folder_permission(request, repo_id, path) != 'rw': + + permission = check_folder_permission(request, repo_id, path) + if permission not in get_available_repo_perms(): + error_msg = 'Permission denied.' return api_error(status.HTTP_403_FORBIDDEN, error_msg) @@ -3125,8 +3137,7 @@ class FileSharedLinkView(APIView): return api_error(status.HTTP_400_BAD_REQUEST, 'Password is too short') if share_type.lower() == 'download': - - if check_folder_permission(request, repo_id, path) is None: + if parse_repo_perm(check_folder_permission(request, repo_id, path)).can_download is False: return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied') if not request.user.permissions.can_generate_share_link(): @@ -3251,7 +3262,9 @@ class DirView(APIView): # permission check permission = check_folder_permission(request, repo_id, path) - if not permission: + if parse_repo_perm(permission).can_download is False and \ + not is_web_request(request): + # preview only repo and this request does not came from web brower error_msg = 'Permission denied.' return api_error(status.HTTP_403_FORBIDDEN, error_msg) @@ -3983,7 +3996,7 @@ class SharedRepo(APIView): share_type = request.GET.get('share_type') permission = request.GET.get('permission') - if permission not in ('r', 'rw'): + if permission not in get_available_repo_perms(): error_msg = 'permission invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) @@ -4440,7 +4453,7 @@ class GroupRepos(APIView): 'NOT allow to create encrypted library.') permission = request.data.get("permission", 'r') - if permission != 'r' and permission != 'rw': + if permission not in get_available_repo_perms(): return api_error(status.HTTP_400_BAD_REQUEST, 'Invalid permission') org_id = -1 @@ -4812,14 +4825,27 @@ class RepoTokensView(APIView): if any([not _REPO_ID_PATTERN.match(repo_id) for repo_id in repos_id]): return api_error(status.HTTP_400_BAD_REQUEST, "Libraries ids are invalid") + username = request.user.username tokens = {} for repo_id in repos_id: repo = seafile_api.get_repo(repo_id) if not repo: continue - if not check_folder_permission(request, repo.id, '/'): - continue + perm = check_folder_permission(request, repo.id, '/') + if not perm: + res = { + 'reason': 'no permission', + 'unsyncable_path': '/' + } + return Response(res, status=status.HTTP_403_FORBIDDEN) + + if not seafile_api.is_repo_syncable(repo_id, username, perm): + res = { + 'reason': 'unsyncable share permission', + 'unsyncable_path': '/' + } + return Response(res, status=status.HTTP_403_FORBIDDEN) tokens[repo_id] = seafile_api.generate_repo_token(repo_id, request.user.username) @@ -5140,7 +5166,7 @@ class RepoUserFolderPerm(APIView): return api_error(status.HTTP_400_BAD_REQUEST, error_msg) perm = request.data.get('permission', None) - if not perm or perm not in ('r', 'rw'): + if not perm or perm not in get_available_repo_perms(): error_msg = 'permission invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) @@ -5228,7 +5254,7 @@ class RepoUserFolderPerm(APIView): return api_error(status.HTTP_400_BAD_REQUEST, error_msg) perm = request.data.get('permission', None) - if not perm or perm not in ('r', 'rw'): + if not perm or perm not in get_available_repo_perms(): error_msg = 'permission invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) @@ -5415,7 +5441,7 @@ class RepoGroupFolderPerm(APIView): return api_error(status.HTTP_400_BAD_REQUEST, error_msg) perm = request.data.get('permission', None) - if not perm or perm not in ('r', 'rw'): + if not perm or perm not in get_available_repo_perms(): error_msg = 'permission invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) @@ -5502,7 +5528,7 @@ class RepoGroupFolderPerm(APIView): return api_error(status.HTTP_400_BAD_REQUEST, error_msg) perm = request.data.get('permission', None) - if not perm or perm not in ('r', 'rw'): + if not perm or perm not in get_available_repo_perms(): error_msg = 'permission invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) diff --git a/seahub/constants.py b/seahub/constants.py index e71348fbf3..5cf5b78baa 100644 --- a/seahub/constants.py +++ b/seahub/constants.py @@ -6,7 +6,9 @@ DEFAULT_USER = 'default' # Guest user have limited operations, can not create group and library. GUEST_USER = 'guest' -# Permissions +# Repo/folder permissions +PERMISSION_PREVIEW = 'preview' # preview only on the web, can not be downloaded +PERMISSION_PREVIEW_EDIT = 'cloud-edit' # preview only with edit on the web PERMISSION_READ = 'r' PERMISSION_READ_WRITE = 'rw' PERMISSION_ADMIN = 'admin' diff --git a/seahub/group/views.py b/seahub/group/views.py index c2bf4f465e..5ac325ec91 100644 --- a/seahub/group/views.py +++ b/seahub/group/views.py @@ -16,6 +16,7 @@ from django.utils.http import urlquote from django.utils.translation import ugettext as _ from seahub.auth.decorators import login_required, login_required_ajax +from seahub.constants import PERMISSION_PREVIEW import seaserv from seaserv import ccnet_threaded_rpc, seafile_api, \ get_group_repos, get_group, \ @@ -323,8 +324,8 @@ def group_wiki(request, group, page_name="home"): if is_registered_user(username): repo_perm = seafile_api.check_permission_by_path(repo.id, '/', username) else: - # when anonymous user visit public group wiki, set permission as 'r' - repo_perm = 'r' + # when anonymous user visit public group wiki, set permission as preview only + repo_perm = PERMISSION_PREVIEW wiki_index_exists = True index_pagename = 'index' @@ -370,8 +371,8 @@ def group_wiki_pages(request, group): if is_registered_user(username): repo_perm = seafile_api.check_permission_by_path(repo.id, '/', username) else: - # when anonymous user visit public group wiki, set permission as 'r' - repo_perm = 'r' + # when anonymous user visit public group wiki, set permission as preview only + repo_perm = PERMISSION_PREVIEW mods_available = get_available_mods_by_group(group.id) mods_enabled = get_enabled_mods_by_group(group.id) diff --git a/seahub/templates/file_revisions.html b/seahub/templates/file_revisions.html index c4122dafbb..3992b94228 100644 --- a/seahub/templates/file_revisions.html +++ b/seahub/templates/file_revisions.html @@ -85,7 +85,9 @@ {% trans 'Restore' %} <% } %> {% endif %} + {% if can_download_file %} {% trans 'Download' %} + {% endif %} {% trans 'View' %} {% if can_compare %} {% trans 'Diff' %} diff --git a/seahub/templates/js/templates.html b/seahub/templates/js/templates.html index 6e7d92c1d8..1d94de7e82 100644 --- a/seahub/templates/js/templates.html +++ b/seahub/templates/js/templates.html @@ -488,7 +488,7 @@ <% } %> - <% if (!encrypted && (app.pageOptions.can_generate_share_link || app.pageOptions.can_generate_upload_link || is_repo_owner || is_admin)) { %> + <% if (can_share) { %> <% } %> @@ -586,10 +586,11 @@