Introduce update user
parent
864759125f
commit
f38f161646
|
@ -6,9 +6,8 @@ import {
|
|||
createRole as createRoleAJAX,
|
||||
deleteUser as deleteUserAJAX,
|
||||
deleteRole as deleteRoleAJAX,
|
||||
updateRoleUsers as updateRoleUsersAJAX,
|
||||
updateRolePermissions as updateRolePermissionsAJAX,
|
||||
updateUserPermissions as updateUserPermissionsAJAX,
|
||||
updateRole as updateRoleAJAX,
|
||||
updateUser as updateUserAJAX,
|
||||
} from 'src/admin/apis'
|
||||
|
||||
import {killQuery as killQueryProxy} from 'shared/apis/metaQuery'
|
||||
|
@ -192,7 +191,7 @@ export const deleteUserAsync = (user, addFlashMessage) => (dispatch) => {
|
|||
|
||||
export const updateRoleUsersAsync = (role, users) => async (dispatch) => {
|
||||
try {
|
||||
await updateRoleUsersAJAX(role.links.self, users)
|
||||
await updateRoleAJAX(role.links.self, users, role.permissions)
|
||||
dispatch(publishNotification('success', 'Role users updated'))
|
||||
} catch (error) {
|
||||
dispatch(publishNotification('error', `Failed to update role: ${error.data.message}`))
|
||||
|
@ -201,7 +200,7 @@ export const updateRoleUsersAsync = (role, users) => async (dispatch) => {
|
|||
|
||||
export const updateRolePermissionsAsync = (role, permissions) => async (dispatch) => {
|
||||
try {
|
||||
await updateRolePermissionsAJAX(role.links.self, permissions)
|
||||
await updateRoleAJAX(role.links.self, role.users, permissions)
|
||||
dispatch(publishNotification('success', 'Role permissions updated'))
|
||||
} catch (error) {
|
||||
dispatch(publishNotification('error', `Failed to updated role: ${error.data.message}`))
|
||||
|
@ -210,9 +209,24 @@ export const updateRolePermissionsAsync = (role, permissions) => async (dispatch
|
|||
|
||||
export const updateUserPermissionsAsync = (user, permissions) => async (dispatch) => {
|
||||
try {
|
||||
await updateUserPermissionsAJAX(user.links.self, permissions)
|
||||
await updateUserAJAX(user.links.self, user.roles, permissions)
|
||||
dispatch(publishNotification('success', 'User permissions updated'))
|
||||
} catch (error) {
|
||||
dispatch(publishNotification('error', `Failed to updated user: ${error.data.message}`))
|
||||
}
|
||||
}
|
||||
|
||||
export const updateUserRolesAsync = (user, roles) => async (dispatch) => {
|
||||
console.log('The backend for this is not hooked up yet')
|
||||
console.log('Once it is go into admin/actions/index and delete these lines')
|
||||
console.log('user to update: ', user)
|
||||
console.log('to be updated with these roles: ', roles)
|
||||
return
|
||||
|
||||
try {
|
||||
await updateUserAJAX(user.links.self, roles, user.permissions)
|
||||
dispatch(publishNotification('success', 'User roles updated'))
|
||||
} catch (error) {
|
||||
dispatch(publishNotification('error', `Failed to updated user: ${error.data.message}`))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,26 +97,13 @@ export const deleteUser = async (url, addFlashMessage, username) => {
|
|||
}
|
||||
}
|
||||
|
||||
export const updateRoleUsers = async (url, users) => {
|
||||
export const updateRole = async (url, users, permissions) => {
|
||||
try {
|
||||
await AJAX({
|
||||
method: 'PATCH',
|
||||
url,
|
||||
data: {
|
||||
users,
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
export const updateRolePermissions = async (url, permissions) => {
|
||||
try {
|
||||
await AJAX({
|
||||
method: 'PATCH',
|
||||
url,
|
||||
data: {
|
||||
permissions,
|
||||
},
|
||||
})
|
||||
|
@ -125,12 +112,13 @@ export const updateRolePermissions = async (url, permissions) => {
|
|||
}
|
||||
}
|
||||
|
||||
export const updateUserPermissions = async (url, permissions) => {
|
||||
export const updateUser = async (url, roles, permissions) => {
|
||||
try {
|
||||
await AJAX({
|
||||
method: 'PATCH',
|
||||
url,
|
||||
data: {
|
||||
roles,
|
||||
permissions,
|
||||
},
|
||||
})
|
||||
|
|
|
@ -25,6 +25,7 @@ const AdminTabs = ({
|
|||
onFilterUsers,
|
||||
onUpdateRoleUsers,
|
||||
onUpdateRolePermissions,
|
||||
onUpdateUserRoles,
|
||||
onUpdateUserPermissions,
|
||||
}) => {
|
||||
let tabs = [
|
||||
|
@ -44,6 +45,7 @@ const AdminTabs = ({
|
|||
onDelete={onDeleteUser}
|
||||
onFilter={onFilterUsers}
|
||||
onUpdatePermissions={onUpdateUserPermissions}
|
||||
onUpdateRoles={onUpdateUserRoles}
|
||||
/>
|
||||
),
|
||||
},
|
||||
|
@ -127,6 +129,7 @@ AdminTabs.propTypes = {
|
|||
onUpdateRolePermissions: func.isRequired,
|
||||
hasRoles: bool.isRequired,
|
||||
onUpdateUserPermissions: func,
|
||||
onUpdateUserRoles: func,
|
||||
}
|
||||
|
||||
export default AdminTabs
|
||||
|
|
|
@ -20,11 +20,16 @@ const UserRow = ({
|
|||
onCancel,
|
||||
onDelete,
|
||||
onUpdatePermissions,
|
||||
onUpdateRoles,
|
||||
}) => {
|
||||
const handleUpdatePermissions = (allowed) => {
|
||||
onUpdatePermissions(user, [{scope: 'all', allowed}])
|
||||
}
|
||||
|
||||
const handleUpdateRoles = (roleNames) => {
|
||||
onUpdateRoles(user, allRoles.filter(r => roleNames.find(rn => rn === r.name)))
|
||||
}
|
||||
|
||||
if (isEditing) {
|
||||
return (
|
||||
<tr className="admin-table--edit-row">
|
||||
|
@ -48,7 +53,7 @@ const UserRow = ({
|
|||
items={allRoles.map((r) => r.name)}
|
||||
selectedItems={roles ? roles.map((r) => r.name) : []/* TODO remove check when server returns empty list */}
|
||||
label={roles && roles.length ? '' : 'Select Roles'}
|
||||
onApply={() => '//TODO'}
|
||||
onApply={handleUpdateRoles}
|
||||
/>
|
||||
</td> :
|
||||
null
|
||||
|
@ -99,6 +104,7 @@ UserRow.propTypes = {
|
|||
onSave: func,
|
||||
onDelete: func.isRequired,
|
||||
onUpdatePermissions: func,
|
||||
onUpdateRoles: func,
|
||||
}
|
||||
|
||||
export default UserRow
|
||||
|
|
|
@ -17,6 +17,7 @@ const UsersTable = ({
|
|||
onDelete,
|
||||
onFilter,
|
||||
onUpdatePermissions,
|
||||
onUpdateRoles,
|
||||
}) => (
|
||||
<div className="panel panel-info">
|
||||
<FilterBar type="users" onFilter={onFilter} isEditing={isEditing} onClickCreate={onClickCreate} />
|
||||
|
@ -47,6 +48,7 @@ const UsersTable = ({
|
|||
hasRoles={hasRoles}
|
||||
allPermissions={permissions}
|
||||
onUpdatePermissions={onUpdatePermissions}
|
||||
onUpdateRoles={onUpdateRoles}
|
||||
/>) :
|
||||
<EmptyRow tableName={'Users'} />
|
||||
}
|
||||
|
@ -86,6 +88,7 @@ UsersTable.propTypes = {
|
|||
permissions: arrayOf(string),
|
||||
hasRoles: bool.isRequired,
|
||||
onUpdatePermissions: func,
|
||||
onUpdateRoles: func,
|
||||
}
|
||||
|
||||
export default UsersTable
|
||||
|
|
|
@ -18,9 +18,11 @@ import {
|
|||
updateRoleUsersAsync,
|
||||
updateRolePermissionsAsync,
|
||||
updateUserPermissionsAsync,
|
||||
updateUserRolesAsync,
|
||||
filterUsers as filterUsersAction,
|
||||
filterRoles as filterRolesAction,
|
||||
} from 'src/admin/actions'
|
||||
|
||||
import AdminTabs from 'src/admin/components/AdminTabs'
|
||||
|
||||
const isValidUser = (user) => {
|
||||
|
@ -49,6 +51,7 @@ class AdminPage extends Component {
|
|||
this.handleUpdateRoleUsers = ::this.handleUpdateRoleUsers
|
||||
this.handleUpdateRolePermissions = ::this.handleUpdateRolePermissions
|
||||
this.handleUpdateUserPermissions = ::this.handleUpdateUserPermissions
|
||||
this.handleUpdateUserRoles = ::this.handleUpdateUserRoles
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
@ -130,6 +133,10 @@ class AdminPage extends Component {
|
|||
this.props.updateUserPermissions(user, permissions)
|
||||
}
|
||||
|
||||
handleUpdateUserRoles(user, roles) {
|
||||
this.props.updateUserRoles(user, roles)
|
||||
}
|
||||
|
||||
render() {
|
||||
const {users, roles, source, permissions, filterUsers, filterRoles} = this.props
|
||||
const hasRoles = !!source.links.roles
|
||||
|
@ -174,6 +181,7 @@ class AdminPage extends Component {
|
|||
onUpdateRoleUsers={this.handleUpdateRoleUsers}
|
||||
onUpdateRolePermissions={this.handleUpdateRolePermissions}
|
||||
onUpdateUserPermissions={this.handleUpdateUserPermissions}
|
||||
onUpdateUserRoles={this.handleUpdateUserRoles}
|
||||
/> :
|
||||
<span>Loading...</span>
|
||||
}
|
||||
|
@ -221,6 +229,7 @@ AdminPage.propTypes = {
|
|||
updateRoleUsers: func,
|
||||
updateRolePermissions: func,
|
||||
updateUserPermissions: func,
|
||||
updateUserRoles: func,
|
||||
}
|
||||
|
||||
const mapStateToProps = ({admin: {users, roles, permissions}}) => ({
|
||||
|
@ -248,6 +257,7 @@ const mapDispatchToProps = (dispatch) => ({
|
|||
updateRoleUsers: bindActionCreators(updateRoleUsersAsync, dispatch),
|
||||
updateRolePermissions: bindActionCreators(updateRolePermissionsAsync, dispatch),
|
||||
updateUserPermissions: bindActionCreators(updateUserPermissionsAsync, dispatch),
|
||||
updateUserRoles: bindActionCreators(updateUserRolesAsync, dispatch),
|
||||
})
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(AdminPage)
|
||||
|
|
Loading…
Reference in New Issue