Wire up remove & add user to organization from AllUsersPage

pull/2733/head^2
Jared Scheib 2018-01-26 20:05:20 -08:00
parent d28fbf71ae
commit 086c784811
3 changed files with 20 additions and 19 deletions

View File

@ -38,17 +38,21 @@ class AllUsersTable extends Component {
updateAuthConfigAsync(links.config.auth, authConfig, updatedAuthConfig)
}
// handleAddToOrganization = user => organization => {
// console.log('handleAddToOrganization', user.name, organization)
// const organizationRole = organization + organizationDefaultRole -- need to get this fresh from server or have server determine it, which requires a change to ValidUpdate
// this.props.onUpdateUserRole({...user, roles: [...user.roles, organizationRole]})
// }
handleAddToOrganization = user => organization => {
// '*' tells the server to fill in the current defaultRole of that org
const newRoles = user.roles.concat({
organization: organization.id,
name: '*',
})
this.props.onUpdateUserRoles(user, newRoles)
}
// handleRemoveFromOrganization = user => organization => {
// console.log('handleRemoveFromOrganization', user.name, organization)
// const roles = newOrganizationRole.filter(o => o.id === organization.id)
// this.props.onUpdateUserRole({...user, roles})
// }
handleRemoveFromOrganization = user => role => {
const newRoles = user.roles.filter(
r => r.organization !== role.organization // TODO: the organization upstream of this should use .id instead of .organization for this property
)
this.props.onUpdateUserRoles(user, newRoles)
}
handleChangeSuperAdmin = user => newStatus => {
this.props.onUpdateUserSuperAdmin(user, newStatus)
@ -178,7 +182,7 @@ AllUsersTable.propTypes = {
})
),
onCreateUser: func.isRequired,
onUpdateUserRole: func.isRequired,
onUpdateUserRoles: func.isRequired,
onUpdateUserSuperAdmin: func.isRequired,
onDeleteUser: func.isRequired,
actionsConfig: shape({

View File

@ -80,7 +80,7 @@ const AllUsersTableRow = ({
</span>
</td>
<DeleteConfirmTableCell
text="Remove"
text="Delete"
onDelete={onDelete}
item={user}
buttonSize="btn-xs"

View File

@ -28,13 +28,10 @@ class AllUsersPage extends Component {
createUserAsync(links.users, user)
}
handleUpdateUserRole = (user, currentRole, {name}) => {
handleUpdateUserRoles = (user, roles) => {
const {actionsAdmin: {updateUserAsync}} = this.props
const updatedRole = {...currentRole, name}
const newRoles = user.roles.map(
r => (r.organization === currentRole.organization ? updatedRole : r)
)
updateUserAsync(user, {...user, roles: newRoles})
const updatedUser = {...user, roles}
updateUserAsync(user, updatedUser)
}
handleUpdateUserSuperAdmin = (user, superAdmin) => {
@ -86,7 +83,7 @@ class AllUsersPage extends Component {
users={users}
organizations={organizations}
onCreateUser={this.handleCreateUser}
onUpdateUserRole={this.handleUpdateUserRole}
onUpdateUserRoles={this.handleUpdateUserRoles}
onUpdateUserSuperAdmin={this.handleUpdateUserSuperAdmin}
onDeleteUser={this.handleDeleteUser}
links={links}