apostrophe 3.42.0 → 3.44.0
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 +32 -4
- package/force-deploy +1 -0
- package/modules/@apostrophecms/admin-bar/ui/apos/components/TheAposContextBar.vue +3 -2
- package/modules/@apostrophecms/doc-type/index.js +10 -0
- package/modules/@apostrophecms/doc-type/ui/apos/components/AposDocContextMenu.vue +17 -3
- package/modules/@apostrophecms/doc-type/ui/apos/components/AposDocEditor.vue +18 -5
- package/modules/@apostrophecms/i18n/i18n/de.json +1 -0
- package/modules/@apostrophecms/i18n/i18n/en.json +2 -0
- package/modules/@apostrophecms/i18n/i18n/es.json +1 -0
- package/modules/@apostrophecms/i18n/i18n/fr.json +1 -0
- package/modules/@apostrophecms/i18n/i18n/pt-BR.json +1 -0
- package/modules/@apostrophecms/i18n/i18n/sk.json +1 -0
- package/modules/@apostrophecms/i18n/index.js +3 -0
- package/modules/@apostrophecms/i18n/ui/apos/components/AposI18nLocalize.vue +25 -13
- package/modules/@apostrophecms/image/ui/apos/components/AposMediaManagerEditor.vue +1 -1
- package/modules/@apostrophecms/login/index.js +2 -1
- package/modules/@apostrophecms/login/ui/apos/components/TheAposLoginHeader.vue +1 -1
- package/modules/@apostrophecms/modal/ui/apos/mixins/AposEditorMixin.js +2 -1
- package/modules/@apostrophecms/modal/ui/apos/mixins/AposModalTabsMixin.js +3 -2
- package/modules/@apostrophecms/module/index.js +11 -0
- package/modules/@apostrophecms/page/index.js +13 -5
- package/modules/@apostrophecms/piece-type/index.js +50 -3
- package/modules/@apostrophecms/piece-type/ui/apos/components/AposDocsManager.vue +1 -1
- package/modules/@apostrophecms/piece-type/ui/apos/components/AposDocsManagerDisplay.vue +3 -3
- package/modules/@apostrophecms/schema/ui/apos/components/AposInputArray.vue +9 -1
- package/modules/@apostrophecms/schema/ui/apos/components/AposInputCheckboxes.vue +27 -3
- package/modules/@apostrophecms/schema/ui/apos/components/AposInputRelationship.vue +15 -13
- package/modules/@apostrophecms/ui/ui/apos/components/AposCombo.vue +381 -0
- package/modules/@apostrophecms/ui/ui/apos/components/AposSlat.vue +11 -6
- package/modules/@apostrophecms/ui/ui/apos/components/AposSlatList.vue +4 -4
- package/package.json +1 -1
- package/test/login.js +6 -1
- package/test/pieces-public-api.js +32 -0
- package/test/pieces-tasks.js +94 -0
- package/test/pieces.js +16 -48
- package/test-lib/util.js +52 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.44.0 (2023-04-13)
|
|
4
|
+
|
|
5
|
+
### Adds
|
|
6
|
+
|
|
7
|
+
* `checkboxes` fields now support a new `style: 'combobox'` option for a better multiple-select experience when there
|
|
8
|
+
are many choices.
|
|
9
|
+
* If the new `guestApiAccess` option is set to `true` for a piece type or for `@apostrophecms/page`,
|
|
10
|
+
Apostrophe will allow all logged-in users to access the GET-method REST APIs of that
|
|
11
|
+
module, not just users with editing privileges, even if `publicApiProjection` is not set.
|
|
12
|
+
This is useful when the goal is to allow REST API access to "guest" users who have
|
|
13
|
+
project-specific reasons to fetch access content via REST APIs.
|
|
14
|
+
* `test-lib/utils.js` has new `createUser` and `loginAs` methods for the convenience of
|
|
15
|
+
those writing mocha tests of Apostrophe modules.
|
|
16
|
+
|
|
17
|
+
## 3.43.0 (2023-03-29)
|
|
18
|
+
|
|
19
|
+
### Adds
|
|
20
|
+
|
|
21
|
+
* Add the possibility to override the default "Add Item" button label by setting the `itemLabel` option of an `array` field.
|
|
22
|
+
* Adds `touch` task for every piece type. This task invokes `update` on each piece, which will execute all of the same event handlers that normally execute when a piece of that type is updated. Example usage: `node app article:touch`.
|
|
23
|
+
|
|
24
|
+
### Fixes
|
|
25
|
+
|
|
26
|
+
* Hide the suggestion help from the relationship input list when the user starts typing a search term.
|
|
27
|
+
* Hide the suggestion hint from the relationship input list when the user starts typing a search term except when there are no matches to display.
|
|
28
|
+
* Disable context menu for related items when their `relationship` field has no sub-[`fields`](https://v3.docs.apostrophecms.org/guide/relationships.html#providing-context-with-fields) configured.
|
|
29
|
+
|
|
3
30
|
## 3.42.0 (2023-03-16)
|
|
4
31
|
|
|
5
32
|
### Adds
|
|
@@ -31,17 +58,18 @@ current selection. Currently this works best with newly inserted documents.
|
|
|
31
58
|
* Localized strings in the admin UI can now use `$t(key)` to localize a string inside
|
|
32
59
|
an interpolated variable. This was accomplished by setting `skipOnVariables` to false
|
|
33
60
|
for i18next, solely on the front end for admin UI purposes.
|
|
34
|
-
* The syntax of the method defined for dynamic `choices` now accepts a module prefix to get the method from, and the `()` suffix.
|
|
61
|
+
* The syntax of the method defined for dynamic `choices` now accepts a module prefix to get the method from, and the `()` suffix.
|
|
35
62
|
This has been done for consistency with the external conditions syntax shipped in the previous release. See the documentation for more information.
|
|
36
63
|
* Added the `viewPermission` property of schema fields, and renamed `permission` to `editPermission` (with backwards
|
|
37
64
|
compatibility) for clarity. You can now decide if a schema field requires permissions to be visible or editable.
|
|
38
65
|
See the documentation for more information.
|
|
66
|
+
* Display the right environment label on login page. By default, based on `NODE_ENV`, overriden by `environmentLabel` option in `@apostrophecms/login` module. The environment variable `APOS_ENV_LABEL` will override this. Note that `NODE_ENV` should generally only be set to `development` (the default) or `production` as many Node.js modules opt into optimizations suitable for all deployed environments when it is set to `production`. This is why we offer the separate `APOS_ENV_LABEL` variable.
|
|
39
67
|
|
|
40
|
-
### Fixes
|
|
68
|
+
### Fixes
|
|
41
69
|
|
|
42
70
|
* Do not log unnecessary "required" errors for hidden fields.
|
|
43
71
|
* Fixed a bug that prevented "Text Align" from working properly in the rich text editor in certain cases.
|
|
44
|
-
* Fix typo in `@apostrophecms/doc-type` and `@apostrophecms/submitted-drafts` where we were using `canCreate` instead of `showCreate` to display the `Create New` button or showing the `Copy` button in `Manager` modals.
|
|
72
|
+
* Fix typo in `@apostrophecms/doc-type` and `@apostrophecms/submitted-drafts` where we were using `canCreate` instead of `showCreate` to display the `Create New` button or showing the `Copy` button in `Manager` modals.
|
|
45
73
|
* Send external condition results in an object so that numbers are supported as returned values.
|
|
46
74
|
|
|
47
75
|
## 3.41.1 (2023-03-07)
|
|
@@ -52,7 +80,7 @@ No changes. Publishing to make sure 3.x is tagged `latest` in npm, rather than 2
|
|
|
52
80
|
|
|
53
81
|
### Adds
|
|
54
82
|
|
|
55
|
-
* Handle external conditions to display fields according to the result of a module method, or multiple methods from different modules.
|
|
83
|
+
* Handle external conditions to display fields according to the result of a module method, or multiple methods from different modules.
|
|
56
84
|
This can be useful for displaying fields according to the result of an external API or any business logic run on the server. See the documentation for more information.
|
|
57
85
|
|
|
58
86
|
### Fixes
|
package/force-deploy
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
4
|
|
@@ -79,10 +79,11 @@ export default {
|
|
|
79
79
|
},
|
|
80
80
|
computed: {
|
|
81
81
|
contextBarActive() {
|
|
82
|
-
return window.apos.adminBar.contextBar && this.canEdit;
|
|
82
|
+
return window.apos.adminBar.contextBar && (this.canEdit || this.moduleOptions.canLocalize);
|
|
83
83
|
},
|
|
84
84
|
canEdit() {
|
|
85
|
-
return this.context._edit || ((this.context.aposLocale && this.context.aposLocale.endsWith(':published')) &&
|
|
85
|
+
return this.context._edit || ((this.context.aposLocale && this.context.aposLocale.endsWith(':published')) &&
|
|
86
|
+
this.draftIsEditable);
|
|
86
87
|
},
|
|
87
88
|
classes() {
|
|
88
89
|
if (!this.contextBarActive) {
|
|
@@ -763,6 +763,11 @@ module.exports = {
|
|
|
763
763
|
async findOneForCopying(req, criteria) {
|
|
764
764
|
return self.findOneForEditing(req, criteria);
|
|
765
765
|
},
|
|
766
|
+
// Identical to findOneForEditing by default, but could be
|
|
767
|
+
// overridden usefully in subclasses.
|
|
768
|
+
async findOneForLocalizing(req, criteria) {
|
|
769
|
+
return self.findOneForEditing(req, criteria);
|
|
770
|
+
},
|
|
766
771
|
// Submit the current draft for review. The identity
|
|
767
772
|
// of `req.user` is associated with the submission.
|
|
768
773
|
// Returns the `submitted` object, with `by`, `byId`,
|
|
@@ -1424,8 +1429,13 @@ module.exports = {
|
|
|
1424
1429
|
label,
|
|
1425
1430
|
pluralLabel,
|
|
1426
1431
|
relatedDocument: self.options.relatedDocument,
|
|
1432
|
+
canEdit: self.apos.permission.can(req, 'edit', self.name, 'draft'),
|
|
1427
1433
|
canPublish: self.apos.permission.can(req, 'publish', self.name)
|
|
1428
1434
|
};
|
|
1435
|
+
browserOptions.canLocalize = browserOptions.canEdit &&
|
|
1436
|
+
self.options.localized &&
|
|
1437
|
+
Object.keys(self.apos.i18n.locales).length > 1 &&
|
|
1438
|
+
Object.values(self.apos.i18n.locales).some(locale => locale._edit);
|
|
1429
1439
|
browserOptions.action = self.action;
|
|
1430
1440
|
browserOptions.schema = self.allowedSchema(req);
|
|
1431
1441
|
browserOptions.localized = self.isLocalized();
|
|
@@ -181,6 +181,10 @@ export default {
|
|
|
181
181
|
return menu;
|
|
182
182
|
},
|
|
183
183
|
customMenusByContext() {
|
|
184
|
+
if (!this.canEdit) {
|
|
185
|
+
return [];
|
|
186
|
+
}
|
|
187
|
+
|
|
184
188
|
const menus = this.customOperationsByContext
|
|
185
189
|
.map(op => ({
|
|
186
190
|
label: op.label,
|
|
@@ -233,7 +237,7 @@ export default {
|
|
|
233
237
|
}
|
|
234
238
|
},
|
|
235
239
|
canDismissSubmission() {
|
|
236
|
-
return this.context.submitted && (this.canPublish || (this.context.submitted.byId === apos.login.user._id));
|
|
240
|
+
return this.canEdit && this.context.submitted && (this.canPublish || (this.context.submitted.byId === apos.login.user._id));
|
|
237
241
|
},
|
|
238
242
|
canDiscardDraft() {
|
|
239
243
|
if (!this.manuallyPublished) {
|
|
@@ -242,6 +246,9 @@ export default {
|
|
|
242
246
|
if (!this.context._id) {
|
|
243
247
|
return false;
|
|
244
248
|
}
|
|
249
|
+
if (!this.canEdit) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
245
252
|
return (
|
|
246
253
|
(!this.context.lastPublishedAt) &&
|
|
247
254
|
!this.moduleOptions.singleton
|
|
@@ -251,10 +258,12 @@ export default {
|
|
|
251
258
|
);
|
|
252
259
|
},
|
|
253
260
|
canLocalize() {
|
|
254
|
-
return
|
|
261
|
+
return this.moduleOptions.canLocalize &&
|
|
262
|
+
this.context._id;
|
|
255
263
|
},
|
|
256
264
|
canArchive() {
|
|
257
265
|
return (
|
|
266
|
+
this.canEdit &&
|
|
258
267
|
this.context._id &&
|
|
259
268
|
!this.moduleOptions.singleton &&
|
|
260
269
|
!this.context.archived &&
|
|
@@ -264,6 +273,7 @@ export default {
|
|
|
264
273
|
},
|
|
265
274
|
canUnpublish() {
|
|
266
275
|
return (
|
|
276
|
+
this.canEdit &&
|
|
267
277
|
!this.context.parked &&
|
|
268
278
|
this.moduleOptions.canPublish &&
|
|
269
279
|
this.context.lastPublishedAt &&
|
|
@@ -271,10 +281,14 @@ export default {
|
|
|
271
281
|
);
|
|
272
282
|
},
|
|
273
283
|
canCopy() {
|
|
274
|
-
return this.canEdit &&
|
|
284
|
+
return this.canEdit &&
|
|
285
|
+
this.moduleOptions.canEdit &&
|
|
286
|
+
!this.moduleOptions.singleton &&
|
|
287
|
+
this.context._id;
|
|
275
288
|
},
|
|
276
289
|
canRestore() {
|
|
277
290
|
return (
|
|
291
|
+
this.canEdit &&
|
|
278
292
|
this.context._id &&
|
|
279
293
|
this.context.archived &&
|
|
280
294
|
((this.moduleOptions.canPublish && this.context.lastPublishedAt) || !this.manuallyPublished)
|
|
@@ -162,6 +162,7 @@ export default {
|
|
|
162
162
|
ref: null
|
|
163
163
|
},
|
|
164
164
|
published: null,
|
|
165
|
+
readOnly: false,
|
|
165
166
|
restoreOnly: false,
|
|
166
167
|
saveMenu: null,
|
|
167
168
|
generation: 0
|
|
@@ -174,14 +175,24 @@ export default {
|
|
|
174
175
|
followingUtils() {
|
|
175
176
|
return this.followingValues('utility');
|
|
176
177
|
},
|
|
178
|
+
canEdit() {
|
|
179
|
+
if (this.original && this.original._id) {
|
|
180
|
+
return this.original._edit || this.moduleOptions.canEdit;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return this.moduleOptions.canEdit;
|
|
184
|
+
},
|
|
177
185
|
canPublish() {
|
|
178
186
|
if (this.original && this.original._id) {
|
|
179
|
-
return this.original._publish;
|
|
187
|
+
return this.original._publish || this.moduleOptions.canPublish;
|
|
180
188
|
}
|
|
181
189
|
|
|
182
190
|
return this.moduleOptions.canPublish;
|
|
183
191
|
},
|
|
184
192
|
saveDisabled() {
|
|
193
|
+
if (!this.canEdit) {
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
185
196
|
if (this.restoreOnly) {
|
|
186
197
|
// Can always restore if it's a read-only view of the archive
|
|
187
198
|
return false;
|
|
@@ -421,10 +432,6 @@ export default {
|
|
|
421
432
|
async loadDoc() {
|
|
422
433
|
let docData;
|
|
423
434
|
try {
|
|
424
|
-
if (!await this.lock(this.getOnePath, this.docId)) {
|
|
425
|
-
await this.lockNotAvailable();
|
|
426
|
-
return;
|
|
427
|
-
}
|
|
428
435
|
docData = await apos.http.get(this.getOnePath, {
|
|
429
436
|
busy: true,
|
|
430
437
|
qs: {
|
|
@@ -438,6 +445,12 @@ export default {
|
|
|
438
445
|
} else {
|
|
439
446
|
this.restoreOnly = false;
|
|
440
447
|
}
|
|
448
|
+
const canEdit = docData._edit || this.moduleOptions.canEdit;
|
|
449
|
+
this.readOnly = canEdit === false;
|
|
450
|
+
if (canEdit && !await this.lock(this.getOnePath, this.docId)) {
|
|
451
|
+
await this.lockNotAvailable();
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
441
454
|
} catch {
|
|
442
455
|
await apos.notify('apostrophe:loadDocFailed', {
|
|
443
456
|
type: 'warning',
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
"addWidgetType": "{{ label }} hinzufügen",
|
|
5
5
|
"admin": "Administrator",
|
|
6
6
|
"affirmativeLabel": "Ja, fortsetzen.",
|
|
7
|
+
"allSelected": "Alle ausgewählt",
|
|
7
8
|
"altText": "Alternativtext",
|
|
8
9
|
"altTextHelp": "Bildbeschreibung oder alternativer Text, der für Bildschirmleser verwendet wird.",
|
|
9
10
|
"any": "Irgendwas",
|
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
"addItem": "Add Item",
|
|
6
6
|
"addRowAfter": "Add Row After",
|
|
7
7
|
"addRowBefore": "Add Row Before",
|
|
8
|
+
"addType": "Add {{ type }}",
|
|
8
9
|
"addWidgetType": "Add {{ label }}",
|
|
9
10
|
"admin": "Admin",
|
|
10
11
|
"affirmativeLabel": "Yes, continue.",
|
|
12
|
+
"allSelected": "All Selected",
|
|
11
13
|
"altText": "Alt Text",
|
|
12
14
|
"altTextHelp": "Image description used for accessibility",
|
|
13
15
|
"anchorId": "Anchor ID",
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
"addItem": "Ajouter un élément",
|
|
4
4
|
"addWidgetType": "Ajouter {{ label }}",
|
|
5
5
|
"affirmativeLabel": "Oui, continuer.",
|
|
6
|
+
"allSelected": "Tout Selectionné",
|
|
6
7
|
"altText": "Texte alternatif",
|
|
7
8
|
"altTextHelp": "Description d'image utilisée pour l'accessibilité",
|
|
8
9
|
"any": "Quelconque",
|
|
@@ -278,7 +278,8 @@ export default {
|
|
|
278
278
|
([ locale, options ]) => {
|
|
279
279
|
return {
|
|
280
280
|
name: locale,
|
|
281
|
-
label: options.label || locale
|
|
281
|
+
label: options.label || locale,
|
|
282
|
+
_edit: options._edit
|
|
282
283
|
};
|
|
283
284
|
}
|
|
284
285
|
),
|
|
@@ -382,12 +383,12 @@ export default {
|
|
|
382
383
|
: apos.modules[this.doc.type].action;
|
|
383
384
|
},
|
|
384
385
|
filteredLocales() {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
.includes(this.wizard.sections.selectLocales.filter.toLowerCase());
|
|
386
|
+
const matches = term =>
|
|
387
|
+
term
|
|
388
|
+
.toLowerCase()
|
|
389
|
+
.includes(this.wizard.sections.selectLocales.filter.toLowerCase());
|
|
390
390
|
|
|
391
|
+
return this.locales.filter(({ name, label }) => {
|
|
391
392
|
return matches(name) || matches(label);
|
|
392
393
|
});
|
|
393
394
|
},
|
|
@@ -395,7 +396,7 @@ export default {
|
|
|
395
396
|
return this.wizard.values.toLocales.data;
|
|
396
397
|
},
|
|
397
398
|
allSelected() {
|
|
398
|
-
return this.selectedLocales.length === this.locales.filter(locale => !this.isCurrentLocale(locale)).length;
|
|
399
|
+
return this.selectedLocales.length === this.locales.filter(locale => !this.isCurrentLocale(locale) && this.canEditLocale(locale)).length;
|
|
399
400
|
},
|
|
400
401
|
relatedDocTypes() {
|
|
401
402
|
const types = {};
|
|
@@ -532,6 +533,9 @@ export default {
|
|
|
532
533
|
isCurrentLocale(locale) {
|
|
533
534
|
return window.apos.i18n.locale === locale.name;
|
|
534
535
|
},
|
|
536
|
+
canEditLocale(locale) {
|
|
537
|
+
return !!locale._edit;
|
|
538
|
+
},
|
|
535
539
|
isSelected(locale) {
|
|
536
540
|
return this.wizard.values.toLocales.data.some(
|
|
537
541
|
({ name }) => name === locale.name
|
|
@@ -541,13 +545,13 @@ export default {
|
|
|
541
545
|
return !!this.localized[locale.name];
|
|
542
546
|
},
|
|
543
547
|
selectAll() {
|
|
544
|
-
this.wizard.values.toLocales.data = this.locales.filter(locale => !this.isCurrentLocale(locale));
|
|
548
|
+
this.wizard.values.toLocales.data = this.locales.filter(locale => !this.isCurrentLocale(locale) && this.canEditLocale(locale));
|
|
545
549
|
},
|
|
546
550
|
deselectAll() {
|
|
547
551
|
this.wizard.values.toLocales.data = [];
|
|
548
552
|
},
|
|
549
553
|
toggleLocale(locale) {
|
|
550
|
-
if (!this.isSelected(locale) && !this.isCurrentLocale(locale)) {
|
|
554
|
+
if (!this.isSelected(locale) && !this.isCurrentLocale(locale) && this.canEditLocale(locale)) {
|
|
551
555
|
this.wizard.values.toLocales.data.push(locale);
|
|
552
556
|
} else if (this.isSelected(locale)) {
|
|
553
557
|
this.wizard.values.toLocales.data = this.wizard.values.toLocales.data.filter(l => l !== locale);
|
|
@@ -590,6 +594,9 @@ export default {
|
|
|
590
594
|
if (this.isCurrentLocale(locale)) {
|
|
591
595
|
classes['apos-current-locale'] = true;
|
|
592
596
|
}
|
|
597
|
+
if (!this.canEditLocale(locale)) {
|
|
598
|
+
classes['apos-disabled-locale'] = true;
|
|
599
|
+
}
|
|
593
600
|
return classes;
|
|
594
601
|
},
|
|
595
602
|
// Singular type name for label (returns an i18next key)
|
|
@@ -948,15 +955,18 @@ export default {
|
|
|
948
955
|
line-height: 1;
|
|
949
956
|
border-radius: var(--a-border-radius);
|
|
950
957
|
|
|
951
|
-
&:not(.apos-current-locale)
|
|
958
|
+
&:not(.apos-current-locale),
|
|
959
|
+
&:not(.apos-disabled-locale) {
|
|
952
960
|
cursor: pointer;
|
|
953
961
|
}
|
|
954
962
|
|
|
955
|
-
&:not(.apos-current-locale):hover
|
|
963
|
+
&:not(.apos-current-locale):hover,
|
|
964
|
+
&:not(.apos-disabled-locale):hover {
|
|
956
965
|
background-color: var(--a-base-10);
|
|
957
966
|
}
|
|
958
967
|
|
|
959
|
-
&:not(.apos-current-locale):active
|
|
968
|
+
&:not(.apos-current-locale):active,
|
|
969
|
+
&:not(.apos-disabled-locale):active {
|
|
960
970
|
background-color: var(--a-base-9);
|
|
961
971
|
}
|
|
962
972
|
|
|
@@ -974,11 +984,13 @@ export default {
|
|
|
974
984
|
}
|
|
975
985
|
|
|
976
986
|
&.apos-current-locale,
|
|
987
|
+
&.apos-disabled-locale,
|
|
977
988
|
.apos-current-locale-icon {
|
|
978
989
|
color: var(--a-base-5);
|
|
979
990
|
}
|
|
980
991
|
|
|
981
|
-
&.apos-current-locale
|
|
992
|
+
&.apos-current-locale,
|
|
993
|
+
&.apos-disabled-locale {
|
|
982
994
|
font-style: italic;
|
|
983
995
|
}
|
|
984
996
|
|
|
@@ -158,7 +158,7 @@ export default {
|
|
|
158
158
|
return window.apos.modules[this.activeMedia.type] || {};
|
|
159
159
|
},
|
|
160
160
|
canLocalize() {
|
|
161
|
-
return
|
|
161
|
+
return this.moduleOptions.canLocalize && this.activeMedia._id;
|
|
162
162
|
},
|
|
163
163
|
moreMenu() {
|
|
164
164
|
const menu = [ {
|
|
@@ -382,8 +382,9 @@ module.exports = {
|
|
|
382
382
|
}
|
|
383
383
|
}
|
|
384
384
|
}
|
|
385
|
+
|
|
385
386
|
return {
|
|
386
|
-
env: process.env.NODE_ENV || 'development',
|
|
387
|
+
env: process.env.APOS_ENV_LABEL || self.options.environmentLabel || process.env.NODE_ENV || 'development',
|
|
387
388
|
name: (process.env.npm_package_name && process.env.npm_package_name.replace(/-/g, ' ')) || 'Apostrophe',
|
|
388
389
|
version: aposPackage.version || '3',
|
|
389
390
|
requirementProps
|
|
@@ -24,6 +24,7 @@ export default {
|
|
|
24
24
|
},
|
|
25
25
|
serverErrors: null,
|
|
26
26
|
restoreOnly: false,
|
|
27
|
+
readOnly: false,
|
|
27
28
|
changed: [],
|
|
28
29
|
externalConditionsResults: {}
|
|
29
30
|
};
|
|
@@ -32,7 +33,7 @@ export default {
|
|
|
32
33
|
computed: {
|
|
33
34
|
schema() {
|
|
34
35
|
let schema = (this.moduleOptions.schema || []).filter(field => apos.schema.components.fields[field.type]);
|
|
35
|
-
if (this.restoreOnly) {
|
|
36
|
+
if (this.restoreOnly || this.readOnly) {
|
|
36
37
|
schema = klona(schema);
|
|
37
38
|
for (const field of schema) {
|
|
38
39
|
field.readOnly = true;
|
|
@@ -802,6 +802,17 @@ module.exports = {
|
|
|
802
802
|
}
|
|
803
803
|
},
|
|
804
804
|
|
|
805
|
+
// Modules that have REST APIs use this method
|
|
806
|
+
// to determine if a request is qualified to access
|
|
807
|
+
// it without restriction to the `publicApiProjection`
|
|
808
|
+
canAccessApi(req) {
|
|
809
|
+
if (self.options.guestApiAccess) {
|
|
810
|
+
return !!req.user;
|
|
811
|
+
} else {
|
|
812
|
+
return self.apos.permission.can(req, 'view-draft');
|
|
813
|
+
}
|
|
814
|
+
},
|
|
815
|
+
|
|
805
816
|
// Merge in the event emitter / responder capabilities
|
|
806
817
|
...require('./lib/events.js')(self)
|
|
807
818
|
};
|
|
@@ -133,7 +133,7 @@ module.exports = {
|
|
|
133
133
|
const autocomplete = self.apos.launder.string(req.query.autocomplete);
|
|
134
134
|
|
|
135
135
|
if (autocomplete.length) {
|
|
136
|
-
if (!self.apos.permission.can(req, '
|
|
136
|
+
if (!self.apos.permission.can(req, 'view', '@apostrophecms/any-page-type')) {
|
|
137
137
|
throw self.apos.error('forbidden');
|
|
138
138
|
}
|
|
139
139
|
return {
|
|
@@ -145,7 +145,7 @@ module.exports = {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
if (all) {
|
|
148
|
-
if (!self.apos.permission.can(req, '
|
|
148
|
+
if (!self.apos.permission.can(req, 'view', '@apostrophecms/any-page-type')) {
|
|
149
149
|
throw self.apos.error('forbidden');
|
|
150
150
|
}
|
|
151
151
|
const page = await self.getRestQuery(req).permission(false).and({ level: 0 }).children({
|
|
@@ -418,7 +418,7 @@ module.exports = {
|
|
|
418
418
|
},
|
|
419
419
|
':_id/localize': async (req) => {
|
|
420
420
|
const _id = self.inferIdLocaleAndMode(req, req.params._id);
|
|
421
|
-
const draft = await self.
|
|
421
|
+
const draft = await self.findOneForLocalizing(req.clone({
|
|
422
422
|
mode: 'draft'
|
|
423
423
|
}), {
|
|
424
424
|
aposDocId: _id.split(':')[0]
|
|
@@ -819,6 +819,11 @@ database.`);
|
|
|
819
819
|
// A list of all valid page types, including parked pages etc. This is
|
|
820
820
|
// not a menu of choices for creating a page manually
|
|
821
821
|
browserOptions.validPageTypes = self.apos.instancesOf('@apostrophecms/page-type').map(module => module.__meta.name);
|
|
822
|
+
browserOptions.canEdit = self.apos.permission.can(req, 'edit', '@apostrophecms/any-page-type', 'draft');
|
|
823
|
+
browserOptions.canLocalize = browserOptions.canEdit &&
|
|
824
|
+
browserOptions.localized &&
|
|
825
|
+
Object.keys(self.apos.i18n.locales).length > 1 &&
|
|
826
|
+
Object.values(self.apos.i18n.locales).some(locale => locale._edit);
|
|
822
827
|
return browserOptions;
|
|
823
828
|
},
|
|
824
829
|
// Returns a query that finds pages the current user can edit
|
|
@@ -2212,7 +2217,7 @@ database.`);
|
|
|
2212
2217
|
.applyBuildersSafely(req.query);
|
|
2213
2218
|
// Minimum standard for a REST query without a public projection
|
|
2214
2219
|
// is being allowed to view drafts on the site
|
|
2215
|
-
if (!self.
|
|
2220
|
+
if (!self.canAccessApi(req)) {
|
|
2216
2221
|
if (!self.options.publicApiProjection) {
|
|
2217
2222
|
// Shouldn't be needed thanks to publicApiCheck, but be sure
|
|
2218
2223
|
query.and({
|
|
@@ -2243,6 +2248,9 @@ database.`);
|
|
|
2243
2248
|
async findOneForEditing(req, criteria, builders) {
|
|
2244
2249
|
return self.findForEditing(req, criteria, builders).toObject();
|
|
2245
2250
|
},
|
|
2251
|
+
async findOneForLocalizing(req, criteria, builders) {
|
|
2252
|
+
return self.findForEditing(req, criteria, builders).toObject();
|
|
2253
|
+
},
|
|
2246
2254
|
// Throws a `notfound` exception if a public API projection is
|
|
2247
2255
|
// not specified and the user does not have the `view-draft` permission,
|
|
2248
2256
|
// which all roles capable of editing the site at all will have. This is needed because
|
|
@@ -2250,7 +2258,7 @@ database.`);
|
|
|
2250
2258
|
// we also want to flunk all public access to REST APIs if not specifically configured.
|
|
2251
2259
|
publicApiCheck(req) {
|
|
2252
2260
|
if (!self.options.publicApiProjection) {
|
|
2253
|
-
if (!self.
|
|
2261
|
+
if (!self.canAccessApi(req)) {
|
|
2254
2262
|
throw self.apos.error('notfound');
|
|
2255
2263
|
}
|
|
2256
2264
|
}
|
|
@@ -408,7 +408,7 @@ module.exports = {
|
|
|
408
408
|
},
|
|
409
409
|
':_id/localize': async (req) => {
|
|
410
410
|
const _id = self.inferIdLocaleAndMode(req, req.params._id);
|
|
411
|
-
const draft = await self.
|
|
411
|
+
const draft = await self.findOneForLocalizing(req.clone({
|
|
412
412
|
mode: 'draft'
|
|
413
413
|
}), {
|
|
414
414
|
aposDocId: _id.split(':')[0]
|
|
@@ -1002,7 +1002,7 @@ module.exports = {
|
|
|
1002
1002
|
getRestQuery(req) {
|
|
1003
1003
|
const query = self.find(req).attachments(true);
|
|
1004
1004
|
query.applyBuildersSafely(req.query);
|
|
1005
|
-
if (!self.
|
|
1005
|
+
if (!self.canAccessApi(req)) {
|
|
1006
1006
|
if (!self.options.publicApiProjection) {
|
|
1007
1007
|
// Shouldn't be needed thanks to publicApiCheck, but be sure
|
|
1008
1008
|
query.and({
|
|
@@ -1024,7 +1024,7 @@ module.exports = {
|
|
|
1024
1024
|
// we also want to flunk all public access to REST APIs if not specifically configured.
|
|
1025
1025
|
publicApiCheck(req) {
|
|
1026
1026
|
if (!self.options.publicApiProjection) {
|
|
1027
|
-
if (!self.
|
|
1027
|
+
if (!self.canAccessApi(req)) {
|
|
1028
1028
|
throw self.apos.error('notfound');
|
|
1029
1029
|
}
|
|
1030
1030
|
}
|
|
@@ -1206,6 +1206,53 @@ module.exports = {
|
|
|
1206
1206
|
|
|
1207
1207
|
console.log(`Done unlocalizing module ${self.name}`);
|
|
1208
1208
|
}
|
|
1209
|
+
},
|
|
1210
|
+
|
|
1211
|
+
touch: {
|
|
1212
|
+
usage: 'Invoke this task to touch (update without any change) all docs of this type.',
|
|
1213
|
+
async task(argv) {
|
|
1214
|
+
const req = self.apos.task.getAdminReq();
|
|
1215
|
+
let errCount = 0;
|
|
1216
|
+
let count = 0;
|
|
1217
|
+
let cursor;
|
|
1218
|
+
const criteria = self.options.autopublish
|
|
1219
|
+
? { aposMode: 'draft' }
|
|
1220
|
+
: {};
|
|
1221
|
+
|
|
1222
|
+
try {
|
|
1223
|
+
// We have 30 minutes (by default) for each iteration.
|
|
1224
|
+
// https://www.mongodb.com/docs/manual/reference/method/cursor.noCursorTimeout/#session-idle-timeout-overrides-nocursortimeout
|
|
1225
|
+
cursor = (await self.find(req, criteria)
|
|
1226
|
+
.locale(null)
|
|
1227
|
+
.limit(0)
|
|
1228
|
+
.toMongo())
|
|
1229
|
+
.addCursorFlag('noCursorTimeout', true);
|
|
1230
|
+
|
|
1231
|
+
for await (const doc of cursor) {
|
|
1232
|
+
try {
|
|
1233
|
+
await self.update(req, doc);
|
|
1234
|
+
count++;
|
|
1235
|
+
} catch (e) {
|
|
1236
|
+
errCount++;
|
|
1237
|
+
self.apos.util.error(e);
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
} catch (error) {
|
|
1241
|
+
self.apos.util.error(error);
|
|
1242
|
+
} finally {
|
|
1243
|
+
if (cursor) {
|
|
1244
|
+
await cursor.close();
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
console.log(`Touched ${count} doc(s) with ${errCount} error(s)`);
|
|
1248
|
+
|
|
1249
|
+
// Return, useful for tests and internal API's
|
|
1250
|
+
// It's in effect only when invoked via apos.task.invoke().
|
|
1251
|
+
return {
|
|
1252
|
+
touched: count,
|
|
1253
|
+
errors: errCount
|
|
1254
|
+
};
|
|
1255
|
+
}
|
|
1209
1256
|
}
|
|
1210
1257
|
};
|
|
1211
1258
|
}
|