Skip to content

Commit a69a86a

Browse files
committed
extra check to delete account
1 parent 60acacf commit a69a86a

File tree

3 files changed

+149
-4
lines changed

3 files changed

+149
-4
lines changed

ui/public/locales/en.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,7 @@
855855
"label.endipv6": "IPv6 end IP",
856856
"label.endpoint": "Endpoint",
857857
"label.endport": "End port",
858+
"label.enter.account.name": "Enter the account name",
858859
"label.enter.code": "Enter 2FA code to verify",
859860
"label.enter.static.pin": "Enter static PIN to verify",
860861
"label.enter.token": "Enter token",
@@ -2719,7 +2720,11 @@
27192720
"message.dedicating.host": "Dedicating host...",
27202721
"message.dedicating.pod": "Dedicating pod...",
27212722
"message.dedicating.zone": "Dedicating zone...",
2722-
"message.delete.account": "Please confirm that you want to delete this Account.",
2723+
"message.delete.account.confirm": "Please confirm that you want to delete this account by entering the name of the account below.",
2724+
"message.delete.account.failed": "Delete account failed",
2725+
"message.delete.account.processing": "Deleting account",
2726+
"message.delete.account.success": "Successfully deleted account",
2727+
"message.delete.account.warning": "Deleting this account will delete all of the instances, volumes and snapshots associated with the account.",
27232728
"message.delete.acl.processing": "Removing ACL rule...",
27242729
"message.delete.acl.rule": "Remove ACL rule",
27252730
"message.delete.acl.rule.failed": "Failed to remove ACL rule.",
@@ -2806,6 +2811,7 @@
28062811
"message.enabling.security.group.provider": "Enabling security group provider",
28072812
"message.enter.valid.nic.ip": "Please enter a valid IP address for NIC",
28082813
"message.error.access.key": "Please enter access key.",
2814+
"message.error.account.delete.name.mismatch": "Name entered doesn't match the account name.",
28092815
"message.error.add.guest.network": "Either IPv4 fields or IPv6 fields need to be filled when adding a guest Network.",
28102816
"message.error.add.interface.static.route": "Adding interface Static Route failed",
28112817
"message.error.add.logical.router": "Adding Logical Router failed",

ui/src/config/section/account.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ export default {
225225
message: 'message.delete.account',
226226
dataView: true,
227227
disabled: (record, store) => {
228-
return record.id !== 'undefined' && store.userInfo.accountid === record.id
228+
return (record.id !== 'undefined' && store.userInfo.accountid === record.id) || record.state !== 'disabled'
229229
},
230-
groupAction: true,
230+
231231
popup: true,
232-
groupMap: (selection) => { return selection.map(x => { return { id: x } }) }
232+
component: shallowRef(defineAsyncComponent(() => import('@/views/iam/DeleteAccount.vue')))
233233
}
234234
]
235235
}

ui/src/views/iam/DeleteAccount.vue

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
<template>
19+
<a-form
20+
class="form"
21+
:ref="formRef"
22+
:model="form"
23+
:rules="rules"
24+
layout="vertical"
25+
@finish="handleSubmit"
26+
v-ctrl-enter="handleSubmit"
27+
>
28+
<div style="margin-bottom: 10px">
29+
<a-alert type="warning">
30+
<template #message>
31+
<div v-html="$t('message.delete.account.warning')"></div>
32+
</template>
33+
</a-alert>
34+
</div>
35+
<div style="margin-bottom: 10px">
36+
<a-alert>
37+
<template #message>
38+
<div v-html="$t('message.delete.account.confirm')"></div>
39+
</template>
40+
</a-alert>
41+
</div>
42+
<a-form-item name="name" ref="name">
43+
<a-input
44+
v-model:value="form.name"
45+
:placeholder="$t('label.enter.account.name')"
46+
style="width: 100%"/>
47+
</a-form-item>
48+
<p v-if="error" class="error">{{ error }}</p>
49+
<div :span="24" class="actions">
50+
<a-button @click="closeModal">{{ $t('label.cancel') }}</a-button>
51+
<a-button type="primary" ref="submit" @click="handleSubmit">{{ $t('label.ok') }}</a-button>
52+
</div>
53+
</a-form>
54+
</template>
55+
56+
<script>
57+
import { ref, reactive } from 'vue'
58+
import { api } from '@/api'
59+
export default {
60+
name: 'DeleteAccount',
61+
props: {
62+
resource: {
63+
type: Object,
64+
required: true
65+
}
66+
},
67+
data () {
68+
return {
69+
error: ''
70+
}
71+
},
72+
created () {
73+
this.initForm()
74+
},
75+
methods: {
76+
initForm () {
77+
this.formRef = ref()
78+
this.form = reactive({
79+
})
80+
this.rules = reactive({
81+
name: [{ required: true, message: this.$t('label.required') }]
82+
})
83+
},
84+
closeModal () {
85+
this.$emit('close-action')
86+
},
87+
handleSubmit (e) {
88+
e.preventDefault()
89+
this.formRef.value.validate().then(async () => {
90+
if (this.form.name !== this.resource.name) {
91+
this.error = `${this.$t('message.error.account.delete.name.mismatch')}`
92+
return
93+
}
94+
api('deleteAccount', {
95+
id: this.resource.id
96+
}).then(response => {
97+
this.$pollJob({
98+
jobId: response.deleteaccountresponse.jobid,
99+
title: this.$t('label.action.delete.account'),
100+
description: this.resource.id,
101+
successMessage: `${this.$t('message.delete.account.success')} - ${this.resource.name}`,
102+
errorMessage: `${this.$t('message.delete.account.failed')} - ${this.resource.name}`,
103+
loadingMessage: `${this.$t('message.delete.account.processing')} - ${this.resource.name}`,
104+
catchMessage: this.$t('error.fetching.async.job.result')
105+
})
106+
this.closeModal()
107+
}).catch(error => {
108+
this.$notifyError(error)
109+
})
110+
}).catch((error) => {
111+
this.formRef.value.scrollToField(error.errorFields[0].name)
112+
})
113+
}
114+
}
115+
}
116+
</script>
117+
118+
<style lang="scss" scoped>
119+
.form {
120+
width: 80vw;
121+
@media (min-width: 500px) {
122+
width: 400px;
123+
}
124+
}
125+
.actions {
126+
display: flex;
127+
justify-content: flex-end;
128+
margin-top: 20px;
129+
button {
130+
&:not(:last-child) {
131+
margin-right: 10px;
132+
}
133+
}
134+
}
135+
.error {
136+
color: red;
137+
margin-top: 10px;
138+
}
139+
</style>

0 commit comments

Comments
 (0)