mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-11 20:01:10 +00:00
lib decrypt
This commit is contained in:
70
frontend/src/components/dialog/lib-decrypt-dialog.js
Normal file
70
frontend/src/components/dialog/lib-decrypt-dialog.js
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { Link } from '@reach/router';
|
||||||
|
import { Button, Modal, ModalHeader, Input, ModalBody, ModalFooter, Form, FormGroup, Label, Col, FormText } from 'reactstrap';
|
||||||
|
import { gettext, siteRoot } from '../../utils/constants';
|
||||||
|
import { seafileAPI } from '../../utils/seafile-api';
|
||||||
|
|
||||||
|
|
||||||
|
class LibDecryptDialog extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
password: '',
|
||||||
|
showError: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSubmit = () => {
|
||||||
|
let repoID = this.props.repoID;
|
||||||
|
let password = this.state.password;
|
||||||
|
seafileAPI.setRepoDecryptPassword(repoID, password).then(res => {
|
||||||
|
this.props.onLibDecryptDialog();
|
||||||
|
}).catch(res => {
|
||||||
|
this.setState({
|
||||||
|
showError: true
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
handleKeyPress = (e) => {
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
this.handleSubmit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleChange = (e) => {
|
||||||
|
this.setState({
|
||||||
|
password: e.target.value,
|
||||||
|
showError: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
toggle = () => {
|
||||||
|
window.history.back();
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<Modal isOpen={true}>
|
||||||
|
<ModalBody>
|
||||||
|
<button type="button" className="close" onClick={this.toggle}><span aria-hidden="true">×</span></button>
|
||||||
|
<Form className="lib-decrypt-form text-center">
|
||||||
|
<img src={siteRoot + 'media/img/lock.png'} alt=""/>
|
||||||
|
<p>{gettext('This library is password protected')}</p>
|
||||||
|
{this.state.showError &&
|
||||||
|
<p className="error">{gettext('Wrong password')}</p>
|
||||||
|
}
|
||||||
|
<Input type="password" name="password" placeholder={gettext('Password')} onChange={this.handleChange}/>
|
||||||
|
<br />
|
||||||
|
<Button onClick={this.handleSubmit}>{gettext('Submit')}</Button>
|
||||||
|
<br />
|
||||||
|
<p className="tip">*{gettext('The password will be kept in the server for only 1 hour.')}</p>
|
||||||
|
</Form>
|
||||||
|
</ModalBody>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LibDecryptDialog;
|
@@ -11,6 +11,8 @@ import CurDirPath from '../cur-dir-path';
|
|||||||
import DirentListView from '../dirent-list-view/dirent-list-view';
|
import DirentListView from '../dirent-list-view/dirent-list-view';
|
||||||
import DirentDetail from '../dirent-detail/dirent-details';
|
import DirentDetail from '../dirent-detail/dirent-details';
|
||||||
import FileUploader from '../file-uploader/file-uploader';
|
import FileUploader from '../file-uploader/file-uploader';
|
||||||
|
import ModalPortal from '../modal-portal';
|
||||||
|
import LibDecryptDialog from '../dialog/lib-decrypt-dialog';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
currentRepo: PropTypes.object,
|
currentRepo: PropTypes.object,
|
||||||
@@ -110,6 +112,7 @@ class DirPanel extends React.Component {
|
|||||||
return (
|
return (
|
||||||
<div className="main-panel wiki-main-panel o-hidden">
|
<div className="main-panel wiki-main-panel o-hidden">
|
||||||
<div className="main-panel-north">
|
<div className="main-panel-north">
|
||||||
|
{!this.props.libNeedDecrypt &&
|
||||||
<div className="cur-view-toolbar border-left-show">
|
<div className="cur-view-toolbar border-left-show">
|
||||||
<span className="sf2-icon-menu hidden-md-up d-md-none side-nav-toggle" title={gettext('Side Nav Menu')} onClick={this.props.onMenuClick}></span>
|
<span className="sf2-icon-menu hidden-md-up d-md-none side-nav-toggle" title={gettext('Side Nav Menu')} onClick={this.props.onMenuClick}></span>
|
||||||
<div className="dir-operation">
|
<div className="dir-operation">
|
||||||
@@ -137,6 +140,7 @@ class DirPanel extends React.Component {
|
|||||||
switchViewMode={this.switchViewMode}
|
switchViewMode={this.switchViewMode}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
<CommonToolbar
|
<CommonToolbar
|
||||||
repoID={this.props.repoID}
|
repoID={this.props.repoID}
|
||||||
onSearchedClick={this.props.onSearchedClick}
|
onSearchedClick={this.props.onSearchedClick}
|
||||||
@@ -144,6 +148,7 @@ class DirPanel extends React.Component {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="main-panel-center flex-direction-row">
|
<div className="main-panel-center flex-direction-row">
|
||||||
|
{!this.props.libNeedDecrypt &&
|
||||||
<div className="cur-view-container">
|
<div className="cur-view-container">
|
||||||
<div className="cur-view-path">
|
<div className="cur-view-path">
|
||||||
<CurDirPath
|
<CurDirPath
|
||||||
@@ -190,6 +195,7 @@ class DirPanel extends React.Component {
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
{this.state.isDirentDetailShow && (
|
{this.state.isDirentDetailShow && (
|
||||||
<div className="cur-view-detail">
|
<div className="cur-view-detail">
|
||||||
<DirentDetail
|
<DirentDetail
|
||||||
@@ -201,6 +207,13 @@ class DirPanel extends React.Component {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{this.props.libNeedDecrypt && (
|
||||||
|
<ModalPortal>
|
||||||
|
<LibDecryptDialog repoID={this.props.repoID}
|
||||||
|
onLibDecryptDialog={this.props.onLibDecryptDialog}
|
||||||
|
/>
|
||||||
|
</ModalPortal>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@@ -27,6 +27,7 @@ class DirView extends React.Component {
|
|||||||
repoName: '',
|
repoName: '',
|
||||||
repoID: '',
|
repoID: '',
|
||||||
permission: true,
|
permission: true,
|
||||||
|
libNeedDecrypt: false,
|
||||||
isDirentSelected: false,
|
isDirentSelected: false,
|
||||||
isAllDirentSelected: false,
|
isAllDirentSelected: false,
|
||||||
isDirentListLoading: true,
|
isDirentListLoading: true,
|
||||||
@@ -55,12 +56,16 @@ class DirView extends React.Component {
|
|||||||
repoName: repo.repo_name,
|
repoName: repo.repo_name,
|
||||||
permission: repo.permission === 'rw',
|
permission: repo.permission === 'rw',
|
||||||
currentRepo: repo,
|
currentRepo: repo,
|
||||||
|
libNeedDecrypt: res.data.lib_need_decrypt,
|
||||||
});
|
});
|
||||||
|
|
||||||
let repoName = repo.repo_name;
|
let repoName = repo.repo_name;
|
||||||
let index = location.indexOf(repoName);
|
let index = location.indexOf(repoName);
|
||||||
let path = location.slice(index + repoName.length);
|
let path = location.slice(index + repoName.length);
|
||||||
this.updateDirentList(path);
|
|
||||||
this.setState({path: path});
|
this.setState({path: path});
|
||||||
|
if (!res.data.lib_need_decrypt) {
|
||||||
|
this.updateDirentList(path);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,6 +432,13 @@ class DirView extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onLibDecryptDialog = () => {
|
||||||
|
this.setState({
|
||||||
|
libNeedDecrypt: !this.state.libNeedDecrypt
|
||||||
|
})
|
||||||
|
this.updateDirentList(this.state.path);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<DirPanel
|
<DirPanel
|
||||||
@@ -462,6 +474,8 @@ class DirView extends React.Component {
|
|||||||
switchViewMode={this.switchViewMode}
|
switchViewMode={this.switchViewMode}
|
||||||
onSearchedClick={this.onSearchedClick}
|
onSearchedClick={this.onSearchedClick}
|
||||||
onFileUploadSuccess={this.onFileUploadSuccess}
|
onFileUploadSuccess={this.onFileUploadSuccess}
|
||||||
|
libNeedDecrypt={this.state.libNeedDecrypt}
|
||||||
|
onLibDecryptDialog={this.onLibDecryptDialog}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -268,6 +268,12 @@ class RepoView(APIView):
|
|||||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||||
|
|
||||||
username = request.user.username
|
username = request.user.username
|
||||||
|
|
||||||
|
lib_need_decrypt = False
|
||||||
|
if repo.encrypted \
|
||||||
|
and not seafile_api.is_password_set(repo.id, username):
|
||||||
|
lib_need_decrypt = True
|
||||||
|
|
||||||
repo_owner = get_repo_owner(request, repo_id)
|
repo_owner = get_repo_owner(request, repo_id)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -292,6 +298,8 @@ class RepoView(APIView):
|
|||||||
"is_admin": is_repo_admin(username, repo_id),
|
"is_admin": is_repo_admin(username, repo_id),
|
||||||
"is_virtual": repo.is_virtual,
|
"is_virtual": repo.is_virtual,
|
||||||
"has_been_shared_out": has_been_shared_out,
|
"has_been_shared_out": has_been_shared_out,
|
||||||
|
|
||||||
|
"lib_need_decrypt": lib_need_decrypt,
|
||||||
}
|
}
|
||||||
|
|
||||||
return Response(result)
|
return Response(result)
|
||||||
|
Reference in New Issue
Block a user