Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix existing files not conforming with name patterns #4715

Merged
merged 3 commits into from Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Expand Up @@ -23,6 +23,9 @@ Bugfixes
generated links) (:pr:`4717`)
- Correctly grant access to attachments inside public sessions/contribs even if the event
is more restricted (:pr:`4721`)
- Fix missing filename pattern check when suggesting files from Paper Peer Reviewing to submit
for Editing (:pr:`4715`)
- Fix filename pattern check in Editing when a filename contains dots (:pr:`4715`)

Version 2.3.1
-------------
Expand Down
Expand Up @@ -91,7 +91,7 @@ export function Dropzone({
// in that case only its type is available but not the name
return true;
}
const filename = file.name.slice(0, file.name.indexOf('.'));
const filename = file.name.slice(0, file.name.lastIndexOf('.'));
if (!templateRe.test(filename)) {
dispatch(actions.invalidTemplate(id, file.name));
return false;
Expand All @@ -102,7 +102,7 @@ export function Dropzone({
});

return (
<div {...getRootProps()} styleName="outer-dropzone">
<div {...getRootProps()}>
<input {...getInputProps()} />
<div styleName="dropzone" className={isDragActive ? 'active' : ''}>
<Icon color="grey" size="big" name={showNewFileIcon ? 'plus circle' : 'exchange'} />
Expand Down Expand Up @@ -190,23 +190,25 @@ function FileType({
))}
</div>
)}
<Dropzone dropzoneRef={ref} fileType={fileType} files={files} uploadURL={uploadURL} />
{uploadableFiles && uploadableFiles.length > 0 && (
<Dropdown
className="primary"
style={{marginTop: '1em'}}
text={Translate.string('Use an existing file')}
options={uploadableFiles.map((uf, i) => ({
text: uf.filename,
value: i,
disabled: files.some(f => f.id === uf.id),
}))}
onChange={onChangeDropdown}
selectOnNavigation={false}
selectOnBlur={false}
value={null}
/>
)}
<div styleName="outer-dropzone">
{uploadableFiles && uploadableFiles.length > 0 && (
<Dropdown
className="primary"
style={{marginBottom: '1em'}}
text={Translate.string('Use an existing file')}
options={uploadableFiles.map((uf, i) => ({
text: uf.filename,
value: i,
disabled: files.some(f => f.id === uf.id),
}))}
onChange={onChangeDropdown}
selectOnNavigation={false}
selectOnBlur={false}
value={null}
/>
)}
<Dropzone dropzoneRef={ref} fileType={fileType} files={files} uploadURL={uploadURL} />
</div>
</div>
);
}
Expand Down
Expand Up @@ -5,6 +5,7 @@
// modify it under the terms of the MIT License; see the
// LICENSE file for more details.

import globToRegExp from 'glob-to-regexp';
import _ from 'lodash';
import PropTypes from 'prop-types';
import React from 'react';
Expand Down Expand Up @@ -108,11 +109,22 @@ export function mapFileTypes(fileTypes, files, uploadableFiles = []) {
...fileType,
files: files.filter(file => file.fileType === fileType.id).map(f => ({...f, claimed: true})),
invalidFiles: [],
uploadableFiles: uploadableFiles.filter(
uploadableFiles: filesForFileType(uploadableFiles, fileType),
}));
}

function filesForFileType(files, fileType) {
const templateRe = fileType.filenameTemplate && globToRegExp(fileType.filenameTemplate);
return files
.filter(
file =>
!fileType.filenameTemplate ||
templateRe.test(file.filename.slice(0, file.filename.lastIndexOf('.')))
)
.filter(
file =>
!fileType.extensions.length || fileType.extensions.includes(file.filename.split('.').pop())
),
}));
);
}

export function getFilesFromRevision(fileTypes, revision) {
Expand Down