2018-12-06 03:28:16 +00:00
|
|
|
import React, { Fragment } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Modal, ModalHeader, ModalBody, TabContent, TabPane, Nav, NavItem, NavLink } from 'reactstrap';
|
2020-04-01 10:03:46 +00:00
|
|
|
import { gettext, username, canGenerateShareLink, canGenerateUploadLink, canInvitePeople, additionalShareDialogNote } from '../../utils/constants';
|
2018-12-06 03:28:16 +00:00
|
|
|
import ShareToUser from './share-to-user';
|
|
|
|
import ShareToGroup from './share-to-group';
|
2019-11-18 09:55:17 +00:00
|
|
|
import ShareToInvitePeople from './share-to-invite-people';
|
2018-12-06 03:28:16 +00:00
|
|
|
import GenerateShareLink from './generate-share-link';
|
|
|
|
import GenerateUploadLink from './generate-upload-link';
|
2019-07-22 10:29:59 +00:00
|
|
|
import InternalLink from './internal-link';
|
2019-06-20 09:13:15 +00:00
|
|
|
import { seafileAPI } from '../../utils/seafile-api';
|
2019-06-20 10:23:13 +00:00
|
|
|
import Loading from '../loading';
|
2019-07-16 02:01:09 +00:00
|
|
|
import { Utils } from '../../utils/utils';
|
|
|
|
import toaster from '../toast';
|
2019-06-20 10:23:13 +00:00
|
|
|
import '../../css/share-link-dialog.css';
|
2018-12-06 03:28:16 +00:00
|
|
|
|
|
|
|
const propTypes = {
|
2018-12-14 13:39:17 +00:00
|
|
|
isGroupOwnedRepo: PropTypes.bool,
|
2018-12-14 07:49:24 +00:00
|
|
|
itemType: PropTypes.string.isRequired, // there will be three choose: ['library', 'dir', 'file']
|
2018-12-06 03:28:16 +00:00
|
|
|
itemName: PropTypes.string.isRequired,
|
2018-12-14 07:09:07 +00:00
|
|
|
itemPath: PropTypes.string.isRequired,
|
2018-12-06 03:28:16 +00:00
|
|
|
toggleDialog: PropTypes.func.isRequired,
|
2019-02-25 10:17:04 +00:00
|
|
|
repoID: PropTypes.string.isRequired,
|
|
|
|
repoEncrypted: PropTypes.bool,
|
|
|
|
userPerm: PropTypes.string,
|
|
|
|
enableDirPrivateShare: PropTypes.bool,
|
2018-12-06 03:28:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ShareDialog extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2019-06-20 09:13:15 +00:00
|
|
|
activeTab: this.getInitialActiveTab(),
|
2019-06-20 09:21:21 +00:00
|
|
|
isRepoJudgemented: false,
|
2019-06-20 09:13:15 +00:00
|
|
|
isRepoOwner: false,
|
2018-12-06 03:28:16 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-06-20 09:13:15 +00:00
|
|
|
componentDidMount() {
|
|
|
|
let repoID = this.props.repoID;
|
|
|
|
seafileAPI.getRepoInfo(repoID).then(res => {
|
|
|
|
let isRepoOwner = res.data.owner_email === username;
|
|
|
|
this.setState({
|
2019-06-20 09:21:21 +00:00
|
|
|
isRepoJudgemented: true,
|
2019-06-20 09:13:15 +00:00
|
|
|
isRepoOwner: isRepoOwner,
|
|
|
|
});
|
2019-07-16 02:01:09 +00:00
|
|
|
}).catch(error => {
|
|
|
|
let errMessage = Utils.getErrorMsg(error);
|
|
|
|
toaster.danger(errMessage);
|
2019-06-20 09:13:15 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-29 02:06:26 +00:00
|
|
|
getInitialActiveTab = () => {
|
2019-11-22 06:36:37 +00:00
|
|
|
const { repoEncrypted, userPerm, enableDirPrivateShare } = this.props;
|
2019-01-29 02:06:26 +00:00
|
|
|
const enableShareLink = !repoEncrypted && canGenerateShareLink;
|
|
|
|
const enableUploadLink = !repoEncrypted && canGenerateUploadLink && userPerm == 'rw';
|
|
|
|
|
|
|
|
if (enableShareLink) {
|
|
|
|
return 'shareLink';
|
|
|
|
} else if (enableUploadLink) {
|
|
|
|
return 'uploadLink';
|
|
|
|
} else if (enableDirPrivateShare) {
|
|
|
|
return 'shareToUser';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 03:28:16 +00:00
|
|
|
toggle = (tab) => {
|
|
|
|
if (this.state.activeTab !== tab) {
|
2019-11-22 06:36:37 +00:00
|
|
|
this.setState({ activeTab: tab });
|
2018-12-06 03:28:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderDirContent = () => {
|
2019-01-29 02:06:26 +00:00
|
|
|
|
2019-06-20 10:23:13 +00:00
|
|
|
if (!this.state.isRepoJudgemented) {
|
|
|
|
return <Loading />;
|
|
|
|
}
|
|
|
|
|
|
|
|
let activeTab = this.state.activeTab;
|
2019-11-22 06:36:37 +00:00
|
|
|
const { repoEncrypted, userPerm, enableDirPrivateShare, itemType } = this.props;
|
2019-01-29 02:06:26 +00:00
|
|
|
const enableShareLink = !repoEncrypted && canGenerateShareLink;
|
|
|
|
const enableUploadLink = !repoEncrypted && canGenerateUploadLink && userPerm == 'rw';
|
2019-07-22 10:29:59 +00:00
|
|
|
|
2018-12-06 03:28:16 +00:00
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<div className="share-dialog-side">
|
2018-12-06 06:39:21 +00:00
|
|
|
<Nav pills vertical>
|
2019-01-29 02:06:26 +00:00
|
|
|
{enableShareLink &&
|
2019-01-31 09:37:02 +00:00
|
|
|
<NavItem>
|
|
|
|
<NavLink className={activeTab === 'shareLink' ? 'active' : ''} onClick={this.toggle.bind(this, 'shareLink')}>
|
|
|
|
{gettext('Share Link')}
|
|
|
|
</NavLink>
|
|
|
|
</NavItem>
|
2019-01-29 02:06:26 +00:00
|
|
|
}
|
|
|
|
{enableUploadLink &&
|
2019-01-31 09:37:02 +00:00
|
|
|
<NavItem>
|
|
|
|
<NavLink className={activeTab === 'uploadLink' ? 'active' : ''} onClick={this.toggle.bind(this, 'uploadLink')}>
|
|
|
|
{gettext('Upload Link')}
|
|
|
|
</NavLink>
|
|
|
|
</NavItem>
|
2019-01-29 02:06:26 +00:00
|
|
|
}
|
2019-11-22 06:36:37 +00:00
|
|
|
{itemType === 'dir' &&
|
2019-08-12 06:04:14 +00:00
|
|
|
<NavItem>
|
|
|
|
<NavLink className={activeTab === 'internalLink' ? 'active' : ''} onClick={this.toggle.bind(this, 'internalLink')}>
|
|
|
|
{gettext('Internal Link')}
|
|
|
|
</NavLink>
|
|
|
|
</NavItem>
|
|
|
|
}
|
2019-01-29 02:06:26 +00:00
|
|
|
{enableDirPrivateShare &&
|
2019-01-31 09:37:02 +00:00
|
|
|
<Fragment>
|
|
|
|
<NavItem>
|
|
|
|
<NavLink className={activeTab === 'shareToUser' ? 'active' : ''} onClick={this.toggle.bind(this, 'shareToUser')}>
|
|
|
|
{gettext('Share to user')}
|
|
|
|
</NavLink>
|
|
|
|
</NavItem>
|
|
|
|
<NavItem>
|
|
|
|
<NavLink className={activeTab === 'shareToGroup' ? 'active' : ''} onClick={this.toggle.bind(this, 'shareToGroup')}>
|
|
|
|
{gettext('Share to group')}
|
|
|
|
</NavLink>
|
|
|
|
</NavItem>
|
2019-11-18 09:55:17 +00:00
|
|
|
{canInvitePeople &&
|
2019-11-22 06:36:37 +00:00
|
|
|
<NavItem>
|
|
|
|
<NavLink className={activeTab === 'invitePeople' ? 'active' : ''} onClick={this.toggle.bind(this, 'invitePeople')}>
|
2020-01-03 08:50:17 +00:00
|
|
|
{gettext('Invite Guest')}
|
2019-11-22 06:36:37 +00:00
|
|
|
</NavLink>
|
|
|
|
</NavItem>
|
2019-11-18 09:55:17 +00:00
|
|
|
}
|
2019-01-31 09:37:02 +00:00
|
|
|
</Fragment>
|
2019-01-29 02:06:26 +00:00
|
|
|
}
|
2018-12-06 03:28:16 +00:00
|
|
|
</Nav>
|
|
|
|
</div>
|
|
|
|
<div className="share-dialog-main">
|
|
|
|
<TabContent activeTab={this.state.activeTab}>
|
2019-11-22 06:36:37 +00:00
|
|
|
{(enableShareLink && activeTab === 'shareLink') &&
|
2019-01-31 09:37:02 +00:00
|
|
|
<TabPane tabId="shareLink">
|
2019-11-22 06:36:37 +00:00
|
|
|
<GenerateShareLink
|
|
|
|
itemPath={this.props.itemPath}
|
2019-01-31 09:37:02 +00:00
|
|
|
repoID={this.props.repoID}
|
2019-11-22 06:36:37 +00:00
|
|
|
closeShareDialog={this.props.toggleDialog}
|
2019-10-12 06:54:25 +00:00
|
|
|
itemType={itemType}
|
2019-02-25 10:17:04 +00:00
|
|
|
/>
|
2019-01-31 09:37:02 +00:00
|
|
|
</TabPane>
|
2019-01-29 02:06:26 +00:00
|
|
|
}
|
2019-11-22 06:36:37 +00:00
|
|
|
{(enableUploadLink && activeTab === 'uploadLink') &&
|
2019-01-31 09:37:02 +00:00
|
|
|
<TabPane tabId="uploadLink">
|
2019-11-22 06:36:37 +00:00
|
|
|
<GenerateUploadLink
|
|
|
|
itemPath={this.props.itemPath}
|
|
|
|
repoID={this.props.repoID}
|
|
|
|
closeShareDialog={this.props.toggleDialog}
|
2019-01-31 09:37:02 +00:00
|
|
|
/>
|
|
|
|
</TabPane>
|
2019-01-29 02:06:26 +00:00
|
|
|
}
|
2019-11-22 06:36:37 +00:00
|
|
|
{(itemType === 'dir' && activeTab === 'internalLink') &&
|
|
|
|
<InternalLink
|
|
|
|
path={this.props.itemPath}
|
|
|
|
repoID={this.props.repoID}
|
2019-08-05 09:31:15 +00:00
|
|
|
direntType={itemType}
|
|
|
|
/>
|
2019-08-12 06:04:14 +00:00
|
|
|
}
|
2019-01-29 02:06:26 +00:00
|
|
|
{enableDirPrivateShare &&
|
2019-01-31 09:37:02 +00:00
|
|
|
<Fragment>
|
2019-11-22 06:36:37 +00:00
|
|
|
{activeTab === 'shareToUser' &&
|
|
|
|
<TabPane tabId="shareToUser">
|
|
|
|
<ShareToUser itemType={this.props.itemType} isGroupOwnedRepo={this.props.isGroupOwnedRepo} itemPath={this.props.itemPath} repoID={this.props.repoID} isRepoOwner={this.state.isRepoOwner} />
|
|
|
|
</TabPane>
|
|
|
|
}
|
|
|
|
{activeTab === 'shareToGroup' &&
|
|
|
|
<TabPane tabId="shareToGroup">
|
|
|
|
<ShareToGroup itemType={this.props.itemType} isGroupOwnedRepo={this.props.isGroupOwnedRepo} itemPath={this.props.itemPath} repoID={this.props.repoID} isRepoOwner={this.state.isRepoOwner} />
|
|
|
|
</TabPane>
|
|
|
|
}
|
|
|
|
{(canInvitePeople && activeTab === 'invitePeople') &&
|
|
|
|
<TabPane tabId="invitePeople">
|
|
|
|
<ShareToInvitePeople itemPath={this.props.itemPath} repoID={this.props.repoID} />
|
|
|
|
</TabPane>
|
2019-11-18 09:55:17 +00:00
|
|
|
}
|
2019-01-31 09:37:02 +00:00
|
|
|
</Fragment>
|
2019-01-29 02:06:26 +00:00
|
|
|
}
|
2018-12-06 03:28:16 +00:00
|
|
|
</TabContent>
|
|
|
|
</div>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderFileContent = () => {
|
2019-07-22 10:29:59 +00:00
|
|
|
let activeTab = this.state.activeTab;
|
2019-10-12 06:54:25 +00:00
|
|
|
const { itemType } = this.props;
|
2019-07-22 10:29:59 +00:00
|
|
|
|
2018-12-06 03:28:16 +00:00
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<div className="share-dialog-side">
|
2018-12-06 06:39:21 +00:00
|
|
|
<Nav pills vertical>
|
2018-12-06 03:28:16 +00:00
|
|
|
<NavItem>
|
2019-07-22 10:29:59 +00:00
|
|
|
<NavLink className={activeTab === 'shareLink' ? 'active' : ''} onClick={(this.toggle.bind(this, 'shareLink'))}>
|
2018-12-06 03:28:16 +00:00
|
|
|
{gettext('Share Link')}
|
|
|
|
</NavLink>
|
|
|
|
</NavItem>
|
2019-07-22 10:29:59 +00:00
|
|
|
<NavItem>
|
|
|
|
<NavLink className={activeTab === 'internalLink' ? 'active' : ''} onClick={this.toggle.bind(this, 'internalLink')}>
|
|
|
|
{gettext('Internal Link')}
|
|
|
|
</NavLink>
|
|
|
|
</NavItem>
|
2018-12-06 03:28:16 +00:00
|
|
|
</Nav>
|
|
|
|
</div>
|
|
|
|
<div className="share-dialog-main">
|
|
|
|
<TabContent activeTab={this.state.activeTab}>
|
2019-11-22 06:36:37 +00:00
|
|
|
{activeTab === 'shareLink' &&
|
|
|
|
<TabPane tabId="shareLink">
|
|
|
|
<GenerateShareLink
|
|
|
|
itemPath={this.props.itemPath}
|
|
|
|
repoID={this.props.repoID}
|
|
|
|
closeShareDialog={this.props.toggleDialog}
|
|
|
|
itemType={itemType}
|
|
|
|
/>
|
|
|
|
</TabPane>
|
|
|
|
}
|
2019-08-12 06:04:14 +00:00
|
|
|
{activeTab === 'internalLink' &&
|
2019-11-22 06:36:37 +00:00
|
|
|
<InternalLink
|
|
|
|
path={this.props.itemPath}
|
|
|
|
repoID={this.props.repoID}
|
2019-07-22 10:29:59 +00:00
|
|
|
/>
|
2019-08-12 06:04:14 +00:00
|
|
|
}
|
2018-12-06 03:28:16 +00:00
|
|
|
</TabContent>
|
|
|
|
</div>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-03-25 10:03:04 +00:00
|
|
|
renderExternalShareMessage = () => {
|
2020-04-01 09:55:59 +00:00
|
|
|
if (additionalShareDialogNote && (typeof additionalShareDialogNote) === 'object') {
|
2020-03-25 10:03:04 +00:00
|
|
|
return (
|
|
|
|
<div className="external-share-message mt-2">
|
2020-04-01 09:55:59 +00:00
|
|
|
<h6>{additionalShareDialogNote.title}</h6>
|
|
|
|
<div style={{fontSize: '14px', color: '#666'}}>{additionalShareDialogNote.content}</div>
|
2020-03-25 10:03:04 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-12-06 03:28:16 +00:00
|
|
|
render() {
|
2019-01-29 02:06:26 +00:00
|
|
|
const { itemType, itemName, repoEncrypted } = this.props;
|
|
|
|
const enableShareLink = !repoEncrypted && canGenerateShareLink;
|
2018-12-06 03:28:16 +00:00
|
|
|
return (
|
|
|
|
<div>
|
2019-03-07 04:23:44 +00:00
|
|
|
<Modal isOpen={true} style={{maxWidth: '720px'}} className="share-dialog" toggle={this.props.toggleDialog}>
|
2020-03-25 10:03:04 +00:00
|
|
|
<ModalHeader toggle={this.props.toggleDialog}>
|
|
|
|
{gettext('Share')} <span className="op-target" title={itemName}>{itemName}</span>
|
|
|
|
{this.renderExternalShareMessage()}
|
|
|
|
</ModalHeader>
|
2019-05-13 08:28:52 +00:00
|
|
|
<ModalBody className="share-dialog-content">
|
2018-12-14 07:09:07 +00:00
|
|
|
{(itemType === 'library' || itemType === 'dir') && this.renderDirContent()}
|
2019-01-29 02:06:26 +00:00
|
|
|
{(itemType === 'file' && enableShareLink) && this.renderFileContent()}
|
2018-12-06 03:28:16 +00:00
|
|
|
</ModalBody>
|
|
|
|
</Modal>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ShareDialog.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default ShareDialog;
|