Skip to content

Commit

Permalink
Add single delete to groups
Browse files Browse the repository at this point in the history
  • Loading branch information
NHAS committed Nov 21, 2024
1 parent 919208b commit 47c62a6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
7 changes: 7 additions & 0 deletions adminui2/src/api/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ export function editGroup(updatedGroup: GroupDTO): Promise<GenericResponseDTO> {
export function createGroup(group: GroupDTO): Promise<GenericResponseDTO> {
return client.post('/api/policy/groups', group).then(res => res.data)
}


export function deleteGroups(groups: string[]): Promise<GenericResponseDTO> {
return client.delete('/api/policy/groups', {data: groups}).then(res => res.data)
}


2 changes: 0 additions & 2 deletions adminui2/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import axios from 'axios'
export const client = axios.create()

client.interceptors.request.use(config => {
console.log('Request Headers:', config.headers)
return config
})

export function setCSRFHeader(csrfToken: string, csrfHeaderName: string) {
console.log('setting: ', csrfHeaderName, csrfToken)
client.defaults.headers.common[csrfHeaderName] = csrfToken
}

Expand Down
38 changes: 35 additions & 3 deletions adminui2/src/pages/Groups.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import { useTextareaInput } from '@/composables/useTextareaInput'
import { Icons } from '@/util/icons'
import { getAllGroups, type GroupDTO, editGroup, createGroup } from '@/api'
import { getAllGroups, type GroupDTO, editGroup, createGroup, deleteGroups } from '@/api'
import ConfirmModal from '@/components/ConfirmModal.vue'
const { data: groupsData, isLoading: isLoadingRules, silentlyRefresh: refreshGroups } = useApi(() => getAllGroups())
Expand Down Expand Up @@ -110,6 +111,26 @@ async function updateGroup() {
catcher(e, 'failed to apply group change: ')
}
}
async function tryDeleteGroups(groups: string[]) {
try {
const resp = await deleteGroups(groups)
refreshGroups()
if (!resp.success) {
toast.error(resp.message ?? 'Failed')
return
} else {
toast.success(groups.join(",") + ' deleted!')
}
} catch (e) {
catcher(e, 'failed delete groups: ')
}
}
</script>

<template>
Expand Down Expand Up @@ -171,13 +192,24 @@ async function updateGroup() {
</tr>
</thead>
<tbody>
<tr class="hover cursor-pointer" v-for="group in currentGroups" :key="group.group" @click="openEditGroup(group)">
<tr class="hover group" v-for="group in currentGroups" :key="group.group">
<td class="font-mono">
<div class="overflow-hidden text-ellipsis whitespace-nowrap">{{ group.group }}</div>
</td>
<td class="font-mono">
<td class="font-mono relative">
<div class="overflow-hidden text-ellipsis whitespace-nowrap">{{ group.members?.join(', ') || '-' }}</div>
<div class="mr-3 absolute right-4 top-1/2 -translate-y-1/2 opacity-0 group-hover:opacity-100 transition-opacity duration-200">
<button class="mr-3" @click="openEditGroup(group)">
<font-awesome-icon :icon="Icons.Edit" class="text-secondary hover:text-secondary-focus" />
</button>
</div>
<ConfirmModal @on-confirm="() => tryDeleteGroups([group.group])">
<button class="absolute right-4 top-1/2 -translate-y-1/2 opacity-0 group-hover:opacity-100 transition-opacity duration-200">
<font-awesome-icon :icon="Icons.Delete" class="text-error hover:text-error-focus" />
</button>
</ConfirmModal>
</td>

</tr>
</tbody>
</table>
Expand Down
1 change: 0 additions & 1 deletion adminui2/src/pages/Rules.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ async function tryDeleteRules(rules: string[] ) {
return
} else {
toast.success('rules ' + rules.join(", ") + ' deleted!')
isRuleModalOpen.value = false
}
} catch (e) {
catcher(e, 'failed to delete rule: ')
Expand Down

0 comments on commit 47c62a6

Please sign in to comment.