1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-14 06:11:16 +00:00

support LIBRARY_TEMPLATES (#4723)

Co-authored-by: lian <lian@seafile.com>
This commit is contained in:
lian
2020-11-20 10:08:49 +08:00
committed by GitHub
parent 87a80eadc5
commit cae1204ab1
5 changed files with 35 additions and 6 deletions

View File

@@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Select from 'react-select'; import Select from 'react-select';
import { Button, Modal, ModalHeader, Input, ModalBody, ModalFooter, Form, FormGroup, Label, Alert } from 'reactstrap'; import { Button, Modal, ModalHeader, Input, ModalBody, ModalFooter, Form, FormGroup, Label, Alert } from 'reactstrap';
import { gettext, enableEncryptedLibrary, repoPasswordMinLength, storages } from '../../utils/constants'; import { gettext, enableEncryptedLibrary, repoPasswordMinLength, storages, libraryTemplates } from '../../utils/constants';
const propTypes = { const propTypes = {
libraryType: PropTypes.string.isRequired, libraryType: PropTypes.string.isRequired,
@@ -22,6 +22,7 @@ class CreateRepoDialog extends React.Component {
errMessage: '', errMessage: '',
permission: 'rw', permission: 'rw',
storage_id: storages.length ? storages[0].id : '', storage_id: storages.length ? storages[0].id : '',
library_template: libraryTemplates.length ? libraryTemplates[0] : '',
isSubmitBtnActive: false, isSubmitBtnActive: false,
}; };
this.newInput = React.createRef(); this.newInput = React.createRef();
@@ -121,6 +122,10 @@ class CreateRepoDialog extends React.Component {
this.setState({storage_id: selectedItem.value}); this.setState({storage_id: selectedItem.value});
} }
handlelibraryTemplatesInputChange = (selectedItem) => {
this.setState({library_template: selectedItem.value});
}
onEncrypted = (e) => { onEncrypted = (e) => {
let isChecked = e.target.checked; let isChecked = e.target.checked;
this.setState({ this.setState({
@@ -162,6 +167,11 @@ class CreateRepoDialog extends React.Component {
repo.storage_id = storage_id; repo.storage_id = storage_id;
} }
const library_template = this.state.library_template;
if (library_template) {
repo.library_template = library_template;
}
return repo; return repo;
} }
@@ -192,6 +202,19 @@ class CreateRepoDialog extends React.Component {
/> />
</FormGroup> </FormGroup>
)} )}
{libraryTemplates.length > 0 && (
<FormGroup>
<Label for="library-templates">{gettext('Library Templates')}</Label>
<Select
id="library-templates"
defaultValue={{value: libraryTemplates[0], label: libraryTemplates[0]}}
options={libraryTemplates.map((item, index) => { return {value: item, label: item}; })}
onChange={this.handlelibraryTemplatesInputChange}
/>
</FormGroup>
)}
{this.props.libraryType === 'group' && ( {this.props.libraryType === 'group' && (
<FormGroup> <FormGroup>
<Label for="exampleSelect">{gettext('Permission')}</Label> <Label for="exampleSelect">{gettext('Permission')}</Label>

View File

@@ -42,6 +42,7 @@ export const enableUploadFolder = window.app.pageOptions.enableUploadFolder ===
export const enableResumableFileUpload = window.app.pageOptions.enableResumableFileUpload === 'True'; export const enableResumableFileUpload = window.app.pageOptions.enableResumableFileUpload === 'True';
export const resumableUploadFileBlockSize = window.app.pageOptions.resumableUploadFileBlockSize; export const resumableUploadFileBlockSize = window.app.pageOptions.resumableUploadFileBlockSize;
export const storages = window.app.pageOptions.storages; // storage backends export const storages = window.app.pageOptions.storages; // storage backends
export const libraryTemplates = window.app.pageOptions.libraryTemplates; // library templates
export const enableRepoSnapshotLabel = window.app.pageOptions.enableRepoSnapshotLabel; export const enableRepoSnapshotLabel = window.app.pageOptions.enableRepoSnapshotLabel;
export const shareLinkPasswordMinLength = window.app.pageOptions.shareLinkPasswordMinLength; export const shareLinkPasswordMinLength = window.app.pageOptions.shareLinkPasswordMinLength;
export const shareLinkExpireDaysMin = window.app.pageOptions.shareLinkExpireDaysMin; export const shareLinkExpireDaysMin = window.app.pageOptions.shareLinkExpireDaysMin;

View File

@@ -50,14 +50,10 @@ try:
library_template = kwargs['library_template'] library_template = kwargs['library_template']
if LIBRARY_TEMPLATES and library_template: if LIBRARY_TEMPLATES and library_template:
if isinstance(library_template, str):
library_template = library_template.encode('utf-8')
try: try:
dir_path_list = LIBRARY_TEMPLATES[library_template] dir_path_list = LIBRARY_TEMPLATES[library_template]
for dir_path in dir_path_list: for dir_path in dir_path_list:
seafile_api.mkdir_with_parents(repo_id, '/', seafile_api.mkdir_with_parents(repo_id, '/', dir_path.strip('/'), creator)
dir_path.strip('/'), related_users)
except Exception as e: except Exception as e:
logger.error(e) logger.error(e)

View File

@@ -81,6 +81,14 @@
{% endfor %} {% endfor %}
return storages; return storages;
})(), })(),
// library template
libraryTemplates: (function () {
var libraryTemplates = [];
{% for template in library_templates %}
libraryTemplates.push("{{template}}");
{% endfor %}
return libraryTemplates;
})(),
enableRepoSnapshotLabel: {% if enable_repo_snapshot_label %} true {% else %} false {% endif %}, enableRepoSnapshotLabel: {% if enable_repo_snapshot_label %} true {% else %} false {% endif %},
shareLinkPasswordMinLength: {{ share_link_password_min_length }}, shareLinkPasswordMinLength: {{ share_link_password_min_length }},
sideNavFooterCustomHtml: "{{ side_nav_footer_custom_html|safe|escapejs }}", sideNavFooterCustomHtml: "{{ side_nav_footer_custom_html|safe|escapejs }}",

View File

@@ -1185,6 +1185,7 @@ def react_fake_view(request, **kwargs):
'max_upload_file_size': max_upload_file_size, 'max_upload_file_size': max_upload_file_size,
'seafile_collab_server': SEAFILE_COLLAB_SERVER, 'seafile_collab_server': SEAFILE_COLLAB_SERVER,
'storages': get_library_storages(request), 'storages': get_library_storages(request),
'library_templates': list(LIBRARY_TEMPLATES.keys()),
'enable_repo_snapshot_label': settings.ENABLE_REPO_SNAPSHOT_LABEL, 'enable_repo_snapshot_label': settings.ENABLE_REPO_SNAPSHOT_LABEL,
'resumable_upload_file_block_size': settings.RESUMABLE_UPLOAD_FILE_BLOCK_SIZE, 'resumable_upload_file_block_size': settings.RESUMABLE_UPLOAD_FILE_BLOCK_SIZE,
'max_number_of_files_for_fileupload': settings.MAX_NUMBER_OF_FILES_FOR_FILEUPLOAD, 'max_number_of_files_for_fileupload': settings.MAX_NUMBER_OF_FILES_FOR_FILEUPLOAD,