2019-05-14 08:38:43 +00:00
import React , { Fragment } from 'react' ;
2018-12-06 03:28:16 +00:00
import PropTypes from 'prop-types' ;
2019-01-04 10:11:13 +00:00
import moment from 'moment' ;
import copy from 'copy-to-clipboard' ;
2020-05-21 03:32:02 +00:00
import { Button , Form , FormGroup , Label , Input , InputGroup , InputGroupAddon , InputGroupText , Alert , FormText } from 'reactstrap' ;
2021-08-12 07:02:03 +00:00
import { isPro , gettext , shareLinkExpireDaysMin , shareLinkExpireDaysMax , shareLinkExpireDaysDefault , shareLinkForceUsePassword , shareLinkPasswordMinLength , shareLinkPasswordStrengthLevel , canSendShareLinkEmail } from '../../utils/constants' ;
2020-01-02 04:05:50 +00:00
import ShareLinkPermissionEditor from '../../components/select-editor/share-link-permission-editor' ;
2018-12-06 03:28:16 +00:00
import { seafileAPI } from '../../utils/seafile-api' ;
2019-05-06 08:08:34 +00:00
import { Utils } from '../../utils/utils' ;
2019-08-20 04:00:58 +00:00
import ShareLink from '../../models/share-link' ;
2019-01-04 10:11:13 +00:00
import toaster from '../toast' ;
2019-05-13 12:01:53 +00:00
import Loading from '../loading' ;
2019-06-27 06:08:10 +00:00
import SendLink from '../send-link' ;
2020-05-21 03:32:02 +00:00
import DateTimePicker from '../date-and-time-picker' ;
2021-01-22 10:18:13 +00:00
import SharedLink from '../shared-link' ;
2018-12-06 03:28:16 +00:00
const propTypes = {
itemPath : PropTypes . string . isRequired ,
2019-01-05 12:40:41 +00:00
repoID : PropTypes . string . isRequired ,
closeShareDialog : PropTypes . func . isRequired ,
2021-09-13 02:37:07 +00:00
userPerm : PropTypes . string ,
2018-12-06 03:28:16 +00:00
} ;
2020-05-21 03:32:02 +00:00
const inputWidth = Utils . isDesktop ( ) ? 250 : 210 ;
2018-12-06 03:28:16 +00:00
class GenerateShareLink extends React . Component {
constructor ( props ) {
super ( props ) ;
2019-07-09 03:06:49 +00:00
2020-05-21 03:32:02 +00:00
this . isExpireDaysNoLimit = ( shareLinkExpireDaysMin === 0 && shareLinkExpireDaysMax === 0 && shareLinkExpireDaysDefault == 0 ) ;
2019-07-09 03:06:49 +00:00
this . defaultExpireDays = this . isExpireDaysNoLimit ? '' : shareLinkExpireDaysDefault ;
2019-08-27 04:04:03 +00:00
2020-05-21 03:32:02 +00:00
let expirationLimitTip = '' ;
if ( shareLinkExpireDaysMin !== 0 && shareLinkExpireDaysMax !== 0 ) {
expirationLimitTip = gettext ( '{minDays_placeholder} - {maxDays_placeholder} days' )
. replace ( '{minDays_placeholder}' , shareLinkExpireDaysMin )
. replace ( '{maxDays_placeholder}' , shareLinkExpireDaysMax ) ;
2020-11-02 05:56:35 +00:00
} else if ( shareLinkExpireDaysMin !== 0 && shareLinkExpireDaysMax === 0 ) {
2020-05-21 03:32:02 +00:00
expirationLimitTip = gettext ( 'Greater than or equal to {minDays_placeholder} days' )
. replace ( '{minDays_placeholder}' , shareLinkExpireDaysMin ) ;
} else if ( shareLinkExpireDaysMin === 0 && shareLinkExpireDaysMax !== 0 ) {
expirationLimitTip = gettext ( 'Less than or equal to {maxDays_placeholder} days' )
. replace ( '{maxDays_placeholder}' , shareLinkExpireDaysMax ) ;
}
this . expirationLimitTip = expirationLimitTip ;
2018-12-06 03:28:16 +00:00
this . state = {
2020-01-02 04:05:50 +00:00
isOpIconShown : false ,
2018-12-06 03:28:16 +00:00
isValidate : false ,
2021-08-12 07:02:03 +00:00
isShowPasswordInput : shareLinkForceUsePassword ? true : false ,
2018-12-14 07:09:07 +00:00
isPasswordVisible : false ,
2019-07-09 03:06:49 +00:00
isExpireChecked : ! this . isExpireDaysNoLimit ,
2020-05-21 03:32:02 +00:00
setExp : 'by-days' ,
expireDays : this . defaultExpireDays ,
expDate : null ,
2018-12-06 03:28:16 +00:00
password : '' ,
passwdnew : '' ,
2021-11-23 04:09:08 +00:00
storedPasswordVisible : false ,
2019-01-04 10:11:13 +00:00
errorInfo : '' ,
sharedLinkInfo : null ,
isNoticeMessageShow : false ,
2019-05-13 12:01:53 +00:00
isLoading : true ,
2019-10-12 06:54:25 +00:00
permissionOptions : [ ] ,
currentPermission : '' ,
2019-06-27 06:08:10 +00:00
isSendLinkShown : false
2018-12-06 03:28:16 +00:00
} ;
}
componentDidMount ( ) {
2020-01-02 04:05:50 +00:00
let path = this . props . itemPath ;
2018-12-06 03:28:16 +00:00
let repoID = this . props . repoID ;
seafileAPI . getShareLink ( repoID , path ) . then ( ( res ) => {
if ( res . data . length !== 0 ) {
2019-08-20 04:00:58 +00:00
let sharedLinkInfo = new ShareLink ( res . data [ 0 ] ) ;
2019-05-13 12:01:53 +00:00
this . setState ( {
isLoading : false ,
sharedLinkInfo : sharedLinkInfo
} ) ;
} else {
this . setState ( { isLoading : false } ) ;
2018-12-06 03:28:16 +00:00
}
2019-07-16 02:01:09 +00:00
} ) . catch ( error => {
let errMessage = Utils . getErrorMsg ( error ) ;
toaster . danger ( errMessage ) ;
2018-12-06 03:28:16 +00:00
} ) ;
2019-08-27 04:04:03 +00:00
2019-10-12 06:54:25 +00:00
if ( isPro ) {
2020-10-20 08:24:58 +00:00
const { itemType , userPerm } = this . props ;
if ( itemType == 'library' ) {
let permissionOptions = Utils . getShareLinkPermissionList ( itemType , userPerm , path ) ;
2019-10-12 06:54:25 +00:00
this . setState ( {
permissionOptions : permissionOptions ,
currentPermission : permissionOptions [ 0 ] ,
} ) ;
} else {
let getDirentInfoAPI ;
if ( this . props . itemType === 'file' ) {
getDirentInfoAPI = seafileAPI . getFileInfo ( repoID , path ) ;
} else if ( this . props . itemType === 'dir' ) {
getDirentInfoAPI = seafileAPI . getDirInfo ( repoID , path ) ;
2019-07-05 07:28:13 +00:00
}
2019-10-12 06:54:25 +00:00
getDirentInfoAPI . then ( ( res ) => {
2019-12-03 05:52:52 +00:00
let canEdit = res . data . can _edit ;
2019-10-12 06:54:25 +00:00
let permission = res . data . permission ;
2019-12-03 05:52:52 +00:00
let permissionOptions = Utils . getShareLinkPermissionList ( this . props . itemType , permission , path , canEdit ) ;
2019-10-12 06:54:25 +00:00
this . setState ( {
permissionOptions : permissionOptions ,
currentPermission : permissionOptions [ 0 ] ,
} ) ;
} ) . catch ( error => {
let errMessage = Utils . getErrorMsg ( error ) ;
toaster . danger ( errMessage ) ;
} ) ;
}
2019-07-05 07:28:13 +00:00
}
2019-05-13 12:01:53 +00:00
}
2018-12-06 03:28:16 +00:00
2020-05-21 03:32:02 +00:00
setExp = ( e ) => {
this . setState ( {
setExp : e . target . value
} ) ;
}
disabledDate = ( current ) => {
if ( ! current ) {
// allow empty select
return false ;
}
if ( this . isExpireDaysNoLimit ) {
return current . isBefore ( moment ( ) , 'day' ) ;
}
const startDay = moment ( ) . add ( shareLinkExpireDaysMin , 'days' ) ;
const endDay = moment ( ) . add ( shareLinkExpireDaysMax , 'days' ) ;
if ( shareLinkExpireDaysMin !== 0 && shareLinkExpireDaysMax !== 0 ) {
return current . isBefore ( startDay , 'day' ) || current . isAfter ( endDay , 'day' ) ;
2020-11-02 05:56:35 +00:00
} else if ( shareLinkExpireDaysMin !== 0 && shareLinkExpireDaysMax === 0 ) {
2020-05-21 03:32:02 +00:00
return current . isBefore ( startDay , 'day' ) ;
} else if ( shareLinkExpireDaysMin === 0 && shareLinkExpireDaysMax !== 0 ) {
return current . isBefore ( moment ( ) , 'day' ) || current . isAfter ( endDay , 'day' ) ;
}
}
onExpDateChanged = ( value ) => {
this . setState ( {
expDate : value
} ) ;
}
2018-12-14 07:09:07 +00:00
onPasswordInputChecked = ( ) => {
2018-12-06 03:28:16 +00:00
this . setState ( {
2018-12-14 07:09:07 +00:00
isShowPasswordInput : ! this . state . isShowPasswordInput ,
2018-12-06 03:28:16 +00:00
password : '' ,
passwdnew : '' ,
errorInfo : ''
} ) ;
}
togglePasswordVisible = ( ) => {
this . setState ( {
2018-12-14 07:09:07 +00:00
isPasswordVisible : ! this . state . isPasswordVisible
2018-12-06 03:28:16 +00:00
} ) ;
}
generatePassword = ( ) => {
2019-05-06 08:08:34 +00:00
let val = Utils . generatePassword ( shareLinkPasswordMinLength ) ;
2018-12-06 03:28:16 +00:00
this . setState ( {
password : val ,
2018-12-14 07:09:07 +00:00
passwdnew : val
2018-12-06 03:28:16 +00:00
} ) ;
}
inputPassword = ( e ) => {
2018-12-14 07:21:48 +00:00
let passwd = e . target . value . trim ( ) ;
this . setState ( { password : passwd } ) ;
2018-12-06 03:28:16 +00:00
}
inputPasswordNew = ( e ) => {
2018-12-14 07:21:48 +00:00
let passwd = e . target . value . trim ( ) ;
this . setState ( { passwdnew : passwd } ) ;
2018-12-06 03:28:16 +00:00
}
2021-11-23 04:09:08 +00:00
toggleStoredPasswordVisible = ( ) => {
this . setState ( {
storedPasswordVisible : ! this . state . storedPasswordVisible
} ) ;
}
2019-08-27 04:04:03 +00:00
setPermission = ( e ) => {
this . setState ( { currentPermission : e . target . value } ) ;
2018-12-06 03:28:16 +00:00
}
generateShareLink = ( ) => {
2018-12-14 07:09:07 +00:00
let isValid = this . validateParamsInput ( ) ;
if ( isValid ) {
2018-12-14 07:49:24 +00:00
this . setState ( { errorInfo : '' } ) ;
2018-12-14 07:09:07 +00:00
let { itemPath , repoID } = this . props ;
2020-05-21 03:32:02 +00:00
let { password , isExpireChecked , setExp , expireDays , expDate } = this . state ;
2019-08-27 04:04:03 +00:00
let permissions ;
if ( isPro ) {
const permissionDetails = Utils . getShareLinkPermissionObject ( this . state . currentPermission ) . permissionDetails ;
permissions = JSON . stringify ( permissionDetails ) ;
}
2020-11-02 05:56:35 +00:00
let expirationTime = '' ;
2020-05-21 03:32:02 +00:00
if ( isExpireChecked ) {
if ( setExp == 'by-days' ) {
expirationTime = moment ( ) . add ( parseInt ( expireDays ) , 'days' ) . format ( ) ;
} else {
expirationTime = expDate . format ( ) ;
}
}
seafileAPI . createShareLink ( repoID , itemPath , password , expirationTime , permissions ) . then ( ( res ) => {
2019-08-20 04:00:58 +00:00
let sharedLinkInfo = new ShareLink ( res . data ) ;
2019-01-04 10:11:13 +00:00
this . setState ( { sharedLinkInfo : sharedLinkInfo } ) ;
2019-07-04 08:22:50 +00:00
} ) . catch ( ( error ) => {
2019-07-16 02:01:09 +00:00
let errMessage = Utils . getErrorMsg ( error ) ;
toaster . danger ( errMessage ) ;
2018-12-06 03:28:16 +00:00
} ) ;
}
}
2019-01-04 10:11:13 +00:00
onCopySharedLink = ( ) => {
let sharedLink = this . state . sharedLinkInfo . link ;
copy ( sharedLink ) ;
toaster . success ( gettext ( 'Share link is copied to the clipboard.' ) ) ;
2019-01-05 12:40:41 +00:00
this . props . closeShareDialog ( ) ;
2019-01-04 10:11:13 +00:00
}
2020-01-02 04:05:50 +00:00
2019-01-04 10:11:13 +00:00
onCopyDownloadLink = ( ) => {
2019-07-16 07:47:20 +00:00
let downloadLink = this . state . sharedLinkInfo . link + '?dl=1' ;
2019-01-04 10:11:13 +00:00
copy ( downloadLink ) ;
toaster . success ( gettext ( 'Direct download link is copied to the clipboard.' ) ) ;
2019-01-05 12:40:41 +00:00
this . props . closeShareDialog ( ) ;
2019-01-04 10:11:13 +00:00
}
2018-12-06 03:28:16 +00:00
deleteShareLink = ( ) => {
2019-01-04 10:11:13 +00:00
let sharedLinkInfo = this . state . sharedLinkInfo ;
seafileAPI . deleteShareLink ( sharedLinkInfo . token ) . then ( ( ) => {
2018-12-06 03:28:16 +00:00
this . setState ( {
password : '' ,
2021-08-12 07:02:03 +00:00
passwdnew : '' ,
isShowPasswordInput : shareLinkForceUsePassword ? true : false ,
2019-07-09 03:06:49 +00:00
expireDays : this . defaultExpireDays ,
isExpireChecked : ! this . isExpireDaysNoLimit ,
2018-12-14 07:49:24 +00:00
errorInfo : '' ,
2019-01-04 10:11:13 +00:00
sharedLinkInfo : null ,
isNoticeMessageShow : false ,
2018-12-06 03:28:16 +00:00
} ) ;
2019-07-16 02:01:09 +00:00
} ) . catch ( ( error ) => {
let errMessage = Utils . getErrorMsg ( error ) ;
toaster . danger ( errMessage ) ;
2018-12-06 03:28:16 +00:00
} ) ;
2018-12-14 07:09:07 +00:00
}
2018-12-06 03:28:16 +00:00
2018-12-14 07:09:07 +00:00
onExpireChecked = ( e ) => {
this . setState ( { isExpireChecked : e . target . checked } ) ;
}
onExpireDaysChanged = ( e ) => {
2018-12-14 07:21:48 +00:00
let day = e . target . value . trim ( ) ;
this . setState ( { expireDays : day } ) ;
2018-12-14 07:09:07 +00:00
}
validateParamsInput = ( ) => {
2020-05-21 03:32:02 +00:00
let { isShowPasswordInput , password , passwdnew , isExpireChecked , setExp , expireDays , expDate } = this . state ;
2018-12-14 07:09:07 +00:00
// validate password
if ( isShowPasswordInput ) {
if ( password . length === 0 ) {
2022-02-17 07:30:06 +00:00
this . setState ( { errorInfo : gettext ( 'Please enter a password.' ) } ) ;
2018-12-14 07:09:07 +00:00
return false ;
}
2019-05-06 08:08:34 +00:00
if ( password . length < shareLinkPasswordMinLength ) {
2022-02-17 07:30:06 +00:00
this . setState ( { errorInfo : gettext ( 'The password is too short.' ) } ) ;
2018-12-14 07:09:07 +00:00
return false ;
}
if ( password !== passwdnew ) {
2022-02-17 07:30:06 +00:00
this . setState ( { errorInfo : gettext ( 'Passwords don\'t match' ) } ) ;
2018-12-14 07:09:07 +00:00
return false ;
}
2021-08-12 07:02:03 +00:00
if ( Utils . getStrengthLevel ( password ) < shareLinkPasswordStrengthLevel ) {
2022-02-17 07:30:06 +00:00
this . setState ( { errorInfo : gettext ( 'The password is too weak. It should include at least {passwordStrengthLevel} of the following: number, upper letter, lower letter and other symbols.' ) . replace ( '{passwordStrengthLevel}' , shareLinkPasswordStrengthLevel ) } ) ;
2021-08-12 07:02:03 +00:00
return false ;
}
2018-12-06 03:28:16 +00:00
}
2020-05-21 03:32:02 +00:00
if ( isExpireChecked ) {
if ( setExp == 'by-date' ) {
if ( ! expDate ) {
2022-02-17 07:46:03 +00:00
this . setState ( { errorInfo : gettext ( 'Please select an expiration time' ) } ) ;
2018-12-14 07:09:07 +00:00
return false ;
}
2020-05-21 03:32:02 +00:00
return true ;
2018-12-14 07:09:07 +00:00
}
2020-05-21 03:32:02 +00:00
// by days
let reg = /^\d+$/ ;
2018-12-14 07:09:07 +00:00
if ( ! expireDays ) {
2022-02-17 07:46:03 +00:00
this . setState ( { errorInfo : gettext ( 'Please enter days' ) } ) ;
2018-12-14 07:09:07 +00:00
return false ;
}
2019-05-29 02:43:30 +00:00
if ( ! reg . test ( expireDays ) ) {
2022-02-17 07:46:03 +00:00
this . setState ( { errorInfo : gettext ( 'Please enter a non-negative integer' ) } ) ;
2018-12-14 07:09:07 +00:00
return false ;
}
expireDays = parseInt ( expireDays ) ;
2020-05-21 03:32:02 +00:00
let minDays = shareLinkExpireDaysMin ;
let maxDays = shareLinkExpireDaysMax ;
2018-12-14 07:09:07 +00:00
2020-05-21 03:32:02 +00:00
if ( minDays !== 0 && maxDays == 0 ) {
2018-12-14 07:09:07 +00:00
if ( expireDays < minDays ) {
this . setState ( { errorInfo : 'Please enter valid days' } ) ;
return false ;
}
}
2020-01-02 04:05:50 +00:00
2018-12-14 07:09:07 +00:00
if ( minDays === 0 && maxDays !== 0 ) {
if ( expireDays > maxDays ) {
this . setState ( { errorInfo : 'Please enter valid days' } ) ;
return false ;
}
}
2020-01-02 04:05:50 +00:00
2018-12-14 07:09:07 +00:00
if ( minDays !== 0 && maxDays !== 0 ) {
2019-05-29 02:43:30 +00:00
if ( expireDays < minDays || expireDays > maxDays ) {
2018-12-14 07:09:07 +00:00
this . setState ( { errorInfo : 'Please enter valid days' } ) ;
return false ;
}
}
2020-05-21 03:32:02 +00:00
2018-12-14 07:09:07 +00:00
this . setState ( { expireDays : expireDays } ) ;
2018-12-06 03:28:16 +00:00
}
2018-12-14 07:09:07 +00:00
return true ;
2018-12-06 03:28:16 +00:00
}
2019-01-04 10:11:13 +00:00
onNoticeMessageToggle = ( ) => {
this . setState ( { isNoticeMessageShow : ! this . state . isNoticeMessageShow } ) ;
}
2019-05-14 08:38:43 +00:00
toggleSendLink = ( ) => {
2019-06-27 06:08:10 +00:00
this . setState ( { isSendLinkShown : ! this . state . isSendLinkShown } ) ;
2019-05-14 08:38:43 +00:00
}
2020-01-02 04:05:50 +00:00
handleMouseOver = ( ) => {
this . setState ( { isOpIconShown : true } ) ;
}
handleMouseOut = ( ) => {
this . setState ( { isOpIconShown : false } ) ;
}
changePerm = ( permission ) => {
const permissionDetails = Utils . getShareLinkPermissionObject ( permission ) . permissionDetails ;
seafileAPI . updateShareLink ( this . state . sharedLinkInfo . token , JSON . stringify ( permissionDetails ) ) . then ( ( res ) => {
let sharedLinkInfo = new ShareLink ( res . data ) ;
this . setState ( { sharedLinkInfo : sharedLinkInfo } ) ;
let message = gettext ( 'Successfully modified permission.' ) ;
toaster . success ( message ) ;
} ) . catch ( ( error ) => {
let errMessage = Utils . getErrorMsg ( error ) ;
toaster . danger ( errMessage ) ;
} ) ;
}
2018-12-06 03:28:16 +00:00
render ( ) {
2019-05-13 12:01:53 +00:00
if ( this . state . isLoading ) {
return < Loading / > ;
}
2022-02-17 07:30:06 +00:00
let passwordLengthTip = gettext ( '(at least {passwordMinLength} characters and includes {passwordStrengthLevel} of the following: number, upper letter, lower letter and other symbols)' ) ;
passwordLengthTip = passwordLengthTip . replace ( '{passwordMinLength}' , shareLinkPasswordMinLength )
. replace ( '{passwordStrengthLevel}' , shareLinkPasswordStrengthLevel ) ;
2019-05-06 08:08:34 +00:00
2021-09-13 02:37:07 +00:00
const { userPerm } = this . props ;
const { isCustomPermission } = Utils . getUserPermission ( userPerm ) ;
2019-01-04 10:11:13 +00:00
if ( this . state . sharedLinkInfo ) {
let sharedLinkInfo = this . state . sharedLinkInfo ;
2020-01-02 04:05:50 +00:00
let currentPermission = Utils . getShareLinkPermissionStr ( sharedLinkInfo . permissions ) ;
const { permissionOptions , isOpIconShown } = this . state ;
2018-12-06 03:28:16 +00:00
return (
2019-01-04 10:11:13 +00:00
< div >
< Form className = "mb-4" >
< FormGroup className = "mb-0" >
< dt className = "text-secondary font-weight-normal" > { gettext ( 'Link:' ) } < / d t >
2021-01-22 10:18:13 +00:00
< dd >
< SharedLink
link = { sharedLinkInfo . link }
linkExpired = { sharedLinkInfo . is _expired }
copyLink = { this . onCopySharedLink }
/ >
2019-01-04 10:11:13 +00:00
< / d d >
< / F o r m G r o u p >
2019-06-11 01:34:11 +00:00
{ ! sharedLinkInfo . is _dir && sharedLinkInfo . permissions . can _download && ( //just for file
2019-01-04 10:11:13 +00:00
< FormGroup className = "mb-0" >
< dt className = "text-secondary font-weight-normal" > { gettext ( 'Direct Download Link:' ) } < / d t >
2021-01-22 10:18:13 +00:00
< dd >
< SharedLink
link = { ` ${ sharedLinkInfo . link } ?dl=1 ` }
linkExpired = { sharedLinkInfo . is _expired }
copyLink = { this . onCopyDownloadLink }
/ >
2019-01-04 10:11:13 +00:00
< / d d >
< / F o r m G r o u p >
) }
2021-11-19 02:53:08 +00:00
{ sharedLinkInfo . password && (
< FormGroup className = "mb-0" >
< dt className = "text-secondary font-weight-normal" > { gettext ( 'Password:' ) } < / d t >
< dd className = "d-flex" >
2021-11-23 04:09:08 +00:00
< div className = "d-flex align-items-center" >
< input id = "stored-password" className = "border-0 mr-1" type = "text" value = { this . state . storedPasswordVisible ? sharedLinkInfo . password : '****************************************' } readOnly = { true } size = { Math . max ( sharedLinkInfo . password . length , 10 ) } / >
< span tabIndex = "0" role = "button" aria - label = { this . state . storedPasswordVisible ? gettext ( 'Hide' ) : gettext ( 'Show' ) } onKeyDown = { this . onIconKeyDown } onClick = { this . toggleStoredPasswordVisible } className = { ` eye-icon fas ${ this . state . storedPasswordVisible ? 'fa-eye' : 'fa-eye-slash' } ` } > < / s p a n >
< / d i v >
2021-11-19 02:53:08 +00:00
< / d d >
< / F o r m G r o u p >
) }
2019-01-04 10:11:13 +00:00
{ sharedLinkInfo . expire _date && (
< FormGroup className = "mb-0" >
< dt className = "text-secondary font-weight-normal" > { gettext ( 'Expiration Date:' ) } < / d t >
2020-04-28 05:09:05 +00:00
< dd > { moment ( sharedLinkInfo . expire _date ) . format ( 'YYYY-MM-DD HH:mm:ss' ) } < / d d >
2019-01-04 10:11:13 +00:00
< / F o r m G r o u p >
) }
2020-01-02 04:05:50 +00:00
{ ( isPro && sharedLinkInfo . permissions ) && (
< FormGroup className = "mb-0" >
2020-01-13 10:29:13 +00:00
< dt className = "text-secondary font-weight-normal" > { gettext ( 'Permission:' ) } < / d t >
2020-01-02 04:05:50 +00:00
< dd style = { { width : '250px' } } onMouseEnter = { this . handleMouseOver } onMouseLeave = { this . handleMouseOut } >
< ShareLinkPermissionEditor
isTextMode = { true }
isEditIconShow = { isOpIconShown && ! sharedLinkInfo . is _expired }
currentPermission = { currentPermission }
permissionOptions = { permissionOptions }
onPermissionChanged = { this . changePerm }
/ >
< / d d >
< / F o r m G r o u p >
) }
2019-01-04 10:11:13 +00:00
< / F o r m >
2019-06-27 06:08:10 +00:00
{ ( canSendShareLinkEmail && ! this . state . isSendLinkShown && ! this . state . isNoticeMessageShow ) &&
2019-05-17 03:14:40 +00:00
< Button onClick = { this . toggleSendLink } className = 'mr-2' > { gettext ( 'Send' ) } < / B u t t o n >
}
2019-06-27 06:08:10 +00:00
{ this . state . isSendLinkShown &&
< SendLink
linkType = 'shareLink'
token = { sharedLinkInfo . token }
toggleSendLink = { this . toggleSendLink }
closeShareDialog = { this . props . closeShareDialog }
/ >
2019-05-14 08:38:43 +00:00
}
2019-06-27 06:08:10 +00:00
{ ( ! this . state . isSendLinkShown && ! this . state . isNoticeMessageShow ) &&
2019-05-14 08:38:43 +00:00
< Button onClick = { this . onNoticeMessageToggle } > { gettext ( 'Delete' ) } < / B u t t o n >
}
{ this . state . isNoticeMessageShow &&
2019-01-04 10:11:13 +00:00
< div className = "alert alert-warning" >
< h4 className = "alert-heading" > { gettext ( 'Are you sure you want to delete the share link?' ) } < / h 4 >
< p className = "mb-4" > { gettext ( 'If the share link is deleted, no one will be able to access it any more.' ) } < / p >
< button className = "btn btn-primary" onClick = { this . deleteShareLink } > { gettext ( 'Delete' ) } < / b u t t o n > { ' ' }
< button className = "btn btn-secondary" onClick = { this . onNoticeMessageToggle } > { gettext ( 'Cancel' ) } < / b u t t o n >
< / d i v >
}
< / d i v >
2018-12-06 03:28:16 +00:00
) ;
} else {
return (
< Form className = "generate-share-link" >
< FormGroup check >
2021-08-12 07:02:03 +00:00
{ shareLinkForceUsePassword ? (
< Label check >
< Input type = "checkbox" checked readOnly disabled / >
< span > { gettext ( 'Add password protection' ) } < / s p a n >
< / L a b e l >
) : (
2018-12-06 03:28:16 +00:00
< Label check >
2020-05-21 03:32:02 +00:00
< Input type = "checkbox" onChange = { this . onPasswordInputChecked } / >
< span > { gettext ( 'Add password protection' ) } < / s p a n >
2018-12-06 03:28:16 +00:00
< / L a b e l >
2021-08-12 07:02:03 +00:00
) }
2020-05-21 03:32:02 +00:00
{ this . state . isShowPasswordInput &&
< div className = "ml-4" >
< FormGroup >
< Label for = "passwd" > { gettext ( 'Password' ) } < / L a b e l >
< span className = "tip" > { passwordLengthTip } < / s p a n >
< InputGroup style = { { width : inputWidth } } >
< Input id = "passwd" type = { this . state . isPasswordVisible ? 'text' : 'password' } value = { this . state . password || '' } onChange = { this . inputPassword } / >
< InputGroupAddon addonType = "append" >
< Button onClick = { this . togglePasswordVisible } > < i className = { ` link-operation-icon fas ${ this . state . isPasswordVisible ? 'fa-eye' : 'fa-eye-slash' } ` } > < / i > < / B u t t o n >
< Button onClick = { this . generatePassword } > < i className = "link-operation-icon fas fa-magic" > < / i > < / B u t t o n >
< / I n p u t G r o u p A d d o n >
< / I n p u t G r o u p >
2019-05-29 02:43:30 +00:00
< / F o r m G r o u p >
2020-05-21 03:32:02 +00:00
< FormGroup >
< Label for = "passwd-again" > { gettext ( 'Password again' ) } < / L a b e l >
< Input id = "passwd-again" style = { { width : inputWidth } } type = { this . state . isPasswordVisible ? 'text' : 'password' } value = { this . state . passwdnew || '' } onChange = { this . inputPasswordNew } / >
< / F o r m G r o u p >
< / d i v >
}
< / F o r m G r o u p >
< FormGroup check >
< Label check >
{ this . isExpireDaysNoLimit ? (
< Input type = "checkbox" onChange = { this . onExpireChecked } / >
2020-11-02 05:56:35 +00:00
) : (
2020-05-21 03:32:02 +00:00
< Input type = "checkbox" checked readOnly disabled / >
) }
< span > { gettext ( 'Add auto expiration' ) } < / s p a n >
< / L a b e l >
{ this . state . isExpireChecked &&
< div className = "ml-4" >
2019-05-29 02:43:30 +00:00
< FormGroup check >
< Label check >
2020-05-21 03:32:02 +00:00
< Input type = "radio" name = "set-exp" value = "by-days" checked = { this . state . setExp == 'by-days' } onChange = { this . setExp } className = "mr-1" / >
< span > { gettext ( 'Expiration days' ) } < / s p a n >
2019-05-29 02:43:30 +00:00
< / L a b e l >
2020-05-21 03:32:02 +00:00
{ this . state . setExp == 'by-days' && (
< Fragment >
< InputGroup style = { { width : inputWidth } } >
< Input type = "text" value = { this . state . expireDays } onChange = { this . onExpireDaysChanged } / >
< InputGroupAddon addonType = "append" >
< InputGroupText > { gettext ( 'days' ) } < / I n p u t G r o u p T e x t >
< / I n p u t G r o u p A d d o n >
< / I n p u t G r o u p >
{ ! this . state . isExpireDaysNoLimit && (
< FormText color = "muted" > { this . expirationLimitTip } < / F o r m T e x t >
) }
< / F r a g m e n t >
2019-05-29 02:43:30 +00:00
) }
2020-05-21 03:32:02 +00:00
< / F o r m G r o u p >
< FormGroup check >
< Label check >
< Input type = "radio" name = "set-exp" value = "by-date" checked = { this . state . setExp == 'by-date' } onChange = { this . setExp } className = "mr-1" / >
< span > { gettext ( 'Expiration time' ) } < / s p a n >
< / L a b e l >
{ this . state . setExp == 'by-date' && (
< DateTimePicker
inputWidth = { inputWidth }
disabledDate = { this . disabledDate }
value = { this . state . expDate }
onChange = { this . onExpDateChanged }
/ >
2019-05-29 02:43:30 +00:00
) }
2020-05-21 03:32:02 +00:00
< / F o r m G r o u p >
< / d i v >
}
< / F o r m G r o u p >
2021-09-13 02:37:07 +00:00
{ ( isPro && ! isCustomPermission ) && (
2020-05-21 03:32:02 +00:00
< FormGroup check >
< Label check >
< span > { gettext ( 'Set permission' ) } < / s p a n >
< / L a b e l >
2019-10-12 06:54:25 +00:00
{ this . state . permissionOptions . map ( ( item , index ) => {
2019-08-27 04:04:03 +00:00
return (
2020-05-21 03:32:02 +00:00
< FormGroup check className = "ml-4" key = { index } >
< Label check >
2019-08-27 04:04:03 +00:00
< Input type = "radio" name = "permission" value = { item } checked = { this . state . currentPermission == item } onChange = { this . setPermission } className = "mr-1" / >
{ Utils . getShareLinkPermissionObject ( item ) . text }
< / L a b e l >
< / F o r m G r o u p >
) ;
} ) }
2020-05-21 03:32:02 +00:00
< / F o r m G r o u p >
2019-08-20 04:00:58 +00:00
) }
2019-02-12 03:16:49 +00:00
{ this . state . errorInfo && < Alert color = "danger" className = "mt-2" > { gettext ( this . state . errorInfo ) } < / A l e r t > }
2019-07-03 02:55:16 +00:00
< Button onClick = { this . generateShareLink } className = "mt-2" > { gettext ( 'Generate' ) } < / B u t t o n >
2018-12-06 03:28:16 +00:00
< / F o r m >
) ;
}
}
}
GenerateShareLink . propTypes = propTypes ;
export default GenerateShareLink ;