Files
wekan/models/customFields.js
T
Lauri Ojansivu 7930da455a Fix a boot-crashing invalid SimpleSchema property on customFields.sort.
The user's own ./build.sh run reproduced it directly: "[uncaughtException]
WeKan is stopping: Error: Invalid definition for sort field: 'decimal' is
not a supported property", thrown from SimpleSchema's own constructor the
moment the server started - before any board could load. `decimal: true`
is not, and has never been, a property SimpleSchema recognizes (its
schemaDefinitionOptions list is autoValue/defaultValue/label/optional/
required/type, plus WeKan's own extendOptions(['index', 'unique']) in
imports/simpleSchema.js); nothing exercises that validation under a plain
Node test, which is why it slipped through review. `type: Number` already
allows fractional values with no extra flag - the same as Lists' own
`sort` field, which this one was deliberately written to mirror (see the
field's own comment) and which never had this property either - so
removing it changes nothing about what the field accepts.

tests/customFieldsSortSchema.test.cjs pins the sort field's definition
against SimpleSchema's actual valid-property list and sweeps every other
file under models/ for the same shape, so it cannot reappear anywhere else
undetected by a Node-only test run.

Verified against a real Meteor boot (`meteor run`) in-sandbox: reproduced
the crash before this commit, starts cleanly after.

Thanks to xet7 !
2026-09-10 23:43:06 +03:00

196 lines
4.5 KiB
JavaScript

import { Mongo } from 'meteor/mongo';
import Cards from '/models/cards';
const { SimpleSchema } = require('/imports/simpleSchema');
const CustomFields = new Mongo.Collection('customFields');
/**
* A custom field on a card in the board
*/
CustomFields.attachSchema(
new SimpleSchema({
boardIds: {
/**
* the ID of the board
*/
type: Array,
},
'boardIds.$': {
type: String,
},
name: {
/**
* name of the custom field
*/
type: String,
},
type: {
/**
* type of the custom field
*/
type: String,
allowedValues: [
'text',
'number',
'date',
'dropdown',
'dropdownMultiSelect',
'checkbox',
'currency',
'stringtemplate',
],
},
settings: {
/**
* settings of the custom field
*/
type: Object,
},
'settings.currencyCode': {
type: String,
optional: true,
},
'settings.dropdownItems': {
/**
* list of drop down items objects
*/
type: Array,
optional: true,
},
'settings.dropdownItems.$': {
type: new SimpleSchema({
_id: {
/**
* ID of the drop down item
*/
type: String,
},
name: {
/**
* name of the drop down item
*/
type: String,
},
}),
},
'settings.stringtemplateFormat': {
type: String,
optional: true,
},
'settings.stringtemplateSeparator': {
type: String,
optional: true,
},
showOnCard: {
/**
* should we show on the cards this custom field
*/
type: Boolean,
defaultValue: false,
},
automaticallyOnCard: {
/**
* should the custom fields automatically be added on cards?
*/
type: Boolean,
defaultValue: false,
},
alwaysOnCard: {
/**
* should the custom field be automatically added to all cards?
*/
type: Boolean,
defaultValue: false,
},
showLabelOnMiniCard: {
/**
* should the label of the custom field be shown on minicards?
*/
type: Boolean,
defaultValue: false,
},
showSumAtTopOfList: {
/**
* should the sum of the custom fields be shown at top of list?
*/
type: Boolean,
defaultValue: false,
},
adminOnly: {
/**
* #3141: when true, this custom field's VALUE is hidden from - and
* cannot be set by - a non board-admin board member: not on the card
* detail view, not on the minicard, and not through the server-side
* setCustomField method (a UI-only hide is not real access control).
* Defaults to false so every existing custom field is unaffected.
*/
type: Boolean,
defaultValue: false,
},
sort: {
/**
* #4165: the user-settable DISPLAY order of the custom field, both in the
* board-settings list and on a card. Ascending, lower first - mirrors
* Lists' own `sort` field. A newly created field defaults to the end of
* the board's current list (the client passes `existingCount` on insert)
* rather than jumping to the top; fields created before this existed have
* no `sort` of their own and fall back to name order (see
* models/lib/customFieldsWD.js).
*/
type: Number,
optional: true,
},
createdAt: {
type: Date,
optional: true,
// eslint-disable-next-line consistent-return
autoValue() {
if (this.isInsert) {
return new Date();
} else if (this.isUpsert) {
return { $setOnInsert: new Date() };
} else {
this.unset();
}
},
},
modifiedAt: {
type: Date,
// eslint-disable-next-line consistent-return
autoValue() {
if (this.isInsert || this.isUpsert || this.isUpdate) {
return new Date();
} else {
this.unset();
}
},
},
}),
);
CustomFields.addToAllCards = async cf => {
await Cards.updateAsync(
{
boardId: { $in: cf.boardIds },
customFields: { $not: { $elemMatch: { _id: cf._id } } },
},
{
$push: { customFields: { _id: cf._id, value: null } },
},
{ multi: true },
);
};
CustomFields.helpers({
async addBoard(boardId) {
if (boardId) {
return await CustomFields.updateAsync(this._id, {
$push: { boardIds: boardId },
});
}
return null;
},
});
export default CustomFields;