@eeacms/volto-cca-policy 0.3.91 → 0.3.92

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
@@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
- ### [0.3.91](https://github.com/eea/volto-cca-policy/compare/1.0.0-alpha.1...0.3.91) - 2 December 2025
7
+ ### [0.3.92](https://github.com/eea/volto-cca-policy/compare/1.0.0-alpha.1...0.3.92) - 8 December 2025
8
8
 
9
9
  #### :rocket: Dependency updates
10
10
 
@@ -26,6 +26,9 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
26
26
 
27
27
  #### :nail_care: Enhancements
28
28
 
29
+ - change: code cleanup, add customization comments [kreafox - [`4418a01`](https://github.com/eea/volto-cca-policy/commit/4418a0157df75b4588956b15e1a0950bbd1f504c)]
30
+ - change: add 301/302 redirect handling [kreafox - [`1125c61`](https://github.com/eea/volto-cca-policy/commit/1125c61f8b963a1f49bb6f7672b68bed03e559f9)]
31
+ - change: update volto customizations [kreafox - [`a712c5d`](https://github.com/eea/volto-cca-policy/commit/a712c5da2f949262dc82b0526d3623c31a1ee105)]
29
32
  - change: update menu layout - refs #294274 [kreafox - [`984cbdf`](https://github.com/eea/volto-cca-policy/commit/984cbdfd8694f52416199a1bfef064fc22ad7ea9)]
30
33
  - change: cleanup, css fix [kreafox - [`cd1f97f`](https://github.com/eea/volto-cca-policy/commit/cd1f97f65b0549188ec336820c517e45ea728f47)]
31
34
  - change: remove website and contribution links from organisation cards, use semantic cards - refs #294273 [kreafox - [`7cffbca`](https://github.com/eea/volto-cca-policy/commit/7cffbca5cc2d422120b08fd683d5235f368256ce)]
@@ -55,6 +58,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
55
58
 
56
59
  #### :hammer_and_wrench: Others
57
60
 
61
+ - code cleanup [kreafox - [`5eb537f`](https://github.com/eea/volto-cca-policy/commit/5eb537f30bfc867e460fd46a145e0f7069b2c6f7)]
58
62
  - Refs #290863 - update message key [iugin - [`871b61c`](https://github.com/eea/volto-cca-policy/commit/871b61cea7070ff5ca6d303dcf5ecaf2fdd4e965)]
59
63
  - Refs #290863 - add translations [iugin - [`63dfc08`](https://github.com/eea/volto-cca-policy/commit/63dfc08243aa19dec5c92d800b22ed739f2f0f75)]
60
64
  - test: try to use specific version for plone-backend [kreafox - [`79c542e`](https://github.com/eea/volto-cca-policy/commit/79c542e8d55d2f1663b768c555880599634ae527)]
@@ -147,8 +151,14 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
147
151
  - Add some loadable for components [Tiberiu Ichim - [`1793962`](https://github.com/eea/volto-cca-policy/commit/179396211c66a6a2465b2d1b6c0f2afc40fc7189)]
148
152
  - Refs #284961 - test [Tripon Eugen - [`c989f1f`](https://github.com/eea/volto-cca-policy/commit/c989f1f8638c0c5233c5c49f8673c9a2cdc7937e)]
149
153
  - Refs #284961 - add translations [Tripon Eugen - [`04ee988`](https://github.com/eea/volto-cca-policy/commit/04ee988c086d393b9b37ce1ea8d24f5e84f266aa)]
150
- ### [1.0.0-alpha.0](https://github.com/eea/volto-cca-policy/compare/0.3.90...1.0.0-alpha.0) - 15 July 2025
154
+ ### [1.0.0-alpha.0](https://github.com/eea/volto-cca-policy/compare/0.3.91...1.0.0-alpha.0) - 15 July 2025
151
155
 
156
+ ### [0.3.91](https://github.com/eea/volto-cca-policy/compare/0.3.90...0.3.91) - 4 December 2025
157
+
158
+ #### :hammer_and_wrench: Others
159
+
160
+ - Refs #290863 - update message key [iugin - [`871b61c`](https://github.com/eea/volto-cca-policy/commit/871b61cea7070ff5ca6d303dcf5ecaf2fdd4e965)]
161
+ - Refs #290863 - add translations [iugin - [`63dfc08`](https://github.com/eea/volto-cca-policy/commit/63dfc08243aa19dec5c92d800b22ed739f2f0f75)]
152
162
  ### [0.3.90](https://github.com/eea/volto-cca-policy/compare/0.3.89...0.3.90) - 20 November 2025
153
163
 
154
164
  #### :nail_care: Enhancements
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-cca-policy",
3
- "version": "0.3.91",
3
+ "version": "0.3.92",
4
4
  "description": "@eeacms/volto-cca-policy: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -1 +1,9 @@
1
- Customized View.jsx to add the stripping of ++api++
1
+ # View Customizations
2
+
3
+ ## Changes
4
+
5
+ 1. **API URL stripping**: Removes `++api++` from URLs
6
+ 2. **Link redirect handling**: Supports 301/302 redirects for Link content types
7
+ - Checks `@components.redirect` from backend serializer
8
+ - Sets correct HTTP status code for SSR (301 vs 302)
9
+ - Backwards compatible with error-based redirects
@@ -18,6 +18,7 @@ import {
18
18
  Tags,
19
19
  Toolbar,
20
20
  } from '@plone/volto/components';
21
+ import { AlternateHrefLangs } from '@plone/volto/components/theme/AlternateHrefLangs/AlternateHrefLangs';
21
22
  import { listActions, getContent } from '@plone/volto/actions';
22
23
  import {
23
24
  BodyClass,
@@ -98,6 +99,8 @@ class View extends Component {
98
99
  * Error type
99
100
  */
100
101
  status: PropTypes.number,
102
+ code: PropTypes.number,
103
+ url: PropTypes.string,
101
104
  }),
102
105
  };
103
106
 
@@ -203,23 +206,33 @@ class View extends Component {
203
206
  */
204
207
  render() {
205
208
  const { views } = config;
206
- if (this.props.error && this.props.error.code === 301) {
207
- // const base = typeof window !== 'undefined' ? window.location.origin : '';
208
209
 
209
- const redirect = flattenToAppURL(this.props.error.url)
210
- .replaceAll('/++api++', '/')
210
+ // customization
211
+ const redirectData =
212
+ this.props.content?.['@components']?.redirect ||
213
+ ([301, 302].includes(this.props.error?.code) && {
214
+ url: this.props.error.url,
215
+ status: this.props.error.code,
216
+ });
217
+
218
+ if (redirectData) {
219
+ const redirect = flattenToAppURL(redirectData.url)
220
+ .replace('/++api++', '')
211
221
  .replaceAll('//', '/')
212
222
  .split('?')[0];
213
- const redirParams = {
214
- pathname: redirect,
215
- search: this.props.location.search,
216
- };
223
+ const targetUrl = `${redirect}${this.props.location.search}`;
224
+
225
+ if (this.props.staticContext) {
226
+ this.props.staticContext.error_code = redirectData.status || 302;
227
+ }
228
+
229
+ const shouldPush = redirectData.status === 302;
217
230
 
218
- // eslint-disable-next-line no-console
219
- console.log('Redirecting', redirParams);
231
+ return <Redirect to={targetUrl} push={shouldPush} />;
232
+ }
233
+ // end of customization
220
234
 
221
- return <Redirect to={redirParams} push={true} />;
222
- } else if (this.props.error && !this.props.connectionRefused) {
235
+ if (this.props.error && !this.props.connectionRefused) {
223
236
  let FoundView;
224
237
  if (this.props.error.status === undefined) {
225
238
  // For some reason, while development and if CORS is in place and the
@@ -247,6 +260,7 @@ class View extends Component {
247
260
  return (
248
261
  <div id="view">
249
262
  <ContentMetadataTags content={this.props.content} />
263
+ <AlternateHrefLangs content={this.props.content} />
250
264
  {/* Body class if displayName in component is set */}
251
265
  <BodyClass
252
266
  className={
@@ -50,10 +50,7 @@ export function addExpandersToPath(path, type, isAnonymous) {
50
50
  } = qs.parseUrl(path, { decode: false });
51
51
 
52
52
  const expandersFromConfig = apiExpanders
53
- .filter((expand) => {
54
- const res = matchPath(url, expand.match) && expand[type];
55
- return res;
56
- })
53
+ .filter((expand) => matchPath(url, expand.match) && expand[type])
57
54
  .map((expand) => expand[type]);
58
55
 
59
56
  const expandMerge = compact(
@@ -70,7 +67,15 @@ export function addExpandersToPath(path, type, isAnonymous) {
70
67
 
71
68
  const querystringFromConfig = apiExpanders
72
69
  .filter((expand) => matchPath(url, expand.match) && expand[type])
73
- .reduce((acc, expand) => ({ ...acc, ...expand?.['querystring'] }), {});
70
+ .reduce((acc, expand) => {
71
+ let querystring = expand?.['querystring'];
72
+ // The querystring accepts being a function to be able to take other
73
+ // config parameters
74
+ if (typeof querystring === 'function') {
75
+ querystring = querystring(config);
76
+ }
77
+ return { ...acc, ...querystring };
78
+ }, {});
74
79
 
75
80
  const queryMerge = { ...query, ...querystringFromConfig };
76
81
 
@@ -128,6 +133,13 @@ const apiMiddlewareFactory =
128
133
  const { settings } = config;
129
134
 
130
135
  const isAnonymous = !getState().userSession.token;
136
+ // const token = getState().userSession.token;
137
+ // let isAnonymous = true;
138
+ // if (token) {
139
+ // const tokenExpiration = jwtDecode(token).exp;
140
+ // const currentTime = new Date().getTime() / 1000;
141
+ // isAnonymous = !token || currentTime > tokenExpiration;
142
+ // }
131
143
 
132
144
  if (typeof action === 'function') {
133
145
  return action(dispatch, getState);
@@ -310,15 +322,23 @@ const apiMiddlewareFactory =
310
322
  }
311
323
 
312
324
  // Redirect
313
- else if (error?.code === 301) {
325
+ // customization
326
+ else if (error?.code === 301 || error?.code === 302) {
327
+ const redirectUrl =
328
+ error.response?.body?.url || error.response?.body?.location;
329
+
314
330
  next({
315
331
  ...rest,
316
- error,
332
+ error: {
333
+ ...error,
334
+ url: redirectUrl,
335
+ },
317
336
  statusCode: error.code,
318
337
  connectionRefused: false,
319
338
  type: SET_APIERROR,
320
339
  });
321
340
  }
341
+ // end of customization
322
342
 
323
343
  // Redirect
324
344
  else if (error?.code === 408) {
@@ -337,7 +357,7 @@ const apiMiddlewareFactory =
337
357
  ...rest,
338
358
  error,
339
359
  statusCode: error.response,
340
- message: error.response.body.message,
360
+ message: error.response?.body?.message,
341
361
  connectionRefused: false,
342
362
  type: SET_APIERROR,
343
363
  });
@@ -321,7 +321,11 @@ server.get('/*', (req, res) => {
321
321
  }
322
322
 
323
323
  if (context.url) {
324
- res.redirect(flattenToAppURL(context.url));
324
+ // customization
325
+ // Use error_code if set (for Link redirects with specific status)
326
+ const redirectStatus = context.error_code || 302;
327
+ res.redirect(redirectStatus, flattenToAppURL(context.url));
328
+ // end of customization
325
329
  } else if (context.error_code) {
326
330
  res.set({
327
331
  'Cache-Control': 'no-cache',