Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webui): display authentication activity
closes #160
- Loading branch information
Showing
7 changed files
with
327 additions
and
126 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
komga-webui/src/components/AuthenticationActivityTable.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,103 @@ | ||
<template> | ||
<v-data-table | ||
:headers="headers" | ||
:items="items" | ||
:options.sync="options" | ||
:server-items-length="totalItems" | ||
:loading="loading" | ||
sort-by="dateTime" | ||
:sort-desc="true" | ||
multi-sort | ||
class="elevation-1" | ||
:footer-props="{ | ||
itemsPerPageOptions: [20, 50, 100] | ||
}" | ||
> | ||
<template v-slot:item.success="{ item }"> | ||
<v-icon v-if="item.success" color="success">mdi-check-circle</v-icon> | ||
<v-icon v-else color="error">mdi-alert-circle</v-icon> | ||
</template> | ||
|
||
<template v-slot:item.dateTime="{ item }"> | ||
{{ | ||
new Intl.DateTimeFormat($i18n.locale, { | ||
dateStyle: 'medium', | ||
timeStyle: 'short' | ||
}).format(new Date(item.dateTime)) | ||
}} | ||
</template> | ||
</v-data-table> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import Vue from 'vue' | ||
export default Vue.extend({ | ||
name: 'AuthenticationActivityTable', | ||
data: function () { | ||
return { | ||
items: [] as AuthenticationActivityDto[], | ||
totalItems: 0, | ||
loading: true, | ||
options: {} as any, | ||
} | ||
}, | ||
props: { | ||
forMe: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
}, | ||
watch: { | ||
options: { | ||
handler() { | ||
this.loadData() | ||
}, | ||
deep: true, | ||
}, | ||
}, | ||
computed: { | ||
headers(): object[] { | ||
const headers = [] | ||
if (!this.forMe) headers.push({text: this.$t('authentication_activity.email').toString(), value: 'email'}) | ||
headers.push( | ||
{text: this.$t('authentication_activity.ip').toString(), value: 'ip'}, | ||
{text: this.$t('authentication_activity.user_agent').toString(), value: 'userAgent'}, | ||
{text: this.$t('authentication_activity.success').toString(), value: 'success'}, | ||
{text: this.$t('authentication_activity.error').toString(), value: 'error'}, | ||
{text: this.$t('authentication_activity.datetime').toString(), value: 'dateTime'}, | ||
) | ||
return headers | ||
}, | ||
}, | ||
async mounted() { | ||
this.loadData() | ||
}, | ||
methods: { | ||
async loadData() { | ||
this.loading = true | ||
const {sortBy, sortDesc, page, itemsPerPage} = this.options | ||
const pageRequest = { | ||
page: page - 1, | ||
size: itemsPerPage, | ||
sort: [], | ||
} as PageRequest | ||
for (let i = 0; i < sortBy.length; i++) { | ||
pageRequest.sort!!.push(`${sortBy[i]},${sortDesc[i] ? 'desc' : 'asc'}`) | ||
} | ||
let itemsPage | ||
if (!this.forMe) itemsPage = await this.$komgaUsers.getAuthenticationActivity(pageRequest) | ||
else itemsPage = await this.$komgaUsers.getMyAuthenticationActivity(pageRequest) | ||
this.totalItems = itemsPage.totalElements | ||
this.items = itemsPage.content | ||
this.loading = false | ||
}, | ||
}, | ||
}) | ||
</script> |
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,138 @@ | ||
<template> | ||
<div style="position: relative"> | ||
<v-list | ||
elevation="3" | ||
> | ||
<div v-for="(u, index) in users" :key="index"> | ||
<v-list-item | ||
> | ||
<v-tooltip bottom> | ||
<template v-slot:activator="{ on }"> | ||
<v-list-item-icon v-on="on"> | ||
<v-icon v-if="u.roles.includes(UserRoles.ADMIN)" color="red">mdi-account-star</v-icon> | ||
<v-icon v-else>mdi-account</v-icon> | ||
</v-list-item-icon> | ||
</template> | ||
<span>{{ | ||
u.roles.includes(UserRoles.ADMIN) ? $t('settings_user.role_administrator') : $t('settings_user.role_user') | ||
}}</span> | ||
</v-tooltip> | ||
|
||
<v-list-item-content> | ||
<v-list-item-title> | ||
{{ u.email }} | ||
</v-list-item-title> | ||
</v-list-item-content> | ||
|
||
<v-list-item-action> | ||
<v-tooltip bottom> | ||
<template v-slot:activator="{ on }"> | ||
<v-btn icon @click="editSharedLibraries(u)" :disabled="u.roles.includes(UserRoles.ADMIN)" | ||
v-on="on"> | ||
<v-icon>mdi-book-lock</v-icon> | ||
</v-btn> | ||
</template> | ||
<span>{{ $t('settings_user.edit_shared_libraries') }}</span> | ||
</v-tooltip> | ||
</v-list-item-action> | ||
|
||
<v-list-item-action> | ||
<v-tooltip bottom> | ||
<template v-slot:activator="{ on }"> | ||
<v-btn icon @click="editUser(u)" :disabled="u.id === me.id" v-on="on"> | ||
<v-icon>mdi-pencil</v-icon> | ||
</v-btn> | ||
</template> | ||
<span>{{ $t('settings_user.edit_user') }}</span> | ||
</v-tooltip> | ||
</v-list-item-action> | ||
|
||
<v-list-item-action> | ||
<v-btn icon @click="promptDeleteUser(u)" | ||
:disabled="u.id === me.id" | ||
> | ||
<v-icon>mdi-delete</v-icon> | ||
</v-btn> | ||
</v-list-item-action> | ||
</v-list-item> | ||
|
||
<v-divider v-if="index !== users.length-1"/> | ||
</div> | ||
</v-list> | ||
|
||
<v-btn fab absolute bottom color="primary" | ||
:right="!$vuetify.rtl" | ||
:left="$vuetify.rtl" | ||
class="mx-6" | ||
small | ||
:to="{name: 'settings-users-add'}"> | ||
<v-icon>mdi-plus</v-icon> | ||
</v-btn> | ||
|
||
<user-shared-libraries-edit-dialog v-model="modalEditSharedLibraries" | ||
:user="userToEditSharedLibraries" | ||
/> | ||
|
||
<user-edit-dialog v-model="modalEditUser" | ||
:user="userToEdit" | ||
/> | ||
|
||
<user-delete-dialog v-model="modalDeleteUser" | ||
:user="userToDelete"> | ||
</user-delete-dialog> | ||
|
||
<router-view/> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import UserDeleteDialog from '@/components/dialogs/UserDeleteDialog.vue' | ||
import UserEditDialog from '@/components/dialogs/UserEditDialog.vue' | ||
import UserSharedLibrariesEditDialog from '@/components/dialogs/UserSharedLibrariesEditDialog.vue' | ||
import {UserRoles} from '@/types/enum-users' | ||
import Vue from 'vue' | ||
export default Vue.extend({ | ||
name: 'UsersList', | ||
components: {UserSharedLibrariesEditDialog, UserDeleteDialog, UserEditDialog}, | ||
data: () => ({ | ||
UserRoles, | ||
modalAddUser: false, | ||
modalDeleteUser: false, | ||
userToDelete: {} as UserDto, | ||
modalEditSharedLibraries: false, | ||
userToEditSharedLibraries: {} as UserWithSharedLibrariesDto, | ||
modalEditUser: false, | ||
userToEdit: {} as UserDto, | ||
}), | ||
computed: { | ||
users(): UserWithSharedLibrariesDto[] { | ||
return this.$store.state.komgaUsers.users | ||
}, | ||
me(): UserDto { | ||
return this.$store.state.komgaUsers.me | ||
}, | ||
}, | ||
async mounted() { | ||
await this.$store.dispatch('getAllUsers') | ||
}, | ||
methods: { | ||
promptDeleteUser(user: UserDto) { | ||
this.userToDelete = user | ||
this.modalDeleteUser = true | ||
}, | ||
editSharedLibraries(user: UserWithSharedLibrariesDto) { | ||
this.userToEditSharedLibraries = user | ||
this.modalEditSharedLibraries = true | ||
}, | ||
editUser(user: UserDto) { | ||
this.userToEdit = user | ||
this.modalEditUser = true | ||
}, | ||
}, | ||
}) | ||
</script> | ||
|
||
<style scoped> | ||
</style> |
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
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.