This is done at docman
level (not Documents
because the behaviour must be consistent whether user rely on the old or the new interface).
Configuration
There is a new entry in docman
administration: "File pattern" that allows to define the pattern:
- by default no pattern is applied
- the pattern is applied at upload
- The original filename is not kept
- The pattern only applies on new files (existing one are left un-touched)
- pattern is defined with variables that comes from Tuleap. There are only 4 variables available:
- Variables are either hard coded:
-
${ID}
=> corresponds to document internal id
- Or comes from document's properties:
-
${TITLE}
=> corresponds to document title
-
${STATUS}
=> corresponds to hard coded "Status" field (either "Draft", "Approved" or "Rejected").
- Or comes from document's versions
-
${VERSION_NAME}
=> corresponds to last uploaded "Version name" (see screenshot bellow)
- The pattern only apply to the basename of the file. Basename being defined by "everything to the last dot of the filename". Examples:
-
review.pdf
=> basename: review
, extension: pdf
-
some file.pdf.docx
=> basename: some file.pdf
, extension: docx
-
my output_docx
=> basename: my output_docx
, no extension
Administration page:
- Only server side validation
- One title, one help text, one string input & a save button
- Uses the tab based organization of pages (as in Search story)
In Document interface:
- When pattern is defined and drag'n drop to create a new file or a new version is used, the modal for creation (or new version accordingly) is raised to allow selection of the title.
Specific case of WebDav:
- As we don't know how WebDav client will manage this server side rename we will do tests with some clients (Cyberduck, Nautilus, Cadaver) if they don't play well with this we will desactivate webdav for project that uses pattern.
Examples
Nominal case
- Defined pattern:
${TITLE}_${ID}_${VERSION_NAME}_${STATUS}
(any char is allowed in addition to the variables that are defined with ${}
- Document
- Title: "my foo bar"
- Id: 12345
- Version name: my v 2.0
- Status: Approved
- Original filename: output.35.pdf
- Generated filename will be:
my foo bar_12345_my v 2.0_Approved.pdf
Creation of document
Pitfall: at file creation, there is no ${VERSION_NAME}
- Defined pattern:
${TITLE}_${ID}_${VERSION_NAME}_${STATUS}
- Document
- Title: "my foo bar"
- Id: 12345
- Status: Draft
- Original filename: output.35.pdf
- Generated filename will be:
my foo bar_12345__Draft.pdf
Minimal pattern
There must be at least either ${TITLE}
or ${ID}
variable in the pattern.
Pattern like: ${VERSION_NAME}_${STATUS}
are not allowed
Filename with extended characters
As of today, file names are stripped at download to avoid clash on non ISO-8859-1 chars. In order to support titles and status we should complete the support of internationalized characters as per https://www.rfc-editor.org/rfc/rfc6266#section-6
Original filename doesn't have extension
If the original file doesn't have an extention (no .pdf
) hence the final file won't have an extension either
- Defined pattern:
${TITLE}_${STATUS}
- Document
- Title: "my foo bar"
- Status: Draft
- Original filename: output.35
- Generated filename will be:
my foo bar_Draft
New version without version name
If Version name is not defined (field is not required) the result might be a hole in the name.
- Defined pattern:
${TITLE}-tuleap#${ID}-${VERSION_NAME}-${STATUS}
- Document
- Title: "my foo bar"
- Id: 12345
- Version: `` (empty)
- Status: Draft
- Original filename: output.35.pdf
- At download, filename will be:
my foo bar-tuleap#12345--Draft.pdf