Skip to content

Commit 01941a4

Browse files
passing and logging authenticated user email in backend logging (#1019)
* Passed the email as new parameter for all api's * removed the profile * Added email as param in each API and logging as well * added email for source list and conditional invoking of post processing api --------- Co-authored-by: Pravesh Kumar <[email protected]>
1 parent 105b5d5 commit 01941a4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+246
-333
lines changed

backend/score.py

Lines changed: 53 additions & 46 deletions
Large diffs are not rendered by default.

frontend/src/API/Index.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,45 @@
11
import axios from 'axios';
22
import { url } from '../utils/Utils';
3+
import { UserCredentials } from '../types';
34

45
const api = axios.create({
56
baseURL: url(),
7+
data: {},
68
});
9+
10+
export const createDefaultFormData = (userCredentials: UserCredentials) => {
11+
const formData = new FormData();
12+
formData.append('uri', userCredentials?.uri ?? '');
13+
formData.append('database', userCredentials?.database ?? '');
14+
formData.append('userName', userCredentials?.userName ?? '');
15+
formData.append('password', userCredentials?.password ?? '');
16+
formData.append('email', userCredentials?.email ?? '');
17+
api.interceptors.request.use(
18+
(config) => {
19+
if (config.data instanceof FormData) {
20+
for (const [key, value] of formData.entries()) {
21+
if (!config.data.has(key)) {
22+
config.data.append(key, value);
23+
}
24+
}
25+
} else {
26+
const formData = new FormData();
27+
for (const [key, value] of formData.entries()) {
28+
formData.append(key, value);
29+
}
30+
for (const [key, value] of Object.entries(config.data || {})) {
31+
formData.append(key, value as any);
32+
}
33+
config.data = formData;
34+
}
35+
36+
return config;
37+
},
38+
(error) => {
39+
return Promise.reject(error);
40+
}
41+
);
42+
return formData;
43+
};
44+
745
export default api;

frontend/src/components/ChatBot/ChatOnlyComponent.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const ChatContent: React.FC<ChatProps> = ({ chatMessages }) => {
3232
const encodedPassword = urlParams.get('password');
3333
const database = urlParams.get('database');
3434
const port = urlParams.get('port');
35+
const email = urlParams.get('email');
3536
const openModal = urlParams.get('open') === 'true';
3637
if (openModal || !(uri && user && encodedPassword && database && port)) {
3738
setOpenConnection((prev) => ({ ...prev, openPopUp: true }));
@@ -42,6 +43,7 @@ const ChatContent: React.FC<ChatProps> = ({ chatMessages }) => {
4243
password: atob(atob(encodedPassword)),
4344
database,
4445
port,
46+
email: email ?? '',
4547
};
4648
setShowBackButton();
4749
setUserCredentials(credentialsForAPI);

frontend/src/components/ChatBot/Chatbot.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ import {
2323
ExtendedRelationship,
2424
Messages,
2525
ResponseMode,
26-
UserCredentials,
2726
metricstate,
2827
multimodelmetric,
2928
nodeDetailsProps,
3029
} from '../../types';
31-
import { useCredentials } from '../../context/UserCredentials';
3230
import { chatBotAPI } from '../../services/QnaAPI';
3331
import { v4 as uuidv4 } from 'uuid';
3432
import { useFileContext } from '../../context/UsersFiles';
@@ -63,7 +61,6 @@ const Chatbot: FC<ChatbotProps> = (props) => {
6361
} = props;
6462
const [inputMessage, setInputMessage] = useState('');
6563
const [loading, setLoading] = useState<boolean>(isLoading);
66-
const { userCredentials } = useCredentials();
6764
const { model, chatModes, selectedRows, filesData } = useFileContext();
6865
const messagesEndRef = useRef<HTMLDivElement>(null);
6966
const [showInfoModal, setShowInfoModal] = useState<boolean>(false);
@@ -215,7 +212,6 @@ const Chatbot: FC<ChatbotProps> = (props) => {
215212
try {
216213
const apiCalls = chatModes.map((mode) =>
217214
chatBotAPI(
218-
userCredentials as UserCredentials,
219215
inputMessage,
220216
sessionId,
221217
model,

frontend/src/components/ChatBot/ChunkInfo.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FC, useContext, useState } from 'react';
2-
import { ChunkProps, UserCredentials } from '../../types';
2+
import { ChunkProps } from '../../types';
33
import { LoadingSpinner, TextLink, Typography } from '@neo4j-ndl/react';
44
import { DocumentTextIconOutline, GlobeAltIconOutline } from '@neo4j-ndl/react/icons';
55
import wikipedialogo from '../../assets/images/wikipedia.svg';
@@ -10,13 +10,11 @@ import ReactMarkdown from 'react-markdown';
1010
import { generateYouTubeLink, getLogo, isAllowedHost } from '../../utils/Utils';
1111
import { ThemeWrapperContext } from '../../context/ThemeWrapper';
1212
import { chatModeLables } from '../../utils/Constants';
13-
import { useCredentials } from '../../context/UserCredentials';
1413
import GraphViewModal from '../Graph/GraphViewModal';
1514
import { handleGraphNodeClick } from './chatInfo';
1615

1716
const ChunkInfo: FC<ChunkProps> = ({ loading, chunks, mode }) => {
1817
const themeUtils = useContext(ThemeWrapperContext);
19-
const { userCredentials } = useCredentials();
2018
const [neoNodes, setNeoNodes] = useState<any[]>([]);
2119
const [neoRels, setNeoRels] = useState<any[]>([]);
2220
const [openGraphView, setOpenGraphView] = useState(false);
@@ -25,7 +23,6 @@ const ChunkInfo: FC<ChunkProps> = ({ loading, chunks, mode }) => {
2523

2624
const handleChunkClick = (elementId: string, viewMode: string) => {
2725
handleGraphNodeClick(
28-
userCredentials as UserCredentials,
2926
elementId,
3027
viewMode,
3128
setNeoNodes,

frontend/src/components/ChatBot/CommunitiesInfo.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import { LoadingSpinner, Flex, Typography, TextLink } from '@neo4j-ndl/react';
22
import { FC, useState } from 'react';
33
import ReactMarkdown from 'react-markdown';
4-
import { CommunitiesProps, UserCredentials } from '../../types';
4+
import { CommunitiesProps } from '../../types';
55
import { chatModeLables } from '../../utils/Constants';
6-
import { useCredentials } from '../../context/UserCredentials';
76
import GraphViewModal from '../Graph/GraphViewModal';
87
import { handleGraphNodeClick } from './chatInfo';
98

109
const CommunitiesInfo: FC<CommunitiesProps> = ({ loading, communities, mode }) => {
11-
const { userCredentials } = useCredentials();
1210
const [neoNodes, setNeoNodes] = useState<any[]>([]);
1311
const [neoRels, setNeoRels] = useState<any[]>([]);
1412
const [openGraphView, setOpenGraphView] = useState(false);
@@ -17,7 +15,6 @@ const CommunitiesInfo: FC<CommunitiesProps> = ({ loading, communities, mode }) =
1715

1816
const handleCommunityClick = (elementId: string, viewMode: string) => {
1917
handleGraphNodeClick(
20-
userCredentials as UserCredentials,
2118
elementId,
2219
viewMode,
2320
setNeoNodes,

frontend/src/components/ChatBot/EntitiesInfo.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import { GraphLabel, LoadingSpinner, TextLink, Typography } from '@neo4j-ndl/react';
22
import { FC, useMemo, useState } from 'react';
3-
import { EntitiesProps, GroupedEntity, UserCredentials } from '../../types';
3+
import { EntitiesProps, GroupedEntity } from '../../types';
44
import { calcWordColor } from '@neo4j-devtools/word-color';
55
import { graphLabels } from '../../utils/Constants';
66
import { parseEntity } from '../../utils/Utils';
7-
import { useCredentials } from '../../context/UserCredentials';
87
import GraphViewModal from '../Graph/GraphViewModal';
98
import { handleGraphNodeClick } from './chatInfo';
109

1110
const EntitiesInfo: FC<EntitiesProps> = ({ loading, mode, graphonly_entities, infoEntities }) => {
12-
const { userCredentials } = useCredentials();
1311
const [neoNodes, setNeoNodes] = useState<any[]>([]);
1412
const [neoRels, setNeoRels] = useState<any[]>([]);
1513
const [openGraphView, setOpenGraphView] = useState(false);
@@ -45,7 +43,6 @@ const EntitiesInfo: FC<EntitiesProps> = ({ loading, mode, graphonly_entities, in
4543

4644
const handleEntityClick = (elementId: string, viewMode: string) => {
4745
handleGraphNodeClick(
48-
userCredentials as UserCredentials,
4946
elementId,
5047
viewMode,
5148
setNeoNodes,

frontend/src/components/ChatBot/chatInfo.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { getNeighbors } from '../../services/GraphQuery';
2-
import { NeoNode, NeoRelationship, UserCredentials } from '../../types';
2+
import { NeoNode, NeoRelationship } from '../../types';
33
import { showNormalToast } from '../../utils/toasts';
44

55
export const handleGraphNodeClick = async (
6-
userCredentials: UserCredentials,
76
elementId: string,
87
viewMode: string,
98
setNeoNodes: React.Dispatch<React.SetStateAction<NeoNode[]>>,
@@ -16,7 +15,7 @@ export const handleGraphNodeClick = async (
1615
setLoadingGraphView(true);
1716
}
1817
try {
19-
const result = await getNeighbors(userCredentials, elementId);
18+
const result = await getNeighbors(elementId);
2019
if (result && result.data.data.nodes.length > 0) {
2120
let { nodes } = result.data.data;
2221
if (viewMode === 'Chunk') {

frontend/src/components/Content.tsx

Lines changed: 36 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@ import { Button, Typography, Flex, StatusIndicator, useMediaQuery } from '@neo4j
44
import { useCredentials } from '../context/UserCredentials';
55
import { useFileContext } from '../context/UsersFiles';
66
import { extractAPI } from '../utils/FileAPI';
7-
import {
8-
BannerAlertProps,
9-
ContentProps,
10-
CustomFile,
11-
OptionType,
12-
UserCredentials,
13-
chunkdata,
14-
FileTableHandle,
15-
} from '../types';
7+
import { BannerAlertProps, ContentProps, CustomFile, OptionType, chunkdata, FileTableHandle } from '../types';
168
import deleteAPI from '../services/DeleteFiles';
179
import { postProcessing } from '../services/PostProcessing';
1810
import { triggerStatusUpdateAPI } from '../services/ServerSideStatusUpdateAPI';
@@ -157,34 +149,36 @@ const Content: React.FC<ContentProps> = ({
157149
(task) => task !== 'graph_schema_consolidation' && task !== 'enable_communities'
158150
)
159151
: postProcessingTasks.filter((task) => task !== 'enable_communities');
160-
const response = await postProcessing(userCredentials as UserCredentials, payload);
161-
if (response.data.status === 'Success') {
162-
const communityfiles = response.data?.data;
163-
if (Array.isArray(communityfiles) && communityfiles.length) {
164-
communityfiles?.forEach((c: any) => {
165-
setFilesData((prev) => {
166-
return prev.map((f) => {
167-
if (f.name === c.filename) {
168-
return {
169-
...f,
170-
chunkNodeCount: c.chunkNodeCount ?? 0,
171-
entityNodeCount: c.entityNodeCount ?? 0,
172-
communityNodeCount: c.communityNodeCount ?? 0,
173-
chunkRelCount: c.chunkRelCount ?? 0,
174-
entityEntityRelCount: c.entityEntityRelCount ?? 0,
175-
communityRelCount: c.communityRelCount ?? 0,
176-
nodesCount: c.nodeCount,
177-
relationshipsCount: c.relationshipCount,
178-
};
179-
}
180-
return f;
152+
if (payload.length) {
153+
const response = await postProcessing(payload);
154+
if (response.data.status === 'Success') {
155+
const communityfiles = response.data?.data;
156+
if (Array.isArray(communityfiles) && communityfiles.length) {
157+
communityfiles?.forEach((c: any) => {
158+
setFilesData((prev) => {
159+
return prev.map((f) => {
160+
if (f.name === c.filename) {
161+
return {
162+
...f,
163+
chunkNodeCount: c.chunkNodeCount ?? 0,
164+
entityNodeCount: c.entityNodeCount ?? 0,
165+
communityNodeCount: c.communityNodeCount ?? 0,
166+
chunkRelCount: c.chunkRelCount ?? 0,
167+
entityEntityRelCount: c.entityEntityRelCount ?? 0,
168+
communityRelCount: c.communityRelCount ?? 0,
169+
nodesCount: c.nodeCount,
170+
relationshipsCount: c.relationshipCount,
171+
};
172+
}
173+
return f;
174+
});
181175
});
182176
});
183-
});
177+
}
178+
showSuccessToast('All Q&A functionality is available now.');
179+
} else {
180+
throw new Error(response.data.error);
184181
}
185-
showSuccessToast('All Q&A functionality is available now.');
186-
} else {
187-
throw new Error(response.data.error);
188182
}
189183
} catch (error) {
190184
if (error instanceof Error) {
@@ -220,7 +214,7 @@ const Content: React.FC<ContentProps> = ({
220214
};
221215
const getChunks = async (name: string, pageNo: number) => {
222216
toggleChunksLoading();
223-
const response = await getChunkText(userCredentials as UserCredentials, name, pageNo);
217+
const response = await getChunkText(name, pageNo);
224218
setTextChunks(response.data.data.pageitems);
225219
if (!totalPageCount) {
226220
setTotalPageCount(response.data.data.total_pages);
@@ -281,7 +275,6 @@ const Content: React.FC<ContentProps> = ({
281275

282276
const apiResponse = await extractAPI(
283277
fileItem.model,
284-
userCredentials as UserCredentials,
285278
fileItem.fileSource,
286279
fileItem.retryOption ?? '',
287280
fileItem.sourceUrl,
@@ -384,7 +377,7 @@ const Content: React.FC<ContentProps> = ({
384377
};
385378

386379
const addFilesToQueue = async (remainingFiles: CustomFile[]) => {
387-
if (!remainingFiles.length) {
380+
if (!remainingFiles.length && postProcessingTasks.length) {
388381
showNormalToast(
389382
<PostProcessingToast
390383
isGdsActive={isGdsActive}
@@ -393,7 +386,7 @@ const Content: React.FC<ContentProps> = ({
393386
/>
394387
);
395388
try {
396-
const response = await postProcessing(userCredentials as UserCredentials, postProcessingTasks);
389+
const response = await postProcessing(postProcessingTasks);
397390
if (response.data.status === 'Success') {
398391
const communityfiles = response.data?.data;
399392
if (Array.isArray(communityfiles) && communityfiles.length) {
@@ -561,7 +554,7 @@ const Content: React.FC<ContentProps> = ({
561554
setConnectionStatus(false);
562555
localStorage.removeItem('password');
563556
localStorage.removeItem('selectedModel');
564-
setUserCredentials({ uri: '', password: '', userName: '', database: '' });
557+
setUserCredentials({ uri: '', password: '', userName: '', database: '', email: '' });
565558
setSelectedNodes([]);
566559
setSelectedRels([]);
567560
localStorage.removeItem('instructions');
@@ -586,7 +579,7 @@ const Content: React.FC<ContentProps> = ({
586579
const retryHandler = async (filename: string, retryoption: string) => {
587580
try {
588581
setRetryLoading(true);
589-
const response = await retry(userCredentials as UserCredentials, filename, retryoption);
582+
const response = await retry(filename, retryoption);
590583
setRetryLoading(false);
591584
if (response.data.status === 'Failure') {
592585
throw new Error(response.data.error);
@@ -677,11 +670,7 @@ const Content: React.FC<ContentProps> = ({
677670
const handleDeleteFiles = async (deleteEntities: boolean) => {
678671
try {
679672
setIsDeleteLoading(true);
680-
const response = await deleteAPI(
681-
userCredentials as UserCredentials,
682-
childRef.current?.getSelectedRows() as CustomFile[],
683-
deleteEntities
684-
);
673+
const response = await deleteAPI(childRef.current?.getSelectedRows() as CustomFile[], deleteEntities);
685674
queue.clear();
686675
setProcessedCount(0);
687676
setRowSelection({});
@@ -716,7 +705,7 @@ const Content: React.FC<ContentProps> = ({
716705
const selectedRows = childRef.current?.getSelectedRows();
717706
if (selectedRows?.length) {
718707
const expiredFilesExists = selectedRows.some(
719-
(c) => c.status !== 'Ready to Reprocess' && isExpired((c?.createdAt as Date) ?? new Date())
708+
(c) => isFileReadyToProcess(c, true) && isExpired((c?.createdAt as Date) ?? new Date())
720709
);
721710
const largeFileExists = selectedRows.some(
722711
(c) => isFileReadyToProcess(c, true) && typeof c.size === 'number' && c.size > largeFileSize
@@ -729,7 +718,7 @@ const Content: React.FC<ContentProps> = ({
729718
handleGenerateGraph(selectedRows.filter((f) => isFileReadyToProcess(f, false)));
730719
}
731720
} else if (filesData.length) {
732-
const expiredFileExists = filesData.some((c) => isExpired(c?.createdAt as Date));
721+
const expiredFileExists = filesData.some((c) => isFileReadyToProcess(c, true) && isExpired(c?.createdAt as Date));
733722
const largeFileExists = filesData.some(
734723
(c) => isFileReadyToProcess(c, true) && typeof c.size === 'number' && c.size > largeFileSize
735724
);

frontend/src/components/DataSources/AWS/S3Modal.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { TextInput } from '@neo4j-ndl/react';
22
import React, { useState } from 'react';
3-
import { CustomFile, CustomFileBase, S3File, S3ModalProps, UserCredentials } from '../../../types';
3+
import { CustomFile, CustomFileBase, S3File, S3ModalProps } from '../../../types';
44
import { urlScanAPI } from '../../../services/URLScan';
5-
import { useCredentials } from '../../../context/UserCredentials';
65
import { validation } from '../../../utils/Utils';
76
import { useFileContext } from '../../../context/UsersFiles';
87
import { v4 as uuidv4 } from 'uuid';
@@ -17,7 +16,6 @@ const S3Modal: React.FC<S3ModalProps> = ({ hideModal, open }) => {
1716
const [statusMessage, setStatusMessage] = useState<string>('');
1817
const [isFocused, setIsFocused] = useState<boolean>(false);
1918
const [isValid, setValid] = useState<boolean>(false);
20-
const { userCredentials } = useCredentials();
2119
const { setFilesData, model, filesData } = useFileContext();
2220

2321
const reset = () => {
@@ -62,7 +60,6 @@ const S3Modal: React.FC<S3ModalProps> = ({ hideModal, open }) => {
6260
setStatusMessage('Scanning...');
6361
const apiResponse = await urlScanAPI({
6462
urlParam: url.trim(),
65-
userCredentials: userCredentials as UserCredentials,
6663
model: model,
6764
accessKey: accessKey.trim(),
6865
secretKey: secretKey.trim(),

0 commit comments

Comments
 (0)