usersettings: implement show and delete linked accounts

This commit is contained in:
Simone Gotti 2019-05-13 17:59:23 +02:00
parent 789d0f5fcd
commit 68da08e94d
2 changed files with 66 additions and 7 deletions

View File

@ -1,5 +1,35 @@
<template> <template>
<div> <div>
<h4 class="title is-4">Linked Accounts</h4>
<div class="message is-danger">
<div
class="message-body"
>Removing a Linked Account will also block all the projects that uses this Linked Account to access their remote repository</div>
</div>
<div v-if="user.linked_accounts">
<div class="item-list" v-for="(la, index) in user.linked_accounts" v-bind:key="index">
<nav class="level item">
<div class="level-left">
<div class="level-item">
<div>
<span class="name">{{la.remote_user_name}}</span>
<span class="remotesource-name">( {{laRemoteSourceName(la)}} )</span>
</div>
</div>
</div>
<div class="level-right">
<div class="level-item">
<button class="button is-primary" @click="deleteLinkedAccount(la)">Delete</button>
</div>
</div>
</nav>
</div>
<div v-if="deleteLinkedAccountError" class="message is-danger">
<div class="message-body">{{ deleteLinkedAccountError }}</div>
</div>
</div>
<div v-else>No linked accounts</div>
<hr>
<h4 class="title is-4">User Tokens</h4> <h4 class="title is-4">User Tokens</h4>
<div v-if="user.tokens"> <div v-if="user.tokens">
<div class="item-list" v-for="token in user.tokens" v-bind:key="token"> <div class="item-list" v-for="token in user.tokens" v-bind:key="token">
@ -38,7 +68,8 @@ import {
fetchCurrentUser, fetchCurrentUser,
fetchRemoteSources, fetchRemoteSources,
createUserToken, createUserToken,
deleteUserToken deleteUserToken,
deleteLinkedAccount
} from "@/util/data.js"; } from "@/util/data.js";
export default { export default {
@ -49,6 +80,7 @@ export default {
return { return {
createUserTokenError: null, createUserTokenError: null,
deleteUserTokenError: null, deleteUserTokenError: null,
deleteLinkedAccountError: null,
user: [], user: [],
remotesources: [], remotesources: [],
token: null, token: null,
@ -59,6 +91,7 @@ export default {
resetErrors() { resetErrors() {
this.createUserTokenError = null; this.createUserTokenError = null;
this.deleteUserTokenError = null; this.deleteUserTokenError = null;
this.deleteLinkedAccountError = null;
}, },
async fetchCurrentUser() { async fetchCurrentUser() {
let { data, error } = await fetchCurrentUser(); let { data, error } = await fetchCurrentUser();
@ -76,6 +109,14 @@ export default {
} }
this.remotesources = data; this.remotesources = data;
}, },
laRemoteSourceName(la) {
for (var i = 0; i < this.remotesources.length; i++) {
let rs = this.remotesources[i];
if (rs.id == la.remote_source_id) {
return rs.name;
}
}
},
async createUserToken() { async createUserToken() {
this.resetErrors(); this.resetErrors();
@ -91,6 +132,9 @@ export default {
this.newtokenname = null; this.newtokenname = null;
this.fetchCurrentUser(); this.fetchCurrentUser();
}, },
closeNewTokenNotification() {
this.token = null;
},
async deleteUserToken(tokenname) { async deleteUserToken(tokenname) {
this.resetErrors(); this.resetErrors();
@ -101,8 +145,15 @@ export default {
} }
this.fetchCurrentUser(); this.fetchCurrentUser();
}, },
closeNewTokenNotification() { async deleteLinkedAccount(la) {
this.token = null; this.resetErrors();
let { error } = await deleteLinkedAccount(this.user.username, la.id);
if (error) {
this.deleteLinkedAccountError = error;
return;
}
this.fetchCurrentUser();
} }
}, },
created: function() { created: function() {
@ -117,15 +168,15 @@ export default {
.item-list { .item-list {
.item { .item {
margin-bottom: 5px; border-bottom: 1px solid $grey-lighter;
border: 1px solid $grey-lighter;
cursor: pointer;
display: flex;
padding: 10px; padding: 10px;
} }
.name { .name {
font-weight: bold; font-weight: bold;
} }
.remotesource-name {
margin-left: 1rem;
}
} }
</style> </style>

View File

@ -124,6 +124,14 @@ export async function deleteUserToken(username, tokenname) {
return await fetch(apiurl(path), init) return await fetch(apiurl(path), init)
} }
export async function deleteLinkedAccount(username, laid) {
let path = "/users/" + username + "/linkedaccounts/" + laid
let init = {
method: "DELETE",
}
return await fetch(apiurl(path), init)
}
export async function restartRun(runid, fromStart) { export async function restartRun(runid, fromStart) {
let path = "/runs/" + runid + "/actions" let path = "/runs/" + runid + "/actions"
let init = { let init = {