Skip to content

Commit

Permalink
Fix issue where users couldn't be added when on a cluster (neo4j#1238)
Browse files Browse the repository at this point in the history
* Fix :server user add for cluster

* Remove unrelated changes

* Rename constant
  • Loading branch information
OskarDamkjaer committed Nov 4, 2020
1 parent 9095f9d commit 86a6787
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 28 deletions.
6 changes: 5 additions & 1 deletion src/browser/modules/Frame/FrameSuccess.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
import React from 'react'
const FrameSuccess = props => {
if (!props || !props.message) return null
return <span className="statusbar--success">{props.message}</span>
return (
<span style={{ paddingLeft: '10px' }} className="statusbar--success">
{props.message}
</span>
)
}

export default FrameSuccess
2 changes: 0 additions & 2 deletions src/browser/modules/Stream/Auth/ConnectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ export default function ConnectForm(props: ConnectFormProps): JSX.Element {
data-testid="username"
onChange={props.onUsernameChange}
defaultValue={props.username}
required
/>
</StyledConnectionLabel>
</StyledConnectionFormEntry>
Expand All @@ -202,7 +201,6 @@ export default function ConnectForm(props: ConnectFormProps): JSX.Element {
onChange={props.onPasswordChange}
defaultValue={props.password}
type="password"
required
/>
</StyledConnectionLabel>
</StyledConnectionFormEntry>
Expand Down
27 changes: 10 additions & 17 deletions src/browser/modules/User/UserAdd.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
createDatabaseUser,
addRoleToUser
} from 'shared/modules/cypher/boltUserHelper'
import { CYPHER_REQUEST } from 'shared/modules/cypher/cypherDuck'
import { ROUTED_CYPHER_WRITE_REQUEST } from 'shared/modules/cypher/cypherDuck'

import RolesSelector from './RolesSelector'
import FrameTemplate from 'browser/modules/Frame/FrameTemplate'
Expand Down Expand Up @@ -111,7 +111,7 @@ export class UserAdd extends Component {
this.state.roles.forEach(role => {
this.props.bus &&
this.props.bus.self(
CYPHER_REQUEST,
ROUTED_CYPHER_WRITE_REQUEST,
{
query: addRoleToUser(
this.state.username,
Expand Down Expand Up @@ -149,7 +149,7 @@ export class UserAdd extends Component {
getRoles() {
this.props.bus &&
this.props.bus.self(
CYPHER_REQUEST,
ROUTED_CYPHER_WRITE_REQUEST,
{
query: listRolesQuery(Boolean(this.props.useSystemDb)),
queryType: NEO4J_BROWSER_USER_ACTION_QUERY,
Expand All @@ -174,7 +174,9 @@ export class UserAdd extends Component {
)
}

submit() {
submit = event => {
event.preventDefault()

this.setState({ isLoading: true, success: null, errors: null })
const errors = []
if (!this.state.username) errors.push('Missing username')
Expand All @@ -193,7 +195,7 @@ export class UserAdd extends Component {
createUser() {
this.props.bus &&
this.props.bus.self(
CYPHER_REQUEST,
ROUTED_CYPHER_WRITE_REQUEST,
{
query: createDatabaseUser(
this.state,
Expand Down Expand Up @@ -297,7 +299,7 @@ export class UserAdd extends Component {
/>
)
frameContents = (
<StyledForm id={`user-add-${formId}`}>
<StyledForm id={`user-add-${formId}`} onSubmit={this.submit}>
<StyledFormElement>
<StyledLabel htmlFor={usernameId}>Username</StyledLabel>
<StyledInput
Expand Down Expand Up @@ -358,11 +360,7 @@ export class UserAdd extends Component {
</StyledFormElement>

<StyledFormElement>
<FormButton
onClick={this.submit.bind(this)}
label="Add User"
disabled={isLoading}
/>
<FormButton type="submit" label="Add User" disabled={isLoading} />
</StyledFormElement>

<StyledLink onClick={this.openListUsersFrame.bind(this)}>
Expand Down Expand Up @@ -402,9 +400,4 @@ const mapStateToProps = state => {
}
}

export default withBus(
connect(
mapStateToProps,
null
)(UserAdd)
)
export default withBus(connect(mapStateToProps, null)(UserAdd))
4 changes: 2 additions & 2 deletions src/browser/modules/User/UserAdd.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import React from 'react'
import { createBus } from 'suber'

import { UserAdd } from './UserAdd'
import { CYPHER_REQUEST } from 'shared/modules/cypher/cypherDuck'
import { ROUTED_CYPHER_WRITE_REQUEST } from 'shared/modules/cypher/cypherDuck'
import { listRolesQuery } from 'shared/modules/cypher/boltUserHelper'

// Stubbing out title bar as it depends on store
Expand All @@ -41,7 +41,7 @@ describe('<UserAdd />', () => {
}

const busCallback = jest.fn()
bus.one(CYPHER_REQUEST, busCallback)
bus.one(ROUTED_CYPHER_WRITE_REQUEST, busCallback)

render(<UserAdd {...props} />)

Expand Down
6 changes: 3 additions & 3 deletions src/browser/modules/User/UserList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
} from 'shared/modules/cypher/boltUserHelper'
import UserInformation from './UserInformation'
import bolt from 'services/bolt/bolt'
import { CYPHER_REQUEST } from 'shared/modules/cypher/cypherDuck'
import { ROUTED_CYPHER_WRITE_REQUEST } from 'shared/modules/cypher/cypherDuck'
import { StyledLink } from 'browser-components/buttons'
import { StyledTable, StyledTh } from 'browser-components/DataTables'
import { StyledButtonContainer } from './styled'
Expand Down Expand Up @@ -100,7 +100,7 @@ export class UserList extends Component {

getUserList() {
this.props.bus.self(
CYPHER_REQUEST,
ROUTED_CYPHER_WRITE_REQUEST,
{
query: listUsersQuery(Boolean(this.props.useSystemDb)),
queryType: NEO4J_BROWSER_USER_ACTION_QUERY,
Expand All @@ -119,7 +119,7 @@ export class UserList extends Component {

getRoles() {
this.props.bus.self(
CYPHER_REQUEST,
ROUTED_CYPHER_WRITE_REQUEST,
{
query: listRolesQuery(Boolean(this.props.useSystemDb)),
queryType: NEO4J_BROWSER_USER_ACTION_QUERY,
Expand Down
6 changes: 3 additions & 3 deletions src/browser/modules/User/UserList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import React from 'react'
import { createBus } from 'suber'

import { UserList } from './UserList'
import { CYPHER_REQUEST } from 'shared/modules/cypher/cypherDuck'
import { ROUTED_CYPHER_WRITE_REQUEST } from 'shared/modules/cypher/cypherDuck'
import {
listRolesQuery,
listUsersQuery
Expand All @@ -44,7 +44,7 @@ describe('<UserList />', () => {
}

const busCallback = jest.fn()
bus.take(CYPHER_REQUEST, busCallback)
bus.take(ROUTED_CYPHER_WRITE_REQUEST, busCallback)

render(<UserList {...props} />)

Expand All @@ -68,7 +68,7 @@ describe('<UserList />', () => {
}

const busCallback = jest.fn()
bus.take(CYPHER_REQUEST, busCallback)
bus.take(ROUTED_CYPHER_WRITE_REQUEST, busCallback)

render(<UserList {...props} />)

Expand Down
30 changes: 30 additions & 0 deletions src/shared/modules/cypher/cypherDuck.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {

const NAME = 'cypher'
export const CYPHER_REQUEST = `${NAME}/REQUEST`
export const ROUTED_CYPHER_WRITE_REQUEST = `${NAME}/ROUTED_WRITE_REQUEST`
export const AD_HOC_CYPHER_REQUEST = `${NAME}/AD_HOC_REQUEST`
export const CLUSTER_CYPHER_REQUEST = `${NAME}/CLUSTER_REQUEST`
export const FORCE_CHANGE_PASSWORD = `${NAME}/FORCE_CHANGE_PASSWORD`
Expand Down Expand Up @@ -117,6 +118,35 @@ export const cypherRequestEpic = (some$, store) =>
}))
})

export const routedCypherRequestEpic = (some$, store) =>
some$.ofType(ROUTED_CYPHER_WRITE_REQUEST).mergeMap(action => {
if (!action.$$responseChannel) return Rx.Observable.of(null)

const [id, promise] = bolt.routedWriteTransaction(
action.query,
action.params,
{
useCypherThread: shouldUseCypherThread(store.getState()),
...getUserTxMetadata(action.queryType || null)({
hasServerSupport: canSendTxMetadata(store.getState())
}),
cancelable: true,
useDb: action.useDb
}
)
return promise
.then(result => ({
type: action.$$responseChannel,
success: true,
result
}))
.catch(error => ({
type: action.$$responseChannel,
success: false,
error
}))
})

export const adHocCypherRequestEpic = (some$, store) =>
some$.ofType(AD_HOC_CYPHER_REQUEST).mergeMap(action => {
const connection = getActiveConnectionData(store.getState())
Expand Down
2 changes: 2 additions & 0 deletions src/shared/rootEpic.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import { clearLocalstorageEpic } from './modules/localstorage/localstorageDuck'
import { populateEditorFromUrlEpic } from './modules/editor/editorDuck'
import {
adHocCypherRequestEpic,
routedCypherRequestEpic,
cypherRequestEpic,
clusterCypherRequestEpic,
handleForcePasswordChangeEpic
Expand Down Expand Up @@ -121,6 +122,7 @@ export default combineEpics(
injectDiscoveryEpic,
populateEditorFromUrlEpic,
adHocCypherRequestEpic,
routedCypherRequestEpic,
cypherRequestEpic,
clusterCypherRequestEpic,
clearLocalstorageEpic,
Expand Down

0 comments on commit 86a6787

Please sign in to comment.