mirror of
https://github.com/strapi/strapi.git
synced 2025-08-22 15:48:59 +00:00
Change frontend routing and prepare for edit
This commit is contained in:
parent
20c436303a
commit
3d66f18e1a
@ -21,6 +21,10 @@ class InputSearch extends React.Component { // eslint-disable-line react/prefer-
|
|||||||
if (nextProps.didDeleteUser !== this.props.didDeleteUser) {
|
if (nextProps.didDeleteUser !== this.props.didDeleteUser) {
|
||||||
this.setState({ users: nextProps.values, filteredUsers: nextProps.values });
|
this.setState({ users: nextProps.values, filteredUsers: nextProps.values });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nextProps.didGetUsers !== this.props.didGetUsers) {
|
||||||
|
this.setState({ users: nextProps.values, filteredUsers: nextProps.values });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChange = ({ target }) => {
|
handleChange = ({ target }) => {
|
||||||
@ -77,6 +81,7 @@ InputSearch.defaultProps = {
|
|||||||
|
|
||||||
InputSearch.propTypes = {
|
InputSearch.propTypes = {
|
||||||
didDeleteUser: PropTypes.bool.isRequired,
|
didDeleteUser: PropTypes.bool.isRequired,
|
||||||
|
didGetUsers: PropTypes.bool.isRequired,
|
||||||
label: PropTypes.string.isRequired,
|
label: PropTypes.string.isRequired,
|
||||||
labelValues: PropTypes.object,
|
labelValues: PropTypes.object,
|
||||||
name: PropTypes.string.isRequired,
|
name: PropTypes.string.isRequired,
|
||||||
|
@ -119,7 +119,7 @@ class ListRow extends React.Component { // eslint-disable-line react/prefer-stat
|
|||||||
handleClick = () => {
|
handleClick = () => {
|
||||||
switch (this.props.settingType) {
|
switch (this.props.settingType) {
|
||||||
case 'roles':
|
case 'roles':
|
||||||
return router.push(`${router.location.pathname}/${this.props.item.id}`);
|
return router.push(`${router.location.pathname}/edit/${this.props.item.id}`);
|
||||||
case 'providers':
|
case 'providers':
|
||||||
case 'email-templates':
|
case 'email-templates':
|
||||||
return router.push(`${router.location.pathname}#edit::${this.props.settingType}::${this.props.item.id}`);
|
return router.push(`${router.location.pathname}#edit::${this.props.settingType}::${this.props.item.id}`);
|
||||||
|
@ -39,7 +39,7 @@ class App extends React.Component {
|
|||||||
<div className={pluginId}>
|
<div className={pluginId}>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route path={`/plugins/${pluginId}/auth/:authType/:id?`} component={AuthPage} exact />
|
<Route path={`/plugins/${pluginId}/auth/:authType/:id?`} component={AuthPage} exact />
|
||||||
<Route path={`/plugins/${pluginId}/:settingType/:id`} component={EditPage} exact />
|
<Route path={`/plugins/${pluginId}/:settingType/:actionType/:id?`} component={EditPage} exact />
|
||||||
<Route path={`/plugins/${pluginId}/:settingType`} component={HomePage} exact />
|
<Route path={`/plugins/${pluginId}/:settingType`} component={HomePage} exact />
|
||||||
<Route component={NotFoundPage} />
|
<Route component={NotFoundPage} />
|
||||||
</Switch>
|
</Switch>
|
||||||
|
@ -3,12 +3,15 @@
|
|||||||
* EditPage actions
|
* EditPage actions
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
import { List, Map } from 'immutable';
|
||||||
import {
|
import {
|
||||||
ADD_USER,
|
ADD_USER,
|
||||||
|
GET_ROLE,
|
||||||
|
GET_ROLE_SUCCEEDED,
|
||||||
ON_CANCEL,
|
ON_CANCEL,
|
||||||
ON_CHANGE_INPUT,
|
ON_CHANGE_INPUT,
|
||||||
ON_CLICK_DELETE,
|
ON_CLICK_DELETE,
|
||||||
|
SET_FORM,
|
||||||
} from './constants';
|
} from './constants';
|
||||||
|
|
||||||
export function addUser(newUser) {
|
export function addUser(newUser) {
|
||||||
@ -18,6 +21,19 @@ export function addUser(newUser) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getRole() {
|
||||||
|
return {
|
||||||
|
type: GET_ROLE,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getRoleSucceeded(data) {
|
||||||
|
return {
|
||||||
|
type: GET_ROLE_SUCCEEDED,
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function onCancel() {
|
export function onCancel() {
|
||||||
return {
|
return {
|
||||||
type: ON_CANCEL,
|
type: ON_CANCEL,
|
||||||
@ -38,3 +54,21 @@ export function onClickDelete(itemToDelete) {
|
|||||||
itemToDelete,
|
itemToDelete,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setForm() {
|
||||||
|
const form = Map({
|
||||||
|
name: '',
|
||||||
|
description: '',
|
||||||
|
users: List([
|
||||||
|
{ name: 'Pierre Burgy' },
|
||||||
|
{ name: 'Jim Laurie' },
|
||||||
|
{ name: 'Aurelien Georget' },
|
||||||
|
{ name: 'Cyril Lopez' },
|
||||||
|
]),
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: SET_FORM,
|
||||||
|
form,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export const ADD_USER = 'UsersPermissions/EditPage/ADD_USER';
|
export const ADD_USER = 'UsersPermissions/EditPage/ADD_USER';
|
||||||
|
export const GET_ROLE = 'UsersPermissions/EditPage/GET_ROLE';
|
||||||
|
export const GET_ROLE_SUCCEEDED = 'UsersPermissions/EditPage/GET_ROLE_SUCCEEDED';
|
||||||
export const ON_CANCEL = 'UsersPermissions/EditPage/ON_CANCEL';
|
export const ON_CANCEL = 'UsersPermissions/EditPage/ON_CANCEL';
|
||||||
export const ON_CHANGE_INPUT = 'UsersPermissions/EditPage/ON_CHANGE_INPUT';
|
export const ON_CHANGE_INPUT = 'UsersPermissions/EditPage/ON_CHANGE_INPUT';
|
||||||
export const ON_CLICK_DELETE = 'UsersPermissions/EditPage/ON_CLICK_DELETE';
|
export const ON_CLICK_DELETE = 'UsersPermissions/EditPage/ON_CLICK_DELETE';
|
||||||
|
export const SET_FORM = 'UsersPermissions/EditPage/SET_FORM';
|
||||||
|
@ -28,6 +28,7 @@ import {
|
|||||||
onCancel,
|
onCancel,
|
||||||
onChangeInput,
|
onChangeInput,
|
||||||
onClickDelete,
|
onClickDelete,
|
||||||
|
setForm,
|
||||||
} from './actions';
|
} from './actions';
|
||||||
|
|
||||||
// Selectors
|
// Selectors
|
||||||
@ -39,6 +40,12 @@ import saga from './saga';
|
|||||||
import styles from './styles.scss';
|
import styles from './styles.scss';
|
||||||
|
|
||||||
export class EditPage extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
export class EditPage extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
||||||
|
componentDidMount() {
|
||||||
|
if (this.props.match.params.actionType === 'create') {
|
||||||
|
this.props.setForm();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pluginHeaderActions = [
|
pluginHeaderActions = [
|
||||||
{
|
{
|
||||||
label: 'users-permissions.EditPage.cancel',
|
label: 'users-permissions.EditPage.cancel',
|
||||||
@ -55,13 +62,12 @@ export class EditPage extends React.Component { // eslint-disable-line react/pre
|
|||||||
];
|
];
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const pluginHeaderTitle = this.props.match.params.id === 'create' ?
|
const pluginHeaderTitle = this.props.match.params.actionType === 'create' ?
|
||||||
'users-permissions.EditPage.header.title.create'
|
'users-permissions.EditPage.header.title.create'
|
||||||
: 'users-permissions.EditPage.header.title';
|
: 'users-permissions.EditPage.header.title';
|
||||||
const pluginHeaderDescription = this.props.match.params.id === 'create' ?
|
const pluginHeaderDescription = this.props.match.params.actionType === 'create' ?
|
||||||
'users-permissions.EditPage.header.description.create'
|
'users-permissions.EditPage.header.description.create'
|
||||||
: 'users-permissions.EditPage.header.description';
|
: 'users-permissions.EditPage.header.description';
|
||||||
|
|
||||||
const pluginHeaderActions = this.props.editPage.showButtons ? this.pluginHeaderActions : [];
|
const pluginHeaderActions = this.props.editPage.showButtons ? this.pluginHeaderActions : [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -119,6 +125,7 @@ export class EditPage extends React.Component { // eslint-disable-line react/pre
|
|||||||
<InputSearch
|
<InputSearch
|
||||||
addUser={this.props.addUser}
|
addUser={this.props.addUser}
|
||||||
didDeleteUser={this.props.editPage.didDeleteUser}
|
didDeleteUser={this.props.editPage.didDeleteUser}
|
||||||
|
didGetUsers={this.props.editPage.didGetUsers}
|
||||||
label="users-permissions.EditPage.form.roles.label.users"
|
label="users-permissions.EditPage.form.roles.label.users"
|
||||||
labelValues={{ number: size(get(this.props.editPage, ['modifiedData', 'users'])) }}
|
labelValues={{ number: size(get(this.props.editPage, ['modifiedData', 'users'])) }}
|
||||||
type="text"
|
type="text"
|
||||||
@ -146,6 +153,7 @@ EditPage.propTypes = {
|
|||||||
onCancel: PropTypes.func.isRequired,
|
onCancel: PropTypes.func.isRequired,
|
||||||
onChangeInput: PropTypes.func.isRequired,
|
onChangeInput: PropTypes.func.isRequired,
|
||||||
onClickDelete: PropTypes.func.isRequired,
|
onClickDelete: PropTypes.func.isRequired,
|
||||||
|
setForm: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
@ -159,6 +167,7 @@ function mapDispatchToProps(dispatch) {
|
|||||||
onCancel,
|
onCancel,
|
||||||
onChangeInput,
|
onChangeInput,
|
||||||
onClickDelete,
|
onClickDelete,
|
||||||
|
setForm,
|
||||||
},
|
},
|
||||||
dispatch,
|
dispatch,
|
||||||
);
|
);
|
||||||
|
@ -4,36 +4,20 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { fromJS, List, Map } from 'immutable';
|
import { fromJS, Map } from 'immutable';
|
||||||
import {
|
import {
|
||||||
ADD_USER,
|
ADD_USER,
|
||||||
ON_CANCEL,
|
ON_CANCEL,
|
||||||
ON_CHANGE_INPUT,
|
ON_CHANGE_INPUT,
|
||||||
ON_CLICK_DELETE,
|
ON_CLICK_DELETE,
|
||||||
|
SET_FORM,
|
||||||
} from './constants';
|
} from './constants';
|
||||||
|
|
||||||
const initialState = fromJS({
|
const initialState = fromJS({
|
||||||
didDeleteUser: false,
|
didDeleteUser: false,
|
||||||
initialData: Map({
|
didGetUsers: false,
|
||||||
name: '',
|
initialData: Map({}),
|
||||||
description: '',
|
modifiedData: Map({}),
|
||||||
users: List([
|
|
||||||
{ name: 'Pierre Burgy' },
|
|
||||||
{ name: 'Jim Laurie' },
|
|
||||||
{ name: 'Aurelien Georget' },
|
|
||||||
{ name: 'Cyril Lopez' },
|
|
||||||
]),
|
|
||||||
}),
|
|
||||||
modifiedData: Map({
|
|
||||||
name: '',
|
|
||||||
description: '',
|
|
||||||
users: List([
|
|
||||||
{ name: 'Pierre Burgy' },
|
|
||||||
{ name: 'Jim Laurie' },
|
|
||||||
{ name: 'Aurelien Georget' },
|
|
||||||
{ name: 'Cyril Lopez' },
|
|
||||||
]),
|
|
||||||
}),
|
|
||||||
showButtons: false,
|
showButtons: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -56,6 +40,11 @@ function editPageReducer(state = initialState, action) {
|
|||||||
.set('didDeleteUser', !state.get('didDeleteUser'))
|
.set('didDeleteUser', !state.get('didDeleteUser'))
|
||||||
.set('showButtons', true)
|
.set('showButtons', true)
|
||||||
.updateIn(['modifiedData', 'users'], list => list.filter(o => o.name !== action.itemToDelete.name));
|
.updateIn(['modifiedData', 'users'], list => list.filter(o => o.name !== action.itemToDelete.name));
|
||||||
|
case SET_FORM:
|
||||||
|
return state
|
||||||
|
.set('didGetUsers', !state.get('didGetUsers'))
|
||||||
|
.set('initialData', action.form)
|
||||||
|
.set('modifiedData', action.form);
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
@ -47,9 +47,9 @@
|
|||||||
"EditPage.form.roles.label.description": "Description",
|
"EditPage.form.roles.label.description": "Description",
|
||||||
"EditPage.form.roles.label.name": "Name",
|
"EditPage.form.roles.label.name": "Name",
|
||||||
"EditPage.form.roles.label.users": "Users associated with this role ({number})",
|
"EditPage.form.roles.label.users": "Users associated with this role ({number})",
|
||||||
"EditPage.header.title": "{name}",
|
"EditPage.header.title": "{name} ",
|
||||||
"EditPage.header.title.create": "Create a new role",
|
"EditPage.header.title.create": "Create a new role",
|
||||||
"EditPage.header.description": "{description}",
|
"EditPage.header.description": "{description} ",
|
||||||
"EditPage.header.description.create": " ",
|
"EditPage.header.description.create": " ",
|
||||||
|
|
||||||
"HeaderNav.link.advancedSettings": "Advanced settings",
|
"HeaderNav.link.advancedSettings": "Advanced settings",
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"1": {
|
||||||
|
"description": "Allow editing and deleting (except users)",
|
||||||
|
"name": "moderateur",
|
||||||
|
"users": [
|
||||||
|
{
|
||||||
|
"id": "11",
|
||||||
|
"name": "John Lennon"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "12",
|
||||||
|
"name": "Paul McCartney"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "13",
|
||||||
|
"name": "George Harrison"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "14",
|
||||||
|
"name": "Ringo Starr"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"permissions": {
|
||||||
|
"application": {
|
||||||
|
"icon": "",
|
||||||
|
"description": "users-permissions.EditPage.permissions.application.description",
|
||||||
|
"controllers": {
|
||||||
|
"invoices": {
|
||||||
|
"actions": {
|
||||||
|
"delete": {
|
||||||
|
"enabled": true,
|
||||||
|
"policy": "entriesCreatedByUser"
|
||||||
|
},
|
||||||
|
"update": {
|
||||||
|
"enabled": false,
|
||||||
|
"policy": "entriesCreatedByUser"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
packages/strapi-plugin-users-permissions/config/roles.json
Normal file
24
packages/strapi-plugin-users-permissions/config/roles.json
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"1": {
|
||||||
|
"description": "Allow editing and deleting (except users)",
|
||||||
|
"name": "moderateur",
|
||||||
|
"permissions": {
|
||||||
|
"application": {
|
||||||
|
"controllers": {
|
||||||
|
"invoices": {
|
||||||
|
"actions": {
|
||||||
|
"delete": {
|
||||||
|
"enabled": true,
|
||||||
|
"policy": "entriesCreatedByUser"
|
||||||
|
},
|
||||||
|
"update": {
|
||||||
|
"enabled": false,
|
||||||
|
"policy": "entriesCreatedByUser"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,14 @@
|
|||||||
"policies": []
|
"policies": []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"method": "GET",
|
||||||
|
"path": "/roles/:id",
|
||||||
|
"handler": "UsersPermissions.getRole",
|
||||||
|
"config": {
|
||||||
|
"policies": []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
|
@ -13,6 +13,11 @@ module.exports = {
|
|||||||
*
|
*
|
||||||
* @return {Object}
|
* @return {Object}
|
||||||
*/
|
*/
|
||||||
|
getRole: async(ctx) => {
|
||||||
|
const { id } = ctx.params;
|
||||||
|
|
||||||
|
ctx.send({ ok: true });
|
||||||
|
},
|
||||||
|
|
||||||
index: async (ctx) => {
|
index: async (ctx) => {
|
||||||
// Add your own logic here.
|
// Add your own logic here.
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"cross-env": "^5.1.1",
|
"cross-env": "^5.1.1",
|
||||||
"eslint": "^4.10.0",
|
"eslint": "^4.11.0",
|
||||||
"eslint-config-airbnb": "^15.1.0",
|
"eslint-config-airbnb": "^15.1.0",
|
||||||
"eslint-config-airbnb-base": "^11.3.2",
|
"eslint-config-airbnb-base": "^11.3.2",
|
||||||
"eslint-config-prettier": "^2.7.0",
|
"eslint-config-prettier": "^2.7.0",
|
||||||
@ -37,7 +37,7 @@
|
|||||||
"eslint-plugin-react": "^7.4.0",
|
"eslint-plugin-react": "^7.4.0",
|
||||||
"eslint-plugin-redux-saga": "^0.4.0",
|
"eslint-plugin-redux-saga": "^0.4.0",
|
||||||
"plop": "^1.9.0",
|
"plop": "^1.9.0",
|
||||||
"prettier": "^1.7.4",
|
"prettier": "^1.8.2",
|
||||||
"rimraf": "^2.6.2",
|
"rimraf": "^2.6.2",
|
||||||
"strapi-helper-plugin": "3.0.0-alpha.6.7",
|
"strapi-helper-plugin": "3.0.0-alpha.6.7",
|
||||||
"webpack": "^3.8.1"
|
"webpack": "^3.8.1"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user