From 086c784811327285b335019fbe786c73ac6129da Mon Sep 17 00:00:00 2001 From: Jared Scheib Date: Fri, 26 Jan 2018 20:05:20 -0800 Subject: [PATCH] Wire up remove & add user to organization from AllUsersPage --- .../components/chronograf/AllUsersTable.js | 26 +++++++++++-------- .../components/chronograf/AllUsersTableRow.js | 2 +- .../containers/chronograf/AllUsersPage.js | 11 +++----- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/ui/src/admin/components/chronograf/AllUsersTable.js b/ui/src/admin/components/chronograf/AllUsersTable.js index 1e8ab6d3c..f2cd721f2 100644 --- a/ui/src/admin/components/chronograf/AllUsersTable.js +++ b/ui/src/admin/components/chronograf/AllUsersTable.js @@ -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({ diff --git a/ui/src/admin/components/chronograf/AllUsersTableRow.js b/ui/src/admin/components/chronograf/AllUsersTableRow.js index ea1530733..9eac9f4c6 100644 --- a/ui/src/admin/components/chronograf/AllUsersTableRow.js +++ b/ui/src/admin/components/chronograf/AllUsersTableRow.js @@ -80,7 +80,7 @@ const AllUsersTableRow = ({ { + 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}