mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-13 22:01:06 +00:00
[file view] added 'share' (#3108)
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import React from 'react';
|
||||
import React, { Fragment } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { ButtonGroup } from 'reactstrap';
|
||||
import IconButton from '../icon-button';
|
||||
import { gettext, siteRoot } from '../../utils/constants';
|
||||
import { Utils } from '../../utils/utils';
|
||||
import ModalPortal from '../modal-portal';
|
||||
import ShareDialog from '../dialog/share-dialog';
|
||||
|
||||
const propTypes = {
|
||||
isLocked: PropTypes.bool.isRequired,
|
||||
@@ -13,8 +15,9 @@ const propTypes = {
|
||||
};
|
||||
|
||||
const {
|
||||
canLockUnlockFile,
|
||||
repoID, repoName, parentDir, filePerm, filePath,
|
||||
canLockUnlockFile, canGenerateShareLink,
|
||||
repoID, repoName, repoEncrypted, parentDir, filePerm, filePath,
|
||||
fileName,
|
||||
canEditFile, err,
|
||||
fileEnc, // for 'edit', not undefined only for some kinds of files (e.g. text file)
|
||||
canDownloadFile, enableComment
|
||||
@@ -22,6 +25,17 @@ const {
|
||||
|
||||
class FileToolbar extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
isShareDialogOpen: false
|
||||
};
|
||||
}
|
||||
|
||||
toggleShareDialog = () => {
|
||||
this.setState({isShareDialogOpen: !this.state.isShareDialogOpen});
|
||||
}
|
||||
|
||||
render() {
|
||||
const { isLocked, lockedByMe } = this.props;
|
||||
|
||||
@@ -38,7 +52,15 @@ class FileToolbar extends React.Component {
|
||||
lockUnlockIcon = 'fa fa-unlock';
|
||||
}
|
||||
}
|
||||
|
||||
let showShareBtn = false;
|
||||
if (!repoEncrypted &&
|
||||
(filePerm == 'rw' || filePerm == 'r') && canGenerateShareLink) {
|
||||
showShareBtn = true;
|
||||
}
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<ButtonGroup className="align-self-center">
|
||||
<IconButton
|
||||
id="open-parent-folder"
|
||||
@@ -55,6 +77,14 @@ class FileToolbar extends React.Component {
|
||||
onClick={this.props.toggleLockFile}
|
||||
/>
|
||||
)}
|
||||
{showShareBtn && (
|
||||
<IconButton
|
||||
id="share-file"
|
||||
icon='fa fa-share-alt'
|
||||
text={gettext('Share')}
|
||||
onClick={this.toggleShareDialog}
|
||||
/>
|
||||
)}
|
||||
{filePerm == 'rw' && (
|
||||
<IconButton
|
||||
id="history"
|
||||
@@ -91,6 +121,21 @@ class FileToolbar extends React.Component {
|
||||
/>
|
||||
)}
|
||||
</ButtonGroup>
|
||||
|
||||
{this.state.isShareDialogOpen &&
|
||||
<ModalPortal>
|
||||
<ShareDialog
|
||||
itemType='file'
|
||||
itemName={fileName}
|
||||
itemPath={filePath}
|
||||
userPerm={filePerm}
|
||||
repoID={repoID}
|
||||
repoEncrypted={false}
|
||||
toggleDialog={this.toggleShareDialog}
|
||||
/>
|
||||
</ModalPortal>
|
||||
}
|
||||
</Fragment>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -10,6 +10,10 @@ window.app.pageOptions = {
|
||||
username: '{{ user.username|escapejs }}',
|
||||
userNickName: '{{request.user.username|email2nickname|escapejs}}',
|
||||
|
||||
canGenerateShareLink: {% if user.permissions.can_generate_share_link %} true {% else %} false {% endif %},
|
||||
shareLinkExpireDaysMin: {{ share_link_expire_days_min }},
|
||||
shareLinkExpireDaysMax: {{ share_link_expire_days_max }},
|
||||
|
||||
// for all types of files
|
||||
fileName: '{{ filename|escapejs }}',
|
||||
isStarred: {% if is_starred %}true{% else %}false{% endif %},
|
||||
@@ -19,6 +23,7 @@ window.app.pageOptions = {
|
||||
lastModificationTime: '{{ last_modified }}',
|
||||
repoID: '{{ repo.id }}',
|
||||
repoName: '{{ repo.name|escapejs }}',
|
||||
repoEncrypted: {% if repo.encrypted %}true{% else %}false{% endif %},
|
||||
filePath: '{{ path|escapejs }}',
|
||||
filePerm: '{{ file_perm }}',
|
||||
parentDir: '{{ parent_dir|escapejs }}',
|
||||
|
@@ -512,6 +512,8 @@ def view_lib_file(request, repo_id, path):
|
||||
'highlight_keyword': settings.HIGHLIGHT_KEYWORD,
|
||||
'enable_file_comment': settings.ENABLE_FILE_COMMENT,
|
||||
'enable_watermark': ENABLE_WATERMARK,
|
||||
'share_link_expire_days_min': SHARE_LINK_EXPIRE_DAYS_MIN,
|
||||
'share_link_expire_days_max': SHARE_LINK_EXPIRE_DAYS_MAX,
|
||||
'can_download_file': parse_repo_perm(permission).can_download,
|
||||
'seafile_collab_server': SEAFILE_COLLAB_SERVER,
|
||||
}
|
||||
|
Reference in New Issue
Block a user