Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 3 additions & 42 deletions src/actions/page-template-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* */

import T from "i18n-react/dist/i18n-react";
import moment from "moment-timezone";
import {
getRequest,
putRequest,
Expand All @@ -28,12 +27,10 @@ import { getAccessTokenSafely } from "../utils/methods";
import {
DEFAULT_CURRENT_PAGE,
DEFAULT_ORDER_DIR,
DEFAULT_PER_PAGE,
PAGE_MODULES_DOWNLOAD,
PAGE_MODULES_MEDIA_TYPES,
PAGES_MODULE_KINDS
DEFAULT_PER_PAGE
} from "../utils/constants";
import { snackbarErrorHandler, snackbarSuccessHandler } from "./base-actions";
import { normalizePageTemplateModules } from "../utils/page-template";
import { GLOBAL_PAGE_CLONED } from "./sponsor-pages-actions";

export const ADD_PAGE_TEMPLATE = "ADD_PAGE_TEMPLATE";
Expand Down Expand Up @@ -147,43 +144,7 @@ export const resetPageTemplateForm = () => (dispatch) => {

const normalizeEntity = (entity) => {
const normalizedEntity = { ...entity };

normalizedEntity.modules = entity.modules.map((module) => {
const normalizedModule = { ...module };

if (module.kind === PAGES_MODULE_KINDS.MEDIA) {
if (module.upload_deadline) {
normalizedModule.upload_deadline = moment
.utc(module.upload_deadline)
.unix();
}

if (module.file_type_id) {
normalizedModule.file_type_id =
module.file_type_id?.value || module.file_type_id;
}

if (module.type === PAGE_MODULES_MEDIA_TYPES.INPUT) {
delete normalizedModule.file_type_id;
delete normalizedModule.max_file_size;
}
}

if (module.kind === PAGES_MODULE_KINDS.DOCUMENT) {
if (module.type === PAGE_MODULES_DOWNLOAD.FILE) {
normalizedModule.file = module.file?.[0] || null;
delete normalizedModule.external_url;
} else {
delete normalizedModule.file;
delete normalizedModule.file_id;
}
}

delete normalizedModule._tempId;

return normalizedModule;
});

normalizedEntity.modules = normalizePageTemplateModules(entity.modules);
return normalizedEntity;
};

Expand Down
28 changes: 3 additions & 25 deletions src/actions/show-pages-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ import {
stopLoading
} from "openstack-uicore-foundation/lib/utils/actions";
import T from "i18n-react/dist/i18n-react";
import moment from "moment-timezone";
import { escapeFilterValue, getAccessTokenSafely } from "../utils/methods";
import {
DEFAULT_CURRENT_PAGE,
DEFAULT_ORDER_DIR,
DEFAULT_PER_PAGE,
PAGES_MODULE_KINDS
DEFAULT_PER_PAGE
} from "../utils/constants";
import { snackbarErrorHandler, snackbarSuccessHandler } from "./base-actions";
import { normalizePageTemplateModules } from "../utils/page-template";

export const REQUEST_SHOW_PAGES = "REQUEST_SHOW_PAGES";
export const RECEIVE_SHOW_PAGES = "RECEIVE_SHOW_PAGES";
Expand Down Expand Up @@ -136,28 +135,7 @@ const normalizeShowPage = (entity) => {
delete normalizedEntity.sponsorship_types;
}

normalizedEntity.modules = entity.modules.map((module) => {
const normalizedModule = { ...module };

if (module.kind === PAGES_MODULE_KINDS.MEDIA && module.upload_deadline) {
normalizedModule.upload_deadline = moment
.utc(module.upload_deadline)
.unix();
}

if (module.kind === PAGES_MODULE_KINDS.MEDIA && module.file_type_id) {
normalizedModule.file_type_id =
module.file_type_id?.value || module.file_type_id;
}

if (module.kind === PAGES_MODULE_KINDS.DOCUMENT && module.file) {
normalizedModule.file = module.file[0] || null;
}

delete normalizedModule._tempId;

return normalizedModule;
});
normalizedEntity.modules = normalizePageTemplateModules(entity.modules);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MEDIUM] Normalization scope expanded — verify API compatibility

The previous inline code here only handled:

  • MEDIA upload_deadline → unix timestamp
  • MEDIA file_type_id → unwrap .value
  • DOCUMENT file → extract file[0]

The centralized normalizePageTemplateModules now also:

  1. Deletes file_type_id and max_file_size for MEDIA/INPUT modules
  2. Deletes external_url for DOCUMENT/FILE modules
  3. Deletes file and file_id for DOCUMENT/URL modules

These additional field deletions were previously only applied in page-template-actions. If the show-pages API endpoint has different expectations (e.g., ignores extra fields vs. requires them), this could cause unintended data loss on save.

The same applies to sponsor-pages-actions.js which had the same inline logic.

Suggested fix: Verify that the show-pages and sponsor-pages API endpoints accept the same normalized payload as the page-templates endpoint.


return normalizedEntity;
};
Expand Down
28 changes: 5 additions & 23 deletions src/actions/sponsor-pages-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
escapeFilterValue
} from "openstack-uicore-foundation/lib/utils/actions";
import T from "i18n-react/dist/i18n-react";
import moment from "moment-timezone";
import {
getAccessTokenSafely,
normalizeSelectAllField
Expand All @@ -34,6 +33,7 @@ import {
DEFAULT_PER_PAGE,
PAGES_MODULE_KINDS
} from "../utils/constants";
import { normalizePageTemplateModules } from "../utils/page-template";

export const GLOBAL_PAGE_CLONED = "GLOBAL_PAGE_CLONED";
export const RESET_EDIT_PAGE = "RESET_EDIT_PAGE";
Expand Down Expand Up @@ -566,28 +566,10 @@ const normalizeSponsorCustomPage = (entity, summitTZ) => {
normalizedEntity.allowed_add_ons = entity.allowed_add_ons.map((e) => e.id);
}

normalizedEntity.modules = entity.modules.map((module) => {
const normalizedModule = { ...module };

if (module.kind === PAGES_MODULE_KINDS.MEDIA && module.upload_deadline) {
normalizedModule.upload_deadline = moment
.tz(module.upload_deadline, summitTZ)
.unix();
}

if (module.kind === PAGES_MODULE_KINDS.MEDIA && module.file_type_id) {
normalizedModule.file_type_id =
module.file_type_id?.value || module.file_type_id;
}

if (module.kind === PAGES_MODULE_KINDS.DOCUMENT && module.file) {
normalizedModule.file = module.file[0] || null;
}

delete normalizedModule._tempId;

return normalizedModule;
});
normalizedEntity.modules = normalizePageTemplateModules(
entity.modules,
summitTZ
);

return normalizedEntity;
};
Loading
Loading