mirror of
https://github.com/haiwen/seahub.git
synced 2025-07-12 22:49:15 +00:00
repair invalid bug
This commit is contained in:
parent
8c49e44c89
commit
ad6faba6bc
@ -14,9 +14,10 @@ class GenerateShareLink extends React.Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
passwordVisible: false,
|
|
||||||
showPasswordInput: false,
|
|
||||||
isValidate: false,
|
isValidate: false,
|
||||||
|
isShowPasswordInput: false,
|
||||||
|
isPasswordVisible: false,
|
||||||
|
isExpireChecked: false,
|
||||||
password: '',
|
password: '',
|
||||||
passwdnew: '',
|
passwdnew: '',
|
||||||
expireDays: '',
|
expireDays: '',
|
||||||
@ -28,6 +29,7 @@ class GenerateShareLink extends React.Component {
|
|||||||
'can_edit': false,
|
'can_edit': false,
|
||||||
'can_download': true
|
'can_download': true
|
||||||
};
|
};
|
||||||
|
this.isExpireDaysNoLimit = (parseInt(shareLinkExpireDaysMin) === 0 && parseInt(shareLinkExpireDaysMax) === 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -47,9 +49,9 @@ class GenerateShareLink extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addPassword = () => {
|
onPasswordInputChecked = () => {
|
||||||
this.setState({
|
this.setState({
|
||||||
showPasswordInput: !this.state.showPasswordInput,
|
isShowPasswordInput: !this.state.isShowPasswordInput,
|
||||||
password: '',
|
password: '',
|
||||||
passwdnew: '',
|
passwdnew: '',
|
||||||
errorInfo: ''
|
errorInfo: ''
|
||||||
@ -58,7 +60,7 @@ class GenerateShareLink extends React.Component {
|
|||||||
|
|
||||||
togglePasswordVisible = () => {
|
togglePasswordVisible = () => {
|
||||||
this.setState({
|
this.setState({
|
||||||
passwordVisible: !this.state.passwordVisible
|
isPasswordVisible: !this.state.isPasswordVisible
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,20 +68,16 @@ class GenerateShareLink extends React.Component {
|
|||||||
let val = Math.random().toString(36).substr(5);
|
let val = Math.random().toString(36).substr(5);
|
||||||
this.setState({
|
this.setState({
|
||||||
password: val,
|
password: val,
|
||||||
passwordnew: val
|
passwdnew: val
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
inputPassword = (e) => {
|
inputPassword = (e) => {
|
||||||
this.setState({
|
this.setState({password: e.target.value});
|
||||||
password: e.target.value
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inputPasswordNew = (e) => {
|
inputPasswordNew = (e) => {
|
||||||
this.setState({
|
this.setState({passwdnew: e.target.value});
|
||||||
passwordnew: e.target.value
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setPermission = (permission) => {
|
setPermission = (permission) => {
|
||||||
@ -97,35 +95,13 @@ class GenerateShareLink extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
generateShareLink = () => {
|
generateShareLink = () => {
|
||||||
let path = this.props.itemPath;
|
let isValid = this.validateParamsInput();
|
||||||
let repoID = this.props.repoID;
|
if (isValid) {
|
||||||
if (this.state.showPasswordInput && (this.state.password == '')) {
|
let { itemPath, repoID } = this.props;
|
||||||
this.setState({
|
|
||||||
errorInfo: gettext('Please enter password')
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (this.state.showPasswordInput && (this.state.showPasswordInput && this.state.password.length < 8)) {
|
|
||||||
this.setState({
|
|
||||||
errorInfo: gettext('Password is too short')
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (this.state.showPasswordInput && (this.state.password !== this.state.passwordnew)) {
|
|
||||||
this.setState({
|
|
||||||
errorInfo: gettext('Passwords don\'t match')
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (this.state.expireDays === '') {
|
|
||||||
this.setState({
|
|
||||||
errorInfo: gettext('Please enter days')
|
|
||||||
});
|
|
||||||
} else if (!this.state.isValidate) {
|
|
||||||
// errMessage had been setted
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
let { password, expireDays } = this.state;
|
let { password, expireDays } = this.state;
|
||||||
let permissions = this.permissions;
|
let permissions = this.permissions;
|
||||||
permissions = JSON.stringify(permissions);
|
permissions = JSON.stringify(permissions);
|
||||||
seafileAPI.createShareLink(repoID, path, password, expireDays, permissions).then((res) => {
|
seafileAPI.createShareLink(repoID, itemPath, password, expireDays, permissions).then((res) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
link: res.data.link,
|
link: res.data.link,
|
||||||
token: res.data.token
|
token: res.data.token
|
||||||
@ -139,49 +115,100 @@ class GenerateShareLink extends React.Component {
|
|||||||
this.setState({
|
this.setState({
|
||||||
link: '',
|
link: '',
|
||||||
token: '',
|
token: '',
|
||||||
showPasswordInput: false,
|
|
||||||
password: '',
|
password: '',
|
||||||
passwordnew: '',
|
passwordnew: '',
|
||||||
|
isShowPasswordInput: false,
|
||||||
|
expireDays: '',
|
||||||
|
isExpireChecked: false,
|
||||||
});
|
});
|
||||||
this.permissions = {
|
this.permissions = {
|
||||||
'can_edit': false,
|
'can_edit': false,
|
||||||
'can_download': true
|
'can_download': true
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onExpireHandler = (e) => {
|
onExpireChecked = (e) => {
|
||||||
let day = e.target.value;
|
this.setState({isExpireChecked: e.target.checked});
|
||||||
|
}
|
||||||
|
|
||||||
|
onExpireDaysChanged = (e) => {
|
||||||
|
this.setState({expireDays: e.target.value});
|
||||||
|
}
|
||||||
|
|
||||||
|
validateParamsInput = () => {
|
||||||
|
let { isShowPasswordInput , password, passwdnew, isExpireChecked, expireDays } = this.state;
|
||||||
|
// validate password
|
||||||
|
if (isShowPasswordInput) {
|
||||||
|
if (password.length === 0) {
|
||||||
|
this.setState({errorInfo: 'Please enter password'});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (password.length < 8) {
|
||||||
|
this.setState({errorInfo: 'Password is too short'});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (password !== passwdnew) {
|
||||||
|
this.setState({errorInfo: 'Passwords don\'t match'});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate days
|
||||||
|
// no limit
|
||||||
let reg = /^\d+$/;
|
let reg = /^\d+$/;
|
||||||
let flag = reg.test(day);
|
if (this.isExpireDaysNoLimit) {
|
||||||
if (!flag) {
|
if (isExpireChecked) {
|
||||||
this.setState({
|
if (!expireDays) {
|
||||||
isValidate: false,
|
this.setState({errorInfo: gettext('Please enter days')});
|
||||||
errorInfo: gettext('Please enter a non-negative integer'),
|
return false;
|
||||||
expireDays: day,
|
}
|
||||||
});
|
let flag = reg.test(expireDays);
|
||||||
return;
|
if (!flag) {
|
||||||
}
|
this.setState({errorInfo: 'Please enter a non-negative integer'});
|
||||||
|
return false;
|
||||||
day = parseInt(day);
|
}
|
||||||
|
this.setState({expireDays: parseInt(expireDays)});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!expireDays) {
|
||||||
|
this.setState({errorInfo: gettext('Please enter days')});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let flag = reg.test(expireDays);
|
||||||
|
if (!flag) {
|
||||||
|
this.setState({errorInfo: 'Please enter a non-negative integer'});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (day < shareLinkExpireDaysMin || day > shareLinkExpireDaysMax) {
|
expireDays = parseInt(expireDays);
|
||||||
let errorMessage = gettext('Please enter a value between day1 and day2');
|
let minDays = parseInt(shareLinkExpireDaysMin);
|
||||||
errorMessage = errorMessage.replace('day1', shareLinkExpireDaysMin);
|
let maxDays = parseInt(shareLinkExpireDaysMax);
|
||||||
errorMessage = errorMessage.replace('day2', shareLinkExpireDaysMax);
|
|
||||||
this.setState({
|
if (minDays !== 0 && maxDays !== maxDays) {
|
||||||
isValidate: false,
|
if (expireDays < minDays) {
|
||||||
errorInfo: errorMessage,
|
this.setState({errorInfo: 'Please enter valid days'});
|
||||||
expireDays: day
|
return false;
|
||||||
});
|
}
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
if (minDays === 0 && maxDays !== 0 ) {
|
||||||
|
if (expireDays > maxDays) {
|
||||||
|
this.setState({errorInfo: 'Please enter valid days'});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minDays !== 0 && maxDays !== 0) {
|
||||||
|
if (expireDays < minDays || expireDays < maxDays) {
|
||||||
|
this.setState({errorInfo: 'Please enter valid days'});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.setState({expireDays: expireDays});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({
|
return true;
|
||||||
isValidate: true,
|
|
||||||
errorInfo: '',
|
|
||||||
expireDays: day
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -197,35 +224,48 @@ class GenerateShareLink extends React.Component {
|
|||||||
<Form className="generate-share-link">
|
<Form className="generate-share-link">
|
||||||
<FormGroup check>
|
<FormGroup check>
|
||||||
<Label check>
|
<Label check>
|
||||||
<Input type="checkbox" onChange={this.addPassword}/>{' '}{gettext('Add password protection')}
|
<Input type="checkbox" onChange={this.onPasswordInputChecked}/>{' '}{gettext('Add password protection')}
|
||||||
</Label>
|
</Label>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
{this.state.showPasswordInput &&
|
{this.state.isShowPasswordInput &&
|
||||||
<FormGroup className="link-operation-content">
|
<FormGroup className="link-operation-content">
|
||||||
<Label>{gettext('Password')}</Label><span className="tip"> ({gettext('at least 8 characters')}) </span>
|
<Label>{gettext('Password')}</Label><span className="tip"> ({gettext('at least 8 characters')}) </span>
|
||||||
<InputGroup className="passwd">
|
<InputGroup className="passwd">
|
||||||
<Input type={this.state.passwordVisible ? 'text' : 'password'} value={this.state.password || ''} onChange={this.inputPassword}/>
|
<Input type={this.state.isPasswordVisible ? 'text' : 'password'} value={this.state.password || ''} onChange={this.inputPassword}/>
|
||||||
<InputGroupAddon addonType="append">
|
<InputGroupAddon addonType="append">
|
||||||
<Button onClick={this.togglePasswordVisible}><i className={`link-operation-icon fas ${this.state.passwordVisible ? 'fa-eye': 'fa-eye-slash'}`}></i></Button>
|
<Button onClick={this.togglePasswordVisible}><i className={`link-operation-icon fas ${this.state.isPasswordVisible ? 'fa-eye': 'fa-eye-slash'}`}></i></Button>
|
||||||
<Button onClick={this.generatePassword}><i className="link-operation-icon fas fa-magic"></i></Button>
|
<Button onClick={this.generatePassword}><i className="link-operation-icon fas fa-magic"></i></Button>
|
||||||
</InputGroupAddon>
|
</InputGroupAddon>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
<Label>{gettext('Password again')}</Label>
|
<Label>{gettext('Password again')}</Label>
|
||||||
<Input className="passwd" type={this.state.passwordVisible ? 'text' : 'password'} value={this.state.passwordnew || ''} onChange={this.inputPasswordNew} />
|
<Input className="passwd" type={this.state.isPasswordVisible ? 'text' : 'password'} value={this.state.passwdnew || ''} onChange={this.inputPasswordNew} />
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
}
|
}
|
||||||
<FormGroup check>
|
{this.isExpireDaysNoLimit && (
|
||||||
<Label check>
|
<FormGroup check>
|
||||||
<Input className="expire-checkbox" type="checkbox" checked readOnly/>{' '}{gettext('Add auto expiration')}
|
<Label check>
|
||||||
<Input className="expire-input" type="text" value={this.state.expireDays} onChange={this.onExpireHandler}/> <span>{gettext('days')}</span>
|
<Input className="expire-checkbox" type="checkbox" onChange={this.onExpireChecked}/>{' '}{gettext('Add auto expiration')}
|
||||||
{parseInt(shareLinkExpireDaysMin) === 0 && parseInt(shareLinkExpireDaysMax) === 0 && (
|
<Input className="expire-input" type="text" value={this.state.expireDays} onChange={this.onExpireDaysChanged} readOnly={!this.state.isExpireChecked}/><span>{gettext('days')}</span>
|
||||||
<span> ({gettext('no limit')})</span>
|
</Label>
|
||||||
)}
|
</FormGroup>
|
||||||
{parseInt(shareLinkExpireDaysMax) !== 0 && (
|
)}
|
||||||
<span> ({shareLinkExpireDaysMin} - {shareLinkExpireDaysMax}{gettext('days')})</span>
|
{!this.isExpireDaysNoLimit && (
|
||||||
)}
|
<FormGroup check>
|
||||||
</Label>
|
<Label check>
|
||||||
</FormGroup>
|
<Input className="expire-checkbox" type="checkbox" onChange={this.onExpireChecked} checked readOnly/>{' '}{gettext('Add auto expiration')}
|
||||||
|
<Input className="expire-input" type="text" value={this.state.expireDays} onChange={this.onExpireDaysChanged} /> <span>{gettext('days')}</span>
|
||||||
|
{(parseInt(shareLinkExpireDaysMin) !== 0 && parseInt(shareLinkExpireDaysMax) !== 0) && (
|
||||||
|
<span> ({shareLinkExpireDaysMin} - {shareLinkExpireDaysMax}{' '}{gettext('days')})</span>
|
||||||
|
)}
|
||||||
|
{(parseInt(shareLinkExpireDaysMin) !== 0 && parseInt(shareLinkExpireDaysMax) === 0) && (
|
||||||
|
<span> ({gettext('Greater than or equal to')} {shareLinkExpireDaysMin}{' '}{gettext('days')})</span>
|
||||||
|
)}
|
||||||
|
{(parseInt(shareLinkExpireDaysMin) === 0 && parseInt(shareLinkExpireDaysMax) !== 0) && (
|
||||||
|
<span> ({gettext('Less than or equal to')} {shareLinkExpireDaysMax}{' '}{gettext('days')})</span>
|
||||||
|
)}
|
||||||
|
</Label>
|
||||||
|
</FormGroup>
|
||||||
|
)}
|
||||||
<FormGroup check>
|
<FormGroup check>
|
||||||
<Label check>
|
<Label check>
|
||||||
<Input type="checkbox" checked readOnly/>{' '}{gettext('Set permission')}
|
<Input type="checkbox" checked readOnly/>{' '}{gettext('Set permission')}
|
||||||
|
@ -9,10 +9,10 @@ import GenerateUploadLink from './generate-upload-link';
|
|||||||
import '../../css/share-link-dialog.css';
|
import '../../css/share-link-dialog.css';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
itemPath: PropTypes.string.isRequired,
|
itemType: PropTypes.bool.isRequired, // there will be three choose: ['library', 'dir', 'file']
|
||||||
itemName: PropTypes.string.isRequired,
|
itemName: PropTypes.string.isRequired,
|
||||||
|
itemPath: PropTypes.string.isRequired,
|
||||||
toggleDialog: PropTypes.func.isRequired,
|
toggleDialog: PropTypes.func.isRequired,
|
||||||
isDir: PropTypes.bool.isRequired,
|
|
||||||
repoID: PropTypes.string.isRequired
|
repoID: PropTypes.string.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -79,14 +79,13 @@ class ShareDialog extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderFileContent = () => {
|
renderFileContent = () => {
|
||||||
let activeTab = this.state.activeTab;
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<div className="share-dialog-side">
|
<div className="share-dialog-side">
|
||||||
<Nav pills vertical>
|
<Nav pills vertical>
|
||||||
<NavItem>
|
<NavItem>
|
||||||
<NavLink
|
<NavLink
|
||||||
className={activeTab === 'shareLink' ? 'active' : ''} onClick={() => {this.toggle.bind(this, 'shareLink');}}>
|
className="active" onClick={() => {this.toggle.bind(this, 'shareLink');}}>
|
||||||
{gettext('Share Link')}
|
{gettext('Share Link')}
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</NavItem>
|
</NavItem>
|
||||||
@ -104,15 +103,14 @@ class ShareDialog extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let itemName = this.props.itemName;
|
let { itemType, itemName } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Modal isOpen={true} style={{maxWidth: '720px'}} className="share-dialog">
|
<Modal isOpen={true} style={{maxWidth: '720px'}} className="share-dialog">
|
||||||
<ModalHeader toggle={this.props.toggleDialog}>Share <span className="sf-font" title={itemName}>{itemName}</span></ModalHeader>
|
<ModalHeader toggle={this.props.toggleDialog}>{gettext('Share')} <span className="sf-font" title={itemName}>{itemName}</span></ModalHeader>
|
||||||
<ModalBody className="share-dialog-content">
|
<ModalBody className="share-dialog-content">
|
||||||
{this.props.isDir && this.renderDirContent()}
|
{(itemType === 'library' || itemType === 'dir') && this.renderDirContent()}
|
||||||
{!this.props.isDir && this.renderFileContent()}
|
{itemType === 'file' && this.renderFileContent()}
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
</Modal>
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
|
@ -477,9 +477,9 @@ class DirentListItem extends React.Component {
|
|||||||
{this.state.isShareDialogShow &&
|
{this.state.isShareDialogShow &&
|
||||||
<ModalPortal>
|
<ModalPortal>
|
||||||
<ShareDialog
|
<ShareDialog
|
||||||
isDir={dirent.isDir()}
|
itemType={dirent.type}
|
||||||
itemPath={direntPath}
|
|
||||||
itemName={dirent.name}
|
itemName={dirent.name}
|
||||||
|
itemPath={direntPath}
|
||||||
repoID={this.props.repoID}
|
repoID={this.props.repoID}
|
||||||
toggleDialog={this.onItemShare}
|
toggleDialog={this.onItemShare}
|
||||||
/>
|
/>
|
||||||
|
Loading…
Reference in New Issue
Block a user