mirror of
https://github.com/strapi/strapi.git
synced 2025-12-12 15:32:42 +00:00
Add handler to get the plugins routes
This commit is contained in:
parent
6478d87a6f
commit
ad9b39e164
@ -56,7 +56,7 @@ class ListRow extends React.Component { // eslint-disable-line react/prefer-stat
|
||||
{this.props.item.description}
|
||||
</div>
|
||||
<div className="col-md-1">
|
||||
<strong>{this.props.item.nb_users}</strong>
|
||||
<strong>{this.props.item.nb_users || 0}</strong>
|
||||
{this.props.item.nb_users > 1 ? (
|
||||
'users'
|
||||
) : (
|
||||
|
||||
@ -21,7 +21,7 @@ class Policies extends React.Component { // eslint-disable-line react/prefer-sta
|
||||
const baseTitle = 'users-permissions.Policies.header';
|
||||
const title = this.props.shouldDisplayPoliciesHint ? 'hint' : 'title';
|
||||
const value = get(this.props.values, this.props.inputSelectName);
|
||||
|
||||
console.log(this.props.routes);
|
||||
return (
|
||||
<div className={cn('col-md-5',styles.policies)}>
|
||||
<div className="container-fluid">
|
||||
@ -52,8 +52,13 @@ Policies.contextTypes = {
|
||||
onChange: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
Policies.defaultProps = {
|
||||
routes: {},
|
||||
};
|
||||
|
||||
Policies.propTypes = {
|
||||
inputSelectName: PropTypes.string.isRequired,
|
||||
routes: PropTypes.object,
|
||||
selectOptions: PropTypes.array.isRequired,
|
||||
shouldDisplayPoliciesHint: PropTypes.bool.isRequired,
|
||||
values: PropTypes.object.isRequired,
|
||||
|
||||
@ -13,6 +13,7 @@ import {
|
||||
GET_POLICIES_SUCCEEDED,
|
||||
GET_ROLE,
|
||||
GET_ROLE_SUCCEEDED,
|
||||
GET_ROUTES_SUCCEEDED,
|
||||
GET_USER,
|
||||
GET_USER_SUCCEEDED,
|
||||
ON_CANCEL,
|
||||
@ -95,6 +96,13 @@ export function getRoleSucceeded(data) {
|
||||
};
|
||||
}
|
||||
|
||||
export function getRoutesSucceeded(routes) {
|
||||
return {
|
||||
type: GET_ROUTES_SUCCEEDED,
|
||||
routes,
|
||||
};
|
||||
}
|
||||
|
||||
export function getUser(user) {
|
||||
return {
|
||||
type: GET_USER,
|
||||
|
||||
@ -11,6 +11,7 @@ export const GET_POLICIES = 'UsersPermissions/EditPage/GET_POLICIES';
|
||||
export const GET_POLICIES_SUCCEEDED = 'UsersPermissions/EditPage/GET_POLICIES_SUCCEEDED';
|
||||
export const GET_ROLE = 'UsersPermissions/EditPage/GET_ROLE';
|
||||
export const GET_ROLE_SUCCEEDED = 'UsersPermissions/EditPage/GET_ROLE_SUCCEEDED';
|
||||
export const GET_ROUTES_SUCCEEDED = 'UsersPermissions/EditPage/GET_ROUTES_SUCCEEDED';
|
||||
export const GET_USER = 'UsersPermissions/EditPage/GET_USER';
|
||||
export const GET_USER_SUCCEEDED = 'UsersPermissions/EditPage/GET_USER_SUCCEEDED';
|
||||
export const ON_CANCEL = 'UsersPermissions/EditPage/ON_CANCEL';
|
||||
|
||||
@ -207,6 +207,7 @@ export class EditPage extends React.Component { // eslint-disable-line react/pre
|
||||
<Policies
|
||||
shouldDisplayPoliciesHint={this.props.editPage.shouldDisplayPoliciesHint}
|
||||
inputSelectName={this.props.editPage.inputPoliciesPath}
|
||||
routes={this.props.editPage.routes}
|
||||
selectOptions={this.props.editPage.policies}
|
||||
values={this.props.editPage.modifiedData}
|
||||
/>
|
||||
|
||||
@ -12,6 +12,7 @@ import {
|
||||
GET_POLICIES_SUCCEEDED,
|
||||
GET_ROLE_SUCCEEDED,
|
||||
GET_USER_SUCCEEDED,
|
||||
GET_ROUTES_SUCCEEDED,
|
||||
ON_CANCEL,
|
||||
ON_CHANGE_INPUT,
|
||||
ON_CLICK_ADD,
|
||||
@ -41,6 +42,7 @@ const initialState = fromJS({
|
||||
modifiedData: Map({}),
|
||||
policies: List([]),
|
||||
roleId: '',
|
||||
routes: Map([]),
|
||||
shouldDisplayPoliciesHint: true,
|
||||
users: List([]),
|
||||
});
|
||||
@ -61,6 +63,8 @@ function editPageReducer(state = initialState, action) {
|
||||
.set('didGetUsers', !state.get('didGetUsers'))
|
||||
.set('initialData', action.form)
|
||||
.set('modifiedData', action.form);
|
||||
case GET_ROUTES_SUCCEEDED:
|
||||
return state.set('routes', Map(action.routes.routes));
|
||||
case GET_USER_SUCCEEDED:
|
||||
return state
|
||||
.set('didFetchUsers', !state.get('didFetchUsers'))
|
||||
|
||||
@ -14,6 +14,7 @@ import {
|
||||
getPermissionsSucceeded,
|
||||
getPoliciesSucceeded,
|
||||
getRoleSucceeded,
|
||||
getRoutesSucceeded,
|
||||
getUserSucceeded,
|
||||
submitSucceeded,
|
||||
} from './actions';
|
||||
@ -53,9 +54,13 @@ export function* permissionsGet() {
|
||||
|
||||
export function* policiesGet() {
|
||||
try {
|
||||
const response = yield call(request, '/users-permissions/policies', { method: 'GET' });
|
||||
const response = yield [
|
||||
call(request, '/users-permissions/policies', { method: 'GET' }),
|
||||
call(request, '/users-permissions/routes', { method: 'GET' }),
|
||||
];
|
||||
|
||||
yield put(getPoliciesSucceeded(response));
|
||||
yield put(getPoliciesSucceeded(response[0]));
|
||||
yield put(getRoutesSucceeded(response[1]));
|
||||
} catch(err) {
|
||||
strapi.notification.error('users-permissions.EditPage.notification.policies.error');
|
||||
}
|
||||
|
||||
@ -247,6 +247,10 @@
|
||||
"identity": {
|
||||
"enabled": true,
|
||||
"policy": ""
|
||||
},
|
||||
"getRoutes": {
|
||||
"enabled": true,
|
||||
"policy": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -501,6 +505,10 @@
|
||||
"identity": {
|
||||
"enabled": false,
|
||||
"policy": ""
|
||||
},
|
||||
"getRoutes": {
|
||||
"enabled": false,
|
||||
"policy": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,6 +56,14 @@
|
||||
"policies": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"path": "/routes",
|
||||
"handler": "UsersPermissions.getRoutes",
|
||||
"config": {
|
||||
"policies": []
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"method": "POST",
|
||||
|
||||
@ -95,6 +95,17 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
getRoutes: async (ctx) => {
|
||||
try {
|
||||
const routes = await strapi.plugins['users-permissions'].services.userspermissions.getRoutes();
|
||||
|
||||
ctx.send({ routes });
|
||||
} catch(err) {
|
||||
console.log(err);
|
||||
ctx.badRequest(null, [{ messages: [{ id: 'Not found' }] }]);
|
||||
}
|
||||
},
|
||||
|
||||
index: async (ctx) => {
|
||||
// Add your own logic here.
|
||||
|
||||
|
||||
@ -95,6 +95,14 @@ module.exports = {
|
||||
return formattedRoles;
|
||||
},
|
||||
|
||||
getRoutes: async () => {
|
||||
return Object.keys(strapi.plugins).reduce((acc, current) => {
|
||||
acc[current] = strapi.plugins[current].config.routes;
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
},
|
||||
|
||||
getRoleConfigPath: () => (
|
||||
path.join(
|
||||
strapi.config.appPath,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user