1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-07 18:03:48 +00:00

show share info when delete repo

This commit is contained in:
lian
2022-01-19 18:03:09 +08:00
parent 523f23fc93
commit 1e9193e573
3 changed files with 75 additions and 17 deletions

View File

@@ -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 {
<ModalHeader toggle={toggleDialog}>{gettext('Delete Library')}</ModalHeader>
<ModalBody>
<p dangerouslySetInnerHTML={{__html: message}}></p>
<p className="error" dangerouslySetInnerHTML={{__html: alert_message}}></p>
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={toggleDialog}>{gettext('Cancel')}</Button>

View File

@@ -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
@@ -84,7 +84,8 @@ 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)
@@ -135,11 +136,9 @@ class ReposView(APIView):
shared_repos = seafile_api.get_org_share_in_repo_list(org_id,
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}
@@ -162,10 +161,8 @@ class ReposView(APIView):
group_id = get_group_id_by_repo_owner(owner_email)
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",
@@ -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)

View File

@@ -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<repo_id>[-0-9a-f]{36})/share-links/(?P<token>[a-f0-9]+)/$', RepoShareLink.as_view(), name='api-v2.1-repo-share-link'),
url(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/upload-links/$', RepoUploadLinks.as_view(), name='api-v2.1-repo-upload-links'),
url(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/upload-links/(?P<token>[a-f0-9]+)/$', RepoUploadLink.as_view(), name='api-v2.1-repo-upload-link'),
url(r'^api/v2.1/repos/(?P<repo_id>[-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<repo_id>[-0-9a-f]{36})/repo-api-tokens/$', RepoAPITokensView.as_view(), name='api-v2.1-repo-api-tokens'),