apostrophe 3.60.0 → 3.60.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,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.60.1 (2023-12-06)
4
+
5
+ ### Fixes
6
+
7
+ * corrected an issue where the use of the doc template library can result in errors at startup when
8
+ replicating certain content to new locales. This was not a bug in the doc template library.
9
+ Apostrophe was not invoking `findForEditing` where it should have.
10
+
3
11
  ## 3.60.0 (2023-11-29)
4
12
 
5
13
  ### Adds
@@ -1028,9 +1028,16 @@ module.exports = {
1028
1028
  });
1029
1029
  const toId = draft._id.replace(`:${draft.aposLocale}`, `:${toLocale}:draft`);
1030
1030
  const actionModule = self.apos.page.isPage(draft) ? self.apos.page : self;
1031
+ // Use findForEditing so that we are successful even for edge cases
1032
+ // like doc templates that don't appear in public renderings, but
1033
+ // also use permission('view') so that we are not actually restricted
1034
+ // to what we can edit, avoiding any confusion about whether there
1035
+ // is really an existing localized doc or not and preventing the
1036
+ // possibility of inserting an unwanted duplicate. The update() call will
1037
+ // still stop us if edit permissions are an issue
1031
1038
  const existing = await actionModule.findForEditing(toReq, {
1032
1039
  _id: toId
1033
- }).toObject();
1040
+ }).permission('view').toObject();
1034
1041
  // We only want to copy schema properties, leave non-schema
1035
1042
  // properties of the source document alone
1036
1043
  const data = Object.fromEntries(Object.entries(draft).filter(([ key, value ]) => self.schema.find(field => field.name === key)));
@@ -1056,8 +1063,15 @@ module.exports = {
1056
1063
  // A page that is not the home page, being replicated for the first time
1057
1064
  let { lastTargetId, lastPosition } = await self.apos.page.inferLastTargetIdAndPosition(draft);
1058
1065
  let localizedTargetId = lastTargetId.replace(`:${draft.aposLocale}`, `:${toLocale}:draft`);
1066
+ // When fetching the target (parent or peer), always use findForEditing
1067
+ // so we don't miss doc templates and other edge cases, but also use
1068
+ // .permission('view') because we are not actually editing the target
1069
+ // and should not be blocked over edit permissions. Later change this check
1070
+ // to 'create' ("can create a child of this doc"), but not until we're ready
1071
+ // to do it for all creation attempts
1059
1072
  const localizedTarget = await actionModule
1060
- .find(toReq, self.apos.page.getIdCriteria(localizedTargetId))
1073
+ .findForEditing(toReq, self.apos.page.getIdCriteria(localizedTargetId))
1074
+ .permission('view')
1061
1075
  .archived(null)
1062
1076
  .areas(false)
1063
1077
  .relationships(false)
@@ -1070,7 +1084,13 @@ module.exports = {
1070
1084
  parentNotLocalized: true
1071
1085
  });
1072
1086
  } else {
1073
- const originalTarget = await actionModule.find(req, self.apos.page.getIdCriteria(lastTargetId)).archived(null).areas(false).relationships(false).toObject();
1087
+ const originalTarget = await actionModule
1088
+ .findForEditing(req, self.apos.page.getIdCriteria(lastTargetId))
1089
+ .permission('view')
1090
+ .archived(null)
1091
+ .areas(false)
1092
+ .relationships(false)
1093
+ .toObject();
1074
1094
  if (!originalTarget) {
1075
1095
  // Almost impossible (race conditions like someone removing it while we're in the modal)
1076
1096
  throw self.apos.error('notfound');
@@ -1078,7 +1098,13 @@ module.exports = {
1078
1098
  const criteria = {
1079
1099
  path: self.apos.page.getParentPath(originalTarget)
1080
1100
  };
1081
- const localizedTarget = await actionModule.find(toReq, criteria).archived(null).areas(false).relationships(false).toObject();
1101
+ const localizedTarget = await actionModule
1102
+ .findForEditing(toReq, criteria)
1103
+ .permission('view')
1104
+ .archived(null)
1105
+ .areas(false)
1106
+ .relationships(false)
1107
+ .toObject();
1082
1108
  if (!localizedTarget) {
1083
1109
  throw self.apos.error('notfound', req.t('apostrophe:parentNotLocalized'), {
1084
1110
  // Also provide as data for code that prefers to localize client side
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apostrophe",
3
- "version": "3.60.0",
3
+ "version": "3.60.1",
4
4
  "description": "The Apostrophe Content Management System.",
5
5
  "main": "index.js",
6
6
  "scripts": {