mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
227 lines
6.0 KiB
227 lines
6.0 KiB
3 years ago
|
<template>
|
||
|
<div>
|
||
3 years ago
|
<v-toolbar flat height="38" class="mt-5">
|
||
3 years ago
|
<v-spacer />
|
||
3 years ago
|
|
||
3 years ago
|
<x-btn
|
||
3 years ago
|
v-ge="['roles', 'reload']"
|
||
3 years ago
|
outlined
|
||
|
tooltip="Reload API tokens"
|
||
|
color="primary"
|
||
|
small
|
||
|
:disabled="loading"
|
||
|
@click="loadApiTokens"
|
||
|
@click.prevent
|
||
|
>
|
||
|
<v-icon small left>
|
||
|
refresh
|
||
|
</v-icon>
|
||
3 years ago
|
<!-- Reload -->
|
||
3 years ago
|
{{ $t("general.reload") }}
|
||
3 years ago
|
</x-btn>
|
||
|
<x-btn
|
||
|
v-if="_isUIAllowed('newUser')"
|
||
3 years ago
|
v-ge="['roles', 'add new']"
|
||
3 years ago
|
outlined
|
||
|
tooltip="Generate new API token"
|
||
3 years ago
|
color="primary"
|
||
|
small
|
||
|
:disabled="loading"
|
||
3 years ago
|
@click="showNewTokenDlg"
|
||
3 years ago
|
>
|
||
|
<v-icon small left>
|
||
|
mdi-plus
|
||
|
</v-icon>
|
||
3 years ago
|
<!--New Token-->
|
||
3 years ago
|
{{ $t("activity.newToken") }}
|
||
3 years ago
|
</x-btn>
|
||
|
</v-toolbar>
|
||
|
|
||
|
<v-container fluid>
|
||
3 years ago
|
<v-simple-table
|
||
|
v-if="tokens"
|
||
|
dense
|
||
|
class="mx-auto caption text-center"
|
||
|
style="max-width: 700px"
|
||
|
>
|
||
3 years ago
|
<thead>
|
||
3 years ago
|
<tr class="">
|
||
|
<th class="caption text-center">
|
||
3 years ago
|
<!--Description-->
|
||
3 years ago
|
{{ $t("labels.description") }}
|
||
3 years ago
|
</th>
|
||
|
<th class="caption text-center">
|
||
3 years ago
|
<!--Token-->
|
||
3 years ago
|
{{ $t("labels.token") }}
|
||
3 years ago
|
</th>
|
||
|
<th class="caption text-center">
|
||
3 years ago
|
<!--Actions-->
|
||
3 years ago
|
{{ $t("labels.action") }}
|
||
3 years ago
|
</th>
|
||
|
</tr>
|
||
3 years ago
|
</thead>
|
||
3 years ago
|
|
||
|
<tr v-if="!tokens.length">
|
||
|
<td colspan="3">
|
||
3 years ago
|
<div class="text-center caption grey--text">
|
||
3 years ago
|
No tokens available
|
||
|
</div>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
3 years ago
|
<tr v-for="(token, i) in tokens" :key="i">
|
||
3 years ago
|
<td class="caption text-center">
|
||
|
{{ token.description }}
|
||
|
</td>
|
||
3 years ago
|
<td class="caption text-center">
|
||
|
<div class="d-flex justify-center">
|
||
|
<span v-if="token.show">{{ token.token }}</span>
|
||
|
<span v-else>****************************************</span>
|
||
|
</div>
|
||
|
</td>
|
||
|
<td class="caption">
|
||
3 years ago
|
<x-icon
|
||
|
x-small
|
||
|
icon.class="ml-2"
|
||
3 years ago
|
:tooltip="`${token.show ? 'Hide' : 'Show'} API token`"
|
||
|
@click="$set(token, 'show', !token.show)"
|
||
3 years ago
|
>
|
||
3 years ago
|
{{ token.show ? "visibility_off" : "visibility" }}
|
||
3 years ago
|
</x-icon>
|
||
|
|
||
|
<!-- <v-spacer></v-spacer>-->
|
||
3 years ago
|
<x-icon
|
||
|
x-small
|
||
|
icon.class="ml-2"
|
||
|
tooltip="Copy token to clipboard"
|
||
|
@click="copyToken(token.token)"
|
||
|
>
|
||
3 years ago
|
mdi-content-copy
|
||
|
</x-icon>
|
||
|
<x-icon
|
||
3 years ago
|
tooltip="Remove API token"
|
||
|
class="ml-2"
|
||
|
color="error"
|
||
|
x-small
|
||
3 years ago
|
@click.prevent.stop="deleteToken(token)"
|
||
3 years ago
|
>
|
||
|
mdi-delete-outline
|
||
3 years ago
|
</x-icon>
|
||
|
</td>
|
||
|
</tr>
|
||
3 years ago
|
<!-- <tr>
|
||
3 years ago
|
<td colspan="3" class="text-center">
|
||
3 years ago
|
<x-btn tooltip="Generate new api token" outlined x-small color="primary" @click="showNewTokenDlg">
|
||
3 years ago
|
<v-icon>mdi-plus</v-icon>
|
||
3 years ago
|
<!–Add New Token–>
|
||
3 years ago
|
{{ $t('activity.newToken') }}
|
||
3 years ago
|
</x-btn>
|
||
|
</td>
|
||
3 years ago
|
</tr>-->
|
||
3 years ago
|
</v-simple-table>
|
||
|
</v-container>
|
||
|
|
||
|
<v-dialog v-model="newTokenDialog" width="400">
|
||
3 years ago
|
<v-card class="px-15 py-5" style="min-height: 100%">
|
||
3 years ago
|
<h4 class="text-center text-capitalize mt-2 d-100 display-1">
|
||
|
<template>Generate Token</template>
|
||
|
</h4>
|
||
|
|
||
|
<v-form v-model="valid" @submit.prevent="generateToken">
|
||
|
<v-row class="mt-4">
|
||
|
<v-col cols="12">
|
||
|
<v-text-field
|
||
3 years ago
|
v-model="tokenObj.description"
|
||
3 years ago
|
filled
|
||
|
dense
|
||
3 years ago
|
:label="$t('labels.description')"
|
||
3 years ago
|
/>
|
||
3 years ago
|
</v-col>
|
||
|
</v-row>
|
||
|
</v-form>
|
||
|
|
||
|
<v-card-actions class="justify-center">
|
||
3 years ago
|
<x-btn
|
||
3 years ago
|
v-ge="['rows', 'save']"
|
||
3 years ago
|
tooltip="Generate new api token"
|
||
|
color="primary"
|
||
|
btn.class="mt-5 mb-3 pr-5"
|
||
|
@click="generateToken"
|
||
3 years ago
|
>
|
||
|
Generate
|
||
|
</x-btn>
|
||
|
</v-card-actions>
|
||
|
</v-card>
|
||
|
</v-dialog>
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
3 years ago
|
import { copyTextToClipboard } from '~/helpers/xutils'
|
||
|
|
||
3 years ago
|
export default {
|
||
3 years ago
|
name: 'ApiTokens',
|
||
3 years ago
|
data: () => ({
|
||
|
tokens: null,
|
||
|
newTokenDialog: false,
|
||
|
tokenObj: {},
|
||
|
valid: true
|
||
|
}),
|
||
3 years ago
|
created() {
|
||
3 years ago
|
this.loadApiTokens()
|
||
3 years ago
|
},
|
||
|
methods: {
|
||
3 years ago
|
showNewTokenDlg() {
|
||
|
this.newTokenDialog = true
|
||
3 years ago
|
this.$e('c:api-token:generate')
|
||
3 years ago
|
},
|
||
3 years ago
|
copyToken(token) {
|
||
3 years ago
|
copyTextToClipboard(token)
|
||
3 years ago
|
this.$toast.info('Copied to clipboard').goAway(1000)
|
||
3 years ago
|
|
||
3 years ago
|
this.$e('c:api-token:copy')
|
||
3 years ago
|
},
|
||
3 years ago
|
async loadApiTokens() {
|
||
3 years ago
|
this.tokens = await this.$api.apiToken.list(
|
||
|
this.$store.state.project.projectId
|
||
|
)
|
||
3 years ago
|
},
|
||
3 years ago
|
async generateToken() {
|
||
3 years ago
|
try {
|
||
3 years ago
|
this.newTokenDialog = false
|
||
3 years ago
|
await this.$api.apiToken.create(
|
||
|
this.$store.state.project.projectId,
|
||
|
this.tokenObj
|
||
|
)
|
||
3 years ago
|
this.$toast.success('Token generated successfully').goAway(3000)
|
||
|
this.tokenObj = {}
|
||
|
await this.loadApiTokens()
|
||
3 years ago
|
} catch (e) {
|
||
3 years ago
|
console.log(e)
|
||
3 years ago
|
this.$toast.error(e.message).goAway(3000)
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
3 years ago
|
this.$e('a:api-token:generate')
|
||
3 years ago
|
},
|
||
3 years ago
|
async deleteToken(item) {
|
||
3 years ago
|
try {
|
||
3 years ago
|
await this.$api.apiToken.delete(
|
||
|
this.$store.state.project.projectId,
|
||
|
item.token
|
||
|
)
|
||
3 years ago
|
// this.tokens = //await this.$store.dispatch('sqlMgr/ActSqlOp', [null, 'xcApiTokenDelete', { id: item.id }])
|
||
3 years ago
|
this.$toast.success('Token deleted successfully').goAway(3000)
|
||
|
await this.loadApiTokens()
|
||
3 years ago
|
} catch (e) {
|
||
3 years ago
|
console.log(e)
|
||
3 years ago
|
this.$toast.error(e.message).goAway(3000)
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
3 years ago
|
this.$e('a:api-token:delete')
|
||
3 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
</script>
|
||
|
|
||
3 years ago
|
<style scoped></style>
|