Merge pull request #994 from influxdata/feature/admin_user-permissions
Feature/admin update userpull/1000/head
commit
25258e31ad
|
@ -6,12 +6,12 @@ import {
|
|||
createRole as createRoleAJAX,
|
||||
deleteUser as deleteUserAJAX,
|
||||
deleteRole as deleteRoleAJAX,
|
||||
updateRoleUsers as updateRoleUsersAJAX,
|
||||
updateRolePermissions as updateRolePermissionsAJAX,
|
||||
updateRole as updateRoleAJAX,
|
||||
updateUser as updateUserAJAX,
|
||||
} from 'src/admin/apis'
|
||||
|
||||
import {killQuery as killQueryProxy} from 'shared/apis/metaQuery'
|
||||
import {publishNotification} from 'src/shared/actions/notifications';
|
||||
|
||||
import {ADMIN_NOTIFICATION_DELAY} from 'shared/constants'
|
||||
|
||||
export const loadUsers = ({users}) => ({
|
||||
|
@ -191,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}`))
|
||||
|
@ -200,9 +200,27 @@ 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}`))
|
||||
}
|
||||
}
|
||||
|
||||
export const updateUserPermissionsAsync = (user, permissions) => async (dispatch) => {
|
||||
try {
|
||||
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) => {
|
||||
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,28 @@ 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,
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
export const updateUser = async (url, roles, permissions) => {
|
||||
try {
|
||||
await AJAX({
|
||||
method: 'PATCH',
|
||||
url,
|
||||
data: {
|
||||
roles,
|
||||
permissions,
|
||||
},
|
||||
})
|
||||
|
|
|
@ -25,6 +25,8 @@ const AdminTabs = ({
|
|||
onFilterUsers,
|
||||
onUpdateRoleUsers,
|
||||
onUpdateRolePermissions,
|
||||
onUpdateUserRoles,
|
||||
onUpdateUserPermissions,
|
||||
}) => {
|
||||
let tabs = [
|
||||
{
|
||||
|
@ -42,6 +44,8 @@ const AdminTabs = ({
|
|||
onEdit={onEditUser}
|
||||
onDelete={onDeleteUser}
|
||||
onFilter={onFilterUsers}
|
||||
onUpdatePermissions={onUpdateUserPermissions}
|
||||
onUpdateRoles={onUpdateUserRoles}
|
||||
/>
|
||||
),
|
||||
},
|
||||
|
@ -124,6 +128,8 @@ AdminTabs.propTypes = {
|
|||
onUpdateRoleUsers: func.isRequired,
|
||||
onUpdateRolePermissions: func.isRequired,
|
||||
hasRoles: bool.isRequired,
|
||||
onUpdateUserPermissions: func,
|
||||
onUpdateUserRoles: func,
|
||||
}
|
||||
|
||||
export default AdminTabs
|
||||
|
|
|
@ -19,7 +19,17 @@ const UserRow = ({
|
|||
onSave,
|
||||
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">
|
||||
|
@ -43,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
|
||||
|
@ -55,7 +65,7 @@ const UserRow = ({
|
|||
items={allPermissions}
|
||||
selectedItems={_.get(permissions, ['0', 'allowed'], [])}
|
||||
label={permissions && permissions.length ? '' : 'Select Permissions'}
|
||||
onApply={() => '//TODO'}
|
||||
onApply={handleUpdatePermissions}
|
||||
/> : null
|
||||
}
|
||||
</td>
|
||||
|
@ -93,6 +103,8 @@ UserRow.propTypes = {
|
|||
onEdit: func,
|
||||
onSave: func,
|
||||
onDelete: func.isRequired,
|
||||
onUpdatePermissions: func,
|
||||
onUpdateRoles: func,
|
||||
}
|
||||
|
||||
export default UserRow
|
||||
|
|
|
@ -16,6 +16,8 @@ const UsersTable = ({
|
|||
onCancel,
|
||||
onDelete,
|
||||
onFilter,
|
||||
onUpdatePermissions,
|
||||
onUpdateRoles,
|
||||
}) => (
|
||||
<div className="panel panel-info">
|
||||
<FilterBar type="users" onFilter={onFilter} isEditing={isEditing} onClickCreate={onClickCreate} />
|
||||
|
@ -45,6 +47,8 @@ const UsersTable = ({
|
|||
allRoles={allRoles}
|
||||
hasRoles={hasRoles}
|
||||
allPermissions={permissions}
|
||||
onUpdatePermissions={onUpdatePermissions}
|
||||
onUpdateRoles={onUpdateRoles}
|
||||
/>) :
|
||||
<EmptyRow tableName={'Users'} />
|
||||
}
|
||||
|
@ -83,6 +87,8 @@ UsersTable.propTypes = {
|
|||
allRoles: arrayOf(shape()),
|
||||
permissions: arrayOf(string),
|
||||
hasRoles: bool.isRequired,
|
||||
onUpdatePermissions: func,
|
||||
onUpdateRoles: func,
|
||||
}
|
||||
|
||||
export default UsersTable
|
||||
|
|
|
@ -17,9 +17,12 @@ import {
|
|||
deleteRoleAsync,
|
||||
updateRoleUsersAsync,
|
||||
updateRolePermissionsAsync,
|
||||
updateUserPermissionsAsync,
|
||||
updateUserRolesAsync,
|
||||
filterUsers as filterUsersAction,
|
||||
filterRoles as filterRolesAction,
|
||||
} from 'src/admin/actions'
|
||||
|
||||
import AdminTabs from 'src/admin/components/AdminTabs'
|
||||
|
||||
const isValidUser = (user) => {
|
||||
|
@ -47,6 +50,8 @@ class AdminPage extends Component {
|
|||
this.handleDeleteUser = ::this.handleDeleteUser
|
||||
this.handleUpdateRoleUsers = ::this.handleUpdateRoleUsers
|
||||
this.handleUpdateRolePermissions = ::this.handleUpdateRolePermissions
|
||||
this.handleUpdateUserPermissions = ::this.handleUpdateUserPermissions
|
||||
this.handleUpdateUserRoles = ::this.handleUpdateUserRoles
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
@ -124,6 +129,14 @@ class AdminPage extends Component {
|
|||
this.props.updateRolePermissions(role, permissions)
|
||||
}
|
||||
|
||||
handleUpdateUserPermissions(user, permissions) {
|
||||
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
|
||||
|
@ -167,6 +180,8 @@ class AdminPage extends Component {
|
|||
onFilterRoles={filterRoles}
|
||||
onUpdateRoleUsers={this.handleUpdateRoleUsers}
|
||||
onUpdateRolePermissions={this.handleUpdateRolePermissions}
|
||||
onUpdateUserPermissions={this.handleUpdateUserPermissions}
|
||||
onUpdateUserRoles={this.handleUpdateUserRoles}
|
||||
/> :
|
||||
<span>Loading...</span>
|
||||
}
|
||||
|
@ -213,6 +228,8 @@ AdminPage.propTypes = {
|
|||
filterUsers: func,
|
||||
updateRoleUsers: func,
|
||||
updateRolePermissions: func,
|
||||
updateUserPermissions: func,
|
||||
updateUserRoles: func,
|
||||
}
|
||||
|
||||
const mapStateToProps = ({admin: {users, roles, permissions}}) => ({
|
||||
|
@ -239,6 +256,8 @@ const mapDispatchToProps = (dispatch) => ({
|
|||
filterRoles: bindActionCreators(filterRolesAction, 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