forked from chatwoot/chatwoot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: init auditlogs ui * chore: add api * fix: action * chore: add action,username,time * feat: add pagination support * chore: format time * chore: refactor * chore: refactor auditlogs api response * chore: update icon * chore: rubocop fixes * Fixes the way meta is handled in store * Fixes meta not appearing issue --------- Co-authored-by: Sojan Jose <[email protected]> Co-authored-by: Nithin David Thomas <[email protected]>
- Loading branch information
1 parent
80dcd17
commit 9e2f991
Showing
15 changed files
with
314 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -62,5 +62,8 @@ test/cypress/videos/* | |
/config/*.enc | ||
|
||
.vscode/settings.json | ||
.vscode | ||
|
||
# yalc for local testing | ||
.yalc | ||
yalc.lock |
This file contains 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,16 @@ | ||
/* global axios */ | ||
|
||
import ApiClient from './ApiClient'; | ||
|
||
class AuditLogs extends ApiClient { | ||
constructor() { | ||
super('audit_logs', { accountScoped: true }); | ||
} | ||
|
||
get({ page }) { | ||
const url = page ? `${this.url}?page=${page}` : this.url; | ||
return axios.get(url); | ||
} | ||
} | ||
|
||
export default new AuditLogs(); |
This file contains 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 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,24 @@ | ||
{ | ||
"AUDIT_LOGS": { | ||
"HEADER": "Audit Logs", | ||
"HEADER_BTN_TXT": "Add Audit Logs", | ||
"LOADING": "Fetching Audit Logs", | ||
"SEARCH_404": "There are no items matching this query", | ||
"SIDEBAR_TXT": "<p><b>Audit Logs</b> </p><p> Audit Logs are trails for events and actions in a Chatwoot System. </p>", | ||
"LIST": { | ||
"404": "There are no Audit Logs available in this account.", | ||
"TITLE": "Manage Audit Logs", | ||
"DESC": "Audit Logs are trails for events and actions in a Chatwoot System.", | ||
"TABLE_HEADER": [ | ||
"User", | ||
"Action", | ||
"IP Address", | ||
"Time" | ||
] | ||
}, | ||
"API": { | ||
"SUCCESS_MESSAGE": "AuditLogs retrieved successfully", | ||
"ERROR_MESSAGE": "Could not connect to Woot Server, Please try again later" | ||
} | ||
} | ||
} |
This file contains 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 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
107 changes: 107 additions & 0 deletions
107
app/javascript/dashboard/routes/dashboard/settings/auditlogs/Index.vue
This file contains 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,107 @@ | ||
<template> | ||
<div class="column content-box"> | ||
<!-- List Audit Logs --> | ||
<div class="row"> | ||
<div class="small-8 columns with-right-space "> | ||
<p | ||
v-if="!uiFlags.fetchingList && !records.length" | ||
class="no-items-error-message" | ||
> | ||
{{ $t('AUDIT_LOGS.LIST.404') }} | ||
</p> | ||
<woot-loading-state | ||
v-if="uiFlags.fetchingList" | ||
:message="$t('AUDIT_LOGS.LOADING')" | ||
/> | ||
|
||
<table | ||
v-if="!uiFlags.fetchingList && records.length" | ||
class="woot-table" | ||
> | ||
<thead> | ||
<!-- Header --> | ||
<th | ||
v-for="thHeader in $t('AUDIT_LOGS.LIST.TABLE_HEADER')" | ||
:key="thHeader" | ||
> | ||
{{ thHeader }} | ||
</th> | ||
</thead> | ||
<tbody> | ||
<tr v-for="auditLogItem in records" :key="auditLogItem.id"> | ||
<td class="wrap-break-words">{{ auditLogItem.username }}</td> | ||
<td class="wrap-break-words"> | ||
{{ auditLogItem.auditable_type }}.{{ auditLogItem.action }} | ||
</td> | ||
<td class="remote-address"> | ||
{{ auditLogItem.remote_address }} | ||
</td> | ||
<td class="wrap-break-words"> | ||
{{ dynamicTime(auditLogItem.created_at) }} | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
<table-footer | ||
:current-page="Number(meta.currentPage)" | ||
:total-count="meta.totalEntries" | ||
:page-size="meta.perPage" | ||
@page-change="onPageChange" | ||
/> | ||
</div> | ||
</template> | ||
<script> | ||
import { mapGetters } from 'vuex'; | ||
import TableFooter from 'dashboard/components/widgets/TableFooter'; | ||
import timeMixin from 'dashboard/mixins/time'; | ||
import alertMixin from 'shared/mixins/alertMixin'; | ||
export default { | ||
components: { | ||
TableFooter, | ||
}, | ||
mixins: [alertMixin, timeMixin], | ||
data() { | ||
return { | ||
loading: {}, | ||
auditLogsAPI: { | ||
message: '', | ||
}, | ||
}; | ||
}, | ||
computed: { | ||
...mapGetters({ | ||
records: 'auditlogs/getAuditLogs', | ||
uiFlags: 'auditlogs/getUIFlags', | ||
meta: 'auditlogs/getMeta', | ||
}), | ||
}, | ||
mounted() { | ||
// Fetch API Call | ||
this.$store.dispatch('auditlogs/fetch', { page: 1 }); | ||
}, | ||
methods: { | ||
onPageChange(page) { | ||
window.history.pushState({}, null, `${this.$route.path}?page=${page}`); | ||
try { | ||
this.$store.dispatch('auditlogs/fetch', { page }); | ||
} catch (error) { | ||
const errorMessage = | ||
error?.message || this.$t('AUDIT_LOGS.API.ERROR_MESSAGE'); | ||
this.showAlert(errorMessage); | ||
} | ||
}, | ||
}, | ||
}; | ||
</script> | ||
<style scoped> | ||
.remote-address { | ||
width: 14rem; | ||
} | ||
.wrap-break-words { | ||
word-break: break-all; | ||
white-space: normal; | ||
} | ||
</style> |
30 changes: 30 additions & 0 deletions
30
app/javascript/dashboard/routes/dashboard/settings/auditlogs/audit.routes.js
This file contains 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,30 @@ | ||
import SettingsContent from '../Wrapper'; | ||
import AuditLogsHome from './Index'; | ||
import { frontendURL } from '../../../../helper/URLHelper'; | ||
|
||
export default { | ||
routes: [ | ||
{ | ||
path: frontendURL('accounts/:accountId/settings/audit-log'), | ||
component: SettingsContent, | ||
props: { | ||
headerTitle: 'AUDIT_LOGS.HEADER', | ||
icon: 'key', | ||
showNewButton: false, | ||
}, | ||
children: [ | ||
{ | ||
path: '', | ||
name: 'auditlogs_wrapper', | ||
redirect: 'list', | ||
}, | ||
{ | ||
path: 'list', | ||
name: 'auditlogs_list', | ||
roles: ['administrator'], | ||
component: AuditLogsHome, | ||
}, | ||
], | ||
}, | ||
], | ||
}; |
This file contains 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 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 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,79 @@ | ||
import * as MutationHelpers from 'shared/helpers/vuex/mutationHelpers'; | ||
import * as types from '../mutation-types'; | ||
import AuditLogsAPI from '../../api/auditLogs'; | ||
import { throwErrorMessage } from 'dashboard/store/utils/api'; | ||
|
||
const state = { | ||
records: [], | ||
meta: { | ||
currentPage: 1, | ||
perPage: 15, | ||
totalEntries: 0, | ||
}, | ||
uiFlags: { | ||
fetchingList: false, | ||
}, | ||
}; | ||
|
||
const getters = { | ||
getAuditLogs(_state) { | ||
return _state.records; | ||
}, | ||
getUIFlags(_state) { | ||
return _state.uiFlags; | ||
}, | ||
getMeta(_state) { | ||
return _state.meta; | ||
}, | ||
}; | ||
|
||
const actions = { | ||
async fetch({ commit }, { page } = {}) { | ||
commit(types.default.SET_AUDIT_LOGS_UI_FLAG, { fetchingList: true }); | ||
try { | ||
const response = await AuditLogsAPI.get({ page }); | ||
const { audit_logs: logs = [] } = response.data; | ||
const { | ||
total_entries: totalEntries, | ||
per_page: perPage, | ||
current_page: currentPage, | ||
} = response.data; | ||
commit(types.default.SET_AUDIT_LOGS, logs); | ||
commit(types.default.SET_AUDIT_LOGS_META, { | ||
totalEntries, | ||
perPage, | ||
currentPage, | ||
}); | ||
commit(types.default.SET_AUDIT_LOGS_UI_FLAG, { fetchingList: false }); | ||
return logs; | ||
} catch (error) { | ||
commit(types.default.SET_AUDIT_LOGS_UI_FLAG, { fetchingList: false }); | ||
return throwErrorMessage(error); | ||
} | ||
}, | ||
}; | ||
|
||
const mutations = { | ||
[types.default.SET_AUDIT_LOGS_UI_FLAG](_state, data) { | ||
_state.uiFlags = { | ||
..._state.uiFlags, | ||
...data, | ||
}; | ||
}, | ||
|
||
[types.default.SET_AUDIT_LOGS]: MutationHelpers.set, | ||
[types.default.SET_AUDIT_LOGS_META](_state, data) { | ||
_state.meta = { | ||
..._state.meta, | ||
...data, | ||
}; | ||
}, | ||
}; | ||
|
||
export default { | ||
namespaced: true, | ||
state, | ||
getters, | ||
actions, | ||
mutations, | ||
}; |
This file contains 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 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 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.