Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions e2e_tests/integration/0.index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,15 @@ describe('Neo4j Browser', () => {
cy.get('[data-testid="user-details-roles"]').should('have.length', 0)
cy.get('[data-testid="navigationDBMS"]').click()
})

it('does not show trial banner since we have licence or community', () => {
cy.get(Editor).type(`RETURN 1{enter}`, { force: true })

cy.get('#MAIN_WRAPPER_DOM_ID')
.contains('30 days has expired')
.should('not.exist')
cy.get('#MAIN_WRAPPER_DOM_ID')
.contains(' This is a time limited trial')
.should('not.exist')
})
})
6 changes: 4 additions & 2 deletions src/browser/modules/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import {
import {
findDatabaseByNameOrAlias,
getEdition,
getTrialStatus,
isServerConfigDone,
shouldAllowOutgoingConnections
} from 'shared/modules/dbMeta/dbMetaDuck'
Expand Down Expand Up @@ -180,7 +181,6 @@ export function App(props: any) {
}, [titleString])

const wrapperClassNames = codeFontLigatures ? '' : 'disable-font-ligatures'

return (
<ErrorBoundary>
<DesktopApi
Expand Down Expand Up @@ -282,6 +282,7 @@ export function App(props: any) {
setConsentBannerShownCount(consentBannerShownCount + 1)
}
openSettingsDrawer={openSettingsDrawer}
trialStatus={props.trialStatus}
/>
</StyledMainWrapper>
</StyledBody>
Expand Down Expand Up @@ -329,7 +330,8 @@ const mapStateToProps = (state: GlobalState) => {
? isConnectedAuraHost(state)
? 'AURA HOST'
: 'NON-AURA HOST'
: 'NOT CONNECTED'
: 'NOT CONNECTED',
trialStatus: getTrialStatus(state)
}
}
type DesktopTrackingSettings = {
Expand Down
56 changes: 54 additions & 2 deletions src/browser/modules/Main/Main.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@
import { render } from '@testing-library/react'
import React from 'react'
import configureMockStore from 'redux-mock-store'
import { TrialStatus } from 'shared/modules/dbMeta/dbMetaDuck'

import Main from './Main'

const mockStore = configureMockStore()
const store = mockStore({})

const defaultTrialStatus: TrialStatus = {
commerialLicenseAccepted: null,
expired: null,
daysRemaing: null
}

jest.mock(
'../Editor/MainEditor',
() =>
Expand Down Expand Up @@ -63,7 +70,11 @@ const mainBaseProps = {
describe('<Main />', () => {
it('should display an ErrorBanner when useDb is unavailable', () => {
const { queryByText } = render(
<Main {...mainBaseProps} isDatabaseUnavailable={true} />
<Main
{...mainBaseProps}
isDatabaseUnavailable={true}
trialStatus={defaultTrialStatus}
/>
)

expect(
Expand All @@ -73,11 +84,52 @@ describe('<Main />', () => {

it('should not show Errorbanner before we have a useDb', () => {
const { queryByText } = render(
<Main {...mainBaseProps} useDb={null} isDatabaseUnavailable={true} />
<Main
{...mainBaseProps}
useDb={null}
isDatabaseUnavailable={true}
trialStatus={defaultTrialStatus}
/>
)

expect(
queryByText(`Database '${useDb}' is unavailable.`, { exact: false })
).toBeFalsy()
})

it('should not show Errorbanner if trial expired', () => {
const { queryByText } = render(
<Main
{...mainBaseProps}
useDb={null}
isDatabaseUnavailable={true}
trialStatus={{ ...defaultTrialStatus, expired: true }}
/>
)

expect(
queryByText(
`Thank you for installing Neo4j. This is a time limited trial, and the 30 days has expired. Please contact [email protected] or [email protected] to continue using the software. Use of this Software without a proper commercial or evaluation license with Neo4j,Inc. or its affiliates is prohibited`,
{ exact: false }
)
).toBeTruthy()
})

it('should not show WarningBanner if trial active', () => {
const { queryByText } = render(
<Main
{...mainBaseProps}
useDb={null}
isDatabaseUnavailable={true}
trialStatus={{ ...defaultTrialStatus, daysRemaing: 19 }}
/>
)

expect(
queryByText(
`Thank you for installing Neo4j. This is a time limited trial, you have 19 days remaining out of 30 days. Please contact [email protected] if you require more time.`,
{ exact: false }
)
).toBeTruthy()
})
})
43 changes: 40 additions & 3 deletions src/browser/modules/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Stream from '../Stream/Stream'
import AutoExecButton from '../Stream/auto-exec-button'
import { useSlowConnectionState } from './main.hooks'
import {
DismissConsentBanner,
DismissBanner,
ErrorBanner,
NotAuthedBanner,
StyledMain,
Expand All @@ -38,6 +38,7 @@ import {
DISCONNECTED_STATE,
PENDING_STATE
} from 'shared/modules/connections/connectionsDuck'
import { TrialStatus } from 'shared/modules/dbMeta/dbMetaDuck'

type MainProps = {
connectionState: number
Expand All @@ -49,10 +50,13 @@ type MainProps = {
dismissConsentBanner: () => void
incrementConsentBannerShownCount: () => void
openSettingsDrawer: () => void
trialStatus: TrialStatus
}

const Main = React.memo(function Main(props: MainProps) {
const [past5Sec, past10Sec] = useSlowConnectionState(props)
const [showRemaningTrialBanner, setShowRemaningTrialBanner] =
React.useState(true)
const {
connectionState,
isDatabaseUnavailable,
Expand All @@ -61,7 +65,8 @@ const Main = React.memo(function Main(props: MainProps) {
useDb,
dismissConsentBanner,
incrementConsentBannerShownCount,
openSettingsDrawer
openSettingsDrawer,
trialStatus
} = props

useEffect(() => {
Expand All @@ -83,7 +88,7 @@ const Main = React.memo(function Main(props: MainProps) {
</UnderlineClickable>{' '}
at any time.
</span>
<DismissConsentBanner onClick={dismissConsentBanner} />
<DismissBanner onClick={dismissConsentBanner} />
</UdcConsentBanner>
)}
{useDb && isDatabaseUnavailable && (
Expand Down Expand Up @@ -118,6 +123,38 @@ const Main = React.memo(function Main(props: MainProps) {
Server is taking a long time to respond...
</WarningBanner>
)}

{trialStatus.expired && (
<ErrorBanner>
Thank you for installing Neo4j. This is a time limited trial, and the
30 days has expired. Please contact [email protected] or
[email protected] to continue using the software. Use of this
Software without a proper commercial or evaluation license with
Neo4j,Inc. or its affiliates is prohibited.
</ErrorBanner>
)}

{trialStatus.daysRemaing !== null &&
trialStatus.expired !== true &&
showRemaningTrialBanner && (
<WarningBanner>
Thank you for installing Neo4j. This is a time limited trial, you
have {trialStatus.daysRemaing} days remaining out of 30 days. Please
contact [email protected] if you require more time.
<div
style={{
position: 'absolute',
right: 20,
display: 'inline-block'
}}
>
<DismissBanner
onClick={() => setShowRemaningTrialBanner(false)}
/>
</div>
</WarningBanner>
)}

<ErrorBoundary>
<Stream />
</ErrorBoundary>
Expand Down
2 changes: 1 addition & 1 deletion src/browser/modules/Main/styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const UdcConsentBanner = styled(Banner)`
display: flex;
justify-content: space-between;
`
export const DismissConsentBanner = styled.span`
export const DismissBanner = styled.span`
&:hover {
cursor: pointer;
}
Expand Down
10 changes: 10 additions & 0 deletions src/shared/modules/dbMeta/__snapshots__/dbMetaDuck.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ Object {
"retainConnectionCredentials": false,
"retainEditorHistory": false,
},
"trialStatus": Object {
"commerialLicenseAccepted": null,
"daysRemaing": null,
"expired": null,
},
}
`;

Expand Down Expand Up @@ -98,5 +103,10 @@ Object {
"retainConnectionCredentials": false,
"retainEditorHistory": false,
},
"trialStatus": Object {
"commerialLicenseAccepted": null,
"daysRemaing": null,
"expired": null,
},
}
`;
34 changes: 32 additions & 2 deletions src/shared/modules/dbMeta/dbMetaDuck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { versionHasEditorHistorySetting } from './utils'
import {
extractTrialStatus as extractTrialStatus,
versionHasEditorHistorySetting
} from './utils'
import { isConfigValFalsy } from 'services/bolt/boltHelpers'
import { GlobalState } from 'shared/globalState'
import { APP_START } from 'shared/modules/app/appDuck'
Expand All @@ -28,6 +31,7 @@ import { QueryResult } from 'neo4j-driver'
export const UPDATE_META = 'meta/UPDATE_META'
export const PARSE_META = 'meta/PARSE_META'
export const UPDATE_SERVER = 'meta/UPDATE_SERVER'
export const UPDATE_TRIAL_STATUS = 'meta/UPDATE_TRIAL_STATUS'
export const UPDATE_SETTINGS = 'meta/UPDATE_SETTINGS'
export const CLEAR_META = 'meta/CLEAR'
export const FORCE_FETCH = 'meta/FORCE_FETCH'
Expand Down Expand Up @@ -61,6 +65,8 @@ MATCH ()-[]->() RETURN { name:'relationships', data: count(*)} AS result
export const serverInfoQuery =
'CALL dbms.components() YIELD name, versions, edition'

export const trialStatusQuery = 'CALL dbms.acceptedLicenseAgreement()'

export function fetchMetaData() {
return {
type: FORCE_FETCH
Expand Down Expand Up @@ -95,6 +101,14 @@ export const updateServerInfo = (res: QueryResult) => {
}
}

export const updateTrialStatus = (res: QueryResult) => {
const extrated = extractTrialStatus(res)
return {
type: UPDATE_TRIAL_STATUS,
...extrated
}
}

export const updateCountAutomaticRefresh = (countAutomaticRefresh: {
enabled?: boolean
loading?: boolean
Expand Down Expand Up @@ -126,6 +140,18 @@ export type ClientSettings = {
metricsPrefix: string
}

export type TrialStatus = {
commerialLicenseAccepted: boolean | null
expired: boolean | null
daysRemaing: number | null
}

const initialTrialStatus = {
commerialLicenseAccepted: null,
expired: null,
daysRemaing: null
}

/**
* Initial client settings, used before the actual settings is loaded. Not to be
* confused with the default values for the setting, since not always the same.
Expand Down Expand Up @@ -163,7 +189,8 @@ export const initialState = {
countAutomaticRefresh: {
enabled: true,
loading: false
}
},
trialStatus: initialTrialStatus
}

export type Database = {
Expand Down Expand Up @@ -221,6 +248,9 @@ export const getStoreId = (state: any) =>
export const isServerConfigDone = (state: GlobalState): boolean =>
state[NAME].serverConfigDone

export const getTrialStatus = (state: GlobalState): TrialStatus =>
state[NAME].trialStatus

export const getAvailableSettings = (state: any): ClientSettings =>
(state[NAME] || initialState).settings
export const getAllowOutgoingConnections = (state: any) =>
Expand Down
26 changes: 23 additions & 3 deletions src/shared/modules/dbMeta/dbMetaEpics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ import {
getCountAutomaticRefreshEnabled,
DB_META_FORCE_COUNT,
DB_META_COUNT_DONE,
metaCountQuery
metaCountQuery,
trialStatusQuery,
updateTrialStatus
} from './dbMetaDuck'
import {
ClientSettings,
Expand Down Expand Up @@ -271,6 +273,20 @@ async function fetchServerInfo(store: any) {
} catch {}
}

async function fetchTrialStatus(store: any) {
try {
const trialStatus = await bolt.directTransaction(
trialStatusQuery,
{},
{
...backgroundTxMetadata,
useDb: (await bolt.hasMultiDbSupport()) ? SYSTEM_DB : undefined
}
)
store.dispatch(updateTrialStatus(trialStatus))
} catch {}
}

const switchToRequestedDb = (store: any) => {
if (getUseDb(store.getState())) return

Expand Down Expand Up @@ -338,8 +354,12 @@ export const dbMetaEpic = (some$: any, store: any) =>
.merge(some$.ofType(CONNECTION_SUCCESS))
.mergeMap(() =>
Rx.Observable.fromPromise(
// Server version and edition
fetchServerInfo(store)
Promise.all([
// Server version and edition
fetchServerInfo(store),
//If license is accepted otherwise how long remains of the trial
fetchTrialStatus(store)
])
)
)
.mergeMap(() =>
Expand Down
Loading