mirror of
https://github.com/strapi/strapi.git
synced 2025-12-05 03:21:22 +00:00
Merge branch 'content-42/fix-date-field' of github.com:strapi/strapi into content-42/fix-date-field
This commit is contained in:
commit
a812010b85
@ -71,10 +71,10 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@swc-node/jest": "1.4.3",
|
||||
"@testing-library/react": "11.2.6",
|
||||
"@testing-library/react": "11.2.7",
|
||||
"@testing-library/react-hooks": "3.4.2",
|
||||
"@testing-library/user-event": "13.5.0",
|
||||
"axios-mock-adapter": "1.19.0",
|
||||
"axios-mock-adapter": "1.20.0",
|
||||
"babel-eslint": "10.1.0",
|
||||
"chalk": "4.1.1",
|
||||
"chokidar": "3.5.1",
|
||||
@ -87,7 +87,7 @@
|
||||
"eslint-config-airbnb-base": "14.2.1",
|
||||
"eslint-config-prettier": "6.15.0",
|
||||
"eslint-plugin-import": "2.22.1",
|
||||
"eslint-plugin-jsdoc": "36.1.0",
|
||||
"eslint-plugin-jsdoc": "36.1.1",
|
||||
"eslint-plugin-jsx-a11y": "6.4.1",
|
||||
"eslint-plugin-node": "11.1.0",
|
||||
"eslint-plugin-react": "7.23.2",
|
||||
|
||||
@ -6,6 +6,8 @@
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import parseISO from 'date-fns/parseISO';
|
||||
import formatISO from 'date-fns/formatISO';
|
||||
import { useIntl } from 'react-intl';
|
||||
import { Checkbox } from '@strapi/design-system/Checkbox';
|
||||
import { DatePicker } from '@strapi/design-system/DatePicker';
|
||||
@ -156,6 +158,12 @@ const GenericInput = ({
|
||||
);
|
||||
}
|
||||
case 'date': {
|
||||
let selectedDate = null;
|
||||
|
||||
if (value) {
|
||||
selectedDate = parseISO(value);
|
||||
}
|
||||
|
||||
return (
|
||||
<DatePicker
|
||||
clearLabel={formatMessage({ id: 'clearLabel', defaultMessage: 'Clear' })}
|
||||
@ -167,14 +175,14 @@ const GenericInput = ({
|
||||
hint={hint}
|
||||
name={name}
|
||||
onChange={date => {
|
||||
const formattedDate = date.toISOString();
|
||||
|
||||
onChange({ target: { name, value: formattedDate, type } });
|
||||
onChange({
|
||||
target: { name, value: formatISO(date, { representation: 'date' }), type },
|
||||
});
|
||||
}}
|
||||
onClear={() => onChange({ target: { name, value: null, type } })}
|
||||
placeholder={formattedPlaceholder}
|
||||
required={required}
|
||||
selectedDate={value ? new Date(value) : null}
|
||||
selectedDate={selectedDate}
|
||||
selectedDateLabel={formattedDate => `Date picker, current is ${formattedDate}`}
|
||||
/>
|
||||
);
|
||||
|
||||
@ -67,40 +67,25 @@ const authenticate = async ctx => {
|
||||
const verify = async (auth, config) => {
|
||||
const { credentials: user } = auth;
|
||||
|
||||
// public accesss
|
||||
if (!user) {
|
||||
// test against public role
|
||||
const publicPermissions = await strapi.query('plugin::users-permissions.permission').findMany({
|
||||
where: {
|
||||
role: { type: 'public' },
|
||||
},
|
||||
});
|
||||
|
||||
const allowedActions = map('action', publicPermissions);
|
||||
|
||||
// A non authenticated user cannot access routes that do not have a scope
|
||||
if (!config.scope) {
|
||||
if (!config.scope) {
|
||||
if (!user) {
|
||||
// A non authenticated user cannot access routes that do not have a scope
|
||||
throw new UnauthorizedError();
|
||||
} else {
|
||||
// An authenticated user can access non scoped routes
|
||||
return;
|
||||
}
|
||||
|
||||
const isAllowed = castArray(config.scope).every(scope => allowedActions.includes(scope));
|
||||
|
||||
if (!isAllowed) {
|
||||
throw new ForbiddenError();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const permissions = await strapi.query('plugin::users-permissions.permission').findMany({
|
||||
where: { role: user.role.id },
|
||||
});
|
||||
let allowedActions = auth.allowedActions;
|
||||
|
||||
const allowedActions = map('action', permissions);
|
||||
if (!allowedActions) {
|
||||
const permissions = await strapi.query('plugin::users-permissions.permission').findMany({
|
||||
where: { role: user ? user.role.id : { type: 'public' } },
|
||||
});
|
||||
|
||||
// An authenticated user can access non scoped routes
|
||||
if (!config.scope) {
|
||||
return;
|
||||
allowedActions = map('action', permissions);
|
||||
auth.allowedActions = allowedActions;
|
||||
}
|
||||
|
||||
const isAllowed = castArray(config.scope).every(scope => allowedActions.includes(scope));
|
||||
@ -108,12 +93,6 @@ const verify = async (auth, config) => {
|
||||
if (!isAllowed) {
|
||||
throw new ForbiddenError();
|
||||
}
|
||||
|
||||
// TODO: if we need to keep policies for u&p execution
|
||||
// Execute the policies.
|
||||
// if (permission.policy) {
|
||||
// return await strapi.plugin('users-permissions').policy(permission.policy)(ctx, next);
|
||||
// }
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
||||
40
yarn.lock
40
yarn.lock
@ -3486,10 +3486,10 @@
|
||||
"@babel/runtime" "^7.5.4"
|
||||
"@types/testing-library__react-hooks" "^3.4.0"
|
||||
|
||||
"@testing-library/react@11.2.6":
|
||||
version "11.2.6"
|
||||
resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-11.2.6.tgz#586a23adc63615985d85be0c903f374dab19200b"
|
||||
integrity sha512-TXMCg0jT8xmuU8BkKMtp8l7Z50Ykew5WNX8UoIKTaLFwKkP2+1YDhOLA2Ga3wY4x29jyntk7EWfum0kjlYiSjQ==
|
||||
"@testing-library/react@11.2.7":
|
||||
version "11.2.7"
|
||||
resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-11.2.7.tgz#b29e2e95c6765c815786c0bc1d5aed9cb2bf7818"
|
||||
integrity sha512-tzRNp7pzd5QmbtXNG/mhdcl7Awfu/Iz1RaVHY75zTdOkmHCuzMhRL83gWHSgOAcjS3CCbyfwUHMZgRJb4kAfpA==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.12.5"
|
||||
"@testing-library/dom" "^7.28.1"
|
||||
@ -4945,13 +4945,14 @@ axe-core@^4.0.2:
|
||||
resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.3.5.tgz#78d6911ba317a8262bfee292aeafcc1e04b49cc5"
|
||||
integrity sha512-WKTW1+xAzhMS5dJsxWkliixlO/PqC4VhmO9T4juNYcaTg9jzWiJsou6m5pxWYGfigWbwzJWeFY6z47a+4neRXA==
|
||||
|
||||
axios-mock-adapter@1.19.0:
|
||||
version "1.19.0"
|
||||
resolved "https://registry.yarnpkg.com/axios-mock-adapter/-/axios-mock-adapter-1.19.0.tgz#9d72e321a6c5418e1eff067aa99761a86c5188a4"
|
||||
integrity sha512-D+0U4LNPr7WroiBDvWilzTMYPYTuZlbo6BI8YHZtj7wYQS8NkARlP9KBt8IWWHTQJ0q/8oZ0ClPBtKCCkx8cQg==
|
||||
axios-mock-adapter@1.20.0:
|
||||
version "1.20.0"
|
||||
resolved "https://registry.yarnpkg.com/axios-mock-adapter/-/axios-mock-adapter-1.20.0.tgz#21f5b4b625306f43e8c05673616719da86e20dcb"
|
||||
integrity sha512-shZRhTjLP0WWdcvHKf3rH3iW9deb3UdKbdnKUoHmmsnBhVXN3sjPJM6ZvQ2r/ywgvBVQrMnjrSyQab60G1sr2w==
|
||||
dependencies:
|
||||
fast-deep-equal "^3.1.3"
|
||||
is-buffer "^2.0.3"
|
||||
is-blob "^2.1.0"
|
||||
is-buffer "^2.0.5"
|
||||
|
||||
axios@0.24.0:
|
||||
version "0.24.0"
|
||||
@ -7733,10 +7734,10 @@ eslint-plugin-import@2.22.1:
|
||||
resolve "^1.17.0"
|
||||
tsconfig-paths "^3.9.0"
|
||||
|
||||
eslint-plugin-jsdoc@36.1.0:
|
||||
version "36.1.0"
|
||||
resolved "https://registry.yarnpkg.com/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-36.1.0.tgz#8dfe5f27edfb6aa3812e6d86ccaea849ddc86b03"
|
||||
integrity sha512-Qpied2AJCQcScxfzTObLKRiP5QgLXjMU/ITjBagEV5p2Q/HpumD1EQtazdRYdjDSwPmXhwOl2yquwOGQ4HOJNw==
|
||||
eslint-plugin-jsdoc@36.1.1:
|
||||
version "36.1.1"
|
||||
resolved "https://registry.yarnpkg.com/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-36.1.1.tgz#124cd0e53a5d07f01ebde916a96dd1a6009625d6"
|
||||
integrity sha512-nuLDvH1EJaKx0PCa9oeQIxH6pACIhZd1gkalTUxZbaxxwokjs7TplqY0Q8Ew3CoZaf5aowm0g/Z3JGHCatt+gQ==
|
||||
dependencies:
|
||||
"@es-joy/jsdoccomment" "0.10.8"
|
||||
comment-parser "1.2.4"
|
||||
@ -8365,9 +8366,9 @@ fn.name@1.x.x:
|
||||
integrity sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==
|
||||
|
||||
follow-redirects@^1.0.0, follow-redirects@^1.14.4, follow-redirects@^1.14.7:
|
||||
version "1.14.7"
|
||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.7.tgz#2004c02eb9436eee9a21446a6477debf17e81685"
|
||||
integrity sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==
|
||||
version "1.14.8"
|
||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.8.tgz#016996fb9a11a100566398b1c6839337d7bfa8fc"
|
||||
integrity sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA==
|
||||
|
||||
font-awesome@^4.7.0:
|
||||
version "4.7.0"
|
||||
@ -9802,6 +9803,11 @@ is-binary-path@~2.1.0:
|
||||
dependencies:
|
||||
binary-extensions "^2.0.0"
|
||||
|
||||
is-blob@^2.1.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/is-blob/-/is-blob-2.1.0.tgz#e36cd82c90653f1e1b930f11baf9c64216a05385"
|
||||
integrity sha512-SZ/fTft5eUhQM6oF/ZaASFDEdbFVe89Imltn9uZr03wdKMcWNVYSMjQPFtg05QuNkt5l5c135ElvXEQG0rk4tw==
|
||||
|
||||
is-bluebird@^1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/is-bluebird/-/is-bluebird-1.0.2.tgz#096439060f4aa411abee19143a84d6a55346d6e2"
|
||||
@ -9820,7 +9826,7 @@ is-buffer@^1.1.5:
|
||||
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
|
||||
integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==
|
||||
|
||||
is-buffer@^2.0.0, is-buffer@^2.0.3:
|
||||
is-buffer@^2.0.0, is-buffer@^2.0.5:
|
||||
version "2.0.5"
|
||||
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.5.tgz#ebc252e400d22ff8d77fa09888821a24a658c191"
|
||||
integrity sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user