apostrophe 3.28.0 → 3.28.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.28.1 (2022-09-15)
4
+
5
+ ### Fixes
6
+
7
+ * `AposInputBoolean` can now be `required` and have the value `false`.
8
+ * Schema fields containing boolean filters can now list both `yes` and `no` choices according to available values in the database.
9
+ * Fix attachment `getHeight()` and `getWidth()` template helpers by changing the assignment of the `attachment._crop` property.
10
+ * Change assignment of `attachment._focalPoint` for consistency.
11
+
3
12
  ## 3.28.0 (2022-08-31)
4
13
 
5
14
  ### Fixes
@@ -708,8 +708,8 @@ module.exports = {
708
708
  if (ancestorFields) {
709
709
  value = _.clone(value);
710
710
  o.attachment = value;
711
- value._crop = _.pick(ancestorFields, 'width', 'height', 'top', 'left');
712
- value._focalPoint = _.pick(ancestorFields, 'x', 'y');
711
+ value._crop = ancestorFields.width ? _.pick(ancestorFields, 'width', 'height', 'top', 'left') : undefined;
712
+ value._focalPoint = (typeof ancestorFields.x === 'number') ? _.pick(ancestorFields, 'x', 'y') : undefined;
713
713
  break;
714
714
  }
715
715
  }
@@ -753,7 +753,7 @@ module.exports = {
753
753
  isShareDraftRequest(req) {
754
754
  const { aposShareId, aposShareKey } = req.query;
755
755
 
756
- return (
756
+ return Boolean(
757
757
  typeof aposShareId === 'string' &&
758
758
  aposShareId.length &&
759
759
  typeof aposShareKey === 'string' &&
@@ -165,7 +165,7 @@ module.exports = (self) => {
165
165
  destination[field.name] = self.apos.launder.boolean(data[field.name], field.def);
166
166
  },
167
167
  isEmpty: function (field, value) {
168
- return !value;
168
+ return !value && value !== false;
169
169
  },
170
170
  exporters: {
171
171
  string: function (req, field, object, output) {
@@ -190,7 +190,7 @@ module.exports = (self) => {
190
190
  return self.apos.launder.booleanOrNull(b);
191
191
  },
192
192
  choices: async function () {
193
- const values = query.toDistinct(field.name);
193
+ const values = await query.toDistinct(field.name);
194
194
  const choices = [];
195
195
  if (_.includes(values, true)) {
196
196
  choices.push({
@@ -198,7 +198,7 @@ module.exports = (self) => {
198
198
  label: 'apostrophe:yes'
199
199
  });
200
200
  }
201
- if (_.includes(values, true)) {
201
+ if (_.includes(values, false)) {
202
202
  choices.push({
203
203
  value: '0',
204
204
  label: 'apostrophe:no'
@@ -81,7 +81,7 @@ export default {
81
81
  },
82
82
  validate(value) {
83
83
  if (this.field.required) {
84
- if (!value) {
84
+ if (!value && value !== false) {
85
85
  return 'required';
86
86
  }
87
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apostrophe",
3
- "version": "3.28.0",
3
+ "version": "3.28.1",
4
4
  "description": "The Apostrophe Content Management System.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test/areas.js CHANGED
@@ -336,11 +336,29 @@ describe('Areas', function() {
336
336
  }, true)
337
337
  );
338
338
  assert(
339
- apos.schema.fieldTypes.boolean.isEmpty({
339
+ !apos.schema.fieldTypes.boolean.isEmpty({
340
340
  type: 'boolean',
341
341
  name: 'test'
342
342
  }, false)
343
343
  );
344
+ assert(
345
+ apos.schema.fieldTypes.boolean.isEmpty({
346
+ type: 'boolean',
347
+ name: 'test'
348
+ }, null)
349
+ );
350
+ assert(
351
+ apos.schema.fieldTypes.boolean.isEmpty({
352
+ type: 'boolean',
353
+ name: 'test'
354
+ }, undefined)
355
+ );
356
+ assert(
357
+ apos.schema.fieldTypes.boolean.isEmpty({
358
+ type: 'boolean',
359
+ name: 'test'
360
+ }, 0)
361
+ );
344
362
  assert(
345
363
  !apos.schema.fieldTypes.boolean.empty({
346
364
  type: 'boolean',
@@ -348,11 +366,29 @@ describe('Areas', function() {
348
366
  }, true)
349
367
  );
350
368
  assert(
351
- apos.schema.fieldTypes.boolean.empty({
369
+ !apos.schema.fieldTypes.boolean.empty({
352
370
  type: 'boolean',
353
371
  name: 'test'
354
372
  }, false)
355
373
  );
374
+ assert(
375
+ apos.schema.fieldTypes.boolean.empty({
376
+ type: 'boolean',
377
+ name: 'test'
378
+ }, null)
379
+ );
380
+ assert(
381
+ apos.schema.fieldTypes.boolean.empty({
382
+ type: 'boolean',
383
+ name: 'test'
384
+ }, undefined)
385
+ );
386
+ assert(
387
+ apos.schema.fieldTypes.boolean.empty({
388
+ type: 'boolean',
389
+ name: 'test'
390
+ }, 0)
391
+ );
356
392
  });
357
393
  });
358
394
 
@@ -73,6 +73,11 @@ describe('Schema builders', function() {
73
73
  idsStorage: 'favoriteIds',
74
74
  label: 'Favorites',
75
75
  withType: 'cat'
76
+ },
77
+ isACatPerson: {
78
+ type: 'boolean',
79
+ label: 'Is a cat person?',
80
+ required: true
76
81
  }
77
82
  }
78
83
  }
@@ -102,9 +107,11 @@ describe('Schema builders', function() {
102
107
  }
103
108
  for (i = 0; (i < people.length); i++) {
104
109
  const person = people[i];
110
+ person.isACatPerson = true;
105
111
  // person 10 has no favorite cat
106
112
  if (i < 10) {
107
113
  person.favoriteIds = [ cats[i].aposDocId ];
114
+ person.isACatPerson = false;
108
115
  }
109
116
  person.catsIds = [];
110
117
  let j;
@@ -299,6 +306,23 @@ describe('Schema builders', function() {
299
306
  assert(cats[0].label);
300
307
  assert(cats[0].slug);
301
308
  });
309
+ it('can obtain choices for isACatPerson', async function() {
310
+ const req = apos.task.getReq();
311
+ const query = apos.people.find(req);
312
+ const isACatPerson = await query.toChoices('isACatPerson');
313
+ const actual = isACatPerson;
314
+ const expected = [
315
+ {
316
+ value: '1',
317
+ label: 'apostrophe:yes'
318
+ },
319
+ {
320
+ value: '0',
321
+ label: 'apostrophe:no'
322
+ }
323
+ ];
324
+ assert.deepEqual(actual, expected);
325
+ });
302
326
 
303
327
  it('builder for favorite (by slug) exists', function() {
304
328
  const req = apos.task.getReq();