1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-10 11:21:29 +00:00

lib decrypt

This commit is contained in:
ilearnit
2018-12-13 09:53:39 +00:00
parent 644acfebf3
commit cccf826116
4 changed files with 106 additions and 1 deletions

View 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;

View File

@@ -11,6 +11,8 @@ import CurDirPath from '../cur-dir-path';
import DirentListView from '../dirent-list-view/dirent-list-view';
import DirentDetail from '../dirent-detail/dirent-details';
import FileUploader from '../file-uploader/file-uploader';
import ModalPortal from '../modal-portal';
import LibDecryptDialog from '../dialog/lib-decrypt-dialog';
const propTypes = {
currentRepo: PropTypes.object,
@@ -110,6 +112,7 @@ class DirPanel extends React.Component {
return (
<div className="main-panel wiki-main-panel o-hidden">
<div className="main-panel-north">
{!this.props.libNeedDecrypt &&
<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>
<div className="dir-operation">
@@ -137,6 +140,7 @@ class DirPanel extends React.Component {
switchViewMode={this.switchViewMode}
/>
</div>
}
<CommonToolbar
repoID={this.props.repoID}
onSearchedClick={this.props.onSearchedClick}
@@ -144,6 +148,7 @@ class DirPanel extends React.Component {
/>
</div>
<div className="main-panel-center flex-direction-row">
{!this.props.libNeedDecrypt &&
<div className="cur-view-container">
<div className="cur-view-path">
<CurDirPath
@@ -190,6 +195,7 @@ class DirPanel extends React.Component {
}
</div>
</div>
}
{this.state.isDirentDetailShow && (
<div className="cur-view-detail">
<DirentDetail
@@ -201,6 +207,13 @@ class DirPanel extends React.Component {
/>
</div>
)}
{this.props.libNeedDecrypt && (
<ModalPortal>
<LibDecryptDialog repoID={this.props.repoID}
onLibDecryptDialog={this.props.onLibDecryptDialog}
/>
</ModalPortal>
)}
</div>
</div>
);

View File

@@ -27,6 +27,7 @@ class DirView extends React.Component {
repoName: '',
repoID: '',
permission: true,
libNeedDecrypt: false,
isDirentSelected: false,
isAllDirentSelected: false,
isDirentListLoading: true,
@@ -55,12 +56,16 @@ class DirView extends React.Component {
repoName: repo.repo_name,
permission: repo.permission === 'rw',
currentRepo: repo,
libNeedDecrypt: res.data.lib_need_decrypt,
});
let repoName = repo.repo_name;
let index = location.indexOf(repoName);
let path = location.slice(index + repoName.length);
this.updateDirentList(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() {
return (
<DirPanel
@@ -462,6 +474,8 @@ class DirView extends React.Component {
switchViewMode={this.switchViewMode}
onSearchedClick={this.onSearchedClick}
onFileUploadSuccess={this.onFileUploadSuccess}
libNeedDecrypt={this.state.libNeedDecrypt}
onLibDecryptDialog={this.onLibDecryptDialog}
/>
);
}

View File

@@ -268,6 +268,12 @@ class RepoView(APIView):
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
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)
try:
@@ -292,6 +298,8 @@ class RepoView(APIView):
"is_admin": is_repo_admin(username, repo_id),
"is_virtual": repo.is_virtual,
"has_been_shared_out": has_been_shared_out,
"lib_need_decrypt": lib_need_decrypt,
}
return Response(result)