Add a button to delete source if it has no more domains associated
This commit is contained in:
parent
2ca7fe83a2
commit
3efa233a7c
|
@ -179,6 +179,22 @@ func updateSource(_ *config.Options, req *RequestResources, body io.Reader) Resp
|
|||
}
|
||||
|
||||
func deleteSource(_ *config.Options, req *RequestResources, body io.Reader) Response {
|
||||
// Check if the source has no more domain associated
|
||||
domains, err := storage.MainStore.GetDomains(req.User)
|
||||
if err != nil {
|
||||
return APIErrorResponse{
|
||||
err: err,
|
||||
}
|
||||
}
|
||||
|
||||
for _, domain := range domains {
|
||||
if domain.IdSource == req.SourceMeta.Id {
|
||||
return APIErrorResponse{
|
||||
err: fmt.Errorf("You cannot delete this source because there is still some domains associated with it."),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := storage.MainStore.DeleteSource(req.SourceMeta); err != nil {
|
||||
return APIErrorResponse{
|
||||
err: err,
|
||||
|
|
|
@ -54,11 +54,15 @@
|
|||
{{ sources[source_specs_selected].description }}
|
||||
</p>
|
||||
|
||||
<div class="text-center">
|
||||
<b-button v-if="source_specs && source_specs.capabilities && source_specs.capabilities.indexOf('ListDomains') > -1" type="button" variant="secondary" @click="showListImportableDomain()">
|
||||
<div class="text-center mb-2">
|
||||
<b-button v-if="source_specs && source_specs.capabilities && source_specs.capabilities.indexOf('ListDomains') > -1" type="button" variant="secondary" class="mb-1" @click="showListImportableDomain()">
|
||||
<b-icon icon="list-task" />
|
||||
List importable domains
|
||||
</b-button>
|
||||
<b-button type="button" variant="danger" class="mb-1" @click="deleteSource()">
|
||||
<b-icon icon="trash-fill" />
|
||||
Delete this source
|
||||
</b-button>
|
||||
</div>
|
||||
</b-col>
|
||||
|
||||
|
@ -114,6 +118,24 @@ export default {
|
|||
},
|
||||
|
||||
methods: {
|
||||
deleteSource () {
|
||||
axios
|
||||
.delete('/api/sources/' + encodeURIComponent(this.$route.params.source))
|
||||
.then(
|
||||
response => {
|
||||
this.$router.push('/sources/')
|
||||
},
|
||||
error => {
|
||||
this.$root.$bvToast.toast(
|
||||
error.response.data.errmsg, {
|
||||
title: 'Something went wrong during source deletion',
|
||||
autoHideDelay: 5000,
|
||||
variant: 'danger',
|
||||
toaster: 'b-toaster-content-right'
|
||||
}
|
||||
)
|
||||
})
|
||||
},
|
||||
showListImportableDomain () {
|
||||
this.$router.push('/sources/' + encodeURIComponent(this.$route.params.source) + '/domains')
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user