From cccf826116bf6570d90da9fd58b96c90638316b0 Mon Sep 17 00:00:00 2001 From: ilearnit Date: Thu, 13 Dec 2018 09:53:39 +0000 Subject: [PATCH] lib decrypt --- .../components/dialog/lib-decrypt-dialog.js | 70 +++++++++++++++++++ frontend/src/components/dir-view/dir-panel.js | 13 ++++ frontend/src/components/dir-view/dir-view.js | 16 ++++- seahub/api2/endpoints/repos.py | 8 +++ 4 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 frontend/src/components/dialog/lib-decrypt-dialog.js diff --git a/frontend/src/components/dialog/lib-decrypt-dialog.js b/frontend/src/components/dialog/lib-decrypt-dialog.js new file mode 100644 index 0000000000..93367bb261 --- /dev/null +++ b/frontend/src/components/dialog/lib-decrypt-dialog.js @@ -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 ( + + + +
+ +

{gettext('This library is password protected')}

+ {this.state.showError && +

{gettext('Wrong password')}

+ } + +
+ +
+

*{gettext('The password will be kept in the server for only 1 hour.')}

+
+
+
+ ); + } +} + +export default LibDecryptDialog; diff --git a/frontend/src/components/dir-view/dir-panel.js b/frontend/src/components/dir-view/dir-panel.js index ae929daf5d..582bf8e3ef 100644 --- a/frontend/src/components/dir-view/dir-panel.js +++ b/frontend/src/components/dir-view/dir-panel.js @@ -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 (
+ {!this.props.libNeedDecrypt &&
@@ -137,6 +140,7 @@ class DirPanel extends React.Component { switchViewMode={this.switchViewMode} />
+ }
+ {!this.props.libNeedDecrypt &&
+ } {this.state.isDirentDetailShow && (
)} + {this.props.libNeedDecrypt && ( + + + + )}
); diff --git a/frontend/src/components/dir-view/dir-view.js b/frontend/src/components/dir-view/dir-view.js index 68d351798e..a68441760b 100644 --- a/frontend/src/components/dir-view/dir-view.js +++ b/frontend/src/components/dir-view/dir-view.js @@ -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 ( ); } diff --git a/seahub/api2/endpoints/repos.py b/seahub/api2/endpoints/repos.py index fcb10c550c..c9712904ff 100644 --- a/seahub/api2/endpoints/repos.py +++ b/seahub/api2/endpoints/repos.py @@ -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)