mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-08 02:10:24 +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 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);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -437,6 +442,13 @@ class DirView extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onLibDecryptDialog = () => {
|
||||||
|
this.setState({
|
||||||
|
libNeedDecrypt: !this.state.libNeedDecrypt
|
||||||
|
})
|
||||||
|
this.updateDirentList(this.state.path);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<DirPanel
|
<DirPanel
|
||||||
@@ -472,6 +484,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}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,8 @@ import MainPanel from './pages/repo-wiki-mode/main-panel';
|
|||||||
import Node from './components/tree-view/node';
|
import Node from './components/tree-view/node';
|
||||||
import Tree from './components/tree-view/tree';
|
import Tree from './components/tree-view/tree';
|
||||||
import toaster from './components/toast';
|
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 Dirent from './models/dirent';
|
||||||
import FileTag from './models/file-tag';
|
import FileTag from './models/file-tag';
|
||||||
import './assets/css/fa-solid.css';
|
import './assets/css/fa-solid.css';
|
||||||
@@ -40,6 +42,7 @@ class Wiki extends Component {
|
|||||||
isDirentSelected: false,
|
isDirentSelected: false,
|
||||||
isAllDirentSelected: false,
|
isAllDirentSelected: false,
|
||||||
selectedDirentList: [],
|
selectedDirentList: [],
|
||||||
|
libNeedDecrypt: false
|
||||||
};
|
};
|
||||||
window.onpopstate = this.onpopstate;
|
window.onpopstate = this.onpopstate;
|
||||||
this.hash = '';
|
this.hash = '';
|
||||||
@@ -53,6 +56,12 @@ class Wiki extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
seafileAPI.getRepoInfo(repoID).then(res => {
|
||||||
|
this.setState({
|
||||||
|
libNeedDecrypt: res.data.lib_need_decrypt,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res.data.lib_need_decrypt) {
|
||||||
if (isDir === 'None') {
|
if (isDir === 'None') {
|
||||||
this.setState({pathExist: false});
|
this.setState({pathExist: false});
|
||||||
} else if (isDir === 'True') {
|
} else if (isDir === 'True') {
|
||||||
@@ -63,6 +72,8 @@ class Wiki extends Component {
|
|||||||
|
|
||||||
this.loadSidePanel(initialPath);
|
this.loadSidePanel(initialPath);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
deleteItemAjaxCallback(path, isDir) {
|
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() {
|
render() {
|
||||||
|
let { libNeedDecrypt } = this.state;
|
||||||
|
if (libNeedDecrypt) {
|
||||||
|
return (
|
||||||
|
<ModalPortal>
|
||||||
|
<LibDecryptDialog repoID={repoID}
|
||||||
|
onLibDecryptDialog={this.onLibDecryptDialog}
|
||||||
|
/>
|
||||||
|
</ModalPortal>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id="main" className="wiki-main">
|
<div id="main" className="wiki-main">
|
||||||
<SidePanel
|
<SidePanel
|
||||||
|
@@ -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