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:
@@ -1,5 +1,6 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import { seafileAPI } from '../../utils/seafile-api';
|
||||||
import { Modal, ModalHeader, ModalBody, ModalFooter, Button } from 'reactstrap';
|
import { Modal, ModalHeader, ModalBody, ModalFooter, Button } from 'reactstrap';
|
||||||
import { gettext } from '../../utils/constants';
|
import { gettext } from '../../utils/constants';
|
||||||
import { Utils } from '../../utils/utils';
|
import { Utils } from '../../utils/utils';
|
||||||
@@ -17,6 +18,8 @@ class DeleteRepoDialog extends Component {
|
|||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
isRequestSended: false,
|
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 = () => {
|
onDeleteRepo = () => {
|
||||||
this.setState({isRequestSended: true}, () => {
|
this.setState({isRequestSended: true}, () => {
|
||||||
this.props.onDeleteRepo(this.props.repo);
|
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 ?');
|
let message = gettext('Are you sure you want to delete %s ?');
|
||||||
message = message.replace('%s', repoName);
|
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;
|
const { toggle: toggleDialog } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -47,6 +63,7 @@ class DeleteRepoDialog extends Component {
|
|||||||
<ModalHeader toggle={toggleDialog}>{gettext('Delete Library')}</ModalHeader>
|
<ModalHeader toggle={toggleDialog}>{gettext('Delete Library')}</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<p dangerouslySetInnerHTML={{__html: message}}></p>
|
<p dangerouslySetInnerHTML={{__html: message}}></p>
|
||||||
|
<p className="error" dangerouslySetInnerHTML={{__html: alert_message}}></p>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button color="secondary" onClick={toggleDialog}>{gettext('Cancel')}</Button>
|
<Button color="secondary" onClick={toggleDialog}>{gettext('Cancel')}</Button>
|
||||||
|
@@ -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 import is_org_context, is_pro_version
|
||||||
from seahub.utils.timeutils import timestamp_to_isoformat_timestr
|
from seahub.utils.timeutils import timestamp_to_isoformat_timestr
|
||||||
from seahub.utils.repo import get_repo_owner, is_repo_admin, \
|
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
|
from seahub.settings import ENABLE_STORAGE_CLASSES
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ logger = logging.getLogger(__name__)
|
|||||||
class ReposView(APIView):
|
class ReposView(APIView):
|
||||||
|
|
||||||
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
||||||
permission_classes = (IsAuthenticated, )
|
permission_classes = (IsAuthenticated,)
|
||||||
throttle_classes = (UserRateThrottle,)
|
throttle_classes = (UserRateThrottle,)
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
@@ -84,10 +84,11 @@ class ReposView(APIView):
|
|||||||
|
|
||||||
if org_id:
|
if org_id:
|
||||||
owned_repos = seafile_api.get_org_owned_repo_list(org_id,
|
owned_repos = seafile_api.get_org_owned_repo_list(org_id,
|
||||||
email, ret_corrupted=True)
|
email,
|
||||||
|
ret_corrupted=True)
|
||||||
else:
|
else:
|
||||||
owned_repos = seafile_api.get_owned_repo_list(email,
|
owned_repos = seafile_api.get_owned_repo_list(email,
|
||||||
ret_corrupted=True)
|
ret_corrupted=True)
|
||||||
|
|
||||||
# Reduce memcache fetch ops.
|
# Reduce memcache fetch ops.
|
||||||
modifiers_set = {x.last_modifier for x in owned_repos}
|
modifiers_set = {x.last_modifier for x in owned_repos}
|
||||||
@@ -133,13 +134,11 @@ class ReposView(APIView):
|
|||||||
|
|
||||||
if org_id:
|
if org_id:
|
||||||
shared_repos = seafile_api.get_org_share_in_repo_list(org_id,
|
shared_repos = seafile_api.get_org_share_in_repo_list(org_id,
|
||||||
email, -1, -1)
|
email, -1, -1)
|
||||||
else:
|
else:
|
||||||
shared_repos = seafile_api.get_share_in_repo_list(
|
shared_repos = seafile_api.get_share_in_repo_list(email, -1, -1)
|
||||||
email, -1, -1)
|
|
||||||
|
|
||||||
repos_with_admin_share_to = ExtraSharePermission.objects.\
|
repos_with_admin_share_to = ExtraSharePermission.objects.get_repos_with_admin_permission(email)
|
||||||
get_repos_with_admin_permission(email)
|
|
||||||
|
|
||||||
# Reduce memcache fetch ops.
|
# Reduce memcache fetch ops.
|
||||||
owners_set = {x.user for x in shared_repos}
|
owners_set = {x.user for x in shared_repos}
|
||||||
@@ -160,12 +159,10 @@ class ReposView(APIView):
|
|||||||
if '@seafile_group' in owner_email:
|
if '@seafile_group' in owner_email:
|
||||||
is_group_owned_repo = True
|
is_group_owned_repo = True
|
||||||
group_id = get_group_id_by_repo_owner(owner_email)
|
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 \
|
owner_name = group_name if is_group_owned_repo else nickname_dict.get(owner_email, '')
|
||||||
nickname_dict.get(owner_email, '')
|
owner_contact_email = '' if is_group_owned_repo else contact_email_dict.get(owner_email, '')
|
||||||
owner_contact_email = '' if is_group_owned_repo else \
|
|
||||||
contact_email_dict.get(owner_email, '')
|
|
||||||
|
|
||||||
repo_info = {
|
repo_info = {
|
||||||
"type": "shared",
|
"type": "shared",
|
||||||
@@ -290,8 +287,8 @@ class ReposView(APIView):
|
|||||||
class RepoView(APIView):
|
class RepoView(APIView):
|
||||||
|
|
||||||
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
||||||
permission_classes = (IsAuthenticated, )
|
permission_classes = (IsAuthenticated,)
|
||||||
throttle_classes = (UserRateThrottle, )
|
throttle_classes = (UserRateThrottle,)
|
||||||
|
|
||||||
def get(self, request, repo_id):
|
def get(self, request, repo_id):
|
||||||
""" Return repo info
|
""" Return repo info
|
||||||
@@ -395,3 +392,46 @@ class RepoView(APIView):
|
|||||||
repo_name=repo.name)
|
repo_name=repo.name)
|
||||||
|
|
||||||
return Response('success', status=status.HTTP_200_OK)
|
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)
|
||||||
|
@@ -50,7 +50,7 @@ from seahub.api2.endpoints.repos_batch import ReposBatchView, \
|
|||||||
ReposAsyncBatchCopyItemView, ReposAsyncBatchMoveItemView, \
|
ReposAsyncBatchCopyItemView, ReposAsyncBatchMoveItemView, \
|
||||||
ReposSyncBatchCopyItemView, ReposSyncBatchMoveItemView, \
|
ReposSyncBatchCopyItemView, ReposSyncBatchMoveItemView, \
|
||||||
ReposBatchDeleteItemView
|
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 import FileView
|
||||||
from seahub.api2.endpoints.file_history import FileHistoryView, NewFileHistoryView
|
from seahub.api2.endpoints.file_history import FileHistoryView, NewFileHistoryView
|
||||||
from seahub.api2.endpoints.dir import DirView, DirDetailView
|
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})/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/$', 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})/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
|
## 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'),
|
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'),
|
||||||
|
Reference in New Issue
Block a user