Skip to content

Commit

Permalink
move creator fields to a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
Feranchz committed Aug 30, 2023
1 parent dd28faa commit 2b71831
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import take from 'lodash/take';
import uniqBy from 'lodash/uniqBy';
import unset from 'lodash/unset';

import { CREATOR_FIELDS } from '../../constants/attributes';
import { getMaxTempKey } from '../../utils';

import { findAllAndReplace, moveFields } from './utils';
Expand Down Expand Up @@ -237,10 +238,9 @@ const reducer = (state, action) =>
const findAllRelationsAndReplaceWithEmptyArray = findAllAndReplace(
components,
(value, { path }) => {
const fieldName = path[path.length - 1]
const fieldName = path[path.length - 1];
// We don't replace creator fields because we already return them without need to populate them separately
const isCreatorField =
fieldName === 'createdBy' || fieldName === 'updatedBy';
const isCreatorField = CREATOR_FIELDS.includes(fieldName);

return value.type === 'relation' && !isCreatorField;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import get from 'lodash/get';
import isArray from 'lodash/isArray';
import isObject from 'lodash/isObject';

import { CREATOR_FIELDS } from '../../../constants/attributes';
import { getInitialDataPathUsingTempKeys } from '../../../utils/paths';

/* eslint-disable indent */
Expand Down Expand Up @@ -30,7 +31,7 @@ const cleanData = ({ browserState, serverState }, currentSchema, componentsSchem
const recursiveCleanData = (browserState, serverState, schema, pathToParent) => {
return Object.keys(browserState).reduce((acc, current) => {
// Creator attributes can be safely ignored because they are handle on the backend
if (current === 'createdBy' || current === 'updatedBy') {
if (CREATOR_FIELDS.includes(current)) {
return acc;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const CREATOR_FIELDS = ['createdBy', 'updatedBy'];

export { CREATOR_FIELDS };
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useRBACProvider, findMatchingPermissions } from '@strapi/helper-plugin';

import { CREATOR_FIELDS } from '../constants/attributes';

const NOT_ALLOWED_FILTERS = ['json', 'component', 'media', 'richtext', 'dynamiczone', 'password'];
const TIMESTAMPS = ['createdAt', 'updatedAt'];
const CREATOR_ATTRIBUTES = ['createdBy', 'updatedBy'];

export const useAllowedAttributes = (contentType, slug) => {
const { allPermissions } = useRBACProvider();
Expand Down Expand Up @@ -38,10 +39,5 @@ export const useAllowedAttributes = (contentType, slug) => {
return true;
});

return [
'id',
...allowedAttributes,
...TIMESTAMPS,
...(canReadAdminUsers ? CREATOR_ATTRIBUTES : []),
];
return ['id', ...allowedAttributes, ...TIMESTAMPS, ...(canReadAdminUsers ? CREATOR_FIELDS : [])];
};
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { useEnterprise } from '../../../hooks/useEnterprise';
import { InjectionZone } from '../../../shared/components';
import { Filter } from '../../components/Filter';
import { AdminUsersFilter } from '../../components/Filter/CustomInputs/AdminUsersFilter';
import { CREATOR_FIELDS } from '../../constants/attributes';
import { useAllowedAttributes } from '../../hooks/useAllowedAttributes';
import { getTrad, getDisplayName } from '../../utils';

Expand All @@ -63,8 +64,7 @@ import { buildValidGetParams } from './utils';
const REVIEW_WORKFLOW_COLUMNS_CE = null;
const REVIEW_WORKFLOW_COLUMNS_CELL_CE = () => null;
const REVIEW_WORKFLOW_FILTER_CE = [];
const CREATOR_ATTRIBUTES = ['createdBy', 'updatedBy'];
const USER_FILTER_ATTRIBUTES = [...CREATOR_ATTRIBUTES, 'strapi_assignee'];
const USER_FILTER_ATTRIBUTES = [...CREATOR_FIELDS, 'strapi_assignee'];

function ListView({
canCreate,
Expand Down

0 comments on commit 2b71831

Please sign in to comment.