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