diff --git a/frontend/src/components/dialog/delete-repo-dialog.js b/frontend/src/components/dialog/delete-repo-dialog.js index 7dc6fa39ab..a78bcd4a55 100644 --- a/frontend/src/components/dialog/delete-repo-dialog.js +++ b/frontend/src/components/dialog/delete-repo-dialog.js @@ -1,5 +1,6 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; +import { seafileAPI } from '../../utils/seafile-api'; import { Modal, ModalHeader, ModalBody, ModalFooter, Button } from 'reactstrap'; import { gettext } from '../../utils/constants'; import { Utils } from '../../utils/utils'; @@ -17,6 +18,8 @@ class DeleteRepoDialog extends Component { super(props); this.state = { isRequestSended: false, + sharedToUserCount: 0, + sharedToGroupCount: 0, }; } @@ -26,6 +29,15 @@ class DeleteRepoDialog extends Component { } } + componentDidMount() { + seafileAPI.getRepoShareInfo(this.props.repo.repo_id).then((res) => { + this.setState({ + sharedToUserCount: res.data['shared_user_emails'].length, + sharedToGroupCount: res.data['shared_group_ids'].length, + }); + }) + } + onDeleteRepo = () => { this.setState({isRequestSended: true}, () => { this.props.onDeleteRepo(this.props.repo); @@ -40,6 +52,10 @@ class DeleteRepoDialog extends Component { let message = gettext('Are you sure you want to delete %s ?'); message = message.replace('%s', repoName); + let alert_message = gettext('This library has been shared to {user_placeholder} users and {group_placeholder} groups.'); + alert_message = alert_message.replace('{user_placeholder}', this.state.sharedToUserCount); + alert_message = alert_message.replace('{group_placeholder}', this.state.sharedToGroupCount); + const { toggle: toggleDialog } = this.props; return ( @@ -47,6 +63,7 @@ class DeleteRepoDialog extends Component { {gettext('Delete Library')}

+

diff --git a/seahub/api2/endpoints/repos.py b/seahub/api2/endpoints/repos.py index a2c3347738..ea071ae626 100644 --- a/seahub/api2/endpoints/repos.py +++ b/seahub/api2/endpoints/repos.py @@ -24,7 +24,7 @@ from seahub.group.utils import group_id_to_name from seahub.utils import is_org_context, is_pro_version from seahub.utils.timeutils import timestamp_to_isoformat_timestr from seahub.utils.repo import get_repo_owner, is_repo_admin, \ - repo_has_been_shared_out, get_related_users_by_repo, normalize_repo_status_code + repo_has_been_shared_out, normalize_repo_status_code from seahub.settings import ENABLE_STORAGE_CLASSES @@ -36,7 +36,7 @@ logger = logging.getLogger(__name__) class ReposView(APIView): authentication_classes = (TokenAuthentication, SessionAuthentication) - permission_classes = (IsAuthenticated, ) + permission_classes = (IsAuthenticated,) throttle_classes = (UserRateThrottle,) def get(self, request): @@ -84,10 +84,11 @@ class ReposView(APIView): if org_id: owned_repos = seafile_api.get_org_owned_repo_list(org_id, - email, ret_corrupted=True) + email, + ret_corrupted=True) else: owned_repos = seafile_api.get_owned_repo_list(email, - ret_corrupted=True) + ret_corrupted=True) # Reduce memcache fetch ops. modifiers_set = {x.last_modifier for x in owned_repos} @@ -133,13 +134,11 @@ class ReposView(APIView): if org_id: shared_repos = seafile_api.get_org_share_in_repo_list(org_id, - email, -1, -1) + email, -1, -1) else: - shared_repos = seafile_api.get_share_in_repo_list( - email, -1, -1) + 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) + repos_with_admin_share_to = ExtraSharePermission.objects.get_repos_with_admin_permission(email) # Reduce memcache fetch ops. owners_set = {x.user for x in shared_repos} @@ -160,12 +159,10 @@ class ReposView(APIView): if '@seafile_group' in owner_email: is_group_owned_repo = True group_id = get_group_id_by_repo_owner(owner_email) - group_name= group_id_to_name(group_id) + group_name = group_id_to_name(group_id) - owner_name = group_name if is_group_owned_repo else \ - nickname_dict.get(owner_email, '') - owner_contact_email = '' if is_group_owned_repo else \ - contact_email_dict.get(owner_email, '') + owner_name = group_name if is_group_owned_repo else nickname_dict.get(owner_email, '') + owner_contact_email = '' if is_group_owned_repo else contact_email_dict.get(owner_email, '') repo_info = { "type": "shared", @@ -290,8 +287,8 @@ class ReposView(APIView): class RepoView(APIView): authentication_classes = (TokenAuthentication, SessionAuthentication) - permission_classes = (IsAuthenticated, ) - throttle_classes = (UserRateThrottle, ) + permission_classes = (IsAuthenticated,) + throttle_classes = (UserRateThrottle,) def get(self, request, repo_id): """ Return repo info @@ -395,3 +392,46 @@ class RepoView(APIView): repo_name=repo.name) return Response('success', status=status.HTTP_200_OK) + + +class RepoShareInfoView(APIView): + + authentication_classes = (TokenAuthentication, SessionAuthentication) + permission_classes = (IsAuthenticated,) + throttle_classes = (UserRateThrottle,) + + def get(self, request, repo_id): + """ Return repo share info + + Permission checking: + 1. all authenticated user can perform this action. + """ + + # resource check + repo = seafile_api.get_repo(repo_id) + if not repo: + error_msg = 'Library %s not found.' % repo_id + return api_error(status.HTTP_404_NOT_FOUND, error_msg) + + # permission check + permission = check_folder_permission(request, repo_id, '/') + if not permission: + error_msg = 'Permission denied.' + return api_error(status.HTTP_403_FORBIDDEN, error_msg) + + if is_org_context(request): + org_id = request.user.org.org_id + repo_owner = seafile_api.get_org_repo_owner(org_id, repo_id) + shared_users = seafile_api.list_org_repo_shared_to(repo_owner, repo_id) + shared_groups = seafile_api.list_org_repo_shared_group(org_id, repo_owner, repo_id) + else: + repo_owner = seafile_api.get_repo_owner(repo_id) + shared_users = seafile_api.list_repo_shared_to(repo_owner, repo_id) + shared_groups = seafile_api.list_repo_shared_group_by_user(repo_owner, repo_id) + + result = { + "shared_user_emails": [item.user for item in shared_users], + "shared_group_ids": [item.group_id for item in shared_groups], + } + + return Response(result) diff --git a/seahub/urls.py b/seahub/urls.py index 4978ae1602..bdb42ae176 100644 --- a/seahub/urls.py +++ b/seahub/urls.py @@ -50,7 +50,7 @@ from seahub.api2.endpoints.repos_batch import ReposBatchView, \ ReposAsyncBatchCopyItemView, ReposAsyncBatchMoveItemView, \ ReposSyncBatchCopyItemView, ReposSyncBatchMoveItemView, \ ReposBatchDeleteItemView -from seahub.api2.endpoints.repos import RepoView, ReposView +from seahub.api2.endpoints.repos import RepoView, ReposView, RepoShareInfoView from seahub.api2.endpoints.file import FileView from seahub.api2.endpoints.file_history import FileHistoryView, NewFileHistoryView from seahub.api2.endpoints.dir import DirView, DirDetailView @@ -404,6 +404,7 @@ urlpatterns = [ url(r'^api/v2.1/repos/(?P[-0-9a-f]{36})/share-links/(?P[a-f0-9]+)/$', RepoShareLink.as_view(), name='api-v2.1-repo-share-link'), url(r'^api/v2.1/repos/(?P[-0-9a-f]{36})/upload-links/$', RepoUploadLinks.as_view(), name='api-v2.1-repo-upload-links'), url(r'^api/v2.1/repos/(?P[-0-9a-f]{36})/upload-links/(?P[a-f0-9]+)/$', RepoUploadLink.as_view(), name='api-v2.1-repo-upload-link'), + url(r'^api/v2.1/repos/(?P[-0-9a-f]{36})/share-info/$', RepoShareInfoView.as_view(), name='api-v2.1-repo-share-info-view'), ## user:: repo-api-tokens url(r'^api/v2.1/repos/(?P[-0-9a-f]{36})/repo-api-tokens/$', RepoAPITokensView.as_view(), name='api-v2.1-repo-api-tokens'),