Skip to content

Commit 53ef912

Browse files
committed
fix: restrict mime type list depending on check operator
fixes #23666 Signed-off-by: Robin Windey <[email protected]>
1 parent de381f3 commit 53ef912

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

apps/workflowengine/src/components/Checks/FileMimeType.vue

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
v-if="!isPredefined"
3535
:value="currentValue.id"
3636
type="text"
37-
:placeholder="t('workflowengine', 'e.g. httpd/unix-directory')"
37+
:placeholder="t('workflowengine', 'e.g. /^application\\/xml$/')"
3838
@input="updateCustom">
3939
</div>
4040
</template>
@@ -56,13 +56,33 @@ export default {
5656
type: String,
5757
default: '',
5858
},
59+
60+
operator: {
61+
type: String,
62+
default: '',
63+
},
5964
},
6065
6166
emits: ['update:model-value'],
6267
6368
data() {
6469
return {
65-
predefinedTypes: [
70+
literalOperators: ['is', '!is'],
71+
regexOperators: ['matches', '!matches'],
72+
predefinedLiteralTypes: [
73+
{
74+
icon: 'icon-folder',
75+
label: t('workflowengine', 'Folder'),
76+
id: 'httpd/unix-directory',
77+
},
78+
{
79+
iconUrl: imagePath('core', 'filetypes/application-pdf'),
80+
label: t('workflowengine', 'PDF documents'),
81+
id: 'application/pdf',
82+
},
83+
],
84+
85+
predefinedRegexTypes: [
6686
{
6787
iconUrl: imagePath('core', 'filetypes/audio'),
6888
label: t('workflowengine', 'Audio'),
@@ -71,7 +91,7 @@ export default {
7191
{
7292
icon: 'icon-folder',
7393
label: t('workflowengine', 'Folder'),
74-
id: 'httpd/unix-directory',
94+
id: '/^httpd\\/unix-directory$/',
7595
},
7696
{
7797
icon: 'icon-picture',
@@ -86,7 +106,7 @@ export default {
86106
{
87107
iconUrl: imagePath('core', 'filetypes/application-pdf'),
88108
label: t('workflowengine', 'PDF documents'),
89-
id: 'application/pdf',
109+
id: '/^application\\/pdf$/',
90110
},
91111
{
92112
iconUrl: imagePath('core', 'filetypes/video'),
@@ -100,16 +120,17 @@ export default {
100120
},
101121
102122
computed: {
123+
availablePredefinedTypes() {
124+
return this.literalOperators.includes(this.operator) ? this.predefinedLiteralTypes : this.predefinedRegexTypes
125+
},
126+
103127
options() {
104-
return [...this.predefinedTypes, this.customValue]
128+
const customTypes = this.regexOperators.includes(this.operator) ? [this.customValue] : []
129+
return [...this.availablePredefinedTypes, ...customTypes]
105130
},
106131
107132
isPredefined() {
108-
const matchingPredefined = this.predefinedTypes.find((type) => this.newValue === type.id)
109-
if (matchingPredefined) {
110-
return true
111-
}
112-
return false
133+
return this.availablePredefinedTypes.some((type) => this.newValue === type.id)
113134
},
114135
115136
customValue() {
@@ -121,7 +142,7 @@ export default {
121142
},
122143
123144
currentValue() {
124-
const matchingPredefined = this.predefinedTypes.find((type) => this.newValue === type.id)
145+
const matchingPredefined = this.availablePredefinedTypes.find((type) => this.newValue === type.id)
125146
if (matchingPredefined) {
126147
return matchingPredefined
127148
}
@@ -137,6 +158,15 @@ export default {
137158
modelValue() {
138159
this.updateInternalValue()
139160
},
161+
162+
// If user changed operation from is/!is to matches/!matches (or vice versa), reset value
163+
operator(newVal, oldVal) {
164+
const switchedGroups = (this.literalOperators.includes(oldVal) && this.regexOperators.includes(newVal))
165+
|| (this.regexOperators.includes(oldVal) && this.literalOperators.includes(newVal))
166+
if (switchedGroups) {
167+
this.setValue(this.options[0])
168+
}
169+
},
140170
},
141171
142172
methods: {

dist/workflowengine-workflowengine.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/workflowengine-workflowengine.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)