-
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #768 from nscuro/apikey-dates-and-comment
Update API key view to include created, last used, and comment
- Loading branch information
Showing
4 changed files
with
197 additions
and
1 deletion.
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
110 changes: 110 additions & 0 deletions
110
src/views/administration/accessmanagement/ApiKeyListGroupItem.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,110 @@ | ||
<template> | ||
<b-list-group-item class="flex-column align-items-start"> | ||
<div class="d-flex w-100 justify-content-between"> | ||
<span class="text-monospace">{{ apiKey.key }}</span> | ||
<div class="d-flex"> | ||
<b-button | ||
size="sm" | ||
class="action-icon" | ||
v-b-tooltip.hover | ||
v-b-modal="`editApiKeyCommentModal-${keyId}`" | ||
:title="$t('admin.edit_api_key_comment')" | ||
> | ||
<span class="fa fa-edit"></span> | ||
</b-button> | ||
<b-button | ||
size="sm" | ||
class="action-icon ml-3" | ||
v-on:click="$emit('removeClicked')" | ||
v-b-tooltip.hover | ||
:title="$t('admin.remove_api_key')" | ||
> | ||
<span class="fa fa-trash-o"></span> | ||
</b-button> | ||
<edit-api-key-comment-modal | ||
:key-id="this.keyId" | ||
:api-key="this.apiKey" | ||
/> | ||
</div> | ||
</div> | ||
<p class="mt-2 font-weight-light"> | ||
<em>{{ comment }}</em> | ||
</p> | ||
<hr /> | ||
<div class="d-flex w-100 justify-content-between text-muted"> | ||
<small :title="$t('admin.api_key_created_tooltip')" | ||
>Created: {{ createdTimestamp }}</small | ||
> | ||
<small :title="$t('admin.api_key_last_used_tooltip')" | ||
>Last Used: {{ lastUsedTimestamp }}</small | ||
> | ||
</div> | ||
</b-list-group-item> | ||
</template> | ||
|
||
<script> | ||
import MurmurHash2 from 'imurmurhash'; | ||
import common from '../../../shared/common'; | ||
import EditApiKeyCommentModal from './EditApiKeyCommentModal.vue'; | ||
export default { | ||
props: { | ||
apiKey: Object, | ||
variant: String, | ||
href: String, | ||
}, | ||
components: { | ||
EditApiKeyCommentModal, | ||
}, | ||
computed: { | ||
keyId: () => { | ||
return MurmurHash2(this.apiKey.key).result(); | ||
}, | ||
comment: () => { | ||
return this.apiKey.comment ? this.apiKey.comment : 'No comment'; | ||
}, | ||
createdTimestamp: () => { | ||
return this.apiKey.created | ||
? common.formatTimestamp(this.apiKey.created, true) | ||
: 'N/A'; | ||
}, | ||
lastUsedTimestamp: () => { | ||
return this.apiKey.lastUsed | ||
? common.formatTimestamp(this.apiKey.lastUsed, true) | ||
: 'N/A'; | ||
}, | ||
}, | ||
}; | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.list-group-item .form-group { | ||
padding-top: 0; | ||
padding-bottom: 0; | ||
margin-top: 0; | ||
margin-bottom: 0; | ||
} | ||
.action-icon { | ||
padding: 0; | ||
margin: 0; | ||
border: 0; | ||
background-color: transparent; | ||
} | ||
.action-icon .fa { | ||
font-size: 1.2rem; | ||
} | ||
.action-icon .fa-edit { | ||
color: var(--secondary); | ||
} | ||
.action-icon .fa-trash-o { | ||
color: var(--danger); | ||
} | ||
.list-group-item:last-child { | ||
margin-bottom: -1px; | ||
} | ||
</style> |
78 changes: 78 additions & 0 deletions
78
src/views/administration/accessmanagement/EditApiKeyCommentModal.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,78 @@ | ||
<template> | ||
<b-modal | ||
:id="`editApiKeyCommentModal-${keyId}`" | ||
size="md" | ||
hide-header-close | ||
no-stacking | ||
:title="$t('admin.edit_api_key_comment')" | ||
> | ||
<b-input-group-form-input | ||
id="name-input" | ||
input-group-size="mb-3" | ||
type="text" | ||
v-model="comment" | ||
lazy="true" | ||
feedback="true" | ||
autofocus="false" | ||
:label="$t('admin.api_key_comment')" | ||
/> | ||
|
||
<template v-slot:modal-footer="{ cancel }"> | ||
<b-button size="md" variant="secondary" @click="cancel()">{{ | ||
$t('message.close') | ||
}}</b-button> | ||
<b-button size="md" variant="primary" @click="updateComment()">{{ | ||
$t('message.update') | ||
}}</b-button> | ||
</template> | ||
</b-modal> | ||
</template> | ||
|
||
<script> | ||
import permissionsMixin from '../../../mixins/permissionsMixin'; | ||
import BInputGroupFormInput from '../../../forms/BInputGroupFormInput'; | ||
export default { | ||
mixins: [permissionsMixin], | ||
components: { | ||
BInputGroupFormInput, | ||
}, | ||
props: { | ||
keyId: String, | ||
apiKey: Object, | ||
}, | ||
data() { | ||
return { | ||
comment: null, | ||
}; | ||
}, | ||
mounted() { | ||
this.comment = this.apiKey.comment; | ||
}, | ||
methods: { | ||
updateComment: () => { | ||
this.axios | ||
.post( | ||
`${this.$api.BASE_URL}/${this.$api.URL_TEAM}/key/${this.apiKey.key}/comment`, | ||
this.comment, | ||
{ | ||
headers: { | ||
'Content-Type': 'text/plain', | ||
}, | ||
}, | ||
) | ||
.then((response) => { | ||
this.apiKey.comment = response.data.comment; | ||
this.$toastr.s(this.$t('admin.api_key_comment_updated')); | ||
this.$root.$emit( | ||
'bv::hide::modal', | ||
`editApiKeyCommentModal-${this.keyId}`, | ||
); | ||
}); | ||
}, | ||
resetValues: () => { | ||
this.comment = null; | ||
}, | ||
}, | ||
}; | ||
</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