mirror of
https://github.com/strapi/strapi.git
synced 2025-12-28 15:44:59 +00:00
Remove useUserPermissions for useRBAC
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
fb0c6e4ef2
commit
146ee5907e
@ -32,7 +32,8 @@
|
||||
"videos"
|
||||
],
|
||||
"plugin": "upload",
|
||||
"required": false
|
||||
"required": false,
|
||||
"pluginOptions": {}
|
||||
},
|
||||
"images": {
|
||||
"collection": "file",
|
||||
@ -41,7 +42,8 @@
|
||||
"images"
|
||||
],
|
||||
"plugin": "upload",
|
||||
"required": false
|
||||
"required": false,
|
||||
"pluginOptions": {}
|
||||
},
|
||||
"city": {
|
||||
"type": "string",
|
||||
@ -57,6 +59,12 @@
|
||||
},
|
||||
"slug": {
|
||||
"type": "uid"
|
||||
},
|
||||
"erzerze": {
|
||||
"type": "string"
|
||||
},
|
||||
"rzarzea": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,52 +0,0 @@
|
||||
{
|
||||
"routes": [
|
||||
{
|
||||
"method": "GET",
|
||||
"path": "/taaaaas",
|
||||
"handler": "taaaaa.find",
|
||||
"config": {
|
||||
"policies": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"path": "/taaaaas/count",
|
||||
"handler": "taaaaa.count",
|
||||
"config": {
|
||||
"policies": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"path": "/taaaaas/:id",
|
||||
"handler": "taaaaa.findOne",
|
||||
"config": {
|
||||
"policies": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"method": "POST",
|
||||
"path": "/taaaaas",
|
||||
"handler": "taaaaa.create",
|
||||
"config": {
|
||||
"policies": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"method": "PUT",
|
||||
"path": "/taaaaas/:id",
|
||||
"handler": "taaaaa.update",
|
||||
"config": {
|
||||
"policies": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"method": "DELETE",
|
||||
"path": "/taaaaas/:id",
|
||||
"handler": "taaaaa.delete",
|
||||
"config": {
|
||||
"policies": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-controllers)
|
||||
* to customize this controller
|
||||
*/
|
||||
|
||||
module.exports = {};
|
||||
@ -1,8 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#lifecycle-hooks)
|
||||
* to customize this model
|
||||
*/
|
||||
|
||||
module.exports = {};
|
||||
@ -1,18 +0,0 @@
|
||||
{
|
||||
"kind": "collectionType",
|
||||
"collectionName": "taaaaas",
|
||||
"info": {
|
||||
"name": "taaaaa"
|
||||
},
|
||||
"options": {
|
||||
"increments": true,
|
||||
"timestamps": true,
|
||||
"draftAndPublish": true
|
||||
},
|
||||
"pluginOptions": {},
|
||||
"attributes": {
|
||||
"eee": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-services)
|
||||
* to customize this service
|
||||
*/
|
||||
|
||||
module.exports = {};
|
||||
@ -1,52 +0,0 @@
|
||||
{
|
||||
"routes": [
|
||||
{
|
||||
"method": "GET",
|
||||
"path": "/tatas",
|
||||
"handler": "tata.find",
|
||||
"config": {
|
||||
"policies": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"path": "/tatas/count",
|
||||
"handler": "tata.count",
|
||||
"config": {
|
||||
"policies": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"path": "/tatas/:id",
|
||||
"handler": "tata.findOne",
|
||||
"config": {
|
||||
"policies": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"method": "POST",
|
||||
"path": "/tatas",
|
||||
"handler": "tata.create",
|
||||
"config": {
|
||||
"policies": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"method": "PUT",
|
||||
"path": "/tatas/:id",
|
||||
"handler": "tata.update",
|
||||
"config": {
|
||||
"policies": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"method": "DELETE",
|
||||
"path": "/tatas/:id",
|
||||
"handler": "tata.delete",
|
||||
"config": {
|
||||
"policies": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-controllers)
|
||||
* to customize this controller
|
||||
*/
|
||||
|
||||
module.exports = {};
|
||||
@ -1,8 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#lifecycle-hooks)
|
||||
* to customize this model
|
||||
*/
|
||||
|
||||
module.exports = {};
|
||||
@ -1,22 +0,0 @@
|
||||
{
|
||||
"kind": "collectionType",
|
||||
"collectionName": "tatas",
|
||||
"info": {
|
||||
"name": "tata",
|
||||
"description": ""
|
||||
},
|
||||
"options": {
|
||||
"increments": true,
|
||||
"timestamps": true,
|
||||
"draftAndPublish": true
|
||||
},
|
||||
"pluginOptions": {},
|
||||
"attributes": {
|
||||
"eee": {
|
||||
"type": "string"
|
||||
},
|
||||
"eeee": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-services)
|
||||
* to customize this service
|
||||
*/
|
||||
|
||||
module.exports = {};
|
||||
@ -34,6 +34,7 @@ const AuthenticatedApp = () => {
|
||||
{
|
||||
queryKey: 'admin-users-permission',
|
||||
queryFn: fetchCurrentUserPermissions,
|
||||
initialData: [],
|
||||
},
|
||||
]);
|
||||
|
||||
|
||||
@ -1,25 +0,0 @@
|
||||
import {
|
||||
GET_USER_PERMISSIONS,
|
||||
GET_USER_PERMISSIONS_SUCCEEDED,
|
||||
GET_USER_PERMISSIONS_ERROR,
|
||||
} from './constants';
|
||||
|
||||
export function getUserPermissions() {
|
||||
return {
|
||||
type: GET_USER_PERMISSIONS,
|
||||
};
|
||||
}
|
||||
|
||||
export function getUserPermissionsError(error) {
|
||||
return {
|
||||
type: GET_USER_PERMISSIONS_ERROR,
|
||||
error,
|
||||
};
|
||||
}
|
||||
|
||||
export function getUserPermissionsSucceeded(data) {
|
||||
return {
|
||||
type: GET_USER_PERMISSIONS_SUCCEEDED,
|
||||
data,
|
||||
};
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
export const GET_USER_PERMISSIONS = 'StrapiAdmin/PermissionsManager/GET_USER_PERMISSIONS';
|
||||
export const GET_USER_PERMISSIONS_ERROR =
|
||||
'StrapiAdmin/PermissionsManager/GET_USER_PERMISSIONS_ERROR';
|
||||
export const GET_USER_PERMISSIONS_SUCCEEDED =
|
||||
'StrapiAdmin/PermissionsManager/GET_USER_PERMISSIONS_SUCCEEDED';
|
||||
@ -1,49 +0,0 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { useSelector, useDispatch } from 'react-redux';
|
||||
import { LoadingIndicatorPage, UserProvider, request } from '@strapi/helper-plugin';
|
||||
import {
|
||||
getUserPermissions,
|
||||
getUserPermissionsError,
|
||||
getUserPermissionsSucceeded,
|
||||
} from './actions';
|
||||
|
||||
const PermissionsManager = ({ children }) => {
|
||||
const { isLoading, userPermissions } = useSelector(state => state.permissionsManager);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const fetchUserPermissions = async (resetState = false) => {
|
||||
if (resetState) {
|
||||
// Show a loader
|
||||
dispatch(getUserPermissions());
|
||||
}
|
||||
|
||||
try {
|
||||
const { data } = await request('/admin/users/me/permissions', { method: 'GET' });
|
||||
|
||||
dispatch(getUserPermissionsSucceeded(data));
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
dispatch(getUserPermissionsError(err));
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchUserPermissions(true);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
if (isLoading) {
|
||||
return <LoadingIndicatorPage />;
|
||||
}
|
||||
|
||||
return <UserProvider value={{ userPermissions, fetchUserPermissions }}>{children}</UserProvider>;
|
||||
};
|
||||
|
||||
PermissionsManager.defaultProps = {};
|
||||
|
||||
PermissionsManager.propTypes = {
|
||||
children: PropTypes.node.isRequired,
|
||||
};
|
||||
|
||||
export default PermissionsManager;
|
||||
@ -1,66 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* PermissionsManager reducer
|
||||
* The goal of this reducer is to provide
|
||||
* the plugins with an access to the user's permissions
|
||||
* in our middleware system
|
||||
*
|
||||
*/
|
||||
|
||||
import produce from 'immer';
|
||||
|
||||
import {
|
||||
GET_USER_PERMISSIONS,
|
||||
GET_USER_PERMISSIONS_ERROR,
|
||||
GET_USER_PERMISSIONS_SUCCEEDED,
|
||||
} from './constants';
|
||||
|
||||
const initialState = {
|
||||
isLoading: true,
|
||||
userPermissions: [],
|
||||
collectionTypesRelatedPermissions: {},
|
||||
};
|
||||
|
||||
const reducer = (state = initialState, action) =>
|
||||
// eslint-disable-next-line consistent-return
|
||||
produce(state, draftState => {
|
||||
switch (action.type) {
|
||||
case GET_USER_PERMISSIONS: {
|
||||
draftState.isLoading = true;
|
||||
draftState.userPermissions = [];
|
||||
draftState.collectionTypesRelatedPermissions = {};
|
||||
break;
|
||||
}
|
||||
|
||||
case GET_USER_PERMISSIONS_ERROR: {
|
||||
draftState.error = action.error;
|
||||
draftState.isLoading = false;
|
||||
break;
|
||||
}
|
||||
case GET_USER_PERMISSIONS_SUCCEEDED: {
|
||||
draftState.isLoading = false;
|
||||
draftState.userPermissions = action.data;
|
||||
draftState.collectionTypesRelatedPermissions = action.data
|
||||
.filter(perm => perm.subject)
|
||||
.reduce((acc, current) => {
|
||||
const { subject, action } = current;
|
||||
|
||||
if (!acc[subject]) {
|
||||
acc[subject] = {};
|
||||
}
|
||||
|
||||
acc[subject] = acc[subject][action]
|
||||
? { ...acc[subject], [action]: [...acc[subject][action], current] }
|
||||
: { ...acc[subject], [action]: [current] };
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
});
|
||||
|
||||
export default reducer;
|
||||
export { initialState };
|
||||
@ -1,103 +0,0 @@
|
||||
import produce from 'immer';
|
||||
import {
|
||||
getUserPermissions,
|
||||
getUserPermissionsError,
|
||||
getUserPermissionsSucceeded,
|
||||
} from '../actions';
|
||||
import permissionsManagerReducer from '../reducer';
|
||||
|
||||
describe('permissionsManagerReducer', () => {
|
||||
let state;
|
||||
|
||||
beforeEach(() => {
|
||||
state = {
|
||||
isLoading: true,
|
||||
userPermissions: [],
|
||||
collectionTypesRelatedPermissions: {},
|
||||
};
|
||||
});
|
||||
|
||||
it('returns the initial state', () => {
|
||||
const expected = state;
|
||||
|
||||
expect(permissionsManagerReducer(undefined, {})).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should handle the getUserPermissions action correctly', () => {
|
||||
state.userPermissions = ['test'];
|
||||
state.collectionTypesRelatedPermissions = null;
|
||||
|
||||
const expected = produce(state, draft => {
|
||||
draft.isLoading = true;
|
||||
draft.userPermissions = [];
|
||||
draft.collectionTypesRelatedPermissions = {};
|
||||
});
|
||||
|
||||
expect(permissionsManagerReducer(state, getUserPermissions())).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should handle the getUserPermissionsError action correctly', () => {
|
||||
const error = 'Error';
|
||||
const expected = produce(state, draft => {
|
||||
draft.isLoading = false;
|
||||
draft.error = error;
|
||||
});
|
||||
|
||||
expect(permissionsManagerReducer(state, getUserPermissionsError(error))).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should handle the getUserPermissionsSucceeded action correctly', () => {
|
||||
const data = [
|
||||
{
|
||||
action: 'create',
|
||||
subject: 'address',
|
||||
properties: {
|
||||
fields: ['f1'],
|
||||
},
|
||||
conditions: [],
|
||||
},
|
||||
{
|
||||
action: 'create',
|
||||
subject: 'address',
|
||||
properties: {
|
||||
fields: ['f2'],
|
||||
},
|
||||
conditions: [],
|
||||
},
|
||||
{
|
||||
action: 'tes',
|
||||
subject: null,
|
||||
properties: {},
|
||||
conditions: [],
|
||||
},
|
||||
];
|
||||
const expected = produce(state, draft => {
|
||||
draft.isLoading = false;
|
||||
draft.userPermissions = data;
|
||||
draft.collectionTypesRelatedPermissions = {
|
||||
address: {
|
||||
create: [
|
||||
{
|
||||
action: 'create',
|
||||
subject: 'address',
|
||||
properties: {
|
||||
fields: ['f1'],
|
||||
},
|
||||
conditions: [],
|
||||
},
|
||||
{
|
||||
action: 'create',
|
||||
subject: 'address',
|
||||
properties: {
|
||||
fields: ['f2'],
|
||||
},
|
||||
conditions: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
expect(permissionsManagerReducer(state, getUserPermissionsSucceeded(data))).toEqual(expected);
|
||||
});
|
||||
});
|
||||
@ -1,11 +1,12 @@
|
||||
import { useContext, useEffect, useReducer } from 'react';
|
||||
import { hasPermissions, UserContext, useStrapiApp } from '@strapi/helper-plugin';
|
||||
import { useEffect, useReducer } from 'react';
|
||||
import { hasPermissions, useRBACProvider, useStrapiApp } from '@strapi/helper-plugin';
|
||||
|
||||
import reducer, { initialState } from './reducer';
|
||||
import init from './init';
|
||||
|
||||
const useSettingsMenu = (noCheck = false) => {
|
||||
const { userPermissions: permissions } = useContext(UserContext);
|
||||
const { allPermissions: permissions } = useRBACProvider();
|
||||
|
||||
const { plugins } = useStrapiApp();
|
||||
|
||||
const [{ isLoading, menu }, dispatch] = useReducer(reducer, initialState, () =>
|
||||
|
||||
@ -11,7 +11,6 @@ import { connect } from 'react-redux';
|
||||
import { createStructuredSelector } from 'reselect';
|
||||
import { compose } from 'redux';
|
||||
import { Switch, Route } from 'react-router-dom';
|
||||
import { injectIntl } from 'react-intl';
|
||||
import { isEmpty } from 'lodash';
|
||||
// Components from @strapi/helper-plugin
|
||||
import {
|
||||
@ -30,7 +29,7 @@ import HomePage from '../HomePage';
|
||||
import MarketplacePage from '../MarketplacePage';
|
||||
import NotFoundPage from '../NotFoundPage';
|
||||
import OnboardingVideos from '../../components/Onboarding';
|
||||
import PermissionsManager from '../../components/PermissionsManager';
|
||||
|
||||
import PluginDispatcher from '../PluginDispatcher';
|
||||
import ProfilePage from '../ProfilePage';
|
||||
import SettingsPage from '../SettingsPage';
|
||||
@ -90,74 +89,53 @@ export class Admin extends React.Component {
|
||||
};
|
||||
|
||||
render() {
|
||||
const {
|
||||
intl: { formatMessage },
|
||||
// FIXME
|
||||
plugins,
|
||||
} = this.props;
|
||||
const { plugins } = this.props;
|
||||
|
||||
return (
|
||||
<PermissionsManager>
|
||||
<GlobalContextProvider
|
||||
emitEvent={this.emitEvent}
|
||||
formatMessage={formatMessage}
|
||||
plugins={plugins}
|
||||
updateMenu={this.state.updateMenu}
|
||||
>
|
||||
<Wrapper>
|
||||
<LeftMenu plugins={plugins} setUpdateMenu={this.setUpdateMenu} />
|
||||
<NavTopRightWrapper>
|
||||
{/* Injection zone not ready yet */}
|
||||
<Logout />
|
||||
</NavTopRightWrapper>
|
||||
<div className="adminPageRightWrapper">
|
||||
<Header />
|
||||
<Content>
|
||||
<Switch>
|
||||
<Route path="/" render={props => this.renderRoute(props, HomePage)} exact />
|
||||
<Route path="/me" component={ProfilePage} />
|
||||
<Route path="/plugins/:pluginId" render={this.renderPluginDispatcher} />
|
||||
<Route path="/list-plugins" exact>
|
||||
<CheckPagePermissions permissions={adminPermissions.marketplace.main}>
|
||||
<InstalledPluginsPage />
|
||||
</CheckPagePermissions>
|
||||
</Route>
|
||||
<Route path="/marketplace">
|
||||
<CheckPagePermissions permissions={adminPermissions.marketplace.main}>
|
||||
<MarketplacePage />
|
||||
</CheckPagePermissions>
|
||||
</Route>
|
||||
<Route path="/settings/:settingId" component={SettingsPage} />
|
||||
<Route path="/settings" component={SettingsPage} exact />
|
||||
<Route key="7" path="" component={NotFoundPage} />
|
||||
<Route key="8" path="/404" component={NotFoundPage} />
|
||||
</Switch>
|
||||
</Content>
|
||||
</div>
|
||||
<GlobalContextProvider emitEvent={this.emitEvent} updateMenu={this.state.updateMenu}>
|
||||
<Wrapper>
|
||||
<LeftMenu plugins={plugins} setUpdateMenu={this.setUpdateMenu} />
|
||||
<NavTopRightWrapper>
|
||||
{/* Injection zone not ready yet */}
|
||||
<Logout />
|
||||
</NavTopRightWrapper>
|
||||
<div className="adminPageRightWrapper">
|
||||
<Header />
|
||||
<Content>
|
||||
<Switch>
|
||||
<Route path="/" render={props => this.renderRoute(props, HomePage)} exact />
|
||||
<Route path="/me" component={ProfilePage} />
|
||||
<Route path="/plugins/:pluginId" render={this.renderPluginDispatcher} />
|
||||
<Route path="/list-plugins" exact>
|
||||
<CheckPagePermissions permissions={adminPermissions.marketplace.main}>
|
||||
<InstalledPluginsPage />
|
||||
</CheckPagePermissions>
|
||||
</Route>
|
||||
<Route path="/marketplace">
|
||||
<CheckPagePermissions permissions={adminPermissions.marketplace.main}>
|
||||
<MarketplacePage />
|
||||
</CheckPagePermissions>
|
||||
</Route>
|
||||
<Route path="/settings/:settingId" component={SettingsPage} />
|
||||
<Route path="/settings" component={SettingsPage} exact />
|
||||
<Route key="7" path="" component={NotFoundPage} />
|
||||
<Route key="8" path="/404" component={NotFoundPage} />
|
||||
</Switch>
|
||||
</Content>
|
||||
</div>
|
||||
|
||||
{process.env.STRAPI_ADMIN_SHOW_TUTORIALS === 'true' && <OnboardingVideos />}
|
||||
</Wrapper>
|
||||
</GlobalContextProvider>
|
||||
</PermissionsManager>
|
||||
{process.env.STRAPI_ADMIN_SHOW_TUTORIALS === 'true' && <OnboardingVideos />}
|
||||
</Wrapper>
|
||||
</GlobalContextProvider>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Admin.defaultProps = {
|
||||
intl: {
|
||||
formatMessage: () => {},
|
||||
locale: 'en',
|
||||
},
|
||||
};
|
||||
|
||||
Admin.propTypes = {
|
||||
global: PropTypes.shape({
|
||||
uuid: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
||||
}).isRequired,
|
||||
intl: PropTypes.shape({
|
||||
formatMessage: PropTypes.func,
|
||||
locale: PropTypes.string,
|
||||
}),
|
||||
|
||||
plugins: PropTypes.object.isRequired,
|
||||
};
|
||||
|
||||
@ -167,4 +145,4 @@ const mapStateToProps = createStructuredSelector({
|
||||
|
||||
const withConnect = connect(mapStateToProps);
|
||||
|
||||
export default compose(injectIntl, withConnect)(Admin);
|
||||
export default compose(withConnect)(Admin);
|
||||
|
||||
@ -2,14 +2,15 @@ import React, { useState } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { IconLinks, Text } from '@buffetjs/core';
|
||||
import { CustomRow } from '@buffetjs/styles';
|
||||
import { useGlobalContext, PopUpWarning, CheckPermissions } from '@strapi/helper-plugin';
|
||||
import { useIntl } from 'react-intl';
|
||||
import { PopUpWarning, CheckPermissions } from '@strapi/helper-plugin';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faTrashAlt } from '@fortawesome/free-solid-svg-icons';
|
||||
import adminPermissions from '../../permissions';
|
||||
import LogoContainer from './Logo';
|
||||
|
||||
const Row = ({ logo, name, description, isRequired, id, icon, onConfirm }) => {
|
||||
const { formatMessage } = useGlobalContext();
|
||||
const { formatMessage } = useIntl();
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const links = [];
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ import matchSorter from 'match-sorter';
|
||||
import { useIntl } from 'react-intl';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { ListButton, useGlobalContext, useQuery, useUserPermissions } from '@strapi/helper-plugin';
|
||||
import { ListButton, useGlobalContext, useQuery, useRBAC } from '@strapi/helper-plugin';
|
||||
import adminPermissions from '../../../permissions';
|
||||
import PageTitle from '../../../components/SettingsPageTitle';
|
||||
import { EmptyRole, RoleListWrapper, RoleRow } from '../../../components/Roles';
|
||||
@ -23,7 +23,7 @@ const RoleListPage = () => {
|
||||
const { toggleHeaderSearch } = useSettingsHeaderSearchContext();
|
||||
const {
|
||||
allowedActions: { canUpdate },
|
||||
} = useUserPermissions(adminPermissions.settings.roles);
|
||||
} = useRBAC(adminPermissions.settings.roles);
|
||||
const query = useQuery();
|
||||
const _q = decodeURIComponent(query.get('_q') || '');
|
||||
const results = matchSorter(roles, _q, { keys: ['name', 'description'] });
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import React, { useMemo } from 'react';
|
||||
import { useUserPermissions, LoadingIndicatorPage } from '@strapi/helper-plugin';
|
||||
import { useRBAC, LoadingIndicatorPage } from '@strapi/helper-plugin';
|
||||
import { Redirect } from 'react-router-dom';
|
||||
import adminPermissions from '../../../permissions';
|
||||
import EditPage from '../EditPage';
|
||||
@ -15,7 +15,7 @@ const ProtectedEditPage = () => {
|
||||
const {
|
||||
isLoading,
|
||||
allowedActions: { canRead, canUpdate },
|
||||
} = useUserPermissions(permissions);
|
||||
} = useRBAC(permissions);
|
||||
|
||||
if (isLoading) {
|
||||
return <LoadingIndicatorPage />;
|
||||
|
||||
@ -3,7 +3,7 @@ import {
|
||||
BaselineAlignment,
|
||||
useQuery,
|
||||
request,
|
||||
useUserPermissions,
|
||||
useRBAC,
|
||||
LoadingIndicatorPage,
|
||||
PopUpWarning,
|
||||
useNotification,
|
||||
@ -25,7 +25,7 @@ const ListPage = () => {
|
||||
const {
|
||||
isLoading: isLoadingForPermissions,
|
||||
allowedActions: { canCreate, canDelete, canRead, canUpdate },
|
||||
} = useUserPermissions(adminPermissions.settings.users);
|
||||
} = useRBAC(adminPermissions.settings.users);
|
||||
const toggleNotification = useNotification();
|
||||
const [isWarningDeleteAllOpened, setIsWarningDeleteAllOpened] = useState(false);
|
||||
const [isModalOpened, setIsModalOpened] = useState(false);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import React, { useEffect, useMemo } from 'react';
|
||||
import { useUserPermissions, LoadingIndicatorPage, useNotification } from '@strapi/helper-plugin';
|
||||
import { useRBAC, LoadingIndicatorPage, useNotification } from '@strapi/helper-plugin';
|
||||
import { Redirect, useLocation } from 'react-router-dom';
|
||||
import { get } from 'lodash';
|
||||
import adminPermissions from '../../../permissions';
|
||||
@ -17,7 +17,7 @@ const ProtectedEditPage = () => {
|
||||
const {
|
||||
isLoading,
|
||||
allowedActions: { canRead, canUpdate },
|
||||
} = useUserPermissions(permissions);
|
||||
} = useRBAC(permissions);
|
||||
const { state } = useLocation();
|
||||
const from = get(state, 'from', '/');
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ import { Router, Route, Switch } from 'react-router-dom';
|
||||
// import { render, cleanup } from '@testing-library/react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { createMemoryHistory } from 'history';
|
||||
import { GlobalContextProvider, UserProvider } from '@strapi/helper-plugin';
|
||||
import { GlobalContextProvider } from '@strapi/helper-plugin';
|
||||
import { IntlProvider } from 'react-intl';
|
||||
|
||||
import translationMessages from '../../../../translations/en.json';
|
||||
@ -30,17 +30,15 @@ describe('Admin | containers | EditView', () => {
|
||||
messages={translationMessages}
|
||||
textComponent="span"
|
||||
>
|
||||
<UserProvider permissions={[]}>
|
||||
<GlobalContextProvider formatMessage={originalIntl.formatMessage}>
|
||||
<Router history={history}>
|
||||
<Switch>
|
||||
<Route path="/settings/webhooks/create">
|
||||
<EditView />
|
||||
</Route>
|
||||
</Switch>
|
||||
</Router>
|
||||
</GlobalContextProvider>
|
||||
</UserProvider>
|
||||
<GlobalContextProvider formatMessage={originalIntl.formatMessage}>
|
||||
<Router history={history}>
|
||||
<Switch>
|
||||
<Route path="/settings/webhooks/create">
|
||||
<EditView />
|
||||
</Route>
|
||||
</Switch>
|
||||
</Router>
|
||||
</GlobalContextProvider>
|
||||
</IntlProvider>
|
||||
);
|
||||
});
|
||||
|
||||
@ -15,7 +15,7 @@ import {
|
||||
request,
|
||||
ListButton,
|
||||
PopUpWarning,
|
||||
useUserPermissions,
|
||||
useRBAC,
|
||||
LoadingIndicatorPage,
|
||||
EmptyState,
|
||||
useNotification,
|
||||
@ -30,7 +30,7 @@ function ListView() {
|
||||
const {
|
||||
isLoading,
|
||||
allowedActions: { canCreate, canRead, canUpdate, canDelete },
|
||||
} = useUserPermissions(adminPermissions.settings.webhooks);
|
||||
} = useRBAC(adminPermissions.settings.webhooks);
|
||||
const toggleNotification = useNotification();
|
||||
const isMounted = useRef(true);
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
@ -2,7 +2,7 @@ import React from 'react';
|
||||
import { Router, Route, Switch } from 'react-router-dom';
|
||||
import { shallow } from 'enzyme';
|
||||
import { createMemoryHistory } from 'history';
|
||||
import { GlobalContextProvider, UserProvider } from '@strapi/helper-plugin';
|
||||
import { GlobalContextProvider } from '@strapi/helper-plugin';
|
||||
import { IntlProvider } from 'react-intl';
|
||||
import Notifications from '../../../../components/Notifications';
|
||||
|
||||
@ -23,15 +23,13 @@ describe('Admin | containers | ListView', () => {
|
||||
>
|
||||
<Notifications>
|
||||
<GlobalContextProvider formatMessage={jest.fn()}>
|
||||
<UserProvider permissions={[]}>
|
||||
<Router history={history}>
|
||||
<Switch>
|
||||
<Route path="/settings/webhooks">
|
||||
<ListView />
|
||||
</Route>
|
||||
</Switch>
|
||||
</Router>
|
||||
</UserProvider>
|
||||
<Router history={history}>
|
||||
<Switch>
|
||||
<Route path="/settings/webhooks">
|
||||
<ListView />
|
||||
</Route>
|
||||
</Switch>
|
||||
</Router>
|
||||
</GlobalContextProvider>
|
||||
</Notifications>
|
||||
</IntlProvider>
|
||||
|
||||
@ -1,14 +1,13 @@
|
||||
import globalReducer from './pages/App/reducer';
|
||||
import languageProviderReducer from './components/LanguageProvider/reducer';
|
||||
import menuReducer from './components/LeftMenu/reducer';
|
||||
import permissionsManagerReducer from './components/PermissionsManager/reducer';
|
||||
import rbacProviderReducer from './components/RBACProvider/reducer';
|
||||
|
||||
const reducers = {
|
||||
app: globalReducer,
|
||||
language: languageProviderReducer,
|
||||
menu: menuReducer,
|
||||
permissionsManager: permissionsManagerReducer,
|
||||
|
||||
rbacProvider: rbacProviderReducer,
|
||||
};
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ import {
|
||||
ListButton,
|
||||
PopUpWarning,
|
||||
request,
|
||||
useUserPermissions,
|
||||
useRBAC,
|
||||
useNotification,
|
||||
LoadingIndicatorPage,
|
||||
} from '@strapi/helper-plugin';
|
||||
@ -36,7 +36,7 @@ const RoleListPage = () => {
|
||||
const {
|
||||
isLoading: isLoadingForPermissions,
|
||||
allowedActions: { canCreate, canDelete, canRead, canUpdate },
|
||||
} = useUserPermissions(adminPermissions.settings.roles);
|
||||
} = useRBAC(adminPermissions.settings.roles);
|
||||
const { getData, roles, isLoading } = useRolesList(false);
|
||||
const getDataRef = useRef(getData);
|
||||
const { toggleHeaderSearch } = useSettingsHeaderSearchContext();
|
||||
|
||||
@ -4,7 +4,7 @@ import {
|
||||
CheckPagePermissions,
|
||||
NotAllowedInput,
|
||||
SizedInput,
|
||||
useUserPermissions,
|
||||
useRBAC,
|
||||
} from '@strapi/helper-plugin';
|
||||
import { useIntl } from 'react-intl';
|
||||
import { getRequestUrl } from '../../../../../admin/src/utils';
|
||||
@ -26,7 +26,7 @@ const SingleSignOn = () => {
|
||||
const {
|
||||
isLoading: isLoadingForPermissions,
|
||||
allowedActions: { canUpdate, canReadRoles },
|
||||
} = useUserPermissions(ssoPermissions);
|
||||
} = useRBAC(ssoPermissions);
|
||||
|
||||
const [
|
||||
{ formErrors, initialData, isLoading, modifiedData, showHeaderButtonLoader },
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import PropTypes from 'prop-types';
|
||||
import { hasPermissions, useUser } from '@strapi/helper-plugin';
|
||||
import { hasPermissions, useRBACProvider } from '@strapi/helper-plugin';
|
||||
import pluginId from '../../pluginId';
|
||||
import pluginPermissions from '../../permissions';
|
||||
import DynamicComponentCard from '../DynamicComponentCard';
|
||||
@ -11,13 +11,13 @@ const DynamicComponent = ({ componentUid, friendlyName, icon, setIsOverDynamicZo
|
||||
const [isOver, setIsOver] = useState(false);
|
||||
const [{ isLoading, canAccess }, setState] = useState({ isLoading: true, canAccess: false });
|
||||
const { push } = useHistory();
|
||||
const { userPermissions } = useUser();
|
||||
const { allPermissions } = useRBACProvider();
|
||||
|
||||
useEffect(() => {
|
||||
const checkPermission = async () => {
|
||||
try {
|
||||
const canAccess = await hasPermissions(
|
||||
userPermissions,
|
||||
allPermissions,
|
||||
pluginPermissions.componentsConfigurations
|
||||
);
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import React, { useCallback, useEffect, useMemo, useRef, useReducer } from 'react';
|
||||
import { cloneDeep, get, isEmpty, isEqual, set } from 'lodash';
|
||||
import PropTypes from 'prop-types';
|
||||
import { useIntl } from 'react-intl';
|
||||
import { Prompt, Redirect } from 'react-router-dom';
|
||||
import {
|
||||
LoadingIndicatorPage,
|
||||
@ -57,7 +58,8 @@ const EditViewDataManagerProvider = ({
|
||||
return hasDraftAndPublish && !initialData.published_at;
|
||||
}, [hasDraftAndPublish, initialData.published_at]);
|
||||
|
||||
const { emitEvent, formatMessage } = useGlobalContext();
|
||||
const { emitEvent } = useGlobalContext();
|
||||
const { formatMessage } = useIntl();
|
||||
const emitEventRef = useRef(emitEvent);
|
||||
|
||||
const shouldRedirectToHomepageWhenEditingEntry = useMemo(() => {
|
||||
|
||||
@ -7,7 +7,7 @@ import { FormattedMessage } from 'react-intl';
|
||||
import {
|
||||
PluginHeader,
|
||||
getFilterType,
|
||||
useUser,
|
||||
useRBACProvider,
|
||||
findMatchingPermissions,
|
||||
useGlobalContext,
|
||||
} from '@strapi/helper-plugin';
|
||||
@ -34,9 +34,9 @@ function FilterPicker({
|
||||
}) {
|
||||
const { emitEvent } = useGlobalContext();
|
||||
const emitEventRef = useRef(emitEvent);
|
||||
const { userPermissions } = useUser();
|
||||
const { allPermissions } = useRBACProvider();
|
||||
const readActionAllowedFields = useMemo(() => {
|
||||
const matchingPermissions = findMatchingPermissions(userPermissions, [
|
||||
const matchingPermissions = findMatchingPermissions(allPermissions, [
|
||||
{
|
||||
action: 'plugins::content-manager.explorer.read',
|
||||
subject: slug,
|
||||
@ -44,7 +44,7 @@ function FilterPicker({
|
||||
]);
|
||||
|
||||
return get(matchingPermissions, ['0', 'properties', 'fields'], []);
|
||||
}, [userPermissions, slug]);
|
||||
}, [allPermissions, slug]);
|
||||
|
||||
let timestamps = get(contentType, ['options', 'timestamps']);
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { useGlobalContext, CheckPermissions } from '@strapi/helper-plugin';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { useIntl } from 'react-intl';
|
||||
import get from 'lodash/get';
|
||||
import { Button } from '@buffetjs/core';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
@ -17,7 +18,8 @@ const permissions = [{ action: 'plugins::content-type-builder.read', subject: nu
|
||||
|
||||
// Create link from content-type-builder to content-manager
|
||||
const LinkToCTB = ({ modifiedData, slug, type }) => {
|
||||
const { emitEvent, formatMessage } = useGlobalContext();
|
||||
const { emitEvent } = useGlobalContext();
|
||||
const { formatMessage } = useIntl();
|
||||
const { push } = useHistory();
|
||||
|
||||
const baseUrl = `/plugins/content-type-builder/${
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import React, { memo, useMemo } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { useUserPermissions, LoadingIndicatorPage } from '@strapi/helper-plugin';
|
||||
import { useRBAC, LoadingIndicatorPage } from '@strapi/helper-plugin';
|
||||
import isEqual from 'react-fast-compare';
|
||||
import EditView from '../EditView';
|
||||
import { generatePermissionsObject } from '../../utils';
|
||||
|
||||
const Permissions = props => {
|
||||
const viewPermissions = useMemo(() => generatePermissionsObject(props.slug), [props.slug]);
|
||||
const { isLoading, allowedActions } = useUserPermissions(viewPermissions, props.userPermissions);
|
||||
const { isLoading, allowedActions } = useRBAC(viewPermissions, props.userPermissions);
|
||||
|
||||
if (isLoading) {
|
||||
return <LoadingIndicatorPage />;
|
||||
|
||||
@ -17,7 +17,7 @@ import {
|
||||
useGlobalContext,
|
||||
useNotification,
|
||||
useQueryParams,
|
||||
useUser,
|
||||
useRBACProvider,
|
||||
request,
|
||||
} from '@strapi/helper-plugin';
|
||||
import pluginId from '../../pluginId';
|
||||
@ -89,9 +89,9 @@ function ListView({
|
||||
} = layout;
|
||||
const toggleNotification = useNotification();
|
||||
const { emitEvent } = useGlobalContext();
|
||||
const { fetchUserPermissions } = useUser();
|
||||
const { refetchPermissions } = useRBACProvider();
|
||||
const emitEventRef = useRef(emitEvent);
|
||||
const fetchPermissionsRef = useRef(fetchUserPermissions);
|
||||
const fetchPermissionsRef = useRef(refetchPermissions);
|
||||
|
||||
const [{ query }, setQuery] = useQueryParams();
|
||||
const params = buildQueryString(query);
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import React, { memo, useMemo } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { useUserPermissions, LoadingIndicatorPage } from '@strapi/helper-plugin';
|
||||
import { useRBAC, LoadingIndicatorPage } from '@strapi/helper-plugin';
|
||||
import isEqual from 'react-fast-compare';
|
||||
import ListView from '../ListView';
|
||||
import { generatePermissionsObject } from '../../utils';
|
||||
|
||||
const Permissions = props => {
|
||||
const viewPermissions = useMemo(() => generatePermissionsObject(props.slug), [props.slug]);
|
||||
const { isLoading, allowedActions } = useUserPermissions(viewPermissions, props.permissions);
|
||||
const { isLoading, allowedActions } = useRBAC(viewPermissions, props.permissions);
|
||||
|
||||
if (isLoading) {
|
||||
return <LoadingIndicatorPage />;
|
||||
|
||||
@ -3,4 +3,4 @@ import pluginId from './pluginId';
|
||||
export const selectPermissions = state => state[`${pluginId}_rbacManager`].permissions;
|
||||
|
||||
export const selectCollectionTypePermissions = state =>
|
||||
state.permissionsManager.collectionTypesRelatedPermissions;
|
||||
state.rbacProvider.collectionTypesRelatedPermissions;
|
||||
|
||||
@ -25,8 +25,9 @@ describe('selectors', () => {
|
||||
});
|
||||
|
||||
describe('selectCollectionTypePermissions', () => {
|
||||
it('resolves the permissions key of the "permissionsManager" store key', () => {
|
||||
store.permissionsManager = {
|
||||
// TODO add store fixture
|
||||
it('resolves the permissions key of the "rbacProvider" store key', () => {
|
||||
store.rbacProvider = {
|
||||
collectionTypesRelatedPermissions: {
|
||||
some: 'permission again',
|
||||
},
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import UserContext from '../../contexts/UserContext';
|
||||
|
||||
const UserProvider = ({ children, value }) => {
|
||||
return <UserContext.Provider value={value}>{children}</UserContext.Provider>;
|
||||
};
|
||||
|
||||
UserProvider.propTypes = {
|
||||
children: PropTypes.node.isRequired,
|
||||
};
|
||||
|
||||
export default UserProvider;
|
||||
@ -1,11 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* UserContext
|
||||
*
|
||||
*/
|
||||
|
||||
import { createContext } from 'react';
|
||||
|
||||
const UserContext = createContext();
|
||||
|
||||
export default UserContext;
|
||||
@ -6,7 +6,7 @@ import reducer from './reducer';
|
||||
import init from './init';
|
||||
import useRBACProvider from '../useRBACProvider';
|
||||
|
||||
const useUserPermissions = (pluginPermissions, permissions) => {
|
||||
const useRBAC = (pluginPermissions, permissions) => {
|
||||
const abortController = new AbortController();
|
||||
const { signal } = abortController;
|
||||
|
||||
@ -84,4 +84,4 @@ const useUserPermissions = (pluginPermissions, permissions) => {
|
||||
return { ...state, setIsLoading };
|
||||
};
|
||||
|
||||
export default useUserPermissions;
|
||||
export default useRBAC;
|
||||
@ -1,6 +1,6 @@
|
||||
import init from '../init';
|
||||
|
||||
describe('HELPER_PLUGIN | hooks | useUserPermissions | init', () => {
|
||||
describe('HELPER_PLUGIN | hooks | useRBAC | init', () => {
|
||||
it('should return the correct state with an empty allowedActions object', () => {
|
||||
const expected = {
|
||||
isLoading: true,
|
||||
@ -1,6 +1,6 @@
|
||||
import reducer from '../reducer';
|
||||
|
||||
describe('HELPER_PLUGIN | hooks | useUserPermissions | reducer', () => {
|
||||
describe('HELPER_PLUGIN | hooks | useRBAC | reducer', () => {
|
||||
describe('DEFAULT_ACTION', () => {
|
||||
it('should return the initialState', () => {
|
||||
const initialState = {
|
||||
@ -1,6 +1,6 @@
|
||||
import generateResultsObject from '../generateResultsObject';
|
||||
|
||||
describe('HELPER_PLUGIN | hooks | useUserPermissions | | utils | generateResultsObject', () => {
|
||||
describe('HELPER_PLUGIN | hooks | useRBAC | | utils | generateResultsObject', () => {
|
||||
it('should return an object with { key: can<PermissionName>, value: bool }', () => {
|
||||
const data = [
|
||||
{ permissionName: 'read', hasPermission: true },
|
||||
@ -1,12 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* useUser
|
||||
*
|
||||
*/
|
||||
|
||||
import { useContext } from 'react';
|
||||
import UserContext from '../../contexts/UserContext';
|
||||
|
||||
const useUser = () => useContext(UserContext);
|
||||
|
||||
export default useUser;
|
||||
@ -87,7 +87,7 @@ export { default as Row } from './components/Row';
|
||||
export { default as SearchInfo } from './components/SearchInfo';
|
||||
export { default as SelectNav } from './components/SelectNav';
|
||||
export { default as SelectWrapper } from './components/SelectWrapper';
|
||||
export { default as UserProvider } from './components/UserProvider';
|
||||
|
||||
export { default as ViewContainer } from './components/ViewContainer';
|
||||
export { default as CheckPagePermissions } from './components/CheckPagePermissions';
|
||||
export { default as CheckPermissions } from './components/CheckPermissions';
|
||||
@ -111,7 +111,6 @@ export { default as AutoReloadOverlayBockerContext } from './contexts/AutoReload
|
||||
export { default as NotificationsContext } from './contexts/NotificationsContext';
|
||||
export { default as OverlayBlockerContext } from './contexts/OverlayBlockerContext';
|
||||
export { GlobalContext, GlobalContextProvider, useGlobalContext } from './contexts/GlobalContext';
|
||||
export { default as UserContext } from './contexts/UserContext';
|
||||
export { default as ContentManagerEditViewDataManagerContext } from './contexts/ContentManagerEditViewDataManagerContext';
|
||||
export { default as RBACProviderContext } from './contexts/RBACProviderContext';
|
||||
|
||||
@ -122,12 +121,12 @@ export { default as useQuery } from './hooks/useQuery';
|
||||
export { default as useLibrary } from './hooks/useLibrary';
|
||||
export { default as useNotification } from './hooks/useNotification';
|
||||
export { default as useStrapiApp } from './hooks/useStrapiApp';
|
||||
export { default as useUser } from './hooks/useUser';
|
||||
export { default as useUserPermissions } from './hooks/useUserPermissions';
|
||||
|
||||
export { default as useQueryParams } from './hooks/useQueryParams';
|
||||
export { default as useOverlayBlocker } from './hooks/useOverlayBlocker';
|
||||
export { default as useAutoReloadOverlayBlocker } from './hooks/useAutoReloadOverlayBlocker';
|
||||
export { default as useRBACProvider } from './hooks/useRBACProvider';
|
||||
export { default as useRBAC } from './hooks/useRBAC';
|
||||
|
||||
// Providers
|
||||
export { default as LibraryProvider } from './providers/LibraryProvider';
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Switch, Route, Redirect } from 'react-router-dom';
|
||||
import { LoadingIndicatorPage, useUserPermissions } from '@strapi/helper-plugin';
|
||||
import { LoadingIndicatorPage, useRBAC } from '@strapi/helper-plugin';
|
||||
import pluginId from '../../pluginId';
|
||||
import pluginPermissions from '../../permissions';
|
||||
import { AppContext } from '../../contexts';
|
||||
@ -8,7 +8,7 @@ import { AppContext } from '../../contexts';
|
||||
import HomePage from '../HomePage';
|
||||
|
||||
const App = () => {
|
||||
const state = useUserPermissions(pluginPermissions);
|
||||
const state = useRBAC(pluginPermissions);
|
||||
|
||||
// Show a loader while all permissions are being checked
|
||||
if (state.isLoading) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { useUserPermissions } from '@strapi/helper-plugin';
|
||||
import { useRBAC } from '@strapi/helper-plugin';
|
||||
import { DndProvider } from 'react-dnd';
|
||||
import HTML5Backend from 'react-dnd-html5-backend';
|
||||
import { omit } from 'lodash';
|
||||
@ -25,7 +25,7 @@ const InputModal = ({
|
||||
}) => {
|
||||
const singularTypes = allowedTypes.map(type => type.substring(0, type.length - 1));
|
||||
const permissions = React.useMemo(() => omit(pluginPermissions, 'main'), []);
|
||||
const { allowedActions, isLoading } = useUserPermissions(permissions);
|
||||
const { allowedActions, isLoading } = useRBAC(permissions);
|
||||
|
||||
if (isLoading) {
|
||||
return null;
|
||||
|
||||
@ -35,7 +35,7 @@ const ModalCreate = ({ alreadyUsedLocales, onClose, isOpened }) => {
|
||||
await refetchPermissions();
|
||||
}
|
||||
|
||||
shouldUpdatePermissions.current = true;
|
||||
shouldUpdatePermissions.current = false;
|
||||
};
|
||||
|
||||
const options = (defaultLocales || [])
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { useUserPermissions } from '@strapi/helper-plugin';
|
||||
import { useRBAC } from '@strapi/helper-plugin';
|
||||
import { useIntl } from 'react-intl';
|
||||
import LocaleSettingsPage from './LocaleSettingsPage';
|
||||
import i18nPermissions from '../../permissions';
|
||||
@ -10,7 +10,7 @@ const ProtectedLocaleSettingsPage = () => {
|
||||
const {
|
||||
isLoading,
|
||||
allowedActions: { canRead, canUpdate, canCreate, canDelete },
|
||||
} = useUserPermissions(i18nPermissions);
|
||||
} = useRBAC(i18nPermissions);
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
import React from 'react';
|
||||
import { createStore, combineReducers } from 'redux';
|
||||
import { Provider } from 'react-redux';
|
||||
import { request, useUserPermissions } from '@strapi/helper-plugin';
|
||||
import { request, useRBAC } from '@strapi/helper-plugin';
|
||||
import { fireEvent, render, screen, within, waitFor } from '@testing-library/react';
|
||||
import { ThemeProvider } from 'styled-components';
|
||||
import { QueryClient, QueryClientProvider } from 'react-query';
|
||||
@ -64,11 +64,11 @@ jest.mock('@strapi/helper-plugin', () => ({
|
||||
Tab: ({ children }) => <div>{children}</div>,
|
||||
TabsPanel: ({ children }) => <div>{children}</div>,
|
||||
TabPanel: ({ children }) => <div>{children}</div>,
|
||||
useUserPermissions: jest.fn(),
|
||||
useRBAC: jest.fn(),
|
||||
request: jest.fn(),
|
||||
selectStyles: () => ({ control: () => ({}), indicatorsContainer: () => ({}) }),
|
||||
useGlobalContext: () => ({ updateMenu: jest.fn() }),
|
||||
useUser: () => ({ fetchUserPermissions: jest.fn() }),
|
||||
useRBACProvider: () => ({ refetchPermissions: jest.fn() }),
|
||||
useNotification: () => toggleNotificationMock,
|
||||
}));
|
||||
|
||||
@ -101,7 +101,7 @@ describe('i18n settings page', () => {
|
||||
])
|
||||
);
|
||||
|
||||
useUserPermissions.mockImplementation(() => ({
|
||||
useRBAC.mockImplementation(() => ({
|
||||
isLoading: false,
|
||||
allowedActions: { canRead: true, canUpdate: true, canCreate: true, canDelete: true },
|
||||
}));
|
||||
@ -473,7 +473,7 @@ describe('i18n settings page', () => {
|
||||
|
||||
describe('permissions', () => {
|
||||
it('shows a loading information when resolving the permissions', () => {
|
||||
useUserPermissions.mockImplementation(() => ({
|
||||
useRBAC.mockImplementation(() => ({
|
||||
isLoading: true,
|
||||
allowedActions: { canRead: false, canUpdate: true, canCreate: true, canDelete: true },
|
||||
}));
|
||||
@ -490,7 +490,7 @@ describe('i18n settings page', () => {
|
||||
it("shows nothing when the user doesn't have read permission", () => {
|
||||
const canRead = false;
|
||||
|
||||
useUserPermissions.mockImplementation(() => ({
|
||||
useRBAC.mockImplementation(() => ({
|
||||
isLoading: false,
|
||||
allowedActions: { canRead, canUpdate: true, canCreate: true, canDelete: true },
|
||||
}));
|
||||
@ -508,7 +508,7 @@ describe('i18n settings page', () => {
|
||||
const canCreate = false;
|
||||
|
||||
request.mockImplementation(() => Promise.resolve([]));
|
||||
useUserPermissions.mockImplementation(() => ({
|
||||
useRBAC.mockImplementation(() => ({
|
||||
isLoading: false,
|
||||
allowedActions: { canRead: true, canUpdate: true, canCreate, canDelete: true },
|
||||
}));
|
||||
@ -527,7 +527,7 @@ describe('i18n settings page', () => {
|
||||
it('hides the "Edit locale" button (pencil) when the user is not allowed to update a locale', async () => {
|
||||
const canUpdate = false;
|
||||
|
||||
useUserPermissions.mockImplementation(() => ({
|
||||
useRBAC.mockImplementation(() => ({
|
||||
isLoading: false,
|
||||
allowedActions: { canRead: true, canUpdate, canCreate: true, canDelete: true },
|
||||
}));
|
||||
@ -545,7 +545,7 @@ describe('i18n settings page', () => {
|
||||
it('hides the "Delete locale" button (garbage) when the user is not allowed to delete a locale', async () => {
|
||||
const canDelete = false;
|
||||
|
||||
useUserPermissions.mockImplementation(() => ({
|
||||
useRBAC.mockImplementation(() => ({
|
||||
isLoading: false,
|
||||
allowedActions: { canRead: true, canUpdate: false, canCreate: true, canDelete },
|
||||
}));
|
||||
|
||||
@ -8,7 +8,7 @@ const addLocaleToCollectionTypesMiddleware = () => ({ getState }) => next => act
|
||||
if (action.data.authorizedCtLinks.length) {
|
||||
const store = getState();
|
||||
const { locales } = store.i18n_locales;
|
||||
const { collectionTypesRelatedPermissions } = store.permissionsManager;
|
||||
const { collectionTypesRelatedPermissions } = store.rbacProvider;
|
||||
|
||||
action.data.authorizedCtLinks = addLocaleToLinksSearch(
|
||||
action.data.authorizedCtLinks,
|
||||
|
||||
@ -8,7 +8,7 @@ const addLocaleToSingleTypesMiddleware = () => ({ getState }) => next => action
|
||||
if (action.data.authorizedStLinks.length) {
|
||||
const store = getState();
|
||||
const { locales } = store.i18n_locales;
|
||||
const { collectionTypesRelatedPermissions } = store.permissionsManager;
|
||||
const { collectionTypesRelatedPermissions } = store.rbacProvider;
|
||||
|
||||
action.data.authorizedStLinks = addLocaleToLinksSearch(
|
||||
action.data.authorizedStLinks,
|
||||
|
||||
@ -6,8 +6,8 @@ describe('i18n | middlewares | addLocaleToCollectionTypesMiddleware', () => {
|
||||
beforeEach(() => {
|
||||
const store = {
|
||||
i18n_locales: { locales: [] },
|
||||
permissionsManager: {
|
||||
userPermissions: [],
|
||||
rbacProvider: {
|
||||
allPermissions: [],
|
||||
collectionTypesRelatedPermissions: {
|
||||
test: {
|
||||
'plugins::content-manager.explorer.read': [],
|
||||
@ -78,8 +78,8 @@ describe('i18n | middlewares | addLocaleToCollectionTypesMiddleware', () => {
|
||||
it('should add a search key with the default locale when the user has the right to read it', () => {
|
||||
const tempStore = {
|
||||
i18n_locales: { locales: [{ code: 'en', isDefault: true }] },
|
||||
permissionsManager: {
|
||||
userPermissions: [],
|
||||
rbacProvider: {
|
||||
allPermissions: [],
|
||||
collectionTypesRelatedPermissions: {
|
||||
test: {
|
||||
'plugins::content-manager.explorer.read': [{ properties: { locales: ['en'] } }],
|
||||
@ -118,8 +118,8 @@ describe('i18n | middlewares | addLocaleToCollectionTypesMiddleware', () => {
|
||||
it('should set the isDisplayed key to false when the user does not have the right to read any locale', () => {
|
||||
const tempStore = {
|
||||
i18n_locales: { locales: [{ code: 'en', isDefault: true }] },
|
||||
permissionsManager: {
|
||||
userPermissions: [],
|
||||
rbacProvider: {
|
||||
allPermissions: [],
|
||||
collectionTypesRelatedPermissions: {
|
||||
test: {
|
||||
'plugins::content-manager.explorer.read': [{ properties: { locales: [] } }],
|
||||
@ -163,8 +163,8 @@ describe('i18n | middlewares | addLocaleToCollectionTypesMiddleware', () => {
|
||||
it('should keep the previous search', () => {
|
||||
const tempStore = {
|
||||
i18n_locales: { locales: [{ code: 'en', isDefault: true }] },
|
||||
permissionsManager: {
|
||||
userPermissions: [],
|
||||
rbacProvider: {
|
||||
allPermissions: [],
|
||||
collectionTypesRelatedPermissions: {
|
||||
test: {
|
||||
'plugins::content-manager.explorer.read': [{ properties: { locales: ['en'] } }],
|
||||
|
||||
@ -6,8 +6,8 @@ describe('i18n | middlewares | addLocaleToSingleTypesMiddleware', () => {
|
||||
beforeEach(() => {
|
||||
const store = {
|
||||
i18n_locales: { locales: [] },
|
||||
permissionsManager: {
|
||||
userPermissions: [],
|
||||
rbacProvider: {
|
||||
allPermissions: [],
|
||||
collectionTypesRelatedPermissions: {
|
||||
test: {
|
||||
'plugins::content-manager.explorer.read': [],
|
||||
@ -78,8 +78,8 @@ describe('i18n | middlewares | addLocaleToSingleTypesMiddleware', () => {
|
||||
it('should add a search key with the default locale when the user has the right to read it', () => {
|
||||
const tempStore = {
|
||||
i18n_locales: { locales: [{ code: 'en', isDefault: true }] },
|
||||
permissionsManager: {
|
||||
userPermissions: [],
|
||||
rbacProvider: {
|
||||
allPermissions: [],
|
||||
collectionTypesRelatedPermissions: {
|
||||
test: {
|
||||
'plugins::content-manager.explorer.read': [{ properties: { locales: ['en'] } }],
|
||||
@ -118,8 +118,8 @@ describe('i18n | middlewares | addLocaleToSingleTypesMiddleware', () => {
|
||||
it('should set the isDisplayed key to false when the user does not have the right to read any locale', () => {
|
||||
const tempStore = {
|
||||
i18n_locales: { locales: [{ code: 'en', isDefault: true }] },
|
||||
permissionsManager: {
|
||||
userPermissions: [],
|
||||
rbacProvider: {
|
||||
allPermissions: [],
|
||||
collectionTypesRelatedPermissions: {
|
||||
test: {
|
||||
'plugins::content-manager.explorer.read': [{ properties: { locales: [] } }],
|
||||
@ -129,8 +129,8 @@ describe('i18n | middlewares | addLocaleToSingleTypesMiddleware', () => {
|
||||
},
|
||||
};
|
||||
// tempStore.set('i18n_locales', { locales: [{ code: 'en', isDefault: true }] });
|
||||
// tempStore.set('permissionsManager', { userPermissions: [] });
|
||||
// tempStore.set('permissionsManager', {
|
||||
// tempStore.set('rbacProvider', { allPermissions: [] });
|
||||
// tempStore.set('rbacProvider', {
|
||||
// collectionTypesRelatedPermissions: {
|
||||
// test: {
|
||||
// 'plugins::content-manager.explorer.read': [{ properties: { locales: [] } }],
|
||||
@ -165,8 +165,8 @@ describe('i18n | middlewares | addLocaleToSingleTypesMiddleware', () => {
|
||||
it('should keep the previous search', () => {
|
||||
const tempStore = {
|
||||
i18n_locales: { locales: [{ code: 'en', isDefault: true }] },
|
||||
permissionsManager: {
|
||||
userPermissions: [],
|
||||
rbacProvider: {
|
||||
allPermissions: [],
|
||||
collectionTypesRelatedPermissions: {
|
||||
test: {
|
||||
'plugins::content-manager.explorer.read': [{ properties: { locales: ['en'] } }],
|
||||
@ -176,8 +176,8 @@ describe('i18n | middlewares | addLocaleToSingleTypesMiddleware', () => {
|
||||
},
|
||||
};
|
||||
// tempStore.set('i18n_locales', { locales: [{ code: 'en', isDefault: true }] });
|
||||
// tempStore.set('permissionsManager', { userPermissions: [] });
|
||||
// tempStore.set('permissionsManager', {
|
||||
// tempStore.set('rbacProvider', { allPermissions: [] });
|
||||
// tempStore.set('rbacProvider', {
|
||||
// collectionTypesRelatedPermissions: {
|
||||
// test: {
|
||||
// 'plugins::content-manager.explorer.read': [{ properties: { locales: ['en'] } }],
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const selectCollectionTypesRelatedPermissions = state =>
|
||||
state.permissionsManager.collectionTypesRelatedPermissions;
|
||||
state.rbacProvider.collectionTypesRelatedPermissions;
|
||||
|
||||
export default selectCollectionTypesRelatedPermissions;
|
||||
|
||||
@ -7,7 +7,7 @@ import {
|
||||
PopUpWarning,
|
||||
SettingsPageTitle,
|
||||
SizedInput,
|
||||
useUserPermissions,
|
||||
useRBAC,
|
||||
request,
|
||||
useNotification,
|
||||
useOverlayBlocker,
|
||||
@ -30,7 +30,7 @@ const AdvancedSettingsPage = () => {
|
||||
const {
|
||||
isLoading: isLoadingForPermissions,
|
||||
allowedActions: { canUpdate },
|
||||
} = useUserPermissions(updatePermissions);
|
||||
} = useRBAC(updatePermissions);
|
||||
const [
|
||||
{ initialData, isConfirmButtonLoading, isLoading, modifiedData, roles },
|
||||
dispatch,
|
||||
|
||||
@ -5,7 +5,7 @@ import { useIntl } from 'react-intl';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import {
|
||||
useUserPermissions,
|
||||
useRBAC,
|
||||
PopUpWarning,
|
||||
request,
|
||||
useGlobalContext,
|
||||
@ -41,7 +41,7 @@ const RoleListPage = () => {
|
||||
const {
|
||||
isLoading: isLoadingForPermissions,
|
||||
allowedActions: { canCreate, canUpdate, canDelete, canRead },
|
||||
} = useUserPermissions(updatePermissions);
|
||||
} = useRBAC(updatePermissions);
|
||||
const shouldFetchData = !isLoadingForPermissions && canRead;
|
||||
|
||||
const { roles, getData, isLoading } = useRolesList(shouldFetchData);
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { useCallback, useEffect, useReducer, useRef } from 'react';
|
||||
import { useUserPermissions, request, useNotification } from '@strapi/helper-plugin';
|
||||
import { useRBAC, request, useNotification } from '@strapi/helper-plugin';
|
||||
import { getRequestURL } from '../../utils';
|
||||
import reducer, { initialState } from './reducer';
|
||||
|
||||
const useUserForm = (endPoint, permissions) => {
|
||||
const { isLoading: isLoadingForPermissions, allowedActions } = useUserPermissions(permissions);
|
||||
const { isLoading: isLoadingForPermissions, allowedActions } = useRBAC(permissions);
|
||||
const [{ formErrors, initialData, isLoading, modifiedData }, dispatch] = useReducer(
|
||||
reducer,
|
||||
initialState
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user