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