-
Notifications
You must be signed in to change notification settings - Fork 1
Audit Log In Detail Pages #1025
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
braydencstratusadv
wants to merge
7
commits into
main
Choose a base branch
from
blc/feat/audit_log
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 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cbd9fb6
Initial commit
braydencstratusadv 9d6e15f
Fix linting issues
braydencstratusadv 177ddee
Format using prettier
braydencstratusadv 6ce9ca5
Fix spacing
braydencstratusadv 7245110
Fix security warning
braydencstratusadv 980ac4c
Fix black formatting issues
braydencstratusadv ec9c4db
Update per PR feedback
braydencstratusadv 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,228 @@ | ||
<script setup lang="ts"> | ||
import { ref } from 'vue'; | ||
import Button from 'primevue/button'; | ||
|
||
export interface EditLogResponse { | ||
modified_on: string | null; | ||
modified_by: string | null; | ||
transaction_id?: string | null; | ||
edit_type?: string | null; | ||
user_email?: string | null; | ||
is_system_edit?: boolean; | ||
method_used?: string; | ||
error?: string; | ||
tile_id?: string | null; | ||
nodegroup_id?: string | null; | ||
} | ||
|
||
const props = defineProps<{ | ||
resourceId: string; | ||
graph: string; | ||
tileIds?: string[]; | ||
nodegroupConfigs?: Array<{ | ||
alias: string; | ||
label?: string; | ||
fetchTiles?: boolean; | ||
}>; | ||
}>(); | ||
|
||
const emit = defineEmits<{ | ||
loaded: [data: EditLogResponse]; | ||
error: [error: string]; | ||
populateAllFields: [ | ||
results: Record< | ||
string, | ||
{ entered_on: string | null; entered_by: string | null } | ||
>, | ||
]; | ||
}>(); | ||
|
||
const loading = ref(false); | ||
const error = ref<string | null>(null); | ||
const dataLoaded = ref(false); | ||
|
||
const formatDisplayName = (response: EditLogResponse): string => { | ||
if (!response.modified_by) { | ||
return 'Unknown'; | ||
} | ||
|
||
if (response.is_system_edit) { | ||
return response.modified_by; | ||
} | ||
|
||
return response.modified_by; | ||
}; | ||
|
||
const formatDate = (dateString: string | null): string => { | ||
if (!dateString) return 'Unknown'; | ||
|
||
try { | ||
const date = new Date(dateString); | ||
return date.toLocaleString(); | ||
} catch { | ||
return dateString; | ||
} | ||
}; | ||
|
||
const loadEditLog = async ( | ||
resourceId: string, | ||
graph: string, | ||
options?: { | ||
tileId?: string; | ||
nodegroupId?: string; | ||
nodegroupAlias?: string; | ||
}, | ||
): Promise<EditLogResponse | null> => { | ||
try { | ||
const params = new URLSearchParams(); | ||
|
||
if (options?.tileId) { | ||
params.append('tile_id', options.tileId); | ||
} | ||
if (options?.nodegroupId) { | ||
params.append('nodegroup_id', options.nodegroupId); | ||
} | ||
if (options?.nodegroupAlias) { | ||
params.append('nodegroup_alias', options.nodegroupAlias); | ||
} | ||
|
||
const queryString = params.toString(); | ||
const url = `/bcap/api/resources/${graph}/${resourceId}/edit-log/${queryString ? `?${queryString}` : ''}`; | ||
|
||
const response = await fetch(url); | ||
|
||
if (!response.ok) { | ||
throw new Error( | ||
`Failed to load edit information: ${response.status}`, | ||
); | ||
} | ||
|
||
const result: EditLogResponse = await response.json(); | ||
return result; | ||
} catch (err) { | ||
const errorMessage = | ||
err instanceof Error ? err.message : 'Unknown error occurred'; | ||
error.value = errorMessage; | ||
console.error('Error loading edit log:', err); | ||
return null; | ||
} | ||
}; | ||
|
||
const populateAllEnteredFields = async () => { | ||
loading.value = true; | ||
const results: Record< | ||
string, | ||
{ entered_on: string | null; entered_by: string | null } | ||
> = {}; | ||
|
||
try { | ||
// If specific tile IDs are provided, fetch data for each | ||
if (props.tileIds && props.tileIds.length > 0) { | ||
const promises = props.tileIds.map(async (tileId) => { | ||
const result = await loadEditLog( | ||
props.resourceId, | ||
props.graph, | ||
{ | ||
tileId: tileId, | ||
}, | ||
); | ||
|
||
if (result) { | ||
return { | ||
tileId: tileId, | ||
data: { | ||
entered_on: formatDate(result.modified_on), | ||
entered_by: formatDisplayName(result), | ||
}, | ||
}; | ||
} | ||
return null; | ||
}); | ||
|
||
const responses = await Promise.all(promises); | ||
|
||
responses.forEach((response) => { | ||
if (response) { | ||
results[`tile_${response.tileId}`] = response.data; | ||
} | ||
}); | ||
} | ||
// If nodegroup configs provided | ||
else if (props.nodegroupConfigs && props.nodegroupConfigs.length > 0) { | ||
const promises = props.nodegroupConfigs.map(async (config) => { | ||
const result = await loadEditLog( | ||
props.resourceId, | ||
props.graph, | ||
{ | ||
nodegroupAlias: config.alias, | ||
}, | ||
); | ||
|
||
if (result) { | ||
return { | ||
alias: config.alias, | ||
data: { | ||
entered_on: formatDate(result.modified_on), | ||
entered_by: formatDisplayName(result), | ||
}, | ||
}; | ||
} | ||
|
||
return null; | ||
}); | ||
|
||
const responses = await Promise.all(promises); | ||
|
||
responses.forEach((response) => { | ||
if (response) { | ||
results[response.alias] = response.data; | ||
} | ||
}); | ||
} | ||
// Fetch resource-level data | ||
else { | ||
const result = await loadEditLog(props.resourceId, props.graph); | ||
if (result) { | ||
results['resource'] = { | ||
entered_on: formatDate(result.modified_on), | ||
entered_by: formatDisplayName(result), | ||
}; | ||
} | ||
} | ||
|
||
emit('populateAllFields', results); | ||
dataLoaded.value = true; | ||
} catch (err) { | ||
console.error('Error loading edit logs:', err); | ||
error.value = err instanceof Error ? err.message : 'Unknown error'; | ||
} finally { | ||
loading.value = false; | ||
} | ||
}; | ||
</script> | ||
|
||
<template> | ||
<Button | ||
:label="loading ? 'Loading...' : 'Populate All Entered On/By Fields'" | ||
:icon="loading ? 'pi pi-spinner pi-spin' : 'pi pi-user-edit'" | ||
:disabled="loading" | ||
class="control-button" | ||
severity="info" | ||
@click="populateAllEnteredFields" | ||
/> | ||
</template> | ||
|
||
<style scoped> | ||
.control-button { | ||
min-width: 180px; | ||
font-size: 1.2rem; | ||
font-weight: 500; | ||
} | ||
|
||
@media (max-width: 768px) { | ||
.control-button { | ||
width: 100%; | ||
min-width: auto; | ||
} | ||
} | ||
</style> |
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
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.
Uh oh!
There was an error while loading. Please reload this page.