mirror of
https://github.com/strapi/strapi.git
synced 2025-12-14 08:44:16 +00:00
Edit role
This commit is contained in:
parent
47c375e83d
commit
38e6df838f
@ -20,6 +20,7 @@ import {
|
|||||||
SET_ACTION_TYPE,
|
SET_ACTION_TYPE,
|
||||||
SET_ERRORS,
|
SET_ERRORS,
|
||||||
SET_FORM,
|
SET_FORM,
|
||||||
|
SET_ROLE_ID,
|
||||||
SUBMIT,
|
SUBMIT,
|
||||||
SUBMIT_ERROR,
|
SUBMIT_ERROR,
|
||||||
SUBMIT_SUCCEEDED,
|
SUBMIT_SUCCEEDED,
|
||||||
@ -141,6 +142,13 @@ export function setForm() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setRoleId(roleId) {
|
||||||
|
return {
|
||||||
|
type: SET_ROLE_ID,
|
||||||
|
roleId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function submit() {
|
export function submit() {
|
||||||
return {
|
return {
|
||||||
type: SUBMIT,
|
type: SUBMIT,
|
||||||
|
|||||||
@ -18,6 +18,7 @@ export const ON_CLICK_DELETE = 'UsersPermissions/EditPage/ON_CLICK_DELETE';
|
|||||||
export const SET_ACTION_TYPE = 'UsersPermissions/EditPage/SET_ACTION_TYPE';
|
export const SET_ACTION_TYPE = 'UsersPermissions/EditPage/SET_ACTION_TYPE';
|
||||||
export const SET_ERRORS = 'UsersPermissions/EditPage/SET_ERRORS';
|
export const SET_ERRORS = 'UsersPermissions/EditPage/SET_ERRORS';
|
||||||
export const SET_FORM = 'UsersPermissions/EditPage/SET_FORM';
|
export const SET_FORM = 'UsersPermissions/EditPage/SET_FORM';
|
||||||
|
export const SET_ROLE_ID = 'UsersPermissions/EditPage/SET_ROLE_ID';
|
||||||
export const SUBMIT = 'UsersPermissions/EditPage/SUBMIT';
|
export const SUBMIT = 'UsersPermissions/EditPage/SUBMIT';
|
||||||
export const SUBMIT_ERROR = 'UsersPermissions/EditPage/SUBMIT_ERROR';
|
export const SUBMIT_ERROR = 'UsersPermissions/EditPage/SUBMIT_ERROR';
|
||||||
export const SUBMIT_SUCCEEDED = 'UsersPermissions/EditPage/SUBMIT_SUCCEEDED';
|
export const SUBMIT_SUCCEEDED = 'UsersPermissions/EditPage/SUBMIT_SUCCEEDED';
|
||||||
|
|||||||
@ -36,6 +36,7 @@ import {
|
|||||||
setActionType,
|
setActionType,
|
||||||
setErrors,
|
setErrors,
|
||||||
setForm,
|
setForm,
|
||||||
|
setRoleId,
|
||||||
submit,
|
submit,
|
||||||
} from './actions';
|
} from './actions';
|
||||||
|
|
||||||
@ -63,6 +64,7 @@ export class EditPage extends React.Component { // eslint-disable-line react/pre
|
|||||||
// Get the available permissions
|
// Get the available permissions
|
||||||
this.props.getPermissions();
|
this.props.getPermissions();
|
||||||
} else {
|
} else {
|
||||||
|
this.props.setRoleId(this.props.match.params.id);
|
||||||
this.props.getRole(this.props.match.params.id);
|
this.props.getRole(this.props.match.params.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -220,6 +222,7 @@ EditPage.propTypes = {
|
|||||||
setActionType: PropTypes.func.isRequired,
|
setActionType: PropTypes.func.isRequired,
|
||||||
setErrors: PropTypes.func.isRequired,
|
setErrors: PropTypes.func.isRequired,
|
||||||
setForm: PropTypes.func.isRequired,
|
setForm: PropTypes.func.isRequired,
|
||||||
|
setRoleId: PropTypes.func.isRequired,
|
||||||
submit: PropTypes.func.isRequired,
|
submit: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -241,6 +244,7 @@ function mapDispatchToProps(dispatch) {
|
|||||||
setActionType,
|
setActionType,
|
||||||
setErrors,
|
setErrors,
|
||||||
setForm,
|
setForm,
|
||||||
|
setRoleId,
|
||||||
submit,
|
submit,
|
||||||
},
|
},
|
||||||
dispatch,
|
dispatch,
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import {
|
|||||||
SET_ACTION_TYPE,
|
SET_ACTION_TYPE,
|
||||||
SET_ERRORS,
|
SET_ERRORS,
|
||||||
SET_FORM,
|
SET_FORM,
|
||||||
|
SET_ROLE_ID,
|
||||||
SUBMIT_ERROR,
|
SUBMIT_ERROR,
|
||||||
SUBMIT_SUCCEEDED,
|
SUBMIT_SUCCEEDED,
|
||||||
} from './constants';
|
} from './constants';
|
||||||
@ -31,6 +32,7 @@ const initialState = fromJS({
|
|||||||
formErrors: List([]),
|
formErrors: List([]),
|
||||||
initialData: Map({}),
|
initialData: Map({}),
|
||||||
modifiedData: Map({}),
|
modifiedData: Map({}),
|
||||||
|
roleId: '',
|
||||||
users: List([]),
|
users: List([]),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -81,6 +83,8 @@ function editPageReducer(state = initialState, action) {
|
|||||||
.set('didGetUsers', !state.get('didGetUsers'))
|
.set('didGetUsers', !state.get('didGetUsers'))
|
||||||
.set('initialData', action.form)
|
.set('initialData', action.form)
|
||||||
.set('modifiedData', action.form);
|
.set('modifiedData', action.form);
|
||||||
|
case SET_ROLE_ID:
|
||||||
|
return state.set('roleId', action.roleId);
|
||||||
case SUBMIT_ERROR:
|
case SUBMIT_ERROR:
|
||||||
return state
|
return state
|
||||||
.set('formErrors', List(action.errors));
|
.set('formErrors', List(action.errors));
|
||||||
|
|||||||
@ -28,6 +28,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
makeSelectActionType,
|
makeSelectActionType,
|
||||||
makeSelectModifiedData,
|
makeSelectModifiedData,
|
||||||
|
makeSelectRoleId,
|
||||||
} from './selectors';
|
} from './selectors';
|
||||||
|
|
||||||
export function* fetchUser(action) {
|
export function* fetchUser(action) {
|
||||||
@ -86,17 +87,16 @@ export function* submit() {
|
|||||||
try {
|
try {
|
||||||
const actionType = yield select(makeSelectActionType());
|
const actionType = yield select(makeSelectActionType());
|
||||||
const body = yield select(makeSelectModifiedData());
|
const body = yield select(makeSelectModifiedData());
|
||||||
|
const roleId = yield select(makeSelectRoleId());
|
||||||
const opts = {
|
const opts = {
|
||||||
method: actionType,
|
method: actionType,
|
||||||
body,
|
body,
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO : handle PUT url
|
const requestURL = actionType === 'POST' ? '/users-permissions/roles' : `/users-permissions/roles/${roleId}`;
|
||||||
const requestURL = actionType === 'POST' ? '/users-permissions/roles' : '/users-permissions/roles/id';
|
|
||||||
yield call(request, requestURL, opts);
|
yield call(request, requestURL, opts);
|
||||||
|
|
||||||
yield put(submitSucceeded());
|
yield put(submitSucceeded());
|
||||||
|
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
console.log(error.response.payload);
|
console.log(error.response.payload);
|
||||||
// TODO handle error message
|
// TODO handle error message
|
||||||
|
|||||||
@ -29,9 +29,15 @@ const makeSelectModifiedData = () => createSelector(
|
|||||||
(substate) => substate.get('modifiedData').toJS(),
|
(substate) => substate.get('modifiedData').toJS(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const makeSelectRoleId = () => createSelector(
|
||||||
|
selectEditPageDomain(),
|
||||||
|
(substate) => substate.get('roleId'),
|
||||||
|
);
|
||||||
|
|
||||||
export default makeSelectEditPage;
|
export default makeSelectEditPage;
|
||||||
export {
|
export {
|
||||||
makeSelectActionType,
|
makeSelectActionType,
|
||||||
makeSelectModifiedData,
|
makeSelectModifiedData,
|
||||||
|
makeSelectRoleId,
|
||||||
selectEditPageDomain,
|
selectEditPageDomain,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -223,6 +223,10 @@
|
|||||||
"createRole": {
|
"createRole": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"policy": ""
|
"policy": ""
|
||||||
|
},
|
||||||
|
"updateRole": {
|
||||||
|
"enabled": false,
|
||||||
|
"policy": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,6 +40,14 @@
|
|||||||
"policies": []
|
"policies": []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"method": "PUT",
|
||||||
|
"path": "/roles/:role",
|
||||||
|
"handler": "UsersPermissions.updateRole",
|
||||||
|
"config": {
|
||||||
|
"policies": []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
|
|||||||
@ -16,9 +16,7 @@ module.exports = {
|
|||||||
*
|
*
|
||||||
* @return {Object}
|
* @return {Object}
|
||||||
*/
|
*/
|
||||||
createRole: async(ctx) => {
|
createRole: async (ctx) => {
|
||||||
console.log(ctx.request.body);
|
|
||||||
|
|
||||||
if (_.isEmpty(ctx.request.body)) {
|
if (_.isEmpty(ctx.request.body)) {
|
||||||
return ctx.badRequest(null, [{ messages: [{ id: 'Cannot be empty' }] }]);
|
return ctx.badRequest(null, [{ messages: [{ id: 'Cannot be empty' }] }]);
|
||||||
}
|
}
|
||||||
@ -30,7 +28,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getPermissions: async(ctx) => {
|
getPermissions: async (ctx) => {
|
||||||
try {
|
try {
|
||||||
const permissions = await strapi.plugins['users-permissions'].services.userspermissions.getActions();
|
const permissions = await strapi.plugins['users-permissions'].services.userspermissions.getActions();
|
||||||
ctx.send({ permissions });
|
ctx.send({ permissions });
|
||||||
@ -39,7 +37,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getRole: async(ctx) => {
|
getRole: async (ctx) => {
|
||||||
const { id } = ctx.params;
|
const { id } = ctx.params;
|
||||||
const role = fakeData[id];
|
const role = fakeData[id];
|
||||||
|
|
||||||
@ -67,5 +65,13 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ctx.send({ hasAdmin: !_.isEmpty(hasAdmin) });
|
ctx.send({ hasAdmin: !_.isEmpty(hasAdmin) });
|
||||||
|
},
|
||||||
|
|
||||||
|
updateRole: async (ctx) => {
|
||||||
|
try {
|
||||||
|
ctx.send({ ok: true });
|
||||||
|
} catch(error) {
|
||||||
|
ctx.badRequest(null, [{ messages: [{ id: 'An error occurred' }] }]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user