mirror of
https://github.com/strapi/strapi.git
synced 2025-12-26 22:54:31 +00:00
Allow name edition in CE
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
012d07cd97
commit
11afd28f35
@ -5,8 +5,10 @@
|
||||
"description": "A Strapi application.",
|
||||
"scripts": {
|
||||
"develop": "strapi develop",
|
||||
"develop:ce": "STRAPI_DISABLE_EE=true strapi develop",
|
||||
"start": "strapi start",
|
||||
"build": "strapi build",
|
||||
"build:ce": "STRAPI_DISABLE_EE=true strapi build",
|
||||
"strapi": "strapi"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import SizedInput from '../../SizedInput';
|
||||
|
||||
const NameInput = inputProps => <SizedInput disabled name="name" type="text" {...inputProps} />;
|
||||
const NameInput = inputProps => <SizedInput name="name" type="text" {...inputProps} />;
|
||||
|
||||
export default NameInput;
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
import React from 'react';
|
||||
import { PropTypes } from 'prop-types';
|
||||
import { useIntl } from 'react-intl';
|
||||
import getNameInputValue from 'ee_else_ce/components/Roles/RoleForm/utils/getNameInputValue';
|
||||
import NameInput from 'ee_else_ce/components/Roles/RoleForm/NameInput';
|
||||
|
||||
import NameInput from './NameInput';
|
||||
|
||||
import FormCard from '../../FormBloc';
|
||||
import SizedInput from '../../SizedInput';
|
||||
import ButtonWithNumber from '../ButtonWithNumber';
|
||||
|
||||
const RoleForm = ({ role, values, errors, onChange, onBlur, isLoading }) => {
|
||||
const nameValue = getNameInputValue(values, role);
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
const actions = [
|
||||
@ -55,7 +54,7 @@ const RoleForm = ({ role, values, errors, onChange, onBlur, isLoading }) => {
|
||||
type="text"
|
||||
error={errors.name ? { id: errors.name } : null}
|
||||
onBlur={onBlur}
|
||||
value={nameValue}
|
||||
value={values.name}
|
||||
onChange={onChange}
|
||||
/>
|
||||
|
||||
|
||||
@ -1,5 +0,0 @@
|
||||
const getNameInputValue = (values, role) => {
|
||||
return role.name;
|
||||
};
|
||||
|
||||
export default getNameInputValue;
|
||||
@ -1,4 +1,4 @@
|
||||
import React, { useMemo, useState, useRef } from 'react';
|
||||
import React, { useState, useRef } from 'react';
|
||||
import { useRouteMatch, useHistory } from 'react-router-dom';
|
||||
import { get, isEmpty } from 'lodash';
|
||||
import { useGlobalContext, request } from 'strapi-helper-plugin';
|
||||
@ -6,14 +6,13 @@ import { Header } from '@buffetjs/custom';
|
||||
import { Padded } from '@buffetjs/core';
|
||||
import { Formik } from 'formik';
|
||||
import { useIntl } from 'react-intl';
|
||||
import getInitialValues from 'ee_else_ce/containers/Roles/EditPage/utils/getInitialValues';
|
||||
import schema from 'ee_else_ce/containers/Roles/EditPage/utils/schema';
|
||||
import BaselineAlignement from '../../../components/BaselineAlignement';
|
||||
import PageTitle from '../../../components/SettingsPageTitle';
|
||||
import ContainerFluid from '../../../components/ContainerFluid';
|
||||
import { Permissions, RoleForm } from '../../../components/Roles';
|
||||
import { useFetchRole, useFetchPermissionsLayout } from '../../../hooks';
|
||||
import { formatPermissionsToApi } from '../../../utils';
|
||||
import schema from './utils/schema';
|
||||
|
||||
const EditPage = () => {
|
||||
const { formatMessage } = useIntl();
|
||||
@ -27,9 +26,7 @@ const EditPage = () => {
|
||||
|
||||
const { isLoading: isLayoutLoading, data: permissionsLayout } = useFetchPermissionsLayout(id);
|
||||
const { role, permissions: rolePermissions, isLoading: isRoleLoading } = useFetchRole(id);
|
||||
const initialValues = useMemo(() => {
|
||||
return getInitialValues(role);
|
||||
}, [role]);
|
||||
|
||||
/* eslint-disable indent */
|
||||
const headerActions = (handleSubmit, handleReset) =>
|
||||
isLayoutLoading && isRoleLoading
|
||||
@ -96,7 +93,10 @@ const EditPage = () => {
|
||||
<PageTitle name="Roles" />
|
||||
<Formik
|
||||
enableReinitialize
|
||||
initialValues={initialValues}
|
||||
initialValues={{
|
||||
name: role.name,
|
||||
description: role.description,
|
||||
}}
|
||||
onSubmit={handleEditRoleSubmit}
|
||||
validationSchema={schema}
|
||||
validateOnChange={false}
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
const getInitialValues = role => {
|
||||
return {
|
||||
description: role.description,
|
||||
};
|
||||
};
|
||||
|
||||
export default getInitialValues;
|
||||
@ -1,7 +1,8 @@
|
||||
import * as yup from 'yup';
|
||||
import { translatedErrors } from 'strapi-helper-plugin';
|
||||
|
||||
const schema = yup.object().shape({
|
||||
name: yup.string(),
|
||||
name: yup.string().required(translatedErrors.required),
|
||||
});
|
||||
|
||||
export default schema;
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
import React from 'react';
|
||||
import SizedInput from '../../../../../admin/src/components/SizedInput';
|
||||
|
||||
const NameInput = inputProps => <SizedInput name="name" type="text" {...inputProps} />;
|
||||
|
||||
export default NameInput;
|
||||
@ -1,5 +0,0 @@
|
||||
const getNameInputValue = values => {
|
||||
return values.name;
|
||||
};
|
||||
|
||||
export default getNameInputValue;
|
||||
@ -1,8 +0,0 @@
|
||||
const getInitialValues = role => {
|
||||
return {
|
||||
name: role.name,
|
||||
description: role.description,
|
||||
};
|
||||
};
|
||||
|
||||
export default getInitialValues;
|
||||
@ -1,8 +0,0 @@
|
||||
import * as yup from 'yup';
|
||||
import { translatedErrors } from 'strapi-helper-plugin';
|
||||
|
||||
const schema = yup.object().shape({
|
||||
name: yup.string().required(translatedErrors.required),
|
||||
});
|
||||
|
||||
export default schema;
|
||||
@ -3,9 +3,8 @@
|
||||
const { yup, formatYupErrors } = require('strapi-utils');
|
||||
const {
|
||||
validateRoleCreateInput,
|
||||
validateRoleUpdateInput,
|
||||
validateRolesDeleteInput,
|
||||
validateRoleDeleteInput,
|
||||
validateRolesDeleteInput,
|
||||
} = require('../validation/role');
|
||||
const { validatedUpdatePermissionsInput } = require('../validation/permission');
|
||||
const { SUPER_ADMIN_CODE } = require('../../services/constants');
|
||||
@ -28,31 +27,6 @@ module.exports = {
|
||||
ctx.created({ data: sanitizedRole });
|
||||
},
|
||||
|
||||
/**
|
||||
* Update a role
|
||||
* @param {KoaContext} ctx - koa context
|
||||
*/
|
||||
async update(ctx) {
|
||||
const { id } = ctx.params;
|
||||
|
||||
try {
|
||||
await validateRoleUpdateInput(ctx.request.body, id);
|
||||
} catch (err) {
|
||||
return ctx.badRequest('ValidationError', err);
|
||||
}
|
||||
|
||||
let role = await strapi.admin.services.role.update({ id }, ctx.request.body);
|
||||
if (!role) {
|
||||
return ctx.notFound('Role not found');
|
||||
}
|
||||
|
||||
const sanitizedRole = strapi.admin.services.role.sanitizeRole(role);
|
||||
|
||||
ctx.body = {
|
||||
data: sanitizedRole,
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete a role
|
||||
* @param {KoaContext} ctx - koa context
|
||||
|
||||
@ -15,14 +15,6 @@ const roleCreateSchema = yup
|
||||
})
|
||||
.noUnknown();
|
||||
|
||||
const roleUpdateSchema = yup
|
||||
.object()
|
||||
.shape({
|
||||
name: yup.string().min(1),
|
||||
description: yup.string().nullable(),
|
||||
})
|
||||
.noUnknown();
|
||||
|
||||
const rolesDeleteSchema = yup
|
||||
.object()
|
||||
.shape({
|
||||
@ -52,10 +44,6 @@ const validateRoleCreateInput = async data => {
|
||||
return roleCreateSchema.validate(data, { strict: true, abortEarly: false }).catch(handleReject);
|
||||
};
|
||||
|
||||
const validateRoleUpdateInput = async data => {
|
||||
return roleUpdateSchema.validate(data, { strict: true, abortEarly: false }).catch(handleReject);
|
||||
};
|
||||
|
||||
const validateRolesDeleteInput = async data => {
|
||||
return rolesDeleteSchema.validate(data, { strict: true, abortEarly: false }).catch(handleReject);
|
||||
};
|
||||
@ -66,7 +54,6 @@ const validateRoleDeleteInput = async data => {
|
||||
|
||||
module.exports = {
|
||||
validateRoleCreateInput,
|
||||
validateRoleUpdateInput,
|
||||
validateRolesDeleteInput,
|
||||
validateRoleDeleteInput,
|
||||
};
|
||||
|
||||
@ -8,7 +8,8 @@
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"no tests yet\"",
|
||||
"develop": "webpack-dev-server --config webpack.config.dev.js"
|
||||
"develop": "webpack-dev-server --config webpack.config.dev.js",
|
||||
"develop:ce": "STRAPI_DISABLE_EE=true webpack-dev-server --config webpack.config.dev.js"
|
||||
},
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
|
||||
@ -7,6 +7,7 @@ const handleReject = error => Promise.reject(formatYupErrors(error));
|
||||
const roleUpdateSchema = yup
|
||||
.object()
|
||||
.shape({
|
||||
name: yup.string().min(1),
|
||||
description: yup.string().nullable(),
|
||||
})
|
||||
.noUnknown();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user