mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-06 17:33:18 +00:00
65
frontend/src/components/dialog/lib-decrypt-dialog.js
Normal file
65
frontend/src/components/dialog/lib-decrypt-dialog.js
Normal file
@@ -0,0 +1,65 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Link } from '@reach/router';
|
||||
import { Button, Modal, Input, ModalBody, Form, FormGroup, Label } 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
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
handleChange = (e) => {
|
||||
this.setState({
|
||||
password: e.target.value,
|
||||
showError: false
|
||||
});
|
||||
}
|
||||
|
||||
toggle = () => {
|
||||
window.location.href = siteRoot;
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Modal isOpen={true} centered={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>
|
||||
}
|
||||
<FormGroup>
|
||||
<Input type="password" name="password" placeholder={gettext('Password')} onChange={this.handleChange}/>
|
||||
</FormGroup>
|
||||
<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 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>
|
||||
);
|
||||
|
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -437,6 +442,13 @@ class DirView extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
onLibDecryptDialog = () => {
|
||||
this.setState({
|
||||
libNeedDecrypt: !this.state.libNeedDecrypt
|
||||
})
|
||||
this.updateDirentList(this.state.path);
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<DirPanel
|
||||
@@ -472,6 +484,8 @@ class DirView extends React.Component {
|
||||
switchViewMode={this.switchViewMode}
|
||||
onSearchedClick={this.onSearchedClick}
|
||||
onFileUploadSuccess={this.onFileUploadSuccess}
|
||||
libNeedDecrypt={this.state.libNeedDecrypt}
|
||||
onLibDecryptDialog={this.onLibDecryptDialog}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
@@ -9,6 +9,8 @@ import MainPanel from './pages/repo-wiki-mode/main-panel';
|
||||
import Node from './components/tree-view/node';
|
||||
import Tree from './components/tree-view/tree';
|
||||
import toaster from './components/toast';
|
||||
import LibDecryptDialog from './components/dialog/lib-decrypt-dialog';
|
||||
import ModalPortal from './components/modal-portal';
|
||||
import Dirent from './models/dirent';
|
||||
import FileTag from './models/file-tag';
|
||||
import './assets/css/fa-solid.css';
|
||||
@@ -40,6 +42,7 @@ class Wiki extends Component {
|
||||
isDirentSelected: false,
|
||||
isAllDirentSelected: false,
|
||||
selectedDirentList: [],
|
||||
libNeedDecrypt: false
|
||||
};
|
||||
window.onpopstate = this.onpopstate;
|
||||
this.hash = '';
|
||||
@@ -53,6 +56,12 @@ class Wiki extends Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
seafileAPI.getRepoInfo(repoID).then(res => {
|
||||
this.setState({
|
||||
libNeedDecrypt: res.data.lib_need_decrypt,
|
||||
});
|
||||
|
||||
if (!res.data.lib_need_decrypt) {
|
||||
if (isDir === 'None') {
|
||||
this.setState({pathExist: false});
|
||||
} else if (isDir === 'True') {
|
||||
@@ -63,6 +72,8 @@ class Wiki extends Component {
|
||||
|
||||
this.loadSidePanel(initialPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
deleteItemAjaxCallback(path, isDir) {
|
||||
@@ -749,7 +760,34 @@ class Wiki extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
onLibDecryptDialog = () => {
|
||||
this.setState({
|
||||
libNeedDecrypt: false,
|
||||
})
|
||||
|
||||
if (isDir === 'None') {
|
||||
this.setState({pathExist: false});
|
||||
} else if (isDir === 'True') {
|
||||
this.showDir(initialPath);
|
||||
} else if (isDir === 'False') {
|
||||
this.showFile(initialPath);
|
||||
}
|
||||
|
||||
this.loadSidePanel(initialPath);
|
||||
}
|
||||
|
||||
render() {
|
||||
let { libNeedDecrypt } = this.state;
|
||||
if (libNeedDecrypt) {
|
||||
return (
|
||||
<ModalPortal>
|
||||
<LibDecryptDialog repoID={repoID}
|
||||
onLibDecryptDialog={this.onLibDecryptDialog}
|
||||
/>
|
||||
</ModalPortal>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div id="main" className="wiki-main">
|
||||
<SidePanel
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user