Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract NeoDash auth module to an abstract interface to allow for different providers #767

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
2869c23
Added abstract class for connection module
nielsdejong Jan 25, 2024
20a154c
first iteration on abstracting connection layer
alfredorubin96 Jan 25, 2024
ee20346
first iteration on abstracting connection layer
alfredorubin96 Jan 25, 2024
70361e8
completely detached runCypherQuery from the application
alfredorubin96 Jan 26, 2024
f22745c
renaming auth module to connection
alfredorubin96 Jan 28, 2024
200701c
deleted old extensions
alfredorubin96 Jan 28, 2024
04d52e7
using Context objext to store current configuration
alfredorubin96 Jan 29, 2024
c602292
cleaning code
alfredorubin96 Jan 29, 2024
26ee2e6
cleaning code
alfredorubin96 Jan 29, 2024
6877693
Merge branch 'develop' into feature/auth-module
alfredorubin96 Mar 11, 2024
6ca2e4b
Merge branch 'develop' into feature/auth-module
alfredorubin96 Mar 11, 2024
e7d7d98
merging with develop
alfredorubin96 Mar 11, 2024
ee8a7de
plugged parsed to chart, to test
alfredorubin96 Mar 13, 2024
d7c250b
to continue testing only on table, report action work
alfredorubin96 Mar 13, 2024
cbc47b5
changing from fields to _fields to make the property private
alfredorubin96 Mar 13, 2024
efd14e5
Merge branch 'develop' into feature/auth-module
nielsdejong Mar 15, 2024
50f16e8
unplugging record parsing from report.tsx and added comments for conn…
alfredorubin96 Mar 28, 2024
0f14d87
Merge branch 'feature/auth-module' of https://github.com/neo4j-labs/n…
alfredorubin96 Mar 28, 2024
4895d8b
cleaning code following sonarqube
alfredorubin96 Mar 28, 2024
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
Prev Previous commit
Next Next commit
cleaning code
  • Loading branch information
alfredorubin96 committed Jan 29, 2024
commit c60229257ef5da64ee80aeddc89fc0628e6473d5
1 change: 0 additions & 1 deletion src/application/ApplicationThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import { applicationGetLoggingSettings } from './logging/LoggingSelectors';
import { createLogThunk } from './logging/LoggingThunk';
import { createUUID } from '../utils/uuid';
import { Neo4jConnectionModule } from '../connection/neo4j/Neo4jConnectionModule';
import { QueryCallback, QueryParams } from '../connection/interfaces';
import { getConnectionModule } from '../connection/utils';

Expand Down Expand Up @@ -264,12 +263,12 @@
if (urlParams.get('credentials')) {
setWelcomeScreenOpen(false);
const connection = decodeURIComponent(urlParams.get('credentials'));
const protocol = connection.split('://')[0];

Check warning on line 266 in src/application/ApplicationThunks.ts

View workflow job for this annotation

GitHub Actions / build-test (18.x)

Use array destructuring
const username = connection.split('://')[1].split(':')[0];

Check warning on line 267 in src/application/ApplicationThunks.ts

View workflow job for this annotation

GitHub Actions / build-test (18.x)

Use array destructuring
const password = connection.split('://')[1].split(':')[1].split('@')[0];

Check warning on line 268 in src/application/ApplicationThunks.ts

View workflow job for this annotation

GitHub Actions / build-test (18.x)

Use array destructuring
const database = connection.split('@')[1].split(':')[0];

Check warning on line 269 in src/application/ApplicationThunks.ts

View workflow job for this annotation

GitHub Actions / build-test (18.x)

Use array destructuring
const url = connection.split('@')[1].split(':')[1];

Check warning on line 270 in src/application/ApplicationThunks.ts

View workflow job for this annotation

GitHub Actions / build-test (18.x)

Use array destructuring
const port = connection.split('@')[1].split(':')[2];

Check warning on line 271 in src/application/ApplicationThunks.ts

View workflow job for this annotation

GitHub Actions / build-test (18.x)

Use array destructuring
// if (url == password) {
// // Special case where a connect link is generated without a password.
// // Here, the format is parsed incorrectly and we open the connection window instead.
Expand Down Expand Up @@ -576,7 +575,7 @@
dispatch(initializeApplicationAsEditorThunk(config, paramsToSetAfterConnecting));
}
} catch (e) {
console.log(e);

Check warning on line 578 in src/application/ApplicationThunks.ts

View workflow job for this annotation

GitHub Actions / build-test (18.x)

Unexpected console statement
dispatch(setWelcomeScreenOpen(false));
dispatch(
createNotificationThunk(
Expand Down
2 changes: 0 additions & 2 deletions src/chart/parameter/ParameterSelectCardSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import { Dropdown } from '@neo4j-ndl/react';
import NeoCodeEditorComponent from '../../component/editor/CodeEditorComponent';
import { QueryCallback, QueryParams, QueryStatus } from '../../connection/interfaces';
import { Neo4jConnectionModule } from '../../connection/neo4j/Neo4jConnectionModule';
import { getConnectionModule } from '../../connection/utils';
import { useConnectionModuleContext } from '../../application/Application';

type ParameterId = string | undefined | null;
Expand Down Expand Up @@ -80,7 +78,7 @@
status == QueryStatus.NO_DATA ? setRecords([]) : () => {};
},
setRecords,
setFields: () => {},

Check warning on line 81 in src/chart/parameter/ParameterSelectCardSettings.tsx

View check run for this annotation

Codecov / codecov/patch

src/chart/parameter/ParameterSelectCardSettings.tsx#L81

Added line #L81 was not covered by tests
setSchema: () => {},
};

Expand Down
6 changes: 1 addition & 5 deletions src/connection/ConnectionModule.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { createContext, useContext } from 'react';

const notImplementedError = (functionName: string): never => {
throw new Error(`Not Implemented: ${functionName}`);

Check warning on line 2 in src/connection/ConnectionModule.ts

View check run for this annotation

Codecov / codecov/patch

src/connection/ConnectionModule.ts#L2

Added line #L2 was not covered by tests
};

export abstract class ConnectionModule {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some docstrings here, since it's a pretty important interface we should document it well

Expand All @@ -11,24 +9,24 @@
this.name = name;
}

authenticate(_credentials: Record<any, any>): void | never {
return notImplementedError('authenticate');

Check warning on line 13 in src/connection/ConnectionModule.ts

View check run for this annotation

Codecov / codecov/patch

src/connection/ConnectionModule.ts#L12-L13

Added lines #L12 - L13 were not covered by tests
}

loadDashboard(_id: string): any | never {
loadDashboard(_id: string): any {
return notImplementedError('loadDashboard');

Check warning on line 17 in src/connection/ConnectionModule.ts

View check run for this annotation

Codecov / codecov/patch

src/connection/ConnectionModule.ts#L16-L17

Added lines #L16 - L17 were not covered by tests
}

saveDashboard(_dashboard: any): boolean | never {
return notImplementedError('saveDashboard');

Check warning on line 21 in src/connection/ConnectionModule.ts

View check run for this annotation

Codecov / codecov/patch

src/connection/ConnectionModule.ts#L20-L21

Added lines #L20 - L21 were not covered by tests
}

deleteDashboard(_id: string): void | never {
return notImplementedError('deleteDashboard');

Check warning on line 25 in src/connection/ConnectionModule.ts

View check run for this annotation

Codecov / codecov/patch

src/connection/ConnectionModule.ts#L24-L25

Added lines #L24 - L25 were not covered by tests
}

async runQuery(_driver, _queryParams: Record<string, any>, _queryCallbacks: Record<string, any>): Promise<void> {
return notImplementedError('runQuery');

Check warning on line 29 in src/connection/ConnectionModule.ts

View check run for this annotation

Codecov / codecov/patch

src/connection/ConnectionModule.ts#L28-L29

Added lines #L28 - L29 were not covered by tests
}

/**
Expand All @@ -36,13 +34,11 @@
* @param records
* @returns
*/
parseRecords(_records: any[]): Record<any, any>[] {
return notImplementedError('parseRecords');

Check warning on line 38 in src/connection/ConnectionModule.ts

View check run for this annotation

Codecov / codecov/patch

src/connection/ConnectionModule.ts#L37-L38

Added lines #L37 - L38 were not covered by tests
}
}

export interface ConnectionModuleState {
connectionModule: ConnectionModule;
}

export declare const ConnectionModuleContext: import('react').Context<ConnectionModuleState>;
25 changes: 15 additions & 10 deletions src/connection/neo4j/Neo4jConnectionModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,34 @@
import { runCypherQuery } from './runCypherQuery';
import { extractQueryCallbacks, extractQueryParams } from './utils';

const notImplementedError = (functionName: string): never => {
throw new Error(`Not Implemented: ${functionName}`);

Check warning on line 7 in src/connection/neo4j/Neo4jConnectionModule.ts

View check run for this annotation

Codecov / codecov/patch

src/connection/neo4j/Neo4jConnectionModule.ts#L7

Added line #L7 was not covered by tests
};

export class Neo4jConnectionModule extends ConnectionModule {
constructor(name) {
super(name);
authenticate(_credentials: Record<any, any>): void | never {
return notImplementedError('authenticate');

Check warning on line 12 in src/connection/neo4j/Neo4jConnectionModule.ts

View check run for this annotation

Codecov / codecov/patch

src/connection/neo4j/Neo4jConnectionModule.ts#L11-L12

Added lines #L11 - L12 were not covered by tests
}

authenticate(_credentials: Record<any, any>): void | never {}

async runQuery(driver, inputQueryParams, inputQuerycallbacks): Promise<void> {
async runQuery(driver, inputQueryParams, inputQueryCallbacks): Promise<void> {
let queryParams = extractQueryParams(inputQueryParams);
let callbacks = extractQueryCallbacks(inputQuerycallbacks);
let callbacks = extractQueryCallbacks(inputQueryCallbacks);
return runCypherQuery({ driver, ...queryParams, ...callbacks });
}

loadDashboard(_id: string): any | never {}
loadDashboard(_id: string): any | never {
return notImplementedError('loadDashboard');

Check warning on line 22 in src/connection/neo4j/Neo4jConnectionModule.ts

View check run for this annotation

Codecov / codecov/patch

src/connection/neo4j/Neo4jConnectionModule.ts#L21-L22

Added lines #L21 - L22 were not covered by tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we including dashboards CRUD operations in the current scope or not yet?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we should, but let's focus first on migrating the format of the records, i think that's more urgent. In the current release we should just create the base for the next releases.

}

saveDashboard(_dashboard: any): boolean | never {
return true;
return notImplementedError('saveDashboard');

Check warning on line 26 in src/connection/neo4j/Neo4jConnectionModule.ts

View check run for this annotation

Codecov / codecov/patch

src/connection/neo4j/Neo4jConnectionModule.ts#L25-L26

Added lines #L25 - L26 were not covered by tests
}

deleteDashboard(_id: string): void | never {}
deleteDashboard(_id: string): void | never {
return notImplementedError('deleteDashboard');

Check warning on line 30 in src/connection/neo4j/Neo4jConnectionModule.ts

View check run for this annotation

Codecov / codecov/patch

src/connection/neo4j/Neo4jConnectionModule.ts#L29-L30

Added lines #L29 - L30 were not covered by tests
}

// TODO: understand how to implement it using only JS objects
parseRecords(records: Neo4jRecord[]): any | never {
return records;

Check warning on line 34 in src/connection/neo4j/Neo4jConnectionModule.ts

View check run for this annotation

Codecov / codecov/patch

src/connection/neo4j/Neo4jConnectionModule.ts#L33-L34

Added lines #L33 - L34 were not covered by tests
}
}
13 changes: 1 addition & 12 deletions src/connection/neo4j/runCypherQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,9 @@
extractNodeAndRelPropertiesFromRecords,
extractNodePropertiesFromRecords,
} from '../../report/ReportRecordProcessing';
import { QueryStatus } from '../interfaces';
import { setErrorDummy, setFieldsDummy, setRecordsDummy, setSchemaDummy, setStatusDummy } from './utils';

export enum QueryStatus {
NO_QUERY, // No query specified
NO_DATA, // No data was returned, therefore we can't draw it.
NO_DRAWABLE_DATA, // There is data returned, but we can't draw it
WAITING, // The report is waiting for custom logic to be executed.
RUNNING, // The report query is running.
TIMED_OUT, // Query has reached the time limit.
COMPLETE, // There is data returned, and we can visualize it all.
COMPLETE_TRUNCATED, // There is data returned, but it's too much so we truncate it.
ERROR, // Something broke, likely the cypher query is invalid.
}

// TODO: create a readOnly version of this method or inject a property
/**
* Runs a Cypher query using the specified driver.
Expand Down Expand Up @@ -138,7 +127,7 @@
setStatus(QueryStatus.ERROR);
// Process other errors.
if (setRecords) {
setError(e.message);

Check warning on line 130 in src/connection/neo4j/runCypherQuery.ts

View check run for this annotation

Codecov / codecov/patch

src/connection/neo4j/runCypherQuery.ts#L130

Added line #L130 was not covered by tests
setRecords([{ error: e.message }]);
}
transaction.rollback();
Expand Down
Loading