mirror of
https://github.com/strapi/strapi.git
synced 2025-10-30 17:37:26 +00:00
Add permissions for create action only for collectionTypes
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
f2c9716156
commit
b8a979f276
@ -9,6 +9,7 @@ import pluginId from '../../pluginId';
|
|||||||
import useEditView from '../../hooks/useEditView';
|
import useEditView from '../../hooks/useEditView';
|
||||||
import ComponentInitializer from '../ComponentInitializer';
|
import ComponentInitializer from '../ComponentInitializer';
|
||||||
import NonRepeatableComponent from '../NonRepeatableComponent';
|
import NonRepeatableComponent from '../NonRepeatableComponent';
|
||||||
|
import NotAllowedInput from '../NotAllowedInput';
|
||||||
import RepeatableComponent from '../RepeatableComponent';
|
import RepeatableComponent from '../RepeatableComponent';
|
||||||
import connect from './utils/connect';
|
import connect from './utils/connect';
|
||||||
import select from './utils/select';
|
import select from './utils/select';
|
||||||
@ -29,6 +30,7 @@ const FieldComponent = ({
|
|||||||
min,
|
min,
|
||||||
name,
|
name,
|
||||||
// Passed thanks to the connect function
|
// Passed thanks to the connect function
|
||||||
|
hasChildrenAllowedFields,
|
||||||
componentValue,
|
componentValue,
|
||||||
removeComponentFromField,
|
removeComponentFromField,
|
||||||
}) => {
|
}) => {
|
||||||
@ -41,6 +43,14 @@ const FieldComponent = ({
|
|||||||
|
|
||||||
const displayedFields = get(currentComponentSchema, ['layouts', 'edit'], []);
|
const displayedFields = get(currentComponentSchema, ['layouts', 'edit'], []);
|
||||||
|
|
||||||
|
if (!hasChildrenAllowedFields) {
|
||||||
|
return (
|
||||||
|
<div className="col-12">
|
||||||
|
<NotAllowedInput label={label} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper className="col-12" isFromDynamicZone={isFromDynamicZone}>
|
<Wrapper className="col-12" isFromDynamicZone={isFromDynamicZone}>
|
||||||
{isFromDynamicZone && (
|
{isFromDynamicZone && (
|
||||||
@ -102,6 +112,7 @@ const FieldComponent = ({
|
|||||||
FieldComponent.defaultProps = {
|
FieldComponent.defaultProps = {
|
||||||
componentValue: null,
|
componentValue: null,
|
||||||
componentFriendlyName: null,
|
componentFriendlyName: null,
|
||||||
|
hasChildrenAllowedFields: false,
|
||||||
icon: 'smile',
|
icon: 'smile',
|
||||||
isFromDynamicZone: false,
|
isFromDynamicZone: false,
|
||||||
isRepeatable: false,
|
isRepeatable: false,
|
||||||
@ -114,6 +125,7 @@ FieldComponent.propTypes = {
|
|||||||
componentFriendlyName: PropTypes.string,
|
componentFriendlyName: PropTypes.string,
|
||||||
componentUid: PropTypes.string.isRequired,
|
componentUid: PropTypes.string.isRequired,
|
||||||
componentValue: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
componentValue: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
||||||
|
hasChildrenAllowedFields: PropTypes.bool,
|
||||||
icon: PropTypes.string,
|
icon: PropTypes.string,
|
||||||
isFromDynamicZone: PropTypes.bool,
|
isFromDynamicZone: PropTypes.bool,
|
||||||
isRepeatable: PropTypes.bool,
|
isRepeatable: PropTypes.bool,
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import React from 'react';
|
|||||||
function connect(WrappedComponent, select) {
|
function connect(WrappedComponent, select) {
|
||||||
return function(props) {
|
return function(props) {
|
||||||
// eslint-disable-next-line react/prop-types
|
// eslint-disable-next-line react/prop-types
|
||||||
const selectors = select(props.name);
|
const selectors = select(props);
|
||||||
|
|
||||||
return <WrappedComponent {...props} {...selectors} />;
|
return <WrappedComponent {...props} {...selectors} />;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,12 +1,37 @@
|
|||||||
import { useContext } from 'react';
|
import { useContext, useMemo } from 'react';
|
||||||
import { get } from 'lodash';
|
import { get } from 'lodash';
|
||||||
import EditViewDataManagerContext from '../../../contexts/EditViewDataManager';
|
import EditViewDataManagerContext from '../../../contexts/EditViewDataManager';
|
||||||
|
|
||||||
function useSelect(name) {
|
function useSelect({ isFromDynamicZone, name }) {
|
||||||
const { modifiedData, removeComponentFromField } = useContext(EditViewDataManagerContext);
|
const {
|
||||||
|
createActionAllowedFields,
|
||||||
|
isCreatingEntry,
|
||||||
|
modifiedData,
|
||||||
|
removeComponentFromField,
|
||||||
|
} = useContext(EditViewDataManagerContext);
|
||||||
|
|
||||||
|
const allowedFields = useMemo(() => {
|
||||||
|
return isCreatingEntry ? createActionAllowedFields : [];
|
||||||
|
}, [isCreatingEntry, createActionAllowedFields]);
|
||||||
|
|
||||||
const componentValue = get(modifiedData, name, null);
|
const componentValue = get(modifiedData, name, null);
|
||||||
|
|
||||||
|
const hasChildrenAllowedFields = useMemo(() => {
|
||||||
|
if (isFromDynamicZone) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const relatedChildrenAllowedFields = allowedFields
|
||||||
|
.map(fieldName => {
|
||||||
|
return fieldName.split('.')[0];
|
||||||
|
})
|
||||||
|
.filter(fieldName => fieldName === name.split('.')[0]);
|
||||||
|
|
||||||
|
return relatedChildrenAllowedFields.length > 0;
|
||||||
|
}, [allowedFields, isFromDynamicZone, name]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
hasChildrenAllowedFields,
|
||||||
removeComponentFromField,
|
removeComponentFromField,
|
||||||
componentValue,
|
componentValue,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -143,7 +143,6 @@ function Inputs({
|
|||||||
|
|
||||||
if (isChildOfDynamicZone) {
|
if (isChildOfDynamicZone) {
|
||||||
// TODO we can simply return true here if we block the dynamic zone
|
// TODO we can simply return true here if we block the dynamic zone
|
||||||
console.log('opooooo');
|
|
||||||
|
|
||||||
return allowedFields.includes(fieldName[0]);
|
return allowedFields.includes(fieldName[0]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,17 +4,19 @@ import EditViewDataManagerContext from '../../../contexts/EditViewDataManager';
|
|||||||
|
|
||||||
function useSelect(keys) {
|
function useSelect(keys) {
|
||||||
const {
|
const {
|
||||||
modifiedData,
|
|
||||||
formErrors,
|
|
||||||
onChange,
|
|
||||||
isCreatingEntry,
|
|
||||||
createActionAllowedFields,
|
createActionAllowedFields,
|
||||||
|
formErrors,
|
||||||
|
isCreatingEntry,
|
||||||
|
modifiedData,
|
||||||
|
onChange,
|
||||||
} = useContext(EditViewDataManagerContext);
|
} = useContext(EditViewDataManagerContext);
|
||||||
const value = get(modifiedData, keys, null);
|
|
||||||
const allowedFields = useMemo(() => {
|
const allowedFields = useMemo(() => {
|
||||||
return isCreatingEntry ? createActionAllowedFields : [];
|
return isCreatingEntry ? createActionAllowedFields : [];
|
||||||
}, [isCreatingEntry, createActionAllowedFields]);
|
}, [isCreatingEntry, createActionAllowedFields]);
|
||||||
|
|
||||||
|
const value = get(modifiedData, keys, null);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
allowedFields,
|
allowedFields,
|
||||||
formErrors,
|
formErrors,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user