-
Couldn't load subscription status.
- Fork 17
task/WP-930: Audit Trails UI #1594
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
Open
erikriv16
wants to merge
24
commits into
main
Choose a base branch
from
task/WP-930
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
d08025a
Adding audit trail to dropdown under Welcome, user! under "manage acc…
4ae5c54
New audit trails page made
8d47648
Returning JSON for most recent session with username as input woring
6857f50
Working UI for recent session, good starting point
8c3e670
Added pop-up modal functionality for data column (now named Details),…
e6458ca
Merge remote-tracking branch 'origin/main' into task/WP-930
530138a
Added antd modal feature, data at bottom of modal, another good start…
8077e97
Merge main into task/WP-930
2287234
Initial push
e06ce9e
Removed comments
31f2134
Delete unnecessary add-ons, linting error fixes
4d1876b
Added extra lines to files, added hooks, minor changes to audittrail.…
7ddcc49
Update designsafe/apps/accounts/templates/designsafe/apps/accounts/ba…
erikriv16 12ce212
Merge branch 'main' into task/WP-930
fnets 76f98e3
Fixed react/server side linting errors
fd31273
Added seperate file for table and added unit tests
5cb1a85
Good saving point, file portal search somewhat working, good exmaples…
3779d92
Another good saving point, going to try to rework search, have submit…
8776e11
Added functioning file search feature
2cf8247
Removed tests.py, fixed linting errors
0459011
Fixed linting errors
d497c04
last lint check
915d9af
Merge branch 'main' into task/WP-930
rstijerina c955edb
Merge branch 'main' into task/WP-930
fnets File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| export * from './useGetRecentSession'; | ||
| export { useGetTapisFileHistory } from './useGetTapisFileHistory'; | ||
| export { useGetPortalFileHistory } from './useGetPortalFileHistory'; | ||
| export { useGetUsernames } from './useGetUsernames'; | ||
| export type { TapisFileAuditEntry } from './useGetTapisFileHistory'; | ||
| export type { PortalFileAuditEntry } from './useGetPortalFileHistory'; |
31 changes: 31 additions & 0 deletions
31
client/modules/_hooks/src/audit/useGetPortalFileHistory.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { useQuery } from '@tanstack/react-query'; | ||
|
|
||
| interface PortalFileAuditResponse { | ||
| data: PortalFileAuditEntry[]; | ||
| } | ||
|
|
||
| export interface PortalFileAuditEntry { | ||
| timestamp: string; | ||
| portal: string; | ||
| username: string; | ||
| action: string; | ||
| tracking_id: string; | ||
| data: object; | ||
| } | ||
|
|
||
| async function fetchPortalFileHistory( | ||
| filename: string | ||
| ): Promise<PortalFileAuditResponse> { | ||
| const encoded = encodeURIComponent(filename); | ||
| const response = await fetch(`/audit/api/file/${encoded}/portal/combined/`); | ||
| if (!response.ok) throw new Error(`API Error: ${response.status}`); | ||
| return response.json(); | ||
| } | ||
|
|
||
| export function useGetPortalFileHistory(filename: string, enabled: boolean) { | ||
| return useQuery<PortalFileAuditResponse, Error>({ | ||
| queryKey: ['portalFileHistory', filename], | ||
| queryFn: () => fetchPortalFileHistory(filename), | ||
| enabled, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { useQuery } from '@tanstack/react-query'; | ||
|
|
||
| interface PortalAuditResponse { | ||
| data: PortalAuditEntry[]; | ||
| } | ||
|
|
||
| export interface PortalAuditEntry { | ||
| timestamp: string; | ||
| portal: string; | ||
| username: string; | ||
| action: string; | ||
| tracking_id: string; | ||
| data: object; | ||
| } | ||
|
|
||
| async function fetchPortalAudit( | ||
| username: string | ||
| ): Promise<PortalAuditResponse> { | ||
| const encoded = encodeURIComponent(username); | ||
| const response = await fetch(`/audit/api/user/${encoded}/portal/`); | ||
| if (!response.ok) { | ||
| throw new Error( | ||
| `API request failed: ${response.status} ${response.statusText}` | ||
| ); | ||
| } | ||
| return response.json(); | ||
| } | ||
|
|
||
| export function useGetRecentSession(username: string, enabled: boolean) { | ||
| return useQuery<PortalAuditResponse, Error>({ | ||
| queryKey: ['audit', username], | ||
| queryFn: () => fetchPortalAudit(username), | ||
| enabled, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { useQuery } from '@tanstack/react-query'; | ||
|
|
||
| interface TapisFileAuditResponse { | ||
| data: TapisFileAuditEntry[]; | ||
| } | ||
|
|
||
| export interface TapisFileAuditEntry { | ||
| writer_logtime: string; //date&time | ||
| obo_user: string; //user | ||
| action: string; //action | ||
| target_path: string; //path flow - maybe location | ||
| source_path: string; //path flow - maybe location | ||
| data: object; //details | ||
| } | ||
|
|
||
| async function fetchTapisFileHistory( | ||
| filename: string | ||
| ): Promise<TapisFileAuditResponse> { | ||
| const encoded = encodeURIComponent(filename); | ||
| const response = await fetch(`/audit/api/file/${encoded}/tapis/`); | ||
| if (!response.ok) throw new Error(`API Error: ${response.status}`); | ||
| return response.json(); | ||
| } | ||
|
|
||
| export function useGetTapisFileHistory(filename: string, enabled: boolean) { | ||
| return useQuery<TapisFileAuditResponse, Error>({ | ||
| queryKey: ['fileHistory', filename], | ||
| queryFn: () => fetchTapisFileHistory(filename), | ||
| enabled, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { useQuery } from '@tanstack/react-query'; | ||
|
|
||
| export async function fetchPortalUsernames(): Promise<string[]> { | ||
| const response = await fetch('/audit/api/usernames/portal'); | ||
| if (!response.ok) throw new Error('Failed to fetch usernames'); | ||
| const data = await response.json(); | ||
| return data.usernames || []; | ||
| } | ||
|
|
||
| export function useGetUsernames() { | ||
| return useQuery<string[], Error>({ | ||
| queryKey: ['portalUsernames'], | ||
| queryFn: fetchPortalUsernames, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| import React, { useState } from 'react'; | ||
| import { AutoComplete } from 'antd'; | ||
| import { | ||
| useGetRecentSession, | ||
| useGetPortalFileHistory, | ||
| useGetUsernames, | ||
| } from '@client/hooks'; | ||
| import AuditTrailSessionTable from './AuditTrailSessionTable'; | ||
| import AuditTrailFileTable from './AuditTrailFileTable'; | ||
|
|
||
| const AuditTrail: React.FC = () => { | ||
| type Mode = 'user-session' | 'portal-file'; | ||
| const [query, setQuery] = useState(''); | ||
| const [mode, setMode] = useState<Mode>('user-session'); | ||
|
|
||
| const { data: allUsernames } = useGetUsernames(); | ||
| const { | ||
| data: portalData, | ||
| error: portalError, | ||
| isLoading: portalLoading, | ||
| refetch: refetchPortal, | ||
| } = useGetRecentSession(query, false); | ||
|
|
||
| const { | ||
| data: fileData, | ||
| error: fileError, | ||
| isLoading: fileLoading, | ||
| refetch: refetchFile, | ||
| } = useGetPortalFileHistory(query, false); | ||
|
|
||
| const filteredUsernames = | ||
| query.length > 0 && allUsernames | ||
| ? allUsernames | ||
| .filter((name) => name.toLowerCase().includes(query.toLowerCase())) | ||
| .slice(0, 20) | ||
| : []; | ||
|
|
||
| const auditData = mode === 'user-session' ? portalData : fileData; | ||
| const auditError = mode === 'user-session' ? portalError : fileError; | ||
| const auditLoading = mode === 'user-session' ? portalLoading : fileLoading; | ||
| const auditRefetch = mode === 'user-session' ? refetchPortal : refetchFile; | ||
|
|
||
| const onSearch = (e: React.FormEvent) => { | ||
| e.preventDefault(); | ||
| const trimmed = query.trim(); | ||
| if (!trimmed) return; | ||
| if (trimmed !== query) setQuery(trimmed); | ||
| auditRefetch(); | ||
| }; | ||
|
|
||
| return ( | ||
| <div> | ||
| <form onSubmit={onSearch} style={{ marginBottom: 16 }}> | ||
| <div | ||
| style={{ | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| flexWrap: 'wrap', | ||
| }} | ||
| > | ||
| <select | ||
| value={mode} | ||
| onChange={(e) => { | ||
| setMode(e.target.value as Mode); | ||
| setQuery(''); | ||
| }} | ||
| style={{ marginRight: 8 }} | ||
| > | ||
| <option value="user-session">Most Recent User Session Data</option> | ||
| <option value="portal-file">File search</option> | ||
| </select> | ||
| {mode === 'user-session' ? ( | ||
| <AutoComplete | ||
| value={query} | ||
| style={{ width: '200px' }} | ||
| options={filteredUsernames.map((name) => ({ | ||
| value: name, | ||
| label: name, | ||
| }))} | ||
| onSelect={(value) => setQuery(value)} | ||
| onSearch={(searchText) => setQuery(searchText)} | ||
| placeholder="Username" | ||
| /> | ||
| ) : ( | ||
| <input | ||
| value={query} | ||
| onChange={(e) => setQuery(e.target.value)} | ||
| placeholder="Filename" | ||
| style={{ width: '200px' }} | ||
| maxLength={512} | ||
| /> | ||
| )} | ||
| <button | ||
| type="submit" | ||
| disabled={auditLoading || !query.trim() || query.length > 512} | ||
| style={{ marginLeft: '10px' }} | ||
| > | ||
| {auditLoading ? 'Loading…' : 'Submit'} | ||
| </button> | ||
| </div> | ||
| </form> | ||
|
|
||
| {mode === 'user-session' ? ( | ||
| <AuditTrailSessionTable | ||
| auditData={auditData} | ||
| auditError={auditError} | ||
| auditLoading={auditLoading} | ||
| /> | ||
| ) : ( | ||
| <AuditTrailFileTable | ||
| auditData={auditData} | ||
| auditError={auditError} | ||
| auditLoading={auditLoading} | ||
| searchTerm={(query || '').trim()} | ||
| /> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default AuditTrail; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Antd components would give us some nice UI styling for free