mirror of
https://github.com/vatesfr/xen-orchestra.git
synced 2026-12-03 05:42:41 -06:00
Compare commits
11 Commits
web-core/r
...
feat/rest-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
576d0670d5 | ||
|
|
8eaa4c507a | ||
|
|
f22c27b863 | ||
|
|
3e8658c906 | ||
|
|
7b7fab8366 | ||
|
|
22bcc37439 | ||
|
|
5ca2958d2a | ||
|
|
205ae67940 | ||
|
|
addfdd5475 | ||
|
|
5512fc65a6 | ||
|
|
1f8f265afc |
@@ -101,6 +101,21 @@ export interface EditVifProps {
|
||||
txChecksumming?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Properties accepted by {@link Xapi.editNetwork}: the fields of `XoNetwork` it can change.
|
||||
*
|
||||
* `nbd` and `insecureNbd` cannot both be true: `editNetwork` throws `invalidParameters` when they are.
|
||||
*/
|
||||
export interface EditNetworkProps {
|
||||
automatic?: boolean
|
||||
defaultIsLocked?: boolean
|
||||
insecureNbd?: boolean
|
||||
MTU?: number
|
||||
name_description?: string
|
||||
name_label?: string
|
||||
nbd?: boolean
|
||||
}
|
||||
|
||||
export type XcpPatches = {
|
||||
changelog?: {
|
||||
author: string
|
||||
@@ -335,6 +350,7 @@ export interface Xapi {
|
||||
checkLimits?: (limits: Record<string, number>, vm: XenApiVmWrapped) => Promise<void>
|
||||
): Promise<void>
|
||||
editVif(id: XoVif['id'], props: EditVifProps): Promise<void>
|
||||
editNetwork(id: XoNetwork['id'], props: EditNetworkProps): Promise<void>
|
||||
startVm(
|
||||
id: XoVm['id'],
|
||||
opts?: {
|
||||
|
||||
@@ -5,5 +5,12 @@ export default {
|
||||
update: {
|
||||
tags: true,
|
||||
other_config: true,
|
||||
automatic: true,
|
||||
defaultIsLocked: true,
|
||||
insecureNbd: true,
|
||||
MTU: true,
|
||||
name_description: true,
|
||||
name_label: true,
|
||||
nbd: true,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -8,9 +8,28 @@ export type SupportedResource = XoAclSupportedResource<SupportedActionsByResourc
|
||||
export type SupportedActions<T extends SupportedResource> = XoAclSupportedActions<SupportedActionsByResource, T>
|
||||
export type TPrivilege<T extends SupportedResource> = XoAclPrivilege<SupportedActionsByResource, T>
|
||||
|
||||
export const UNKNOWN = Symbol('UNKNOWN')
|
||||
|
||||
/**
|
||||
* Lists the top-level fields read by a selector.
|
||||
*/
|
||||
function getSelectorFields(node: CM.Node): string[] {
|
||||
if (node instanceof CM.Property || node instanceof CM.TruthyProperty) {
|
||||
return [node.name]
|
||||
}
|
||||
if (node instanceof CM.Not) {
|
||||
return getSelectorFields(node.child)
|
||||
}
|
||||
if (node instanceof CM.And || node instanceof CM.Or) {
|
||||
return node.children.flatMap(getSelectorFields)
|
||||
}
|
||||
return node instanceof CM.Null ? [] : ['*']
|
||||
}
|
||||
|
||||
export class Privilege<T extends SupportedResource> {
|
||||
#action: TPrivilege<T>['action']
|
||||
#selector?: (object: object) => boolean
|
||||
#selectorFields: string[] = []
|
||||
#resource: TPrivilege<T>['resource']
|
||||
#effect: TPrivilege<T>['effect']
|
||||
|
||||
@@ -28,9 +47,14 @@ export class Privilege<T extends SupportedResource> {
|
||||
Privilege.checkActionIsValid(resource, action)
|
||||
|
||||
this.#action = action
|
||||
this.#selector = selector !== undefined ? CM.parse(selector).createPredicate() : undefined
|
||||
this.#resource = resource
|
||||
this.#effect = effect
|
||||
|
||||
if (selector !== undefined) {
|
||||
const node = CM.parse(selector)
|
||||
this.#selector = node.createPredicate()
|
||||
this.#selectorFields = getSelectorFields(node)
|
||||
}
|
||||
}
|
||||
|
||||
get effect() {
|
||||
@@ -44,11 +68,20 @@ export class Privilege<T extends SupportedResource> {
|
||||
return this.#action === '*' || this.#action === action || action.startsWith(`${this.#action}:`)
|
||||
}
|
||||
|
||||
#matchSelector(object: object) {
|
||||
#matchSelector(object: object, knownFields?: string[]) {
|
||||
if (this.#selector === undefined) {
|
||||
return true
|
||||
}
|
||||
|
||||
// `*` is a term not bound to a property (e.g. `foo`), it may match any field, including missing ones
|
||||
// The `*` check is there to handle the case where a `*` field would exist
|
||||
if (
|
||||
knownFields !== undefined &&
|
||||
this.#selectorFields.some(field => field === '*' || !(field in object || knownFields.includes(field)))
|
||||
) {
|
||||
return UNKNOWN
|
||||
}
|
||||
|
||||
return this.#selector(object)
|
||||
}
|
||||
|
||||
@@ -60,11 +93,12 @@ export class Privilege<T extends SupportedResource> {
|
||||
action: SupportedActions<Resource>
|
||||
resource: Resource
|
||||
object: object
|
||||
}): boolean {
|
||||
knownFields?: string[]
|
||||
}): boolean | typeof UNKNOWN {
|
||||
return (
|
||||
this.#matchResource(constraint.resource) &&
|
||||
this.#matchAction(constraint.action) &&
|
||||
this.#matchSelector(constraint.object)
|
||||
this.#matchSelector(constraint.object, constraint.knownFields)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
SupportedActions,
|
||||
SupportedActionsByResource,
|
||||
SupportedResource,
|
||||
UNKNOWN,
|
||||
} from './class/privilege.mjs'
|
||||
|
||||
// Export all types constructed using SUPPORTED_ACTIONS_BY_RESOURCE
|
||||
@@ -23,6 +24,7 @@ export type AnyPrivilegeOnParam = {
|
||||
resource: Resource
|
||||
action: SupportedActions<Resource>
|
||||
objects: object | object[]
|
||||
knownFields?: string[]
|
||||
}
|
||||
}[SupportedResource]
|
||||
|
||||
@@ -32,12 +34,14 @@ export function hasPrivilegeOn<T extends SupportedResource>({
|
||||
resource,
|
||||
objects,
|
||||
userPrivileges,
|
||||
knownFields,
|
||||
}: {
|
||||
user: XoUser
|
||||
resource: T
|
||||
action: SupportedActions<T>
|
||||
objects: object | object[]
|
||||
userPrivileges: AnyPrivilege[]
|
||||
knownFields?: string[]
|
||||
}) {
|
||||
// Function that will be called outside of the module
|
||||
// We cannot be sure types are respected
|
||||
@@ -63,7 +67,7 @@ export function hasPrivilegeOn<T extends SupportedResource>({
|
||||
return true
|
||||
}
|
||||
|
||||
const effectsByObject = new Map<object, Privilege<T>['effect'][]>()
|
||||
const effectsByObject = new Map<object, { known: boolean; effect: Privilege<T>['effect'] }[]>()
|
||||
if (Array.isArray(objects)) {
|
||||
objects.forEach(obj => effectsByObject.set(obj, []))
|
||||
} else {
|
||||
@@ -74,20 +78,49 @@ export function hasPrivilegeOn<T extends SupportedResource>({
|
||||
const privilege = new CPrivilege(userPrivilege as Privilege<typeof userPrivilege.resource>)
|
||||
|
||||
for (const [object, effects] of effectsByObject.entries()) {
|
||||
if (!privilege.match({ action, resource, object })) {
|
||||
const result = privilege.match({ action, resource, object, knownFields })
|
||||
if (!result) {
|
||||
continue
|
||||
}
|
||||
effects.push(privilege.effect)
|
||||
effects.push({ known: result !== UNKNOWN, effect: privilege.effect })
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
Array.from(effectsByObject.values()).some(
|
||||
effects => effects.length === 0 || effects.some(effect => effect === 'deny')
|
||||
)
|
||||
) {
|
||||
return false
|
||||
let isUndecidable = false
|
||||
for (const effects of effectsByObject.values()) {
|
||||
let hasAllow = false
|
||||
let hasKnownAllow = false
|
||||
let hasUnknownDeny = false
|
||||
|
||||
for (const { known, effect } of effects) {
|
||||
if (effect === 'allow') {
|
||||
hasAllow = true
|
||||
hasKnownAllow ||= known
|
||||
} else if (known) {
|
||||
return false
|
||||
} else {
|
||||
hasUnknownDeny = true
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasAllow) {
|
||||
return false
|
||||
}
|
||||
|
||||
// do not throw yet: another object may still be known to be denied
|
||||
if (hasUnknownDeny || !hasKnownAllow) {
|
||||
isUndecidable = true
|
||||
}
|
||||
}
|
||||
|
||||
if (isUndecidable) {
|
||||
const error: Error & { code?: string } = new Error(
|
||||
`The privilege couldn't be decided because the object is missing fields the selectors need. action: ${action}, resource: ${resource}`
|
||||
)
|
||||
error.code = 'RBAC_UNKNOWN_RESULT'
|
||||
throw error
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -101,6 +134,7 @@ export function getMissingPrivileges(params: AnyPrivilegeOnParam[], userPrivileg
|
||||
action: param.action as SupportedActions<typeof param.resource>,
|
||||
objects: param.objects,
|
||||
userPrivileges,
|
||||
knownFields: param.knownFields,
|
||||
})
|
||||
)
|
||||
.map(({ action, objects, resource }) => {
|
||||
@@ -142,6 +176,7 @@ export function filterObjectsWithPrivilege<Resource extends SupportedResource, O
|
||||
action: SupportedActions<Resource>
|
||||
objects: Object[]
|
||||
userPrivileges: AnyPrivilege[]
|
||||
knownFields?: string[]
|
||||
}) {
|
||||
return param.objects.filter(obj => hasPrivilegeOn({ ...param, objects: obj }))
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import assert from 'node:assert'
|
||||
import type { Branded } from '@vates/types/common'
|
||||
import type { XoUser } from '@vates/types/xo'
|
||||
|
||||
import { Privilege } from '../class/privilege.mjs'
|
||||
import { Privilege, UNKNOWN } from '../class/privilege.mjs'
|
||||
import type { Privilege as TPrivilege } from '../index.mjs'
|
||||
import {
|
||||
filterObjectsWithPrivilege,
|
||||
@@ -81,6 +81,108 @@ suite('Privilege.match behavior', () => {
|
||||
const vmImportPrivilege = new Privilege({ action: 'import:vm', resource: 'sr', effect: 'allow' })
|
||||
assert.strictEqual(vmImportPrivilege.match({ resource: 'sr', action: 'import:vdi:url', object }), false)
|
||||
})
|
||||
|
||||
suite('on a partial object', () => {
|
||||
const ownVmPrivilege = new Privilege({
|
||||
action: 'read',
|
||||
resource: 'vm',
|
||||
selector: 'creation:creator:2',
|
||||
effect: 'allow',
|
||||
})
|
||||
const partialObject = { id: 'alma' }
|
||||
|
||||
test('Should not match a missing property if known fields are not provided', () => {
|
||||
assert.strictEqual(ownVmPrivilege.match({ resource: 'vm', action: 'read', object: partialObject }), false)
|
||||
})
|
||||
|
||||
test('Should not match a missing property if it is a known field', () => {
|
||||
assert.strictEqual(
|
||||
ownVmPrivilege.match({
|
||||
resource: 'vm',
|
||||
action: 'read',
|
||||
object: partialObject,
|
||||
knownFields: ['id', 'creation'],
|
||||
}),
|
||||
false
|
||||
)
|
||||
})
|
||||
|
||||
test('Should return UNKNOWN if the selector uses an unknown field', () => {
|
||||
assert.strictEqual(
|
||||
ownVmPrivilege.match({ resource: 'vm', action: 'read', object: partialObject, knownFields: ['id'] }),
|
||||
UNKNOWN
|
||||
)
|
||||
})
|
||||
|
||||
test('Should not match because of the resource even if the selector is unknown', () => {
|
||||
assert.strictEqual(
|
||||
ownVmPrivilege.match({ resource: 'host', action: 'read', object: partialObject, knownFields: ['id'] }),
|
||||
false
|
||||
)
|
||||
})
|
||||
|
||||
test('Should not match because of the action even if the selector is unknown', () => {
|
||||
assert.strictEqual(
|
||||
ownVmPrivilege.match({ resource: 'vm', action: 'start', object: partialObject, knownFields: ['id'] }),
|
||||
false
|
||||
)
|
||||
})
|
||||
|
||||
test('Should match without selector', () => {
|
||||
assert.strictEqual(
|
||||
privilege.match({ resource: 'vm', action: 'read', object: partialObject, knownFields: [] }),
|
||||
true
|
||||
)
|
||||
})
|
||||
|
||||
test('Should resolve a field present on the object even if it is not listed', () => {
|
||||
assert.strictEqual(
|
||||
ownVmPrivilege.match({
|
||||
resource: 'vm',
|
||||
action: 'read',
|
||||
object: { creation: { creator: '2' } },
|
||||
knownFields: [],
|
||||
}),
|
||||
true
|
||||
)
|
||||
})
|
||||
|
||||
test('Should resolve a field provided by a getter', () => {
|
||||
class Vm {
|
||||
get creation() {
|
||||
return { creator: '2' }
|
||||
}
|
||||
}
|
||||
|
||||
assert.strictEqual(
|
||||
ownVmPrivilege.match({ resource: 'vm', action: 'read', object: new Vm(), knownFields: [] }),
|
||||
true
|
||||
)
|
||||
})
|
||||
|
||||
test('Should return UNKNOWN on a term not bound to a property', () => {
|
||||
const bareTermPrivilege = new Privilege({ action: 'read', resource: 'vm', selector: 'alma', effect: 'allow' })
|
||||
|
||||
assert.strictEqual(
|
||||
bareTermPrivilege.match({ resource: 'vm', action: 'read', object: partialObject, knownFields: ['id'] }),
|
||||
UNKNOWN
|
||||
)
|
||||
})
|
||||
|
||||
test('Should return UNKNOWN if one of the fields is unknown, even if the others decide the result', () => {
|
||||
const orPrivilege = new Privilege({
|
||||
action: 'read',
|
||||
resource: 'vm',
|
||||
selector: '|(id:alma creation:creator:2)',
|
||||
effect: 'allow',
|
||||
})
|
||||
|
||||
assert.strictEqual(
|
||||
orPrivilege.match({ resource: 'vm', action: 'read', object: partialObject, knownFields: ['id'] }),
|
||||
UNKNOWN
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
suite('ACL V2 behavior', async () => {
|
||||
@@ -397,6 +499,205 @@ suite('ACL V2 behavior', async () => {
|
||||
assert.strictEqual(vms.length, 2)
|
||||
})
|
||||
})
|
||||
|
||||
suite('partial objects behavior', () => {
|
||||
const UNKNOWN_RESULT = { code: 'RBAC_UNKNOWN_RESULT' }
|
||||
|
||||
const vmReadAll = {
|
||||
id: privilegeId,
|
||||
action: 'read',
|
||||
resource: 'vm',
|
||||
effect: 'allow',
|
||||
roleId,
|
||||
} satisfies TPrivilege<'vm'>
|
||||
const vmReadOwn = {
|
||||
id: privilegeId,
|
||||
action: 'read',
|
||||
resource: 'vm',
|
||||
selector: `creation:creator:${user.id}`,
|
||||
effect: 'allow',
|
||||
roleId,
|
||||
} satisfies TPrivilege<'vm'>
|
||||
const vmDenyReadOnPool = {
|
||||
id: privilegeId,
|
||||
action: 'read',
|
||||
resource: 'vm',
|
||||
selector: '$pool:2',
|
||||
effect: 'deny',
|
||||
roleId,
|
||||
} satisfies TPrivilege<'vm'>
|
||||
|
||||
const partialVm = { id: 'partial-vm' }
|
||||
const partialVmOnDeniedPool = { id: 'partial-vm-denied', $pool: '2' }
|
||||
|
||||
suite('hasPrivilegeOn', () => {
|
||||
test('Should always return true for admin', () => {
|
||||
assert.strictEqual(
|
||||
hasPrivilegeOn({
|
||||
user: admin,
|
||||
action: 'read',
|
||||
resource: 'vm',
|
||||
objects: partialVm,
|
||||
knownFields: ['id'],
|
||||
userPrivileges: [vmReadOwn],
|
||||
}),
|
||||
true
|
||||
)
|
||||
})
|
||||
|
||||
test('Should keep the current behavior if known fields are not provided', () => {
|
||||
assert.strictEqual(
|
||||
hasPrivilegeOn({ user, action: 'read', resource: 'vm', objects: partialVm, userPrivileges: [vmReadOwn] }),
|
||||
false
|
||||
)
|
||||
})
|
||||
|
||||
test('Should throw if the only allow privilege is unknown', () => {
|
||||
assert.throws(
|
||||
() =>
|
||||
hasPrivilegeOn({
|
||||
user,
|
||||
action: 'read',
|
||||
resource: 'vm',
|
||||
objects: partialVm,
|
||||
knownFields: ['id'],
|
||||
userPrivileges: [vmReadOwn],
|
||||
}),
|
||||
UNKNOWN_RESULT
|
||||
)
|
||||
})
|
||||
|
||||
test('Should return false if the unknown field is known to be absent', () => {
|
||||
assert.strictEqual(
|
||||
hasPrivilegeOn({
|
||||
user,
|
||||
action: 'read',
|
||||
resource: 'vm',
|
||||
objects: partialVm,
|
||||
knownFields: ['id', 'creation'],
|
||||
userPrivileges: [vmReadOwn],
|
||||
}),
|
||||
false
|
||||
)
|
||||
})
|
||||
|
||||
test('Should return true if an allow privilege is known even if another one is unknown', () => {
|
||||
assert.strictEqual(
|
||||
hasPrivilegeOn({
|
||||
user,
|
||||
action: 'read',
|
||||
resource: 'vm',
|
||||
objects: partialVm,
|
||||
knownFields: ['id'],
|
||||
userPrivileges: [vmReadOwn, vmReadAll],
|
||||
}),
|
||||
true
|
||||
)
|
||||
})
|
||||
|
||||
test('Should throw if a deny privilege is unknown, even with a known allow privilege', () => {
|
||||
assert.throws(
|
||||
() =>
|
||||
hasPrivilegeOn({
|
||||
user,
|
||||
action: 'read',
|
||||
resource: 'vm',
|
||||
objects: partialVm,
|
||||
knownFields: ['id'],
|
||||
userPrivileges: [vmReadAll, vmDenyReadOnPool],
|
||||
}),
|
||||
UNKNOWN_RESULT
|
||||
)
|
||||
})
|
||||
|
||||
test('Should return true if a deny privilege is known not to match', () => {
|
||||
assert.strictEqual(
|
||||
hasPrivilegeOn({
|
||||
user,
|
||||
action: 'read',
|
||||
resource: 'vm',
|
||||
objects: partialVm,
|
||||
knownFields: ['id', '$pool'],
|
||||
userPrivileges: [vmReadAll, vmDenyReadOnPool],
|
||||
}),
|
||||
true
|
||||
)
|
||||
})
|
||||
|
||||
test('Should return false if a deny privilege is known to match, even with an unknown allow privilege', () => {
|
||||
assert.strictEqual(
|
||||
hasPrivilegeOn({
|
||||
user,
|
||||
action: 'read',
|
||||
resource: 'vm',
|
||||
objects: partialVmOnDeniedPool,
|
||||
knownFields: ['id', '$pool'],
|
||||
userPrivileges: [vmReadOwn, vmDenyReadOnPool],
|
||||
}),
|
||||
false
|
||||
)
|
||||
})
|
||||
|
||||
test('Should return false if one of the objects is known to be denied, even if another one is unknown', () => {
|
||||
assert.strictEqual(
|
||||
hasPrivilegeOn({
|
||||
user,
|
||||
action: 'read',
|
||||
resource: 'vm',
|
||||
objects: [partialVm, partialVmOnDeniedPool],
|
||||
knownFields: ['id'],
|
||||
userPrivileges: [vmReadAll, vmDenyReadOnPool],
|
||||
}),
|
||||
false
|
||||
)
|
||||
})
|
||||
|
||||
test('Should throw if the other objects are allowed and one is unknown', () => {
|
||||
assert.throws(
|
||||
() =>
|
||||
hasPrivilegeOn({
|
||||
user,
|
||||
action: 'read',
|
||||
resource: 'vm',
|
||||
objects: [{ id: 'allowed-vm', $pool: '1' }, partialVm],
|
||||
knownFields: ['id'],
|
||||
userPrivileges: [vmReadAll, vmDenyReadOnPool],
|
||||
}),
|
||||
UNKNOWN_RESULT
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
suite('getMissingPrivileges', () => {
|
||||
test('Should throw if a privilege is unknown', () => {
|
||||
assert.throws(
|
||||
() =>
|
||||
getMissingPrivileges(
|
||||
[{ user, action: 'read', resource: 'vm', objects: partialVm, knownFields: ['id'] }],
|
||||
[vmReadOwn]
|
||||
),
|
||||
UNKNOWN_RESULT
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
suite('filterObjectsWithPrivilege', () => {
|
||||
test('Should throw if a privilege is unknown on one of the objects', () => {
|
||||
assert.throws(
|
||||
() =>
|
||||
filterObjectsWithPrivilege({
|
||||
user,
|
||||
action: 'read',
|
||||
resource: 'vm',
|
||||
objects: [partialVm],
|
||||
knownFields: ['id'],
|
||||
userPrivileges: [vmReadOwn],
|
||||
}),
|
||||
UNKNOWN_RESULT
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
suite('getActionStrings', () => {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
## **next**
|
||||
|
||||
- [VM/Network] Add possibility to delete a VIF (PR [#10726](https://github.com/vatesfr/xen-orchestra/pull/10726))
|
||||
- [Web-Core/VtsErrorModal] Add an optional details log viewer, unified icon (PR [#10536](https://github.com/vatesfr/xen-orchestra/pull/10536))
|
||||
|
||||
## **0.28.0** (2026/12/01)
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { XenApiNetwork } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { useNetworkDeleteJob } from '@/modules/network/jobs/network-delete.job.ts'
|
||||
import { useDeleteModal } from '@core/composables/modals/use-delete-modal.ts'
|
||||
import { useErrorModal } from '@core/composables/modals/use-error-modal.ts'
|
||||
import { useRouteQuery } from '@core/composables/route-query.composable.ts'
|
||||
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
|
||||
import { toComputed } from '@core/utils/to-computed.util.ts'
|
||||
import type { MaybeRefOrGetter } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
@@ -23,12 +23,7 @@ export function useNetworkDelete(rawNetworks: MaybeRefOrGetter<XenApiNetwork[]>)
|
||||
|
||||
const { open: openNetworkDeleteModal } = useDeleteModal()
|
||||
|
||||
const { open: openNetworkDeleteErrorModal } = useOverlay({
|
||||
component: () => import('@core/components/modal/VtsErrorModal.vue'),
|
||||
events: {
|
||||
onClose: true,
|
||||
},
|
||||
})
|
||||
const { open: openNetworkDeleteErrorModal } = useErrorModal()
|
||||
|
||||
function deleteNetworks() {
|
||||
if (!canDeleteNetworks.value) {
|
||||
|
||||
13
@xen-orchestra/lite/src/route-map.d.ts
vendored
13
@xen-orchestra/lite/src/route-map.d.ts
vendored
@@ -499,6 +499,13 @@ declare module 'vue-router/auto-routes' {
|
||||
Record<never, never>,
|
||||
| never
|
||||
>,
|
||||
'/story/web-core/modal/vts-error-modal': RouteRecordInfo<
|
||||
'/story/web-core/modal/vts-error-modal',
|
||||
'/story/web-core/modal/vts-error-modal',
|
||||
Record<never, never>,
|
||||
Record<never, never>,
|
||||
| never
|
||||
>,
|
||||
'/story/web-core/number-input/vts-number-input': RouteRecordInfo<
|
||||
'/story/web-core/number-input/vts-number-input',
|
||||
'/story/web-core/number-input/vts-number-input',
|
||||
@@ -1737,6 +1744,12 @@ declare module 'vue-router/auto-routes' {
|
||||
views:
|
||||
| never
|
||||
}
|
||||
'src/stories/web-core/modal/vts-error-modal.story.vue': {
|
||||
routes:
|
||||
| '/story/web-core/modal/vts-error-modal'
|
||||
views:
|
||||
| never
|
||||
}
|
||||
'src/stories/web-core/number-input/vts-number-input.story.vue': {
|
||||
routes:
|
||||
| '/story/web-core/number-input/vts-number-input'
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# Usage
|
||||
|
||||
Open the modal with `useErrorModal`.
|
||||
|
||||
```vue-script
|
||||
import { useErrorModal } from '@core/composables/modals/use-error-modal.ts'
|
||||
|
||||
const { open: openErrorModal } = useErrorModal()
|
||||
|
||||
try {
|
||||
// ...
|
||||
} catch (error) {
|
||||
void openErrorModal({
|
||||
props: {
|
||||
title: 'Unable to create cluster',
|
||||
error: 'An error occurred',
|
||||
details: error,
|
||||
},
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
The `details` prop is displayed below the message, even when the `content` slot is overridden:
|
||||
|
||||
```vue-template
|
||||
<VtsErrorModal title="Unable to delete network" :details @close="close()">
|
||||
<template #content>Custom error message</template>
|
||||
</VtsErrorModal>
|
||||
```
|
||||
@@ -0,0 +1,60 @@
|
||||
<template>
|
||||
<ComponentStory
|
||||
v-slot="{ properties, settings }"
|
||||
:params="[
|
||||
prop('title').str().required().preset('Unable to create cluster').widget(),
|
||||
prop('error').str().preset('An error occurred').widget(),
|
||||
prop('details')
|
||||
.type('string | object')
|
||||
.preset(details1)
|
||||
.widget(object())
|
||||
.help('When set, displayed in a log entry viewer below the error message'),
|
||||
event('close'),
|
||||
slot('content').help('Replaces the error message. The details are still displayed below it'),
|
||||
setting('contentSlotContent').widget(text()).help('Leave empty to use the error prop'),
|
||||
]"
|
||||
:presets
|
||||
>
|
||||
<VtsErrorModal class="story" v-bind="properties">
|
||||
<template v-if="settings.contentSlotContent" #content>{{ settings.contentSlotContent }}</template>
|
||||
</VtsErrorModal>
|
||||
</ComponentStory>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import ComponentStory from '@/components/component-story/ComponentStory.vue'
|
||||
import { event, prop, setting, slot } from '@/libs/story/story-param.ts'
|
||||
import { object, text } from '@/libs/story/story-widget.ts'
|
||||
import VtsErrorModal from '@core/components/modal/VtsErrorModal.vue'
|
||||
|
||||
const details1 = {
|
||||
code: 'HOST_NOT_ENOUGH_FREE_MEMORY',
|
||||
params: ['8589934592', '2147483648'],
|
||||
call: {
|
||||
method: 'VM.start',
|
||||
params: ['OpaqueRef:3f2a9c1e-7b4d-4e8a-9f6c-2d1b5a8e7c90', false, false],
|
||||
},
|
||||
}
|
||||
|
||||
const details2 =
|
||||
'TypeError: Failed to fetch\n at fetchApi (rest-api.ts:42:11)\n at async createCluster (cluster-create.job.ts:88:5)'
|
||||
|
||||
const presets = {
|
||||
'Without details': {
|
||||
props: { details: undefined },
|
||||
},
|
||||
'With details object': {
|
||||
props: { details: details1 },
|
||||
},
|
||||
'With details string': {
|
||||
props: { details: details2 },
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
.story {
|
||||
position: relative;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -6,7 +6,6 @@
|
||||
prop('accent').required().enum('brand', 'info', 'warning', 'danger').preset('brand').widget(),
|
||||
prop('size').required().enum('small', 'medium', 'large').preset('medium').widget(),
|
||||
prop('disabled').bool().widget(),
|
||||
prop('restricted').bool().widget(),
|
||||
prop('selected').bool().widget(),
|
||||
prop('counter')
|
||||
.type('CounterValue | { value: CounterValue; accent: CounterAccent }')
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
prop('size').type('ButtonSize').enum('small', 'medium').preset('medium').required().widget(),
|
||||
prop('busy').bool().widget(),
|
||||
prop('disabled').bool().widget().ctx(),
|
||||
prop('restricted').bool().widget(),
|
||||
prop('lockIcon').bool().widget(),
|
||||
iconProp('leftIcon'),
|
||||
iconProp('rightIcon'),
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import {
|
||||
Body,
|
||||
Delete,
|
||||
Example,
|
||||
Extension,
|
||||
Get,
|
||||
Middlewares,
|
||||
Patch,
|
||||
Path,
|
||||
Put,
|
||||
Query,
|
||||
@@ -16,8 +18,9 @@ import {
|
||||
} from 'tsoa'
|
||||
import { inject } from 'inversify'
|
||||
import { provide } from 'inversify-binding-decorators'
|
||||
import { Request as ExRequest } from 'express'
|
||||
import type { XoAlarm, XoMessage, XoNetwork, XoTask } from '@vates/types'
|
||||
import { invalidParameters } from 'xo-common/api-errors.js'
|
||||
import { json, NextFunction, Request as ExRequest, Response as ExResponse } from 'express'
|
||||
import type { EditNetworkProps, XoAlarm, XoMessage, XoNetwork, XoTask } from '@vates/types'
|
||||
|
||||
import { AlarmService } from '../alarms/alarm.service.mjs'
|
||||
import { escapeUnsafeComplexMatcher } from '../helpers/utils.helper.mjs'
|
||||
@@ -26,6 +29,8 @@ import { network, networkIds, partialNetworks } from '../open-api/oa-examples/ne
|
||||
import {
|
||||
badRequestResp,
|
||||
forbiddenOperationResp,
|
||||
internalServerErrorResp,
|
||||
invalidParameters as invalidParametersResp,
|
||||
noContentResp,
|
||||
notFoundResp,
|
||||
unauthorizedResp,
|
||||
@@ -36,7 +41,60 @@ import type { SendObjects } from '../helpers/helper.type.mjs'
|
||||
import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs'
|
||||
import { messageIds, partialMessages } from '../open-api/oa-examples/message.oa-example.mjs'
|
||||
import { partialTasks, taskIds } from '../open-api/oa-examples/task.oa-example.mjs'
|
||||
import { acl } from '../middlewares/acl.middleware.mjs'
|
||||
import { acl, actionsFromBody } from '../middlewares/acl.middleware.mjs'
|
||||
import type { AuthenticatedRequest } from '../helpers/helper.type.mjs'
|
||||
|
||||
// the fields come from EditNetworkProps, so a field added there reaches the body too; MTU and insecureNbd
|
||||
// are redeclared only to carry their tsoa JSDoc (validation and description in the OpenAPI spec)
|
||||
type UpdateNetworkRequestBody = Omit<EditNetworkProps, 'MTU' | 'insecureNbd'> & {
|
||||
/**
|
||||
* @isInt
|
||||
* @minimum 68 the MTU must be at least 68 (RFC 791)
|
||||
*/
|
||||
MTU?: number
|
||||
/**
|
||||
* NBD in clear, only on a network dedicated to backups. Mutually exclusive with `nbd`
|
||||
*/
|
||||
insecureNbd?: boolean
|
||||
}
|
||||
|
||||
// the privileges a PATCH checks: update:<field> for each field in the body, and the other NBD
|
||||
// purpose when one is set, since the XAPI side removes it (setNbdPurposes in
|
||||
// xo-server/src/xapi/mixins/networking.mjs): nbd: true removes insecure_nbd, insecureNbd: true removes nbd
|
||||
export function updateNetworkActions({ req }: { req: AuthenticatedRequest }) {
|
||||
const actions = actionsFromBody<'network'>([
|
||||
'update:automatic',
|
||||
'update:defaultIsLocked',
|
||||
'update:insecureNbd',
|
||||
'update:MTU',
|
||||
'update:name_description',
|
||||
'update:name_label',
|
||||
'update:nbd',
|
||||
])({ req })
|
||||
const body: UpdateNetworkRequestBody = req.body
|
||||
if (body.insecureNbd === true) {
|
||||
actions.push('update:nbd')
|
||||
}
|
||||
if (body.nbd === true) {
|
||||
actions.push('update:insecureNbd')
|
||||
}
|
||||
return actions
|
||||
}
|
||||
|
||||
// runs before acl(): a body with no gated field gets no privilege checked, so it is refused here, for a missing
|
||||
// network too. Refusing it in the handler, after the ACL has resolved the network, would answer 404 for a missing
|
||||
// network and 422 for an existing one, which tells them apart
|
||||
export function refuseEmptyUpdate(req: AuthenticatedRequest, _res: ExResponse, next: NextFunction) {
|
||||
if (updateNetworkActions({ req }).length > 0) {
|
||||
return next()
|
||||
}
|
||||
// the api-errors factories throw, so the error is caught to reach next()
|
||||
try {
|
||||
invalidParameters('the body must contain at least one field to update')
|
||||
} catch (error) {
|
||||
return next(error)
|
||||
}
|
||||
}
|
||||
|
||||
@Route('networks')
|
||||
@Security('*')
|
||||
@@ -94,6 +152,56 @@ export class NetworkController extends XapiXoController<XoNetwork> {
|
||||
return this.getObject(id as XoNetwork['id'])
|
||||
}
|
||||
|
||||
/**
|
||||
* Partial update of a network: only the fields present in the body are modified.
|
||||
*
|
||||
* Changing `MTU` unplugs and replugs the network's PIFs and the VIFs of its running VMs: their
|
||||
* traffic is briefly interrupted.
|
||||
* `nbd` and `insecureNbd` are mutually exclusive; setting one to `false` only removes that purpose.
|
||||
* `automatic` adds the network to new VMs automatically; `defaultIsLocked` blocks the traffic of
|
||||
* VIFs with no allowed IP.
|
||||
* A body with none of the fields below is refused with a 422, whether or not the network exists.
|
||||
*
|
||||
* Required privilege per field provided in the body:
|
||||
* - resource: network, action: update:<field>
|
||||
* - and with `nbd: true`, also resource: network, action: update:insecureNbd (it removes the
|
||||
* insecure NBD purpose); with `insecureNbd: true`, also action: update:nbd (it removes the NBD purpose)
|
||||
*
|
||||
* @example id "9fe12ca3-d75d-cfb0-492e-cfd2bc6c568f"
|
||||
* @example body { "name_label": "backups", "MTU": 9000, "insecureNbd": true }
|
||||
*/
|
||||
@Extension('x-mcp-exposure', 'confirm')
|
||||
@Patch('{id}')
|
||||
@Middlewares([
|
||||
json(),
|
||||
refuseEmptyUpdate,
|
||||
acl({
|
||||
resource: 'network',
|
||||
actions: updateNetworkActions,
|
||||
objectId: 'params.id',
|
||||
}),
|
||||
])
|
||||
@SuccessResponse(noContentResp.status, noContentResp.description)
|
||||
@Response(forbiddenOperationResp.status, forbiddenOperationResp.description)
|
||||
@Response(notFoundResp.status, notFoundResp.description)
|
||||
@Response(invalidParametersResp.status, invalidParametersResp.description)
|
||||
@Response(internalServerErrorResp.status, internalServerErrorResp.description)
|
||||
async updateNetwork(@Path() id: string, @Body() body: UpdateNetworkRequestBody): Promise<void> {
|
||||
const networkId = id as XoNetwork['id']
|
||||
const { automatic, defaultIsLocked, insecureNbd, MTU, name_description, name_label, nbd } = body
|
||||
|
||||
// forward only the declared fields: the ACL above checked their privileges and the NBD purpose each one removes
|
||||
await this.getXapi(networkId).editNetwork(networkId, {
|
||||
automatic,
|
||||
defaultIsLocked,
|
||||
insecureNbd,
|
||||
MTU,
|
||||
name_description,
|
||||
name_label,
|
||||
nbd,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Required privilege:
|
||||
* - resource: network, action: delete
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { describe, it, mock } from 'node:test'
|
||||
import { getMissingPrivileges, type AnyPrivilege, type AnyPrivilegeOnParam } from '@xen-orchestra/acl'
|
||||
import type { XoUser } from '@vates/types'
|
||||
import type { NextFunction, Response } from 'express'
|
||||
import { invalidParameters } from 'xo-common/api-errors.js'
|
||||
|
||||
import { NetworkController, refuseEmptyUpdate, updateNetworkActions } from './network.controller.mjs'
|
||||
import type { AuthenticatedRequest } from '../helpers/helper.type.mjs'
|
||||
import type { RestApi } from '../rest-api/rest-api.mjs'
|
||||
|
||||
const user = { id: 'user-1', permission: 'none' } as XoUser
|
||||
const network = { id: 'network-1' }
|
||||
const NETWORK_ID = '9fe12ca3-d75d-cfb0-492e-cfd2bc6c568f'
|
||||
|
||||
function missingPrivileges(body: object, userPrivileges: AnyPrivilege[]) {
|
||||
const req = { body } as AuthenticatedRequest
|
||||
const params = updateNetworkActions({ req }).map(
|
||||
action => ({ user, resource: 'network', action, objects: [network] }) as AnyPrivilegeOnParam
|
||||
)
|
||||
return getMissingPrivileges(params, userPrivileges)
|
||||
}
|
||||
|
||||
describe('updateNetworkActions', () => {
|
||||
it('refuses insecureNbd: true to a user with only update:insecureNbd, as it removes the nbd purpose', () => {
|
||||
const privileges = [
|
||||
{ id: 'privilege-1', resource: 'network', action: 'update:insecureNbd', effect: 'allow', roleId: 'role-1' },
|
||||
] as unknown as AnyPrivilege[]
|
||||
|
||||
const missing = missingPrivileges({ insecureNbd: true }, privileges)
|
||||
|
||||
assert.equal(missing.length, 1)
|
||||
assert.equal(missing[0].action, 'update:nbd')
|
||||
})
|
||||
})
|
||||
|
||||
describe('refuseEmptyUpdate', () => {
|
||||
it('refuses an empty body with a 422 before the ACL resolves the network', () => {
|
||||
const next = mock.fn()
|
||||
|
||||
refuseEmptyUpdate({ body: {} } as AuthenticatedRequest, {} as Response, next as NextFunction)
|
||||
|
||||
assert.equal(next.mock.callCount(), 1)
|
||||
assert.ok(invalidParameters.is(next.mock.calls[0].arguments[0]))
|
||||
})
|
||||
})
|
||||
|
||||
describe('NetworkController.updateNetwork', () => {
|
||||
it('forwards only the seven declared fields to editNetwork, with the id the route got', async () => {
|
||||
const editCalls: unknown[][] = []
|
||||
const restApi = {
|
||||
xoApp: {
|
||||
getXapi: () => ({
|
||||
editNetwork: async (...args: unknown[]) => {
|
||||
editCalls.push(args)
|
||||
},
|
||||
}),
|
||||
},
|
||||
} as unknown as RestApi
|
||||
const controller = new NetworkController(restApi, {} as never)
|
||||
// not an object literal passed inline: an extra key is only allowed on a value, not on a fresh literal
|
||||
const body = {
|
||||
automatic: true,
|
||||
defaultIsLocked: false,
|
||||
insecureNbd: false,
|
||||
MTU: 9000,
|
||||
name_description: 'description',
|
||||
name_label: 'label',
|
||||
nbd: true,
|
||||
notAField: 'dropped',
|
||||
}
|
||||
|
||||
await controller.updateNetwork(NETWORK_ID, body)
|
||||
|
||||
assert.deepEqual(editCalls, [
|
||||
[
|
||||
NETWORK_ID,
|
||||
{
|
||||
automatic: true,
|
||||
defaultIsLocked: false,
|
||||
insecureNbd: false,
|
||||
MTU: 9000,
|
||||
name_description: 'description',
|
||||
name_label: 'label',
|
||||
nbd: true,
|
||||
},
|
||||
],
|
||||
])
|
||||
})
|
||||
})
|
||||
@@ -1,10 +1,62 @@
|
||||
import { invalidParameters } from 'xo-common/api-errors.js'
|
||||
|
||||
import type { CreateBondedNetworkBody, CreateInternalNetworkBody, CreateNetworkBody } from '../pools/pool.type.mjs'
|
||||
import type { ReplaceKey } from '../helpers/helper.type.mjs'
|
||||
import type { AuthenticatedRequest, ReplaceKey } from '../helpers/helper.type.mjs'
|
||||
import type { NextFunction, Response as ExResponse } from 'express'
|
||||
import type { RestApi } from '../rest-api/rest-api.mjs'
|
||||
import type { Xapi, XenApiNetworkWrapped, XoNetwork, XoPool } from '@vates/types'
|
||||
|
||||
type NetworkCreateNames = Pick<
|
||||
CreateNetworkBody,
|
||||
'name' | 'name_label' | 'description' | 'name_description' | 'mtu' | 'MTU'
|
||||
>
|
||||
|
||||
// maps the names the create routes accept to the ones xapi.createNetwork reads (name, description, mtu), and
|
||||
// refuses a body giving both spellings of one field or no name. The create routes call it before their task
|
||||
// starts, so the refusal is a 422 and not a failed task
|
||||
export function normalizeNetworkCreateBody<T extends NetworkCreateNames>(body: T) {
|
||||
const { name, name_label, description, name_description, mtu, MTU, ...rest } = body
|
||||
|
||||
if (name !== undefined && name_label !== undefined) {
|
||||
throw invalidParameters('give either name or name_label, not both')
|
||||
}
|
||||
if (description !== undefined && name_description !== undefined) {
|
||||
throw invalidParameters('give either description or name_description, not both')
|
||||
}
|
||||
if (mtu !== undefined && MTU !== undefined) {
|
||||
throw invalidParameters('give either mtu or MTU, not both')
|
||||
}
|
||||
|
||||
const networkName = name_label ?? name
|
||||
if (networkName === undefined) {
|
||||
throw invalidParameters('name_label is required')
|
||||
}
|
||||
|
||||
return {
|
||||
...rest,
|
||||
name: networkName,
|
||||
description: name_description ?? description,
|
||||
mtu: MTU ?? mtu,
|
||||
}
|
||||
}
|
||||
|
||||
// runs before acl(): acl() awaits its object callback outside any try, and Express 4 does not catch that rejection,
|
||||
// so a refusal thrown there would hang the request. Checked here, the callback below can't throw
|
||||
export function refuseInvalidNetworkCreateBody(req: AuthenticatedRequest, _res: ExResponse, next: NextFunction) {
|
||||
try {
|
||||
normalizeNetworkCreateBody(req.body)
|
||||
} catch (error) {
|
||||
return next(error)
|
||||
}
|
||||
next()
|
||||
}
|
||||
|
||||
// the ACL checks the privileges against the names xapi reads, so the selectors written on name, description and
|
||||
// mtu match whatever spelling the client used
|
||||
export function networkCreateAclObject({ req }: { req: AuthenticatedRequest }) {
|
||||
return normalizeNetworkCreateBody(req.body)
|
||||
}
|
||||
|
||||
export class NetworkService {
|
||||
#restApi: RestApi
|
||||
|
||||
@@ -12,9 +64,12 @@ export class NetworkService {
|
||||
this.#restApi = restApi
|
||||
}
|
||||
|
||||
// body must come from normalizeNetworkCreateBody
|
||||
async create(
|
||||
poolId: XoPool['id'],
|
||||
body: ReplaceKey<CreateNetworkBody, 'pif', 'pifId'> | CreateBondedNetworkBody | CreateInternalNetworkBody
|
||||
body: (ReplaceKey<CreateNetworkBody, 'pif', 'pifId'> | CreateBondedNetworkBody | CreateInternalNetworkBody) & {
|
||||
name: string
|
||||
}
|
||||
): Promise<XoNetwork['id']> {
|
||||
const { nbd, insecureNbd, ...rest } = body
|
||||
if (nbd && insecureNbd) {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { describe, it } from 'node:test'
|
||||
import { invalidParameters } from 'xo-common/api-errors.js'
|
||||
|
||||
import { networkCreateAclObject, normalizeNetworkCreateBody } from './network.service.mjs'
|
||||
|
||||
describe('normalizeNetworkCreateBody', () => {
|
||||
it('maps name_label, name_description and MTU to the names xapi.createNetwork reads', () => {
|
||||
const body = normalizeNetworkCreateBody({
|
||||
name_label: 'label',
|
||||
name_description: 'description',
|
||||
MTU: 9000,
|
||||
vlan: 0,
|
||||
})
|
||||
|
||||
assert.deepEqual(body, { name: 'label', description: 'description', mtu: 9000, vlan: 0 })
|
||||
})
|
||||
|
||||
it('still accepts the deprecated name, description and mtu', () => {
|
||||
const body = normalizeNetworkCreateBody({ name: 'label', description: 'description', mtu: 1450 })
|
||||
|
||||
assert.deepEqual(body, { name: 'label', description: 'description', mtu: 1450 })
|
||||
})
|
||||
|
||||
it('refuses a body giving both spellings of one field', () => {
|
||||
assert.throws(() => normalizeNetworkCreateBody({ name: 'a', name_label: 'b' }), invalidParameters.is)
|
||||
assert.throws(
|
||||
() => normalizeNetworkCreateBody({ name_label: 'a', description: 'b', name_description: 'c' }),
|
||||
invalidParameters.is
|
||||
)
|
||||
assert.throws(() => normalizeNetworkCreateBody({ name_label: 'a', mtu: 1450, MTU: 9000 }), invalidParameters.is)
|
||||
})
|
||||
|
||||
it('refuses a body with no name', () => {
|
||||
assert.throws(() => normalizeNetworkCreateBody({ name_description: 'description' }), invalidParameters.is)
|
||||
})
|
||||
|
||||
it('gives the ACL the old keys for a body sent with the new names', () => {
|
||||
const req = { body: { name_label: 'label', name_description: 'description', MTU: 9000 } }
|
||||
|
||||
assert.deepEqual(networkCreateAclObject({ req } as never), { name: 'label', description: 'description', mtu: 9000 })
|
||||
})
|
||||
})
|
||||
@@ -95,7 +95,12 @@ import { PoolService } from './pool.service.mjs'
|
||||
import { BASE_URL, escapeUnsafeComplexMatcher, NDJSON_CONTENT_TYPE } from '../helpers/utils.helper.mjs'
|
||||
import { messageIds, partialMessages } from '../open-api/oa-examples/message.oa-example.mjs'
|
||||
import type { CreateActionReturnType } from '../abstract-classes/base-controller.mjs'
|
||||
import { NetworkService } from '../networks/network.service.mjs'
|
||||
import {
|
||||
NetworkService,
|
||||
networkCreateAclObject,
|
||||
normalizeNetworkCreateBody,
|
||||
refuseInvalidNetworkCreateBody,
|
||||
} from '../networks/network.service.mjs'
|
||||
import { v2vStartResult } from '../open-api/oa-examples/v2v.oa-example.mjs'
|
||||
import { V2V_TASK_PROPERTY } from '@vates/types'
|
||||
import { V2vService, V2V_TASK_NAME } from '../v2v/v2v.service.mjs'
|
||||
@@ -180,8 +185,8 @@ export class PoolController extends XapiXoController<XoPool> {
|
||||
*
|
||||
* @example id "355ee47d-ff4c-4924-3db2-fd86ae629676"
|
||||
* @example body {
|
||||
* "name": "awes0me_network",
|
||||
* "description": "random description",
|
||||
* "name_label": "awes0me_network",
|
||||
* "name_description": "random description",
|
||||
* "pif": "ad15b2c8-3d9a-194e-c43a-e3dcda74b256",
|
||||
* "vlan": 0
|
||||
* }
|
||||
@@ -192,10 +197,11 @@ export class PoolController extends XapiXoController<XoPool> {
|
||||
@Post('{id}/actions/create_network')
|
||||
@Middlewares([
|
||||
json(),
|
||||
refuseInvalidNetworkCreateBody,
|
||||
acl([
|
||||
// these two rights are a bit redundant, but for now this is the only way to restrict network creation on a given pool
|
||||
{ resource: 'pool', action: 'create:network', objectId: 'params.id' },
|
||||
{ resource: 'network', action: 'create', object: ({ req }) => req.body },
|
||||
{ resource: 'network', action: 'create', object: networkCreateAclObject },
|
||||
]),
|
||||
])
|
||||
@Tags('networks')
|
||||
@@ -211,8 +217,8 @@ export class PoolController extends XapiXoController<XoPool> {
|
||||
@Query() sync?: boolean
|
||||
): CreateActionReturnType<{ id: Unbrand<XoNetwork>['id'] }> {
|
||||
const poolId = id as XoPool['id']
|
||||
const { pif, ...rest } = normalizeNetworkCreateBody(body)
|
||||
const action = async () => {
|
||||
const { pif, ...rest } = body
|
||||
const networkId = await this.#networkService.create(poolId, { pifId: pif as XoPif['id'], ...rest })
|
||||
|
||||
return { id: networkId }
|
||||
@@ -236,8 +242,8 @@ export class PoolController extends XapiXoController<XoPool> {
|
||||
*
|
||||
* @example id "355ee47d-ff4c-4924-3db2-fd86ae629676"
|
||||
* @example body {
|
||||
* "name": "awes0me_bonded_network",
|
||||
* "description": "random description",
|
||||
* "name_label": "awes0me_bonded_network",
|
||||
* "name_description": "random description",
|
||||
* "pifIds": ["ad15b2c8-3d9a-194e-c43a-e3dcda74b256", "7b6bed50-26b2-bd27-8f3a-1b5a81989a92"],
|
||||
* "bondMode": "lacp"
|
||||
* }
|
||||
@@ -248,9 +254,10 @@ export class PoolController extends XapiXoController<XoPool> {
|
||||
@Post('{id}/actions/create_bonded_network')
|
||||
@Middlewares([
|
||||
json(),
|
||||
refuseInvalidNetworkCreateBody,
|
||||
acl([
|
||||
{ resource: 'pool', action: 'create:network', objectId: 'params.id' },
|
||||
{ resource: 'network', action: 'create', object: ({ req }) => req.body },
|
||||
{ resource: 'network', action: 'create', object: networkCreateAclObject },
|
||||
]),
|
||||
])
|
||||
@Tags('networks')
|
||||
@@ -266,8 +273,8 @@ export class PoolController extends XapiXoController<XoPool> {
|
||||
@Query() sync?: boolean
|
||||
): CreateActionReturnType<{ id: Unbrand<XoNetwork>['id'] }> {
|
||||
const poolId = id as XoPool['id']
|
||||
const { pifIds, ...rest } = normalizeNetworkCreateBody(body)
|
||||
const action = async () => {
|
||||
const { pifIds, ...rest } = body
|
||||
const networkId = await this.#networkService.create(poolId, { pifIds: pifIds as XoPif['id'][], ...rest })
|
||||
|
||||
return { id: networkId }
|
||||
@@ -291,8 +298,8 @@ export class PoolController extends XapiXoController<XoPool> {
|
||||
*
|
||||
* @example id "355ee47d-ff4c-4924-3db2-fd86ae629676"
|
||||
* @example body {
|
||||
* "name": "awes0me_internal_network",
|
||||
* "description": "random description"
|
||||
* "name_label": "awes0me_internal_network",
|
||||
* "name_description": "random description"
|
||||
* }
|
||||
*/
|
||||
@Example(taskLocation)
|
||||
@@ -301,9 +308,10 @@ export class PoolController extends XapiXoController<XoPool> {
|
||||
@Post('{id}/actions/create_internal_network')
|
||||
@Middlewares([
|
||||
json(),
|
||||
refuseInvalidNetworkCreateBody,
|
||||
acl([
|
||||
{ resource: 'pool', action: 'create:network', objectId: 'params.id' },
|
||||
{ resource: 'network', action: 'create', object: ({ req }) => req.body },
|
||||
{ resource: 'network', action: 'create', object: networkCreateAclObject },
|
||||
]),
|
||||
])
|
||||
@Tags('networks')
|
||||
@@ -319,8 +327,9 @@ export class PoolController extends XapiXoController<XoPool> {
|
||||
@Query() sync?: boolean
|
||||
): CreateActionReturnType<{ id: Unbrand<XoNetwork>['id'] }> {
|
||||
const poolId = id as XoPool['id']
|
||||
const networkBody = normalizeNetworkCreateBody(body)
|
||||
const action = async () => {
|
||||
const networkId = await this.#networkService.create(poolId, body)
|
||||
const networkId = await this.#networkService.create(poolId, networkBody)
|
||||
|
||||
return { id: networkId }
|
||||
}
|
||||
|
||||
@@ -12,13 +12,28 @@ import type {
|
||||
} from '@vates/types'
|
||||
import { Unbrand } from '../open-api/common/response.common.mjs'
|
||||
|
||||
// the names are the ones PATCH /networks/{id} takes (name_label, name_description, MTU); name, description and mtu
|
||||
// are the names these routes took before and still work. tsoa cannot express "exactly one of", so name and
|
||||
// name_label are both optional here and normalizeNetworkCreateBody (network.service.mts) refuses a body with neither
|
||||
type BaseCreateNetworkBody = {
|
||||
name: string
|
||||
/**
|
||||
* @deprecated use `name_label`
|
||||
*/
|
||||
name?: string
|
||||
name_label?: string
|
||||
/**
|
||||
* @deprecated use `name_description`
|
||||
*/
|
||||
description?: string
|
||||
name_description?: string
|
||||
/**
|
||||
* @deprecated use `MTU`
|
||||
*/
|
||||
mtu?: number
|
||||
/**
|
||||
* @default 1500
|
||||
*/
|
||||
mtu?: number
|
||||
MTU?: number
|
||||
nbd?: boolean
|
||||
/**
|
||||
* NBD in clear, only on a network dedicated to backups. Mutually exclusive with `nbd`
|
||||
|
||||
@@ -89,7 +89,7 @@ const CONTROLLER_PREFIXES = {
|
||||
* 'config.annotation'?: string,
|
||||
* 'config.instanceUuid'?: string,
|
||||
* 'config.firmware'?: string,
|
||||
* 'config.bootOptions.efiSecureBootEnabled'?: unknown,
|
||||
* 'config.bootOptions'?: { efiSecureBootEnabled?: unknown },
|
||||
* 'config.template'?: unknown,
|
||||
* 'config.hardware.numCPU'?: unknown,
|
||||
* 'config.hardware.memoryMB'?: unknown,
|
||||
@@ -379,7 +379,7 @@ export function buildInventory({
|
||||
annotation: properties['config.annotation'],
|
||||
instanceUuid: properties['config.instanceUuid'],
|
||||
firmware: firmware === 'efi' ? 'uefi' : firmware,
|
||||
secureBoot: isTrue(properties['config.bootOptions.efiSecureBootEnabled']),
|
||||
secureBoot: isTrue(properties['config.bootOptions']?.efiSecureBootEnabled),
|
||||
isTemplate: isTrue(properties['config.template']),
|
||||
cpus: toNumber(properties['config.hardware.numCPU']),
|
||||
memory: memoryMb === undefined ? undefined : memoryMb * 1024 * 1024,
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { describe, it } from 'node:test'
|
||||
|
||||
import { countSnapshots, findDatacenter, parseDevices, parseGuestNics, parseVlan } from './_inventory.mjs'
|
||||
import {
|
||||
buildInventory,
|
||||
countSnapshots,
|
||||
findDatacenter,
|
||||
parseDevices,
|
||||
parseGuestNics,
|
||||
parseVlan,
|
||||
} from './_inventory.mjs'
|
||||
|
||||
// shaped as the SOAP library returns them: the nested references and types are not normalized
|
||||
const typed = (type, value) => ({ attributes: { 'xsi:type': type }, ...value })
|
||||
@@ -202,3 +209,37 @@ describe('findDatacenter', function () {
|
||||
assert.equal(findDatacenter('group-a', loop, datacenterIds), undefined)
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildInventory', function () {
|
||||
const EMPTY = {
|
||||
about: {},
|
||||
datacenters: {},
|
||||
clusters: {},
|
||||
hosts: {},
|
||||
datastores: {},
|
||||
networks: {},
|
||||
portgroups: {},
|
||||
folders: {},
|
||||
computeResources: {},
|
||||
}
|
||||
|
||||
it('reads secure boot from the boot options, absent before vSphere 6.5', function () {
|
||||
const { vms } = buildInventory({
|
||||
...EMPTY,
|
||||
vms: {
|
||||
'vm-65': { 'config.bootOptions': { efiSecureBootEnabled: 'true' } },
|
||||
// ESXi 6.0: the boot options have no `efiSecureBootEnabled`
|
||||
'vm-60': { 'config.bootOptions': { bootDelay: '0' } },
|
||||
'vm-none': {},
|
||||
},
|
||||
})
|
||||
assert.deepEqual(
|
||||
vms.map(({ id, secureBoot }) => ({ id, secureBoot })),
|
||||
[
|
||||
{ id: 'vm-65', secureBoot: true },
|
||||
{ id: 'vm-60', secureBoot: false },
|
||||
{ id: 'vm-none', secureBoot: false },
|
||||
]
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -623,7 +623,9 @@ export default class Esxi extends EventEmitter {
|
||||
'config.annotation',
|
||||
'config.instanceUuid',
|
||||
'config.firmware',
|
||||
'config.bootOptions.efiSecureBootEnabled',
|
||||
// the whole object rather than `config.bootOptions.efiSecureBootEnabled`: that property only
|
||||
// exists since vSphere 6.5, and an unknown path fails the whole request (InvalidProperty)
|
||||
'config.bootOptions',
|
||||
'config.template',
|
||||
'config.hardware.numCPU',
|
||||
'config.hardware.memoryMB',
|
||||
@@ -1134,9 +1136,11 @@ export default class Esxi extends EventEmitter {
|
||||
* @returns {Promise<object>} the `info` of the successful task
|
||||
*/
|
||||
async snapshot(vmId, name, description, { signal, timeout = 30 * 60e3 } = {}) {
|
||||
// not `CreateSnapshotEx_Task`: it only exists since vSphere 8 (absent from the WSDL of older
|
||||
// hosts), and its only addition, the quiesce spec, is not used
|
||||
return this.#runTask(
|
||||
'CreateSnapshotEx_Task',
|
||||
{ _this: vmId, name, description, memory: false },
|
||||
'CreateSnapshot_Task',
|
||||
{ _this: vmId, name, description, memory: false, quiesce: false },
|
||||
{ signal, timeout }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -696,7 +696,7 @@ describe('tasks', function () {
|
||||
const controller = new AbortController()
|
||||
const { esxi, vimClient } = await connectedEsxi({
|
||||
responses: {
|
||||
CreateSnapshotEx_Task: () => startedTask(),
|
||||
CreateSnapshot_Task: () => startedTask(),
|
||||
RetrievePropertiesEx: () => {
|
||||
controller.abort()
|
||||
return taskInfo('running')
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
# Directives
|
||||
|
||||
- [vRestricted](../lib/directives/restricted.directive.md)
|
||||
- [vTooltip](../lib/directives/tooltip.directive.md)
|
||||
|
||||
# Utils
|
||||
|
||||
@@ -59,13 +59,12 @@ Testing uses **Vitest 5** with a single `unit` project (see `vitest.config.ts`):
|
||||
| `test/expect-loader.ts` | `hasLoader(wrapper)`: whether a `UiLoader` is rendered; `expectLoaderInsteadOf(wrapper, findContent)`: a `UiLoader` shown and the content it stands for empty (also used by XO 6) |
|
||||
| `test/select.ts` | `openSelect`, `findShownSelections`, `findSelectOptionLabels`, `pickSelectOption(wrapper, label, { detailed? })`: opens a `VtsSelect`, reads the selection it shows, reads or picks its options (`detailed`: the option shows details after its label); `chooseSelectOption(wrapper, label, { container?, detailed? })`: opens the select inside `container`, then picks the option (also used by XO 6) |
|
||||
| `test/is-placeholder-shown.ts` | `isPlaceholderShown(field)`: whether a readonly input shows its placeholder in place of its value |
|
||||
| `test/can-focus-input.ts` | `canFocusInput(wrapper)`: whether the first input of a wrapper attached to the document takes the focus, which an `inert` ancestor prevents |
|
||||
| `test/inject-or-throw.ts` | `injectOrThrow(key)`: `inject(key)`, throwing when nothing provides it |
|
||||
| `test/mount-with-setup.ts` | `mountWithSetup(setup, { global?, attachTo? })`: mounts a component whose `setup` sets up what its render needs below it (a select, a provided context) and returns that render (XO 6 wraps it with its config); `mountWithSetupResult(setup, options)`: the same, keeping what `setup` builds (a form, a composable's return), `setup` returning `{ result, render }`, returns `{ wrapper, result }`; `mountComposableUnderSetup(setup, composable, options)`: runs `composable` (given what `setup` returned) in a child of the component whose `setup` provides what it injects, returns `{ provided, result }` |
|
||||
| `test/mount-with-select.ts` | `renderSelect(id, { accent?, ref? }, slots?)`: renders the `VtsSelect` of a select id, `neutral` accent by default; `mountSelect`: a `VtsSelect` of string sources, its config, accent, wrapper message, option slot and a callback receiving the mounted select |
|
||||
| `test/find-title.ts` | `findTitle`: the `.title` of a `VtsSuccessStateHero` or a list item, `undefined` without one (also used by XO 6) |
|
||||
| `test/create-task-item.ts` | `createTaskItem`: a `Task` as the task lists display it, with the given overrides (also used by XO 6) |
|
||||
| `test/find-tooltip-contents.ts` | `findTooltipContents`: the content of every tooltip currently shown, in order |
|
||||
| `test/hover.ts` | `hover`: moves the mouse over an element |
|
||||
| `tsconfig.vitest.json` | Type-checks test files with the Vitest globals and the `@core-test` alias |
|
||||
| `tsconfig.app.json` | Type-checks the library, test files excluded |
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ const columnTransition = `grid-template-columns ${PANEL_TRANSITION_DURATION}ms`
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) 0;
|
||||
grid-template-rows: minmax(0, 1fr);
|
||||
overflow: hidden;
|
||||
overflow: clip;
|
||||
|
||||
.content {
|
||||
overflow-y: auto;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import VtsLayoutSidebar from '@core/components/layout/VtsLayoutSidebar.vue'
|
||||
import { useRightSidebarStore } from '@core/packages/sidebar'
|
||||
import { canFocusInput } from '@core-test/can-focus-input.ts'
|
||||
import { createGlobalTestConfig } from '@core-test/create-global-test-config.ts'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { h, nextTick } from 'vue'
|
||||
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
})
|
||||
|
||||
function mountSidebar({ isExpanded }: { isExpanded: boolean }) {
|
||||
localStorage.setItem('sidebar.right.expanded', String(isExpanded))
|
||||
|
||||
return mount(VtsLayoutSidebar, {
|
||||
props: { side: 'right' },
|
||||
slots: { default: () => h('input') },
|
||||
global: createGlobalTestConfig(),
|
||||
attachTo: document.body,
|
||||
})
|
||||
}
|
||||
|
||||
it('lets the focus into an expanded sidebar', () => {
|
||||
expect(canFocusInput(mountSidebar({ isExpanded: true }))).toBe(true)
|
||||
})
|
||||
|
||||
it('keeps the focus out of a collapsed sidebar', () => {
|
||||
expect(canFocusInput(mountSidebar({ isExpanded: false }))).toBe(false)
|
||||
})
|
||||
|
||||
it('lets the focus in once the sidebar expands', async () => {
|
||||
const wrapper = mountSidebar({ isExpanded: false })
|
||||
|
||||
useRightSidebarStore().toggleExpand(true)
|
||||
await nextTick()
|
||||
|
||||
expect(canFocusInput(wrapper)).toBe(true)
|
||||
})
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div :class="className" class="vts-layout-sidebar">
|
||||
<div :class="className" class="vts-layout-sidebar" :inert="!sidebar.isExpanded">
|
||||
<VtsResizeHandle v-if="showResizeHandle" :position="resizeHandlePosition" :resizable="sidebar" />
|
||||
<div v-if="slots.header || (showLock && !ui.isSmall)" class="header">
|
||||
<div v-if="slots.header" class="start">
|
||||
|
||||
@@ -1,13 +1,29 @@
|
||||
<template>
|
||||
<UiModal accent="danger" icon="status:danger-picto" @dismiss="emit('close')" @confirm="emit('close')">
|
||||
<UiModal
|
||||
class="vts-error-modal"
|
||||
accent="danger"
|
||||
icon="status:info-picto"
|
||||
@dismiss="emit('close')"
|
||||
@confirm="emit('close')"
|
||||
>
|
||||
<template #title>
|
||||
{{ title }}
|
||||
</template>
|
||||
|
||||
<template #content>
|
||||
<slot name="content">
|
||||
{{ error }}
|
||||
</slot>
|
||||
<div class="content">
|
||||
<slot name="content">
|
||||
{{ error }}
|
||||
</slot>
|
||||
<UiLogEntryViewer
|
||||
v-if="details !== undefined"
|
||||
:label="t('see-details')"
|
||||
:content="details"
|
||||
accent="danger"
|
||||
size="small"
|
||||
class="details"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #buttons>
|
||||
@@ -20,12 +36,14 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
|
||||
import UiLogEntryViewer from '@core/components/ui/log-entry-viewer/UiLogEntryViewer.vue'
|
||||
import UiModal from '@core/components/ui/modal/UiModal.vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
defineProps<{
|
||||
title: string
|
||||
error?: string
|
||||
details?: string | object
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -38,3 +56,19 @@ defineSlots<{
|
||||
|
||||
const { t } = useI18n()
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
.vts-error-modal {
|
||||
.content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
|
||||
.details {
|
||||
text-align: start;
|
||||
/* The small action buttons must not overflow the scrollable modal content */
|
||||
overflow-x: clip;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import VtsSidePanel from '@core/components/panel/VtsSidePanel.vue'
|
||||
import { canFocusInput } from '@core-test/can-focus-input.ts'
|
||||
import { createGlobalTestConfig } from '@core-test/create-global-test-config.ts'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { h } from 'vue'
|
||||
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
})
|
||||
|
||||
function mountPanel({ hasSelection }: { hasSelection: boolean }) {
|
||||
localStorage.setItem('panel.locked', 'false')
|
||||
|
||||
return mount(VtsSidePanel, {
|
||||
props: { hasSelection, persistent: true },
|
||||
slots: { default: () => h('input') },
|
||||
global: createGlobalTestConfig(),
|
||||
attachTo: document.body,
|
||||
})
|
||||
}
|
||||
|
||||
it('lets the focus into a panel that a selection expands', () => {
|
||||
expect(canFocusInput(mountPanel({ hasSelection: true }))).toBe(true)
|
||||
})
|
||||
|
||||
it('keeps the focus out of a collapsed panel', () => {
|
||||
expect(canFocusInput(mountPanel({ hasSelection: false }))).toBe(false)
|
||||
})
|
||||
|
||||
it('lets the focus in once a selection expands the panel', async () => {
|
||||
const wrapper = mountPanel({ hasSelection: false })
|
||||
|
||||
await wrapper.setProps({ hasSelection: true })
|
||||
|
||||
expect(canFocusInput(wrapper)).toBe(true)
|
||||
})
|
||||
@@ -1,6 +1,6 @@
|
||||
<!-- v5 -->
|
||||
<template>
|
||||
<div class="vts-side-panel" :class="{ mobile: uiStore.isSmall }">
|
||||
<div class="vts-side-panel" :class="{ mobile: uiStore.isSmall }" :inert="!panelStore.isExpanded">
|
||||
<VtsResizeHandle v-if="showResizeHandle" position="start" :resizable="panelStore" />
|
||||
<VtsPanel
|
||||
:closable="isClosable"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<template>
|
||||
<UiTableCell :flexible>
|
||||
<div class="username">
|
||||
<div class="user-name">
|
||||
<UiUserLogo size="small" />
|
||||
<UiLink :to :href size="medium" class="link">
|
||||
<UiLink :href size="medium" class="link">
|
||||
<VtsMiddleEllipsis v-if="flexible" :text="content" />
|
||||
<span v-else v-tooltip class="text-ellipsis">{{ content }}</span>
|
||||
</UiLink>
|
||||
@@ -15,19 +15,17 @@ import VtsMiddleEllipsis from '@core/components/middle-ellipsis/VtsMiddleEllipsi
|
||||
import UiLink from '@core/components/ui/link/UiLink.vue'
|
||||
import UiTableCell from '@core/components/ui/table-cell/UiTableCell.vue'
|
||||
import UiUserLogo from '@core/components/ui/user-logo/UiUserLogo.vue'
|
||||
import type { LinkOptions } from '@core/composables/link-component.composable.ts'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive.ts'
|
||||
|
||||
defineProps<
|
||||
Pick<LinkOptions, 'to' | 'href'> & {
|
||||
content: string
|
||||
flexible?: boolean
|
||||
}
|
||||
>()
|
||||
defineProps<{
|
||||
content: string
|
||||
href?: string
|
||||
flexible?: boolean
|
||||
}>()
|
||||
</script>
|
||||
|
||||
<style scoped lang="postcss">
|
||||
.username {
|
||||
.user-name {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.8rem;
|
||||
@@ -1,47 +0,0 @@
|
||||
import UiButtonIcon from '@core/components/ui/button-icon/UiButtonIcon.vue'
|
||||
import { createGlobalTestConfig } from '@core-test/create-global-test-config.ts'
|
||||
import { mount } from '@vue/test-utils'
|
||||
|
||||
function mountButtonIcon({ restricted = false }: { restricted?: boolean } = {}) {
|
||||
const onClick = vi.fn()
|
||||
|
||||
const wrapper = mount(UiButtonIcon, {
|
||||
global: createGlobalTestConfig(),
|
||||
props: { icon: 'fa:trash', accent: 'brand', size: 'medium', restricted },
|
||||
attrs: { onClick },
|
||||
})
|
||||
|
||||
return { wrapper, onClick }
|
||||
}
|
||||
|
||||
it('is marked as disabled but stays focusable when restricted', () => {
|
||||
const { wrapper } = mountButtonIcon({ restricted: true })
|
||||
|
||||
expect(wrapper.attributes('aria-disabled')).toBe('true')
|
||||
expect(wrapper.attributes('disabled')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('is not marked as disabled by default', () => {
|
||||
const { wrapper } = mountButtonIcon()
|
||||
|
||||
expect(wrapper.attributes('aria-disabled')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('has the muted variant when restricted', () => {
|
||||
const restrictedButtonIcon = mountButtonIcon({ restricted: true })
|
||||
const buttonIcon = mountButtonIcon()
|
||||
|
||||
expect(restrictedButtonIcon.wrapper.classes()).toContain('muted')
|
||||
expect(buttonIcon.wrapper.classes()).not.toContain('muted')
|
||||
})
|
||||
|
||||
it('runs its click listener only when not restricted', async () => {
|
||||
const restrictedButtonIcon = mountButtonIcon({ restricted: true })
|
||||
const buttonIcon = mountButtonIcon()
|
||||
|
||||
await restrictedButtonIcon.wrapper.trigger('click')
|
||||
await buttonIcon.wrapper.trigger('click')
|
||||
|
||||
expect(restrictedButtonIcon.onClick).not.toHaveBeenCalled()
|
||||
expect(buttonIcon.onClick).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
@@ -1,7 +1,7 @@
|
||||
<!-- v11 -->
|
||||
<!-- v10 -->
|
||||
<!-- TODO: Add complex icon -->
|
||||
<template>
|
||||
<button v-restricted="restricted" :class="classNames" :disabled class="ui-button-icon" type="button">
|
||||
<button :class="classNames" :disabled class="ui-button-icon" type="button">
|
||||
<VtsIcon :name="icon" size="current" />
|
||||
<UiCounter v-if="counterProps !== undefined" v-bind="counterProps" size="small" variant="primary" class="counter" />
|
||||
</button>
|
||||
@@ -10,7 +10,6 @@
|
||||
<script lang="ts" setup>
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import UiCounter, { type CounterAccent, type CounterValue } from '@core/components/ui/counter/UiCounter.vue'
|
||||
import { vRestricted } from '@core/directives/restricted.directive.ts'
|
||||
import type { IconName } from '@core/icons'
|
||||
import { toVariants } from '@core/utils/to-variants.util.ts'
|
||||
import { computed } from 'vue'
|
||||
@@ -19,12 +18,11 @@ export type ButtonIconAccent = 'brand' | 'info' | 'warning' | 'danger'
|
||||
|
||||
export type ButtonIconSize = 'small' | 'medium' | 'large'
|
||||
|
||||
const { accent, size, disabled, restricted, selected, counter, targetScale } = defineProps<{
|
||||
const { accent, size, disabled, selected, counter, targetScale } = defineProps<{
|
||||
icon: IconName
|
||||
size: ButtonIconSize
|
||||
accent: ButtonIconAccent
|
||||
disabled?: boolean
|
||||
restricted?: boolean
|
||||
selected?: boolean
|
||||
counter?: CounterValue | { value: CounterValue; accent: CounterAccent }
|
||||
targetScale?: number | { x: number; y: number }
|
||||
@@ -57,7 +55,7 @@ const classNames = computed(() => {
|
||||
toVariants({
|
||||
accent,
|
||||
size,
|
||||
muted: disabled || restricted,
|
||||
muted: disabled,
|
||||
selected,
|
||||
}),
|
||||
]
|
||||
@@ -76,7 +74,7 @@ const classNames = computed(() => {
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
|
||||
&.muted {
|
||||
&:disabled {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
import UiButton from '@core/components/ui/button/UiButton.vue'
|
||||
import { createGlobalTestConfig } from '@core-test/create-global-test-config.ts'
|
||||
import { mount } from '@vue/test-utils'
|
||||
|
||||
function mountButton({ restricted = false }: { restricted?: boolean } = {}) {
|
||||
const onClick = vi.fn()
|
||||
|
||||
const wrapper = mount(UiButton, {
|
||||
global: createGlobalTestConfig(),
|
||||
props: { variant: 'primary', accent: 'brand', size: 'medium', restricted },
|
||||
attrs: { onClick },
|
||||
slots: { default: 'Label' },
|
||||
})
|
||||
|
||||
return { wrapper, onClick }
|
||||
}
|
||||
|
||||
it('is marked as disabled but stays focusable when restricted', () => {
|
||||
const { wrapper } = mountButton({ restricted: true })
|
||||
|
||||
expect(wrapper.attributes('aria-disabled')).toBe('true')
|
||||
expect(wrapper.attributes('disabled')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('is not marked as disabled by default', () => {
|
||||
const { wrapper } = mountButton()
|
||||
|
||||
expect(wrapper.attributes('aria-disabled')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('has the disabled variant when restricted', () => {
|
||||
const restrictedButton = mountButton({ restricted: true })
|
||||
const button = mountButton()
|
||||
|
||||
expect(restrictedButton.wrapper.classes()).toContain('disabled')
|
||||
expect(button.wrapper.classes()).not.toContain('disabled')
|
||||
})
|
||||
|
||||
it('runs its click listener only when not restricted', async () => {
|
||||
const restrictedButton = mountButton({ restricted: true })
|
||||
const button = mountButton()
|
||||
|
||||
await restrictedButton.wrapper.trigger('click')
|
||||
await button.wrapper.trigger('click')
|
||||
|
||||
expect(restrictedButton.onClick).not.toHaveBeenCalled()
|
||||
expect(button.onClick).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
@@ -1,12 +1,6 @@
|
||||
<!-- v9 -->
|
||||
<!-- v7 -->
|
||||
<template>
|
||||
<button
|
||||
v-restricted="restricted"
|
||||
:class="classNames"
|
||||
:disabled="busy || isDisabled || lockIcon"
|
||||
class="ui-button"
|
||||
type="button"
|
||||
>
|
||||
<button :class="classNames" :disabled="busy || isDisabled || lockIcon" class="ui-button" type="button">
|
||||
<VtsIcon :name="leftIcon" class="icon" size="current" />
|
||||
<slot />
|
||||
<VtsIcon :name="rightIcon" class="icon" size="current" />
|
||||
@@ -19,7 +13,6 @@
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import UiLoader from '@core/components/ui/loader/UiLoader.vue'
|
||||
import { useDisabled } from '@core/composables/disabled.composable.ts'
|
||||
import { vRestricted } from '@core/directives/restricted.directive.ts'
|
||||
import type { IconName } from '@core/icons'
|
||||
import { toVariants } from '@core/utils/to-variants.util.ts'
|
||||
import { computed } from 'vue'
|
||||
@@ -34,13 +27,12 @@ export type ButtonProps = {
|
||||
size: ButtonSize
|
||||
busy?: boolean
|
||||
disabled?: boolean
|
||||
restricted?: boolean
|
||||
lockIcon?: boolean
|
||||
leftIcon?: IconName
|
||||
rightIcon?: IconName
|
||||
}
|
||||
|
||||
const { accent, variant, size, disabled, restricted, busy, lockIcon } = defineProps<ButtonProps>()
|
||||
const { accent, variant, size, disabled, busy, lockIcon } = defineProps<ButtonProps>()
|
||||
|
||||
defineSlots<{
|
||||
default(): any
|
||||
@@ -62,7 +54,7 @@ const classNames = computed(() => [
|
||||
size,
|
||||
busy,
|
||||
lock: lockIcon,
|
||||
disabled: isDisabled.value || restricted,
|
||||
disabled: isDisabled.value,
|
||||
}),
|
||||
])
|
||||
</script>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<template>
|
||||
<div class="ui-log-entry-viewer" :class="className">
|
||||
<div class="label-container">
|
||||
<div v-if="label" :class="fontClasses.labelClass" class="label">
|
||||
<div :class="fontClasses.labelClass" class="label">
|
||||
{{ label }}
|
||||
</div>
|
||||
<div class="actions">
|
||||
@@ -36,7 +36,7 @@ const {
|
||||
accent,
|
||||
content: rawContent = '',
|
||||
} = defineProps<{
|
||||
label?: string
|
||||
label: string
|
||||
content: string | object | undefined
|
||||
size: LogEntryViewerSize
|
||||
accent: LogEntryViewerAccent
|
||||
@@ -104,7 +104,6 @@ function openRawValueInNewTab() {
|
||||
}
|
||||
|
||||
.actions {
|
||||
margin-inline-start: auto;
|
||||
display: flex;
|
||||
gap: 0.8rem;
|
||||
align-items: center;
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
|
||||
|
||||
export function useErrorModal() {
|
||||
return useOverlay({
|
||||
component: () => import('@core/components/modal/VtsErrorModal.vue'),
|
||||
events: {
|
||||
onClose: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
# Restricted Directive
|
||||
|
||||
Marks an action the user has no permission to run.
|
||||
|
||||
When its value is `true`, the element:
|
||||
|
||||
- keeps the keyboard focus, but is announced as disabled (`aria-disabled="true"`)
|
||||
- ignores clicks
|
||||
- shows a "Permission required" tooltip on hover and on keyboard focus, in place of any other tooltip it has
|
||||
|
||||
The directive adds no style. The component that uses it styles its restricted state.
|
||||
|
||||
## Usage
|
||||
|
||||
Use the directive inside a component, on the native element that runs the action.
|
||||
|
||||
Do not use it on a component. Give the component a `restricted` prop, and let it apply the directive to its own element:
|
||||
|
||||
```vue
|
||||
<template>
|
||||
<button v-restricted="restricted" type="button">
|
||||
<slot />
|
||||
</button>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { vRestricted } from '@core/directives/restricted.directive.ts'
|
||||
|
||||
const { restricted } = defineProps<{
|
||||
restricted?: boolean
|
||||
}>()
|
||||
</script>
|
||||
```
|
||||
@@ -1,64 +0,0 @@
|
||||
import { parseTooltipOptions } from '@core/directives/tooltip.directive.ts'
|
||||
import i18n from '@core/i18n.ts'
|
||||
import { TOOLTIP_FOCUS_EVENTS, TOOLTIP_HOVER_EVENTS, useTooltipStore } from '@core/stores/tooltip.store.ts'
|
||||
import type { Directive } from 'vue'
|
||||
|
||||
const tooltipKeys = new WeakMap<HTMLElement, string>()
|
||||
|
||||
const blockClick = (event: Event) => {
|
||||
event.preventDefault()
|
||||
event.stopImmediatePropagation()
|
||||
}
|
||||
|
||||
const restrict = (target: HTMLElement) => {
|
||||
if (tooltipKeys.has(target)) {
|
||||
return
|
||||
}
|
||||
|
||||
target.setAttribute('aria-disabled', 'true')
|
||||
target.addEventListener('click', blockClick, { capture: true })
|
||||
|
||||
const tooltipKey = useTooltipStore().register({
|
||||
target,
|
||||
options: parseTooltipOptions(i18n.global.t('permission-required')),
|
||||
events: [TOOLTIP_HOVER_EVENTS, TOOLTIP_FOCUS_EVENTS],
|
||||
isPrioritized: true,
|
||||
})
|
||||
|
||||
tooltipKeys.set(target, tooltipKey)
|
||||
}
|
||||
|
||||
const unrestrict = (target: HTMLElement) => {
|
||||
const tooltipKey = tooltipKeys.get(target)
|
||||
|
||||
if (tooltipKey === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
target.removeAttribute('aria-disabled')
|
||||
target.removeEventListener('click', blockClick, { capture: true })
|
||||
useTooltipStore().unregister(tooltipKey)
|
||||
tooltipKeys.delete(target)
|
||||
}
|
||||
|
||||
const applyRestriction = (target: HTMLElement, isRestricted: boolean) => {
|
||||
if (isRestricted) {
|
||||
restrict(target)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
unrestrict(target)
|
||||
}
|
||||
|
||||
export const vRestricted: Directive<HTMLElement, boolean> = {
|
||||
mounted(target, binding) {
|
||||
applyRestriction(target, binding.value)
|
||||
},
|
||||
updated(target, binding) {
|
||||
applyRestriction(target, binding.value)
|
||||
},
|
||||
beforeUnmount(target) {
|
||||
unrestrict(target)
|
||||
},
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
import { vRestricted } from '@core/directives/restricted.directive.ts'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive.ts'
|
||||
import { findTooltipContents } from '@core-test/find-tooltip-contents.ts'
|
||||
import { hover } from '@core-test/hover.ts'
|
||||
import { t } from '@core-test/i18n.ts'
|
||||
import { mountWithSetup } from '@core-test/mount-with-setup.ts'
|
||||
import { h, nextTick, ref, withDirectives } from 'vue'
|
||||
|
||||
function mountButton({ tooltip }: { tooltip?: string } = {}) {
|
||||
const isRestricted = ref(true)
|
||||
const onClick = vi.fn()
|
||||
|
||||
const wrapper = mountWithSetup(
|
||||
() => () => {
|
||||
const button = withDirectives(h('button', { onClick }), [[vRestricted, isRestricted.value]])
|
||||
|
||||
if (tooltip === undefined) {
|
||||
return button
|
||||
}
|
||||
|
||||
return withDirectives(button, [[vTooltip, tooltip]])
|
||||
},
|
||||
{ attachTo: document.body }
|
||||
)
|
||||
|
||||
return { button: wrapper.element as HTMLElement, isRestricted, onClick }
|
||||
}
|
||||
|
||||
function click(button: HTMLElement) {
|
||||
const event = new MouseEvent('click', { bubbles: true, cancelable: true })
|
||||
|
||||
button.dispatchEvent(event)
|
||||
|
||||
return event
|
||||
}
|
||||
|
||||
it('marks a restricted element as disabled for assistive technologies, without disabling it', () => {
|
||||
const { button } = mountButton()
|
||||
|
||||
expect(button.getAttribute('aria-disabled')).toBe('true')
|
||||
expect(button.hasAttribute('disabled')).toBe(false)
|
||||
})
|
||||
|
||||
it('blocks the click listeners of a restricted element', () => {
|
||||
const { button, onClick } = mountButton()
|
||||
|
||||
click(button)
|
||||
|
||||
expect(onClick).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('prevents the default action of a click on a restricted element', () => {
|
||||
const { button } = mountButton()
|
||||
|
||||
const blockedClick = click(button)
|
||||
|
||||
expect(blockedClick.defaultPrevented).toBe(true)
|
||||
})
|
||||
|
||||
it('restricts the element only while its value is true', async () => {
|
||||
const { button, isRestricted, onClick } = mountButton()
|
||||
|
||||
isRestricted.value = false
|
||||
await nextTick()
|
||||
const allowedClick = click(button)
|
||||
|
||||
expect(button.hasAttribute('aria-disabled')).toBe(false)
|
||||
expect(allowedClick.defaultPrevented).toBe(false)
|
||||
expect(onClick).toHaveBeenCalledTimes(1)
|
||||
|
||||
isRestricted.value = true
|
||||
await nextTick()
|
||||
click(button)
|
||||
|
||||
expect(button.getAttribute('aria-disabled')).toBe('true')
|
||||
expect(onClick).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('shows the permission tooltip while the restricted element is hovered', () => {
|
||||
const { button } = mountButton()
|
||||
|
||||
hover(button)
|
||||
|
||||
expect(findTooltipContents()).toEqual([t('permission-required')])
|
||||
|
||||
button.dispatchEvent(new MouseEvent('mouseleave'))
|
||||
|
||||
expect(findTooltipContents()).toEqual([])
|
||||
})
|
||||
|
||||
it('shows the permission tooltip while the restricted element is focused', () => {
|
||||
const { button } = mountButton()
|
||||
|
||||
button.focus()
|
||||
|
||||
expect(findTooltipContents()).toEqual([t('permission-required')])
|
||||
|
||||
button.blur()
|
||||
|
||||
expect(findTooltipContents()).toEqual([])
|
||||
})
|
||||
|
||||
it('hides the permission tooltip when the mouse leaves a restricted element focused by a click', () => {
|
||||
const { button } = mountButton()
|
||||
|
||||
hover(button)
|
||||
button.dispatchEvent(new FocusEvent('focusin'))
|
||||
button.dispatchEvent(new MouseEvent('mouseleave'))
|
||||
|
||||
expect(findTooltipContents()).toEqual([])
|
||||
})
|
||||
|
||||
it('shows the permission tooltip in place of the one the element already has', () => {
|
||||
const { button } = mountButton({ tooltip: 'Name' })
|
||||
|
||||
hover(button)
|
||||
|
||||
expect(findTooltipContents()).toEqual([t('permission-required')])
|
||||
})
|
||||
|
||||
it('shows the tooltip the element already has once it is no longer restricted', async () => {
|
||||
const { button, isRestricted } = mountButton({ tooltip: 'Name' })
|
||||
|
||||
hover(button)
|
||||
isRestricted.value = false
|
||||
await nextTick()
|
||||
|
||||
expect(findTooltipContents()).toEqual(['Name'])
|
||||
})
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { TooltipOptions } from '@core/stores/tooltip.store.ts'
|
||||
import { TOOLTIP_FOCUS_EVENTS, TOOLTIP_HOVER_EVENTS, useTooltipStore } from '@core/stores/tooltip.store.ts'
|
||||
import type { TooltipEvents, TooltipOptions } from '@core/stores/tooltip.store.ts'
|
||||
import { useTooltipStore } from '@core/stores/tooltip.store.ts'
|
||||
import { isObject } from 'lodash-es'
|
||||
import type { Options } from 'placement.js'
|
||||
import type { Directive } from 'vue'
|
||||
@@ -15,7 +15,7 @@ type TooltipDirectiveOptions =
|
||||
vertical?: boolean
|
||||
}
|
||||
|
||||
export const parseTooltipOptions = (options: TooltipDirectiveOptions): TooltipOptions => {
|
||||
const parseOptions = (options: TooltipDirectiveOptions): TooltipOptions => {
|
||||
const {
|
||||
placement,
|
||||
content,
|
||||
@@ -31,41 +31,22 @@ export const parseTooltipOptions = (options: TooltipDirectiveOptions): TooltipOp
|
||||
}
|
||||
}
|
||||
|
||||
const tooltipKeys = new WeakMap<HTMLElement, string>()
|
||||
|
||||
const unregisterTooltip = (target: HTMLElement) => {
|
||||
const tooltipKey = tooltipKeys.get(target)
|
||||
|
||||
if (tooltipKey === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
useTooltipStore().unregister(tooltipKey)
|
||||
tooltipKeys.delete(target)
|
||||
}
|
||||
|
||||
export const vTooltip: Directive<HTMLElement, TooltipDirectiveOptions> = {
|
||||
mounted(target, binding) {
|
||||
unregisterTooltip(target)
|
||||
const store = useTooltipStore()
|
||||
|
||||
const tooltipKey = useTooltipStore().register({
|
||||
target,
|
||||
options: parseTooltipOptions(binding.value),
|
||||
events: [binding.modifiers.focus ? TOOLTIP_FOCUS_EVENTS : TOOLTIP_HOVER_EVENTS],
|
||||
})
|
||||
const events: TooltipEvents = binding.modifiers.focus
|
||||
? { on: 'focusin', off: 'focusout' }
|
||||
: { on: 'mouseenter', off: 'mouseleave' }
|
||||
|
||||
tooltipKeys.set(target, tooltipKey)
|
||||
store.register(target, parseOptions(binding.value), events)
|
||||
},
|
||||
updated(target, binding) {
|
||||
const tooltipKey = tooltipKeys.get(target)
|
||||
|
||||
if (tooltipKey === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
useTooltipStore().updateOptions(tooltipKey, parseTooltipOptions(binding.value))
|
||||
const store = useTooltipStore()
|
||||
store.updateOptions(target, parseOptions(binding.value))
|
||||
},
|
||||
beforeUnmount(target) {
|
||||
unregisterTooltip(target)
|
||||
const store = useTooltipStore()
|
||||
store.unregister(target)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
import { vTooltip } from '@core/directives/tooltip.directive.ts'
|
||||
import { findTooltipContents } from '@core-test/find-tooltip-contents.ts'
|
||||
import { hover } from '@core-test/hover.ts'
|
||||
import { mountWithSetup } from '@core-test/mount-with-setup.ts'
|
||||
import { defineComponent, h, nextTick, ref, type VNode, withDirectives } from 'vue'
|
||||
|
||||
function mountTarget(renderTarget: () => VNode | undefined) {
|
||||
return mountWithSetup(() => renderTarget)
|
||||
}
|
||||
|
||||
it('shows its content while the element is hovered', () => {
|
||||
const target = mountTarget(() => withDirectives(h('div'), [[vTooltip, 'Name']])).element
|
||||
|
||||
hover(target)
|
||||
|
||||
expect(findTooltipContents()).toEqual(['Name'])
|
||||
|
||||
target.dispatchEvent(new MouseEvent('mouseleave'))
|
||||
|
||||
expect(findTooltipContents()).toEqual([])
|
||||
})
|
||||
|
||||
it('shows its content while the element is focused, with the focus modifier', () => {
|
||||
const target = mountWithSetup(
|
||||
() => () => withDirectives(h('button'), [[vTooltip, 'Name', undefined, { focus: true }]]),
|
||||
{ attachTo: document.body }
|
||||
).element
|
||||
|
||||
hover(target)
|
||||
|
||||
expect(findTooltipContents()).toEqual([])
|
||||
|
||||
target.focus()
|
||||
|
||||
expect(findTooltipContents()).toEqual(['Name'])
|
||||
})
|
||||
|
||||
it('follows its value', async () => {
|
||||
const content = ref('Name')
|
||||
const target = mountTarget(() => withDirectives(h('div'), [[vTooltip, content.value]])).element
|
||||
|
||||
hover(target)
|
||||
content.value = 'New name'
|
||||
await nextTick()
|
||||
|
||||
expect(findTooltipContents()).toEqual(['New name'])
|
||||
})
|
||||
|
||||
it('removes its tooltip with the element', async () => {
|
||||
const isRendered = ref(true)
|
||||
|
||||
const wrapper = mountTarget(() => {
|
||||
if (!isRendered.value) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return withDirectives(h('div'), [[vTooltip, 'Name']])
|
||||
})
|
||||
|
||||
hover(wrapper.element)
|
||||
isRendered.value = false
|
||||
await nextTick()
|
||||
|
||||
expect(findTooltipContents()).toEqual([])
|
||||
})
|
||||
|
||||
it('keeps the tooltip of the parent when a component already sets one on its root element', () => {
|
||||
const Child = defineComponent({
|
||||
render: () => withDirectives(h('div'), [[vTooltip, 'Child']]),
|
||||
})
|
||||
|
||||
const target = mountTarget(() => withDirectives(h(Child), [[vTooltip, 'Parent']])).element
|
||||
|
||||
hover(target)
|
||||
|
||||
expect(findTooltipContents()).toEqual(['Parent'])
|
||||
})
|
||||
@@ -27,7 +27,6 @@ import {
|
||||
faBook,
|
||||
faCalendar,
|
||||
faCamera,
|
||||
faCertificate,
|
||||
faCaretDown,
|
||||
faCaretUp,
|
||||
faCheck,
|
||||
@@ -73,7 +72,6 @@ import {
|
||||
faHeadset,
|
||||
faInfo,
|
||||
faInfoCircle,
|
||||
faKey,
|
||||
faKeyboard,
|
||||
faLayerGroup,
|
||||
faLink,
|
||||
@@ -142,7 +140,6 @@ export const faIcons = defineIconPack({
|
||||
building: { icon: faBuilding },
|
||||
camera: { icon: faCamera },
|
||||
calendar: { icon: faCalendar },
|
||||
certificate: { icon: faCertificate },
|
||||
'caret-down': { icon: faCaretDown },
|
||||
'caret-up': { icon: faCaretUp },
|
||||
check: { icon: faCheck },
|
||||
@@ -193,7 +190,6 @@ export const faIcons = defineIconPack({
|
||||
headset: { icon: faHeadset },
|
||||
info: { icon: faInfo },
|
||||
'info-circle': { icon: faInfoCircle },
|
||||
key: { icon: faKey },
|
||||
keyboard: { icon: faKeyboard },
|
||||
'layer-group': { icon: faLayerGroup },
|
||||
link: { icon: faLink },
|
||||
|
||||
@@ -95,7 +95,7 @@ function handleBackdropClick() {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-x: hidden;
|
||||
overflow-x: clip;
|
||||
}
|
||||
|
||||
.header {
|
||||
|
||||
@@ -13,13 +13,10 @@
|
||||
"action:add": "Add",
|
||||
"action:add-filter": "Add filter",
|
||||
"action:add-group": "Add group",
|
||||
"action:add-groups": "Add groups",
|
||||
"action:add-host": "@:action:add @.lower:host",
|
||||
"action:add-host-internal-network-in-xo-5": "Add a host internal network in XO-5",
|
||||
"action:add-network-in-xo-5": "Add network in XO-5",
|
||||
"action:add-roles": "Add roles",
|
||||
"action:add-sort": "Add sort",
|
||||
"action:add-users": "Add users",
|
||||
"action:add-vifs-in-xo-5": "Add VIF in XO-5",
|
||||
"action:apply": "Apply",
|
||||
"action:attach": "Attach",
|
||||
@@ -66,14 +63,11 @@
|
||||
"action:delete-configuration": "Delete configuration",
|
||||
"action:delete-filter": "Delete filter",
|
||||
"action:delete-group": "Delete group",
|
||||
"action:delete-n-groups": "Delete 1 group | Delete {n} groups",
|
||||
"action:delete-n-jobs": "@:action:delete 1 job | @:action:delete {n} jobs",
|
||||
"action:delete-n-networks": "Delete 1 network | Delete {n} networks",
|
||||
"action:delete-n-roles": "Delete 1 role | Delete {n} roles",
|
||||
"action:delete-n-snapshots": "Delete 1 snapshot | Delete {n} snapshots",
|
||||
"action:delete-n-srs": "Delete 1 SR | Delete {n} SRs",
|
||||
"action:delete-n-traffic-rules": "Delete 1 traffic rule | Delete {n} traffic rules",
|
||||
"action:delete-n-users": "Delete 1 user | Delete {n} users",
|
||||
"action:delete-n-vdis": "Delete 1 VDI | Delete {n} VDIs",
|
||||
"action:delete-n-vifs": "Delete 1 VIF | Delete {n} VIFs",
|
||||
"action:delete-n-vms": "Delete 1 VM | Delete {n} VMs",
|
||||
@@ -223,14 +217,11 @@
|
||||
"action:unload": "Unload",
|
||||
"action:update": "Update",
|
||||
"action:use-query-builder": "Use query builder",
|
||||
"action:use-template": "Use this template",
|
||||
"action:visit-pool-dashboard": "Visit pool dashboard",
|
||||
"actions": "Actions",
|
||||
"active-mapping": "Active mapping",
|
||||
"adapter": "Adapter",
|
||||
"add-or": "+OR",
|
||||
"added": "Added",
|
||||
"admin": "Admin",
|
||||
"admin-login": "Admin login",
|
||||
"admin-password": "Admin password",
|
||||
"admin-password-confirm": "Confirm admin password",
|
||||
@@ -456,7 +447,6 @@
|
||||
"default-value": "Default ({value})",
|
||||
"deletable-vms": "Good to go",
|
||||
"deletion-blocked": "Deletion Blocked",
|
||||
"deny": "Deny",
|
||||
"deploy-xoa-available-on-desktop": "XOA deployment is available on your desktop interface",
|
||||
"deploy-xoa-custom-ntp-servers": "Custom NTP servers (separated by spaces)",
|
||||
"deploy-xoa-status:configuring": "Configuring XOA…",
|
||||
@@ -516,7 +506,6 @@
|
||||
"edit-vif:error-message": "An error occurred while editing the VIF. Please review your configuration settings and try again.",
|
||||
"editing-vif": "Editing VIF",
|
||||
"email": "Email",
|
||||
"email-address": "Email address",
|
||||
"email-already-added": "This email address has already been added",
|
||||
"email-mandatory": "Email address is mandatory",
|
||||
"empty": "Empty",
|
||||
@@ -569,7 +558,6 @@
|
||||
"first-of-month": "first of month",
|
||||
"first-of-week": "first of week",
|
||||
"first-of-year": "first of year",
|
||||
"first-name": "First name",
|
||||
"following-hosts-unreachable": "The following hosts are unreachable",
|
||||
"for-backup": "For backup",
|
||||
"for-replication": "For replication",
|
||||
@@ -581,12 +569,10 @@
|
||||
"form:error:field-minimum": "{field} must be {min} or more",
|
||||
"form:error:field-required": "{field} is required",
|
||||
"form:error:integer": "Must be an integer",
|
||||
"form:error:invalid-query": "Invalid query",
|
||||
"form:error:maximum": "Must be {max} or less",
|
||||
"form:error:min-items": "Must contain at least {n} item | Must contain at least {n} items",
|
||||
"form:error:minimum": "Must be {min} or more",
|
||||
"form:error:must-match": "Must match “{text}”",
|
||||
"form:error:password-mismatch": "Passwords do not match",
|
||||
"form:error:required": "This field is required",
|
||||
"form:n-errors-summary": "{n} field needs attention | {n} fields need attention",
|
||||
"form:warning:out-of-range": "Should be between {min} and {max}",
|
||||
@@ -609,11 +595,6 @@
|
||||
"gpu": "GPU",
|
||||
"gpus": "GPUs",
|
||||
"graphics-display": "Graphics & Display",
|
||||
"group": "Group",
|
||||
"group-details": "Group details",
|
||||
"group:delete-warning": "Deleting this group will permanently remove it and revoke all roles and permissions inherited by its members. This action cannot be undone. Proceed with caution. | Deleting these groups will permanently remove them and revoke all roles and permissions inherited by their members. This action cannot be undone. Proceed with caution.",
|
||||
"group:what-is-a-group-description": "A group is a collection of users that share the same roles. Assign roles to a group to automatically grant those permissions to all its members. When a user is added to a group, they inherit all roles assigned to that group; inherited roles cannot be removed individually from a user, only by changing the group's roles or removing the user from the group.",
|
||||
"group:what-is-a-group?": "What is a group?",
|
||||
"groups": "Groups",
|
||||
"guest-tools": "Guest tools",
|
||||
"guest-tools-out-of-date": "Guest tools out of date",
|
||||
@@ -704,8 +685,6 @@
|
||||
"iso-dvd": "ISO/DVD",
|
||||
"item": "Item",
|
||||
"job": "Job",
|
||||
"job-name": "Job name",
|
||||
"job:add:in-progress": "Add in progress…",
|
||||
"job:arg:allocated-space-required": "Allocated space is required",
|
||||
"job:arg:backup-repository-required": "Backup repository is required",
|
||||
"job:arg:bond-mode-required": "@:bond-mode-required",
|
||||
@@ -768,17 +747,11 @@
|
||||
"job:connect:in-progress": "Connect in progress…",
|
||||
"job:create:in-progress": "Create in progress…",
|
||||
"job:delete:in-progress": "Delete in progress…",
|
||||
"job:detach:in-progress": "Detach in progress…",
|
||||
"job:disable:in-progress": "Disable in progress…",
|
||||
"job:disconnect:in-progress": "Disconnect in progress…",
|
||||
"job:edit:in-progress": "Edit in progress…",
|
||||
"job:enable:in-progress": "Enable in progress…",
|
||||
"job:export:in-progress": "Export in progress…",
|
||||
"job:group-delete:missing-group": "No groups to delete",
|
||||
"job:group-delete:synchronized-group": "A synchronized group cannot be deleted",
|
||||
"job:group-users:missing-group": "No group selected",
|
||||
"job:group-users:missing-user": "No user selected",
|
||||
"job:group-users:synchronized-group": "The users of a synchronized group cannot be changed",
|
||||
"job:host-detach:bad-power-state": "@:host-not-running",
|
||||
"job:host-detach:in-progress": "Host detach in progress…",
|
||||
"job:host-detach:master-host": "Master host cannot be detached",
|
||||
@@ -850,13 +823,6 @@
|
||||
"job:plugin-test:not-loaded": "The plugin must be loaded to be tested",
|
||||
"job:plugin-test:not-testable": "This plugin cannot be tested",
|
||||
"job:pool-add-host:in-progress": "Adding host in progress…",
|
||||
"job:role-delete:missing-role": "No roles to delete",
|
||||
"job:role-delete:role-assigned": "A role assigned to users or groups cannot be deleted",
|
||||
"job:role-groups:missing-group": "@:job:group-users:missing-group",
|
||||
"job:role-groups:missing-role": "@:job:role-users:missing-role",
|
||||
"job:role-users:inherited-role": "A role inherited from a group cannot be detached from a user",
|
||||
"job:role-users:missing-role": "No role selected",
|
||||
"job:role-users:missing-user": "No user selected",
|
||||
"job:server-connect:missing-server": "No servers to connect",
|
||||
"job:server-disconnect:missing-server": "No servers to disconnect",
|
||||
"job:server-disconnect:server-disconnected": "One or several servers are already disconnected",
|
||||
@@ -867,8 +833,6 @@
|
||||
"job:traffic-rule-delete:missing-rule": "No traffic rule selected",
|
||||
"job:traffic-rule-edit-order:no-free-priority": "No free priority left on this network to apply this order",
|
||||
"job:traffic-rule-edit-order:not-enough-rules": "Requires at least {n} rules",
|
||||
"job:user-delete:missing-user": "No users to delete",
|
||||
"job:user-delete:self-deletion": "A user cannot delete itself",
|
||||
"job:v2v-start:in-progress": "Migration launch in progress…",
|
||||
"job:v2v-start:missing-vm": "No VMs to migrate",
|
||||
"job:vbd-connect:missing-vbd": "No VBDs to connect",
|
||||
@@ -973,7 +937,6 @@
|
||||
"last-n-backup-runs": "Last backup run | Last {n} backup runs",
|
||||
"last-n-days": "Last day | Last {n} days",
|
||||
"last-n-runs": "Last run | Last {n} runs",
|
||||
"last-name": "Last name",
|
||||
"last-revert": "Last revert",
|
||||
"last-run-number": "Last run #{n}",
|
||||
"last-snapshot": "Last snapshot",
|
||||
@@ -1111,7 +1074,6 @@
|
||||
"n-gb": "{n} GB",
|
||||
"n-gb-left": "{n} GB left",
|
||||
"n-gb-required": "{n} GB required",
|
||||
"n-groups": "1 group | {n} groups",
|
||||
"n-hexadecimal-characters": "{n} hexadecimal characters.",
|
||||
"n-hosts": "1 host | {n} hosts",
|
||||
"n-hosts-awaiting-patch": "{n} host is awaiting this patch | {n} hosts are awaiting this patch",
|
||||
@@ -1130,11 +1092,9 @@
|
||||
"n-pools": "1 pool | {n} pools",
|
||||
"n-private-networks": "1 private network | {n} private networks",
|
||||
"n-ready": "1 ready | {n} ready",
|
||||
"n-roles": "1 role | {n} roles",
|
||||
"n-snapshots": "1 snapshot | {n} snapshots",
|
||||
"n-srs": "1 SR | {n} SRs",
|
||||
"n-traffic-rules": "1 traffic rule | {n} traffic rules",
|
||||
"n-users": "1 user | {n} users",
|
||||
"n-vbds": "1 VBD | {n} VBDs",
|
||||
"n-vcpus": "1 vCPU | {n} vCPUs",
|
||||
"n-vdis": "1 VDI | {n} VDIs",
|
||||
@@ -1189,9 +1149,6 @@
|
||||
"new-network:preferred-center-info": "The host to try first to elect as center of the network",
|
||||
"new-network:select-interface": "Select an interface",
|
||||
"new-traffic-rule:add": "Add new traffic rule",
|
||||
"new-traffic-rule:error-message": "An error occurred while creating the traffic rule. Please review your configuration settings and try again.",
|
||||
"new-user:error-already-exists": "A user with this username or email address already exists.",
|
||||
"new-user:error-message": "An error occurred while creating the user. Please review your settings and try again.",
|
||||
"new-vdi:accepted-formats": "Accepted formats: {formats}",
|
||||
"new-vdi:add": "Add new VDI",
|
||||
"new-vif": "New VIF",
|
||||
@@ -1246,7 +1203,6 @@
|
||||
"next-runs": "Next runs",
|
||||
"nfs": "NFS",
|
||||
"nic-type": "NIC type",
|
||||
"no": "No",
|
||||
"no-active-backup-jobs": "There are no active backup jobs on this site.",
|
||||
"no-alarm-detected": "No alarms detected",
|
||||
"no-alarm-triggered": "No alarm triggered",
|
||||
@@ -1263,7 +1219,6 @@
|
||||
"no-empty-network-to-fill": "No empty network to fill",
|
||||
"no-empty-sr-to-fill": "No empty SR to fill",
|
||||
"no-group-attached": "No group attached",
|
||||
"no-group-detected": "No groups detected",
|
||||
"no-host-attached": "No hosts attached",
|
||||
"no-host-detected": "No hosts detected",
|
||||
"no-job-vm": "This VM isn’t part of any running job.",
|
||||
@@ -1272,13 +1227,10 @@
|
||||
"no-pif-detected": "No PIFs detected",
|
||||
"no-plugin-detected": "No plugins detected",
|
||||
"no-pools-detected": "No pools detected",
|
||||
"no-privilege-attached": "No privilege attached",
|
||||
"no-remembered-connection": "No remembered connection",
|
||||
"no-replicated-vm": "This VM isn’t being replicated. Configure a replication job to enable it.",
|
||||
"no-result": "No results",
|
||||
"no-role-applied": "No role applied",
|
||||
"no-role-detected": "No roles detected",
|
||||
"no-role-template-detected": "No role templates detected",
|
||||
"no-run": "No run",
|
||||
"no-running-vm-detected": "No running VMs detected",
|
||||
"no-selected-vm-can-be-exported": "No selected VM can be exported",
|
||||
@@ -1289,7 +1241,6 @@
|
||||
"no-storage-repository-detected": "No storage repositories detected",
|
||||
"no-task": "No tasks",
|
||||
"no-task-detected": "No tasks detected",
|
||||
"no-user-attached": "No users attached",
|
||||
"no-user-detected": "No users detected",
|
||||
"no-vdi-attached": "No VDIs attached",
|
||||
"no-vdi-detected": "No VDIs detected",
|
||||
@@ -1360,7 +1311,6 @@
|
||||
"partial-deletion": "Partial deletion",
|
||||
"partially-connected": "Partially connected",
|
||||
"password": "Password",
|
||||
"password-confirmation": "Password confirmation",
|
||||
"password-invalid": "Password invalid",
|
||||
"password-required": "Password is required.",
|
||||
"patch-name": "Patch name",
|
||||
@@ -1376,8 +1326,6 @@
|
||||
"pbd-details": "Physical Block Device (PBD) details",
|
||||
"pending": "Pending",
|
||||
"per-vm-options": "Per-VM options",
|
||||
"permission": "Permission",
|
||||
"permission-required": "Permission required",
|
||||
"physical-interface-status": "Physical interface status",
|
||||
"physical-network": "Physical network",
|
||||
"pif": "PIF",
|
||||
@@ -1440,32 +1388,6 @@
|
||||
"priority": "Priority",
|
||||
"priority-within": "Priority within {name}",
|
||||
"private-network": "Private network | Private networks",
|
||||
"privilege": "Privilege",
|
||||
"privilege-number": "Privilege #{n}",
|
||||
"privilege:action": "Action",
|
||||
"privilege:applied-to": "Applied to",
|
||||
"privilege:create-new": "Create new privilege",
|
||||
"privilege:currently-applied-to": "Currently applied to",
|
||||
"privilege:details": "Privilege details",
|
||||
"privilege:dynamic-selection-info": "The privilege will apply to every object matching this query.",
|
||||
"privilege:edit": "Edit privilege",
|
||||
"privilege:effect": "Effect",
|
||||
"privilege:no-object": "No object",
|
||||
"privilege:none-yet": "No privileges yet",
|
||||
"privilege:one-privilege-per-action": "Each action will be a dedicated privilege",
|
||||
"privilege:resource": "Resource",
|
||||
"privilege:review-and-confirm": "Review & confirm",
|
||||
"privilege:scope": "Scope",
|
||||
"privilege:scope-preview": "Scope preview",
|
||||
"privilege:scope-type": "Scope type",
|
||||
"privilege:scope-type:all-objects": "All objects",
|
||||
"privilege:scope-type:dynamic-selection": "Dynamic selection",
|
||||
"privilege:scope-type:manual-selection": "Manual selection",
|
||||
"privilege:select-scope": "Select scope",
|
||||
"privilege:selector": "Selector",
|
||||
"privilege:what-is-a-privilege-description": "A privilege is a granular permission that controls access to a specific action or resource in your environment, such as starting a VM, editing a network, or viewing storage. Each privilege belongs to exactly one role. Assign privileges to a role to define precisely what users with that role are allowed to do.",
|
||||
"privilege:what-is-a-privilege?": "What is a privilege?",
|
||||
"privileges": "Privileges",
|
||||
"pro-support": "{name} pro support",
|
||||
"professional-support": "Professional support",
|
||||
"progress": "Progress",
|
||||
@@ -1478,7 +1400,6 @@
|
||||
"protection-status": "Protection status",
|
||||
"protocol": "Protocol",
|
||||
"protocol:port": "@:{'protocol'}:@:{'port'}",
|
||||
"provider": "Provider",
|
||||
"provider-solutions": "{provider} solutions",
|
||||
"providers": "Providers",
|
||||
"provisioning": "Provisioning",
|
||||
@@ -1573,19 +1494,6 @@
|
||||
"review": "Review",
|
||||
"review-and-confirm": "Review & confirm",
|
||||
"review-and-launch": "Review and launch",
|
||||
"role": "Role",
|
||||
"role-templates": "Role templates",
|
||||
"role:creating": "Creating the new role…",
|
||||
"role:delete-warning": "Deleting this role will permanently remove it along with all its privileges. This action cannot be undone. Proceed with caution. | Deleting these roles will permanently remove them along with all their privileges. This action cannot be undone. Proceed with caution.",
|
||||
"role:details": "Role details",
|
||||
"role:direct-users": "Direct",
|
||||
"role:name-info": "For example: VM Operator, Network Admin, or Read-only Viewer",
|
||||
"role:new": "New role",
|
||||
"role:new-from-template": "New role from template",
|
||||
"role:unable-to-create": "Unable to create the new role",
|
||||
"role:users-from-group": "From {group} group",
|
||||
"role:what-is-a-role-description": "A role is a set of privileges that can be assigned to users and groups. Assigning a role grants all of its privileges at once. A user holds the roles assigned to them directly, plus every role inherited from the groups they belong to.",
|
||||
"role:what-is-a-role?": "What is a role?",
|
||||
"roles": "Roles",
|
||||
"roles-applied": "Roles applied",
|
||||
"root-by-default": "\"root\" by default.",
|
||||
@@ -1611,14 +1519,11 @@
|
||||
"see-details": "See details",
|
||||
"select-at-least-one-backup-repository": "Select at least one backup repository.",
|
||||
"select-at-least-one-day": "Select at least one day of the month or of the week.",
|
||||
"select-at-least-one-group.": "Select at least one group.",
|
||||
"select-at-least-one-hour": "Select at least one hour.",
|
||||
"select-at-least-one-object": "Selection of at least one object is mandatory.",
|
||||
"select-at-least-one-option": "Select at least one option.",
|
||||
"select-at-least-one-role.": "Select at least one role.",
|
||||
"select-at-least-one-storage-repository": "Select at least one storage repository.",
|
||||
"select-at-least-one-storage-target": "Select at least one storage target.",
|
||||
"select-at-least-one-user.": "Select at least one user.",
|
||||
"select-compression": "Select a compression",
|
||||
"select-destination-host": "Select a destination host",
|
||||
"select-format": "Select format",
|
||||
@@ -1885,15 +1790,7 @@
|
||||
"used-space-on-sr": "Used space on SR",
|
||||
"user": "User",
|
||||
"user-config": "User config",
|
||||
"user-details": "User details",
|
||||
"user-management": "User management",
|
||||
"user:create-new": "Create new user",
|
||||
"user:delete-warning": "Deleting this user will permanently remove their access and associated permissions. This action cannot be undone. Proceed with caution. | Deleting these users will permanently remove their access and associated permissions. This action cannot be undone. Proceed with caution.",
|
||||
"user:direct-roles": "Direct roles",
|
||||
"user:groups-assignment": "Groups assignment",
|
||||
"user:roles-assignment": "Roles assignment",
|
||||
"user:roles-from-group": "From {group} group",
|
||||
"user:roles-from-groups-info": "Roles assigned through assigned groups are automatically applied to this user. You can add additional roles below if needed.",
|
||||
"username": "Username",
|
||||
"username-required": "Username is required.",
|
||||
"users": "Users",
|
||||
@@ -2104,7 +2001,6 @@
|
||||
"xoa-ssh-account": "XOA SSH account",
|
||||
"xoa-ssh-password-confirm-different": "SSH password confirmation is different",
|
||||
"xva": "XVA",
|
||||
"yes": "Yes",
|
||||
"you-are-currently-on": "You are currently on: {0}",
|
||||
"your-default-network-is": "Your default network is {name}",
|
||||
"zstd": "ZSTD"
|
||||
|
||||
@@ -13,13 +13,10 @@
|
||||
"action:add": "Ajouter",
|
||||
"action:add-filter": "Ajouter un filtre",
|
||||
"action:add-group": "Ajouter un groupe",
|
||||
"action:add-groups": "Ajouter des groupes",
|
||||
"action:add-host": "@:action:add un @.lower:host",
|
||||
"action:add-host-internal-network-in-xo-5": "Ajouter un réseau interne à l'hôte dans XO-5",
|
||||
"action:add-network-in-xo-5": "Ajouter un réseau dans XO-5",
|
||||
"action:add-roles": "Ajouter des rôles",
|
||||
"action:add-sort": "Ajouter un tri",
|
||||
"action:add-users": "Ajouter des utilisateurs",
|
||||
"action:add-vifs-in-xo-5": "Ajouter un VIF dans XO-5",
|
||||
"action:apply": "Appliquer",
|
||||
"action:attach": "Attacher",
|
||||
@@ -66,14 +63,11 @@
|
||||
"action:delete-configuration": "Supprimer la configuration",
|
||||
"action:delete-filter": "Supprimer le filtre",
|
||||
"action:delete-group": "Supprimer le groupe",
|
||||
"action:delete-n-groups": "Supprimer 1 groupe | Supprimer {n} groupes",
|
||||
"action:delete-n-jobs": "@:action:delete 1 job | @:action:delete {n} jobs",
|
||||
"action:delete-n-networks": "Supprimer 1 réseau | Supprimer {n} réseaux",
|
||||
"action:delete-n-roles": "Supprimer 1 rôle | Supprimer {n} rôles",
|
||||
"action:delete-n-snapshots": "Supprimer 1 instantané | Supprimer {n} instantanés",
|
||||
"action:delete-n-srs": "Supprimer 1 SR | Supprimer {n} SRs",
|
||||
"action:delete-n-traffic-rules": "Supprimer 1 règle de trafic | Supprimer {n} règles de trafic",
|
||||
"action:delete-n-users": "Supprimer 1 utilisateur | Supprimer {n} utilisateurs",
|
||||
"action:delete-n-vdis": "Supprimer 1 VDI | Supprimer {n} VDIs",
|
||||
"action:delete-n-vifs": "Supprimer 1 VIF | Supprimer {n} VIFs",
|
||||
"action:delete-n-vms": "Supprimer 1 VM | Supprimer {n} VMs",
|
||||
@@ -223,14 +217,11 @@
|
||||
"action:unload": "Décharger",
|
||||
"action:update": "Mettre à jour",
|
||||
"action:use-query-builder": "Constructeur de requête",
|
||||
"action:use-template": "Utiliser ce modèle",
|
||||
"action:visit-pool-dashboard": "Visiter le tableau de bord du pool",
|
||||
"actions": "Actions",
|
||||
"active-mapping": "Correspondance active",
|
||||
"adapter": "Carte",
|
||||
"add-or": "+OU",
|
||||
"added": "Ajouté",
|
||||
"admin": "Administrateur",
|
||||
"admin-login": "Nom d'utilisateur administrateur",
|
||||
"admin-password": "Mot de passe administrateur",
|
||||
"admin-password-confirm": "Confirmer le mot de passe administrateur",
|
||||
@@ -456,7 +447,6 @@
|
||||
"default-value": "Par défaut ({value})",
|
||||
"deletable-vms": "Prêtes",
|
||||
"deletion-blocked": "Suppression Bloquée",
|
||||
"deny": "Refuser",
|
||||
"deploy-xoa-available-on-desktop": "Le déploiement de la XOA est disponible sur ordinateur",
|
||||
"deploy-xoa-custom-ntp-servers": "Serveurs NTP (séparés par des espaces)",
|
||||
"deploy-xoa-status:configuring": "Configuration de la XOA…",
|
||||
@@ -516,7 +506,6 @@
|
||||
"edit-vif:error-message": "Une erreur s'est produite lors de la modification du VIF. Veuillez vérifier vos paramètres et réessayer.",
|
||||
"editing-vif": "Modification du VIF",
|
||||
"email": "Email",
|
||||
"email-address": "Adresse e-mail",
|
||||
"email-already-added": "Cette adresse email a déjà été ajoutée",
|
||||
"email-mandatory": "L'adresse email est obligatoire",
|
||||
"empty": "Vide",
|
||||
@@ -569,7 +558,6 @@
|
||||
"first-of-month": "le premier du mois",
|
||||
"first-of-week": "le premier de la semaine",
|
||||
"first-of-year": "le premier de l’année",
|
||||
"first-name": "Prénom",
|
||||
"following-hosts-unreachable": "Les hôtes suivants sont inaccessibles",
|
||||
"for-backup": "Pour la sauvegarde",
|
||||
"for-replication": "Pour la réplication",
|
||||
@@ -581,12 +569,10 @@
|
||||
"form:error:field-minimum": "Le champ {field} doit être supérieur ou égal à {min}",
|
||||
"form:error:field-required": "Le champ {field} est requis",
|
||||
"form:error:integer": "Doit être un entier",
|
||||
"form:error:invalid-query": "Requête invalide",
|
||||
"form:error:maximum": "Doit être inférieur ou égal à {max}",
|
||||
"form:error:min-items": "Doit contenir au moins {n} élément | Doit contenir au moins {n} éléments",
|
||||
"form:error:minimum": "Doit être supérieur ou égal à {min}",
|
||||
"form:error:must-match": "Doit correspondre à « {text} »",
|
||||
"form:error:password-mismatch": "Les mots de passe ne correspondent pas",
|
||||
"form:error:required": "Ce champ est requis",
|
||||
"form:n-errors-summary": "{n} champ est à corriger | {n} champs sont à corriger",
|
||||
"form:warning:out-of-range": "Devrait être compris entre {min} et {max}",
|
||||
@@ -609,11 +595,6 @@
|
||||
"gpu": "GPU",
|
||||
"gpus": "GPUs",
|
||||
"graphics-display": "Graphique & Affichage",
|
||||
"group": "Groupe",
|
||||
"group-details": "Détails du groupe",
|
||||
"group:delete-warning": "Supprimer ce groupe le retirera définitivement et révoquera tous les rôles et permissions hérités par ses membres. Cette action est irréversible. Procédez avec prudence. | Supprimer ces groupes les retirera définitivement et révoquera tous les rôles et permissions hérités par leurs membres. Cette action est irréversible. Procédez avec prudence.",
|
||||
"group:what-is-a-group-description": "Un groupe est un ensemble d'utilisateurs qui partagent les mêmes rôles. Attribuez des rôles à un groupe pour accorder automatiquement ces permissions à tous ses membres. Lorsqu'un utilisateur est ajouté à un groupe, il hérite de tous les rôles attribués à ce groupe ; les rôles hérités ne peuvent pas être retirés individuellement d'un utilisateur, mais uniquement en modifiant les rôles du groupe ou en retirant l'utilisateur du groupe.",
|
||||
"group:what-is-a-group?": "Qu'est-ce qu'un groupe ?",
|
||||
"groups": "Groupes",
|
||||
"guest-tools": "Guest tools",
|
||||
"guest-tools-out-of-date": "Guest tools obsolètes",
|
||||
@@ -704,8 +685,6 @@
|
||||
"iso-dvd": "ISO/DVD",
|
||||
"item": "Élément",
|
||||
"job": "Job",
|
||||
"job-name": "Nom du job",
|
||||
"job:add:in-progress": "Ajout en cours…",
|
||||
"job:arg:allocated-space-required": "L'espace alloué est obligatoire",
|
||||
"job:arg:backup-repository-required": "Le dépôt de sauvegarde est obligatoire",
|
||||
"job:arg:bond-mode-required": "@:bond-mode-required",
|
||||
@@ -768,17 +747,11 @@
|
||||
"job:connect:in-progress": "Connexion en cours…",
|
||||
"job:create:in-progress": "Création en cours…",
|
||||
"job:delete:in-progress": "Suppression en cours…",
|
||||
"job:detach:in-progress": "Détachement en cours…",
|
||||
"job:disable:in-progress": "Désactivation en cours…",
|
||||
"job:disconnect:in-progress": "Déconnexion en cours…",
|
||||
"job:edit:in-progress": "Modification en cours…",
|
||||
"job:enable:in-progress": "Activation en cours…",
|
||||
"job:export:in-progress": "Export en cours…",
|
||||
"job:group-delete:missing-group": "Aucun groupe à supprimer",
|
||||
"job:group-delete:synchronized-group": "Un groupe synchronisé ne peut pas être supprimé",
|
||||
"job:group-users:missing-group": "Aucun groupe sélectionné",
|
||||
"job:group-users:missing-user": "Aucun utilisateur sélectionné",
|
||||
"job:group-users:synchronized-group": "Les utilisateurs d'un groupe synchronisé ne peuvent pas être modifiés",
|
||||
"job:host-detach:bad-power-state": "@:host-not-running",
|
||||
"job:host-detach:in-progress": "Détachement de l'hôte en cours…",
|
||||
"job:host-detach:master-host": "L'hôte primaire ne peut pas être détaché",
|
||||
@@ -850,13 +823,6 @@
|
||||
"job:plugin-test:not-loaded": "Le plugin doit être chargé pour être testé",
|
||||
"job:plugin-test:not-testable": "Ce plugin ne peut pas être testé",
|
||||
"job:pool-add-host:in-progress": "Ajout de l'hôte en cours…",
|
||||
"job:role-delete:missing-role": "Aucun rôle à supprimer",
|
||||
"job:role-delete:role-assigned": "Un rôle attribué à des utilisateurs ou à des groupes ne peut pas être supprimé",
|
||||
"job:role-groups:missing-group": "@:job:group-users:missing-group",
|
||||
"job:role-groups:missing-role": "@:job:role-users:missing-role",
|
||||
"job:role-users:inherited-role": "Un rôle hérité d'un groupe ne peut pas être détaché d'un utilisateur",
|
||||
"job:role-users:missing-role": "Aucun rôle sélectionné",
|
||||
"job:role-users:missing-user": "Aucun utilisateur sélectionné",
|
||||
"job:server-connect:missing-server": "Aucun serveur à connecter",
|
||||
"job:server-disconnect:missing-server": "Aucun serveur à déconnecter",
|
||||
"job:server-disconnect:server-disconnected": "Un ou plusieurs serveurs sont déjà déconnectés",
|
||||
@@ -867,8 +833,6 @@
|
||||
"job:traffic-rule-delete:missing-rule": "Aucune règle de trafic sélectionnée",
|
||||
"job:traffic-rule-edit-order:no-free-priority": "Plus aucune priorité libre sur ce réseau pour appliquer cet ordre",
|
||||
"job:traffic-rule-edit-order:not-enough-rules": "Nécessite au moins {n} règles",
|
||||
"job:user-delete:missing-user": "Aucun utilisateur à supprimer",
|
||||
"job:user-delete:self-deletion": "Un utilisateur ne peut pas se supprimer lui-même",
|
||||
"job:v2v-start:in-progress": "Lancement de la migration en cours…",
|
||||
"job:v2v-start:missing-vm": "Aucune VM à migrer",
|
||||
"job:vbd-connect:missing-vbd": "Aucun VBD à connecter",
|
||||
@@ -973,7 +937,6 @@
|
||||
"last-n-backup-runs": "Dernier run de sauvegarde | {n} dernières sauvegardes",
|
||||
"last-n-days": "Dernier jour | {n} derniers jours",
|
||||
"last-n-runs": "Dernier run | {n} derniers runs",
|
||||
"last-name": "Nom",
|
||||
"last-revert": "Dernière restauration",
|
||||
"last-run-number": "Dernier run #{n}",
|
||||
"last-snapshot": "Dernier instantané",
|
||||
@@ -1111,7 +1074,6 @@
|
||||
"n-gb": "{n} Go",
|
||||
"n-gb-left": "{n} Go libres",
|
||||
"n-gb-required": "{n} Go requis",
|
||||
"n-groups": "0 groupe | 1 groupe | {n} groupes",
|
||||
"n-hexadecimal-characters": "{n} caractères hexadécimaux.",
|
||||
"n-hosts": "0 hôte | 1 hôte | {n} hôtes",
|
||||
"n-hosts-awaiting-patch": "{n} hôte attend ce patch | {n} hôtes attendent ce patch",
|
||||
@@ -1130,11 +1092,9 @@
|
||||
"n-pools": "1 pool | {n} pools",
|
||||
"n-private-networks": "1 réseau privé | {n} réseaux privés",
|
||||
"n-ready": "0 prête | 1 prête | {n} prêtes",
|
||||
"n-roles": "0 rôle | 1 rôle | {n} rôles",
|
||||
"n-snapshots": "0 instantané | 1 instantané | {n} instantanés",
|
||||
"n-srs": "0 SR | 1 SR | {n} SRs",
|
||||
"n-traffic-rules": "1 règle de trafic | {n} règles de trafic",
|
||||
"n-users": "0 utilisateur | 1 utilisateur | {n} utilisateurs",
|
||||
"n-vbds": "0 VBD | 1 VBD | {n} VBDs",
|
||||
"n-vcpus": "0 vCPU | 1 vCPU | {n} vCPUs",
|
||||
"n-vdis": "0 VDI | 1 VDI | {n} VDIs",
|
||||
@@ -1189,9 +1149,6 @@
|
||||
"new-network:preferred-center-info": "L’hôte à essayer en premier pour être élu centre du réseau",
|
||||
"new-network:select-interface": "Sélectionner une interface",
|
||||
"new-traffic-rule:add": "Ajouter une nouvelle règle de trafic",
|
||||
"new-traffic-rule:error-message": "Une erreur s'est produite lors de la création de la règle de trafic. Veuillez vérifier vos paramètres de configuration et réessayer.",
|
||||
"new-user:error-already-exists": "Un utilisateur avec ce nom d'utilisateur ou cette adresse e-mail existe déjà.",
|
||||
"new-user:error-message": "Une erreur s'est produite lors de la création de l'utilisateur. Veuillez vérifier vos paramètres et réessayer.",
|
||||
"new-vdi:accepted-formats": "Formats acceptés : {formats}",
|
||||
"new-vdi:add": "Ajouter un nouveau VDI",
|
||||
"new-vif": "Nouveau VIF",
|
||||
@@ -1246,7 +1203,6 @@
|
||||
"next-runs": "Prochaines exécutions",
|
||||
"nfs": "NFS",
|
||||
"nic-type": "Type de carte réseau (NIC)",
|
||||
"no": "Non",
|
||||
"no-active-backup-jobs": "Il n'y a aucune tâche de sauvegarde active sur ce site.",
|
||||
"no-alarm-detected": "Aucune alarme détectée",
|
||||
"no-alarm-triggered": "Aucune alarme déclenchée",
|
||||
@@ -1263,7 +1219,6 @@
|
||||
"no-empty-network-to-fill": "Aucun réseau vide à remplir",
|
||||
"no-empty-sr-to-fill": "Aucun SR vide à remplir",
|
||||
"no-group-attached": "Pas de groupe attaché",
|
||||
"no-group-detected": "Aucun groupe détecté",
|
||||
"no-host-attached": "Aucun hôte attaché",
|
||||
"no-host-detected": "Aucun hôte détecté",
|
||||
"no-job-vm": "Cette VM ne fait partie d'aucun job actif.",
|
||||
@@ -1272,13 +1227,10 @@
|
||||
"no-pif-detected": "Aucun PIF détecté",
|
||||
"no-plugin-detected": "Aucun plugin détecté",
|
||||
"no-pools-detected": "Aucun pool détecté",
|
||||
"no-privilege-attached": "Aucun privilège attaché",
|
||||
"no-remembered-connection": "Aucune connexion mémorisée",
|
||||
"no-replicated-vm": "Cette VM n'est pas répliquée. Configurez une tâche de réplication pour l'activer.",
|
||||
"no-result": "Aucun résultat",
|
||||
"no-role-applied": "Pas de rôle appliqué",
|
||||
"no-role-detected": "Aucun rôle détecté",
|
||||
"no-role-template-detected": "Aucun modèle de rôle détecté",
|
||||
"no-run": "Aucun run",
|
||||
"no-running-vm-detected": "Aucune VM en cours d'exécution détectée",
|
||||
"no-selected-vm-can-be-exported": "Aucune VM sélectionnée ne peut être exportée",
|
||||
@@ -1289,7 +1241,6 @@
|
||||
"no-storage-repository-detected": "Aucun dépôt de stockage détecté",
|
||||
"no-task": "Aucune tâche",
|
||||
"no-task-detected": "Aucune tâche détectée",
|
||||
"no-user-attached": "Aucun utilisateur attaché",
|
||||
"no-user-detected": "Aucun utilisateur détecté",
|
||||
"no-vdi-attached": "Aucun VDI attaché",
|
||||
"no-vdi-detected": "Aucun VDI détecté",
|
||||
@@ -1360,7 +1311,6 @@
|
||||
"partial-deletion": "Suppression partielle",
|
||||
"partially-connected": "Partiellement connecté",
|
||||
"password": "Mot de passe",
|
||||
"password-confirmation": "Confirmation du mot de passe",
|
||||
"password-invalid": "Mot de passe incorrect",
|
||||
"password-required": "Le mot de passe est requis.",
|
||||
"patch-name": "Nom du patch",
|
||||
@@ -1376,8 +1326,6 @@
|
||||
"pbd-details": "Détails du périphérique de bloc physique (PBD)",
|
||||
"pending": "En cours",
|
||||
"per-vm-options": "Options par VM",
|
||||
"permission": "Permission",
|
||||
"permission-required": "Permission requise",
|
||||
"physical-interface-status": "Statut de l'interface physique",
|
||||
"physical-network": "Réseau physique",
|
||||
"pif": "PIF",
|
||||
@@ -1440,32 +1388,6 @@
|
||||
"priority": "Priorité",
|
||||
"priority-within": "Priorité dans {name}",
|
||||
"private-network": "Réseau privé | Réseaux privés",
|
||||
"privilege": "Privilège",
|
||||
"privilege-number": "Privilège #{n}",
|
||||
"privilege:action": "Action",
|
||||
"privilege:applied-to": "Appliqué à",
|
||||
"privilege:create-new": "Créer un nouveau privilège",
|
||||
"privilege:currently-applied-to": "Appliqué actuellement à",
|
||||
"privilege:details": "Détails du privilège",
|
||||
"privilege:dynamic-selection-info": "Le privilège s'appliquera à tous les objets correspondant à cette requête.",
|
||||
"privilege:edit": "Modifier le privilège",
|
||||
"privilege:effect": "Effet",
|
||||
"privilege:no-object": "Aucun objet",
|
||||
"privilege:none-yet": "Aucun privilège pour le moment",
|
||||
"privilege:one-privilege-per-action": "Chaque action fera l'objet d'un privilège dédié",
|
||||
"privilege:resource": "Ressource",
|
||||
"privilege:review-and-confirm": "Vérifier et confirmer",
|
||||
"privilege:scope": "Portée",
|
||||
"privilege:scope-preview": "Aperçu de la portée",
|
||||
"privilege:scope-type": "Type de portée",
|
||||
"privilege:scope-type:all-objects": "Tous les objets",
|
||||
"privilege:scope-type:dynamic-selection": "Sélection dynamique",
|
||||
"privilege:scope-type:manual-selection": "Sélection manuelle",
|
||||
"privilege:select-scope": "Sélectionner la portée",
|
||||
"privilege:selector": "Sélecteur",
|
||||
"privilege:what-is-a-privilege-description": "Un privilège est une permission fine qui contrôle l'accès à une action ou une ressource précise de votre environnement, comme démarrer une VM, modifier un réseau ou consulter le stockage. Chaque privilège appartient à un seul rôle. Attribuez des privilèges à un rôle pour définir précisément ce que les utilisateurs de ce rôle peuvent faire.",
|
||||
"privilege:what-is-a-privilege?": "Qu'est-ce qu'un privilège ?",
|
||||
"privileges": "Privilèges",
|
||||
"pro-support": "Support pro {name}",
|
||||
"professional-support": "Support professionnel",
|
||||
"progress": "Progression",
|
||||
@@ -1478,7 +1400,6 @@
|
||||
"protection-status": "Statut de la protection",
|
||||
"protocol": "Protocole",
|
||||
"protocol:port": "@:{'protocol'}:@:{'port'}",
|
||||
"provider": "Fournisseur",
|
||||
"provider-solutions": "Solutions {provider}",
|
||||
"providers": "Fournisseurs",
|
||||
"provisioning": "Provisionnement",
|
||||
@@ -1573,19 +1494,6 @@
|
||||
"review": "Revue",
|
||||
"review-and-confirm": "Vérifier et confirmer",
|
||||
"review-and-launch": "Revue et lancement",
|
||||
"role": "Rôle",
|
||||
"role-templates": "Modèles de rôle",
|
||||
"role:creating": "Création du nouveau rôle en cours…",
|
||||
"role:delete-warning": "Supprimer ce rôle le retirera définitivement, ainsi que tous ses privilèges. Cette action est irréversible. Procédez avec prudence. | Supprimer ces rôles les retirera définitivement, ainsi que tous leurs privilèges. Cette action est irréversible. Procédez avec prudence.",
|
||||
"role:details": "Détails du rôle",
|
||||
"role:direct-users": "Direct",
|
||||
"role:name-info": "Par exemple : Opérateur VM, Administrateur réseau ou Lecteur seul",
|
||||
"role:new": "Nouveau rôle",
|
||||
"role:new-from-template": "Nouveau rôle à partir d'un modèle",
|
||||
"role:unable-to-create": "Impossible de créer le nouveau rôle",
|
||||
"role:users-from-group": "Du groupe {group}",
|
||||
"role:what-is-a-role-description": "Un rôle est un ensemble de privilèges attribuable à des utilisateurs et à des groupes. Attribuer un rôle accorde tous ses privilèges d'un coup. Un utilisateur détient les rôles qui lui sont attribués directement, ainsi que tous ceux hérités des groupes auxquels il appartient.",
|
||||
"role:what-is-a-role?": "Qu'est-ce qu'un rôle ?",
|
||||
"roles": "Rôles",
|
||||
"roles-applied": "Rôles appliqués",
|
||||
"root-by-default": "\"root\" par défaut.",
|
||||
@@ -1611,14 +1519,11 @@
|
||||
"see-details": "Voir les détails",
|
||||
"select-at-least-one-backup-repository": "Sélectionnez au moins un backup repository.",
|
||||
"select-at-least-one-day": "Sélectionnez au moins un jour du mois ou de la semaine.",
|
||||
"select-at-least-one-group.": "Sélectionnez au moins un groupe.",
|
||||
"select-at-least-one-hour": "Sélectionnez au moins une heure.",
|
||||
"select-at-least-one-object": "La sélection d’au moins un objet est obligatoire.",
|
||||
"select-at-least-one-option": "Sélectionnez au moins une option.",
|
||||
"select-at-least-one-role.": "Sélectionnez au moins un rôle.",
|
||||
"select-at-least-one-storage-repository": "Sélectionnez au moins un storage repository.",
|
||||
"select-at-least-one-storage-target": "Sélectionnez au moins une cible de stockage.",
|
||||
"select-at-least-one-user.": "Sélectionnez au moins un utilisateur.",
|
||||
"select-compression": "Sélectionnez une compression",
|
||||
"select-destination-host": "Sélectionnez un hôte de destination",
|
||||
"select-format": "Sélectionner le format",
|
||||
@@ -1885,15 +1790,7 @@
|
||||
"used-space-on-sr": "Espace utilisé sur le SR",
|
||||
"user": "Utilisateur",
|
||||
"user-config": "Configuration utilisateur",
|
||||
"user-details": "Détails de l'utilisateur",
|
||||
"user-management": "Gestion des utilisateurs",
|
||||
"user:create-new": "Créer un nouvel utilisateur",
|
||||
"user:delete-warning": "Supprimer cet utilisateur retirera définitivement son accès et les permissions associées. Cette action est irréversible. Procédez avec prudence. | Supprimer ces utilisateurs retirera définitivement leurs accès et les permissions associées. Cette action est irréversible. Procédez avec prudence.",
|
||||
"user:direct-roles": "Rôles directs",
|
||||
"user:groups-assignment": "Affectation des groupes",
|
||||
"user:roles-assignment": "Affectation des rôles",
|
||||
"user:roles-from-group": "Du groupe {group}",
|
||||
"user:roles-from-groups-info": "Les rôles des groupes affectés sont automatiquement appliqués à cet utilisateur. Vous pouvez ajouter des rôles supplémentaires ci-dessous si besoin.",
|
||||
"username": "Nom d'utilisateur",
|
||||
"username-required": "Le nom d'utilisateur est requis.",
|
||||
"users": "Utilisateurs",
|
||||
@@ -2104,7 +2001,6 @@
|
||||
"xoa-ssh-account": "Compte SSH de la XOA",
|
||||
"xoa-ssh-password-confirm-different": "La confirmation du mot de passe SSH est différente",
|
||||
"xva": "XVA",
|
||||
"yes": "Oui",
|
||||
"you-are-currently-on": "Vous êtes actuellement sur : {0}",
|
||||
"your-default-network-is": "Votre réseau par défaut est {name}",
|
||||
"zstd": "ZSTD"
|
||||
|
||||
@@ -14,101 +14,61 @@ export type TooltipOptions = {
|
||||
|
||||
export type TooltipEvents = { on: WindowEventName; off: WindowEventName }
|
||||
|
||||
export type TooltipRegistration = {
|
||||
target: HTMLElement
|
||||
options: TooltipOptions
|
||||
events: TooltipEvents[]
|
||||
isPrioritized?: boolean
|
||||
}
|
||||
|
||||
type Tooltip = {
|
||||
key: string
|
||||
target: HTMLElement
|
||||
options: TooltipOptions
|
||||
isPrioritized: boolean
|
||||
}
|
||||
|
||||
export const TOOLTIP_HOVER_EVENTS: TooltipEvents = { on: 'mouseenter', off: 'mouseleave' }
|
||||
|
||||
export const TOOLTIP_FOCUS_EVENTS: TooltipEvents = { on: 'focusin', off: 'focusout' }
|
||||
|
||||
const isPointerFocus = (eventName: WindowEventName, target: HTMLElement) =>
|
||||
eventName === TOOLTIP_FOCUS_EVENTS.on && !target.matches(':focus-visible')
|
||||
|
||||
export const useTooltipStore = defineStore('tooltip', () => {
|
||||
const scopes = new Map<string, EffectScope>()
|
||||
const registeredTooltips = ref(new Map<string, Tooltip>())
|
||||
const activeKeys = ref(new Set<string>())
|
||||
const targetsScopes = new WeakMap<HTMLElement, EffectScope>()
|
||||
const targets = ref(new Set<HTMLElement>())
|
||||
const targetsOptions = ref(new Map<HTMLElement, TooltipOptions>())
|
||||
const targetsIds = ref(new Map<HTMLElement, string>())
|
||||
|
||||
const register = ({ target, options, events, isPrioritized = false }: TooltipRegistration) => {
|
||||
const key = uniqueId('tooltip-')
|
||||
const register = (target: HTMLElement, options: TooltipOptions, events: TooltipEvents) => {
|
||||
const scope = effectScope()
|
||||
const activeOnEvents = new Set<WindowEventName>()
|
||||
|
||||
scopes.set(key, scope)
|
||||
registeredTooltips.value.set(key, { key, target, options, isPrioritized })
|
||||
targetsScopes.set(target, scope)
|
||||
targetsOptions.value.set(target, options)
|
||||
targetsIds.value.set(target, uniqueId('tooltip-'))
|
||||
|
||||
scope.run(() => {
|
||||
events.forEach(({ on, off }) => {
|
||||
useEventListener(target, on, () => {
|
||||
if (isPointerFocus(on, target)) {
|
||||
return
|
||||
}
|
||||
useEventListener(target, events.on, () => {
|
||||
targets.value.add(target)
|
||||
|
||||
activeOnEvents.add(on)
|
||||
activeKeys.value.add(key)
|
||||
})
|
||||
|
||||
useEventListener(target, off, () => {
|
||||
activeOnEvents.delete(on)
|
||||
|
||||
if (activeOnEvents.size === 0) {
|
||||
activeKeys.value.delete(key)
|
||||
}
|
||||
scope.run(() => {
|
||||
useEventListener(
|
||||
target,
|
||||
events.off,
|
||||
() => {
|
||||
targets.value.delete(target)
|
||||
},
|
||||
{ once: true }
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return key
|
||||
}
|
||||
|
||||
const updateOptions = (key: string, options: TooltipOptions) => {
|
||||
const tooltip = registeredTooltips.value.get(key)
|
||||
|
||||
if (tooltip === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
tooltip.options = options
|
||||
const updateOptions = (target: HTMLElement, options: TooltipOptions) => {
|
||||
targetsOptions.value.set(target, options)
|
||||
}
|
||||
|
||||
const unregister = (key: string) => {
|
||||
activeKeys.value.delete(key)
|
||||
registeredTooltips.value.delete(key)
|
||||
scopes.get(key)?.stop()
|
||||
scopes.delete(key)
|
||||
}
|
||||
|
||||
const activeTooltips = computed(() =>
|
||||
Array.from(activeKeys.value)
|
||||
.map(key => registeredTooltips.value.get(key))
|
||||
.filter(tooltip => tooltip !== undefined)
|
||||
)
|
||||
|
||||
const isOverridden = (tooltip: Tooltip) => {
|
||||
if (tooltip.isPrioritized) {
|
||||
return false
|
||||
}
|
||||
|
||||
return activeTooltips.value.some(
|
||||
activeTooltip => activeTooltip.isPrioritized && activeTooltip.target === tooltip.target
|
||||
)
|
||||
const unregister = (target: HTMLElement) => {
|
||||
targets.value.delete(target)
|
||||
targetsOptions.value.delete(target)
|
||||
targetsScopes.get(target)?.stop()
|
||||
targetsScopes.delete(target)
|
||||
targetsIds.value.delete(target)
|
||||
}
|
||||
|
||||
return {
|
||||
register,
|
||||
unregister,
|
||||
updateOptions,
|
||||
tooltips: computed(() => activeTooltips.value.filter(tooltip => !isOverridden(tooltip))),
|
||||
tooltips: computed(() => {
|
||||
return Array.from(targets.value.values()).map(target => {
|
||||
return {
|
||||
target,
|
||||
options: targetsOptions.value.get(target)!,
|
||||
key: targetsIds.value.get(target)!,
|
||||
}
|
||||
})
|
||||
}),
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
import { parseTooltipOptions } from '@core/directives/tooltip.directive.ts'
|
||||
import {
|
||||
TOOLTIP_FOCUS_EVENTS,
|
||||
TOOLTIP_HOVER_EVENTS,
|
||||
type TooltipRegistration,
|
||||
useTooltipStore,
|
||||
} from '@core/stores/tooltip.store.ts'
|
||||
import { findTooltipContents } from '@core-test/find-tooltip-contents.ts'
|
||||
import { hover } from '@core-test/hover.ts'
|
||||
import { mountComposable } from '@core-test/mount-composable.ts'
|
||||
|
||||
function mountTooltipStore() {
|
||||
return mountComposable(() => ({ tooltipStore: useTooltipStore() })).wrapper.vm.tooltipStore
|
||||
}
|
||||
|
||||
function createRegistration(content: string, overrides: Partial<TooltipRegistration> = {}): TooltipRegistration {
|
||||
return {
|
||||
target: document.createElement('button'),
|
||||
options: parseTooltipOptions(content),
|
||||
events: [TOOLTIP_HOVER_EVENTS],
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
function createFocusableRegistration(content: string): TooltipRegistration {
|
||||
const registration = createRegistration(content, { events: [TOOLTIP_HOVER_EVENTS, TOOLTIP_FOCUS_EVENTS] })
|
||||
|
||||
document.body.append(registration.target)
|
||||
onTestFinished(() => registration.target.remove())
|
||||
|
||||
return registration
|
||||
}
|
||||
|
||||
describe('tooltips', () => {
|
||||
it('lists a tooltip from its "on" event to its "off" event', () => {
|
||||
const registration = createRegistration('Name')
|
||||
|
||||
mountTooltipStore().register(registration)
|
||||
|
||||
expect(findTooltipContents()).toEqual([])
|
||||
|
||||
hover(registration.target)
|
||||
|
||||
expect(findTooltipContents()).toEqual(['Name'])
|
||||
|
||||
registration.target.dispatchEvent(new MouseEvent('mouseleave'))
|
||||
|
||||
expect(findTooltipContents()).toEqual([])
|
||||
})
|
||||
|
||||
it('lists a tooltip on each of its events', () => {
|
||||
const registration = createFocusableRegistration('Name')
|
||||
|
||||
mountTooltipStore().register(registration)
|
||||
registration.target.focus()
|
||||
|
||||
expect(findTooltipContents()).toEqual(['Name'])
|
||||
|
||||
registration.target.blur()
|
||||
|
||||
expect(findTooltipContents()).toEqual([])
|
||||
})
|
||||
|
||||
it('lists a tooltip until all its events are off', () => {
|
||||
const registration = createFocusableRegistration('Name')
|
||||
|
||||
mountTooltipStore().register(registration)
|
||||
registration.target.focus()
|
||||
hover(registration.target)
|
||||
registration.target.blur()
|
||||
|
||||
expect(findTooltipContents()).toEqual(['Name'])
|
||||
|
||||
registration.target.dispatchEvent(new MouseEvent('mouseleave'))
|
||||
|
||||
expect(findTooltipContents()).toEqual([])
|
||||
})
|
||||
|
||||
it('does not list a tooltip on a focus the browser does not show', () => {
|
||||
const registration = createFocusableRegistration('Name')
|
||||
|
||||
mountTooltipStore().register(registration)
|
||||
hover(registration.target)
|
||||
registration.target.dispatchEvent(new FocusEvent('focusin'))
|
||||
registration.target.dispatchEvent(new MouseEvent('mouseleave'))
|
||||
|
||||
expect(findTooltipContents()).toEqual([])
|
||||
})
|
||||
|
||||
it('hides the other tooltips of a target while its prioritized tooltip is listed', () => {
|
||||
const tooltipStore = mountTooltipStore()
|
||||
const registration = createRegistration('Name')
|
||||
|
||||
tooltipStore.register(registration)
|
||||
tooltipStore.register(createRegistration('Reason', { target: registration.target, isPrioritized: true }))
|
||||
hover(registration.target)
|
||||
|
||||
expect(findTooltipContents()).toEqual(['Reason'])
|
||||
})
|
||||
|
||||
it('keeps the tooltips of the other targets while a prioritized tooltip is listed', () => {
|
||||
const tooltipStore = mountTooltipStore()
|
||||
const registration = createRegistration('Name')
|
||||
const prioritizedRegistration = createRegistration('Reason', { isPrioritized: true })
|
||||
|
||||
tooltipStore.register(registration)
|
||||
tooltipStore.register(prioritizedRegistration)
|
||||
hover(registration.target)
|
||||
hover(prioritizedRegistration.target)
|
||||
|
||||
expect(findTooltipContents()).toEqual(['Name', 'Reason'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('updateOptions', () => {
|
||||
it('changes the options of a listed tooltip', () => {
|
||||
const tooltipStore = mountTooltipStore()
|
||||
const registration = createRegistration('Name')
|
||||
|
||||
const tooltipKey = tooltipStore.register(registration)
|
||||
hover(registration.target)
|
||||
tooltipStore.updateOptions(tooltipKey, parseTooltipOptions('New name'))
|
||||
|
||||
expect(findTooltipContents()).toEqual(['New name'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('unregister', () => {
|
||||
it('removes a listed tooltip', () => {
|
||||
const tooltipStore = mountTooltipStore()
|
||||
const registration = createRegistration('Name')
|
||||
|
||||
const tooltipKey = tooltipStore.register(registration)
|
||||
hover(registration.target)
|
||||
tooltipStore.unregister(tooltipKey)
|
||||
|
||||
expect(findTooltipContents()).toEqual([])
|
||||
})
|
||||
|
||||
it('stops listing the tooltip on its events', () => {
|
||||
const tooltipStore = mountTooltipStore()
|
||||
const registration = createRegistration('Name')
|
||||
|
||||
const tooltipKey = tooltipStore.register(registration)
|
||||
tooltipStore.unregister(tooltipKey)
|
||||
hover(registration.target)
|
||||
|
||||
expect(findTooltipContents()).toEqual([])
|
||||
})
|
||||
})
|
||||
@@ -12,14 +12,9 @@ export type CheckboxCellBindings = {
|
||||
onToggle: () => void
|
||||
}
|
||||
|
||||
export type CheckboxHeadCellOptions = {
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
function renderHeadCheckbox(model: Ref<boolean | undefined>, options?: CheckboxHeadCellOptions) {
|
||||
function renderHeadCheckbox(model: Ref<boolean | undefined>) {
|
||||
return h(UiCheckbox, {
|
||||
accent: 'brand',
|
||||
disabled: options?.disabled,
|
||||
modelValue: model.value,
|
||||
'onUpdate:modelValue': (value: boolean | undefined | string[]) => {
|
||||
model.value = value === true
|
||||
@@ -37,12 +32,8 @@ function renderBodyCheckbox({ selected, disabled, onToggle }: CheckboxCellBindin
|
||||
}
|
||||
|
||||
export const useCheckboxColumn = defineColumn(() => ({
|
||||
renderHead: (model?: Ref<boolean | undefined>, options?: CheckboxHeadCellOptions) =>
|
||||
h(VtsHeaderCell, { style: { width: COLUMN_WIDTH } }, () =>
|
||||
model === undefined ? undefined : renderHeadCheckbox(model, options)
|
||||
),
|
||||
renderBody: (bindings?: CheckboxCellBindings) =>
|
||||
h(UiTableCell, { style: { width: COLUMN_WIDTH } }, () =>
|
||||
bindings === undefined ? undefined : renderBodyCheckbox(bindings)
|
||||
),
|
||||
renderHead: (model: Ref<boolean | undefined>) =>
|
||||
h(VtsHeaderCell, { style: { width: COLUMN_WIDTH } }, () => renderHeadCheckbox(model)),
|
||||
renderBody: (bindings: CheckboxCellBindings) =>
|
||||
h(UiTableCell, { style: { width: COLUMN_WIDTH } }, () => renderBodyCheckbox(bindings)),
|
||||
}))
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import VtsUserNameCell from '@core/components/table/cells/VtsUserNameCell.vue'
|
||||
import { defineColumn } from '@core/packages/table/define-column.ts'
|
||||
import { renderHeadCell } from '@core/tables/helpers/render-head-cell.ts'
|
||||
import type { FlexibleColumnConfig } from '@core/tables/types.ts'
|
||||
import { h } from 'vue'
|
||||
|
||||
export const useUserNameColumn = defineColumn((config?: FlexibleColumnConfig) => ({
|
||||
renderHead: () => renderHeadCell(config?.headerLabel),
|
||||
renderBody: (content: string, props?: { href?: string }) =>
|
||||
h(VtsUserNameCell, { content, href: props?.href, flexible: config?.flexible }),
|
||||
}))
|
||||
@@ -1,12 +0,0 @@
|
||||
import VtsUsernameCell from '@core/components/table/cells/VtsUsernameCell.vue'
|
||||
import type { LinkOptions } from '@core/composables/link-component.composable.ts'
|
||||
import { defineColumn } from '@core/packages/table/define-column.ts'
|
||||
import { renderHeadCell } from '@core/tables/helpers/render-head-cell.ts'
|
||||
import type { FlexibleColumnConfig } from '@core/tables/types.ts'
|
||||
import { h } from 'vue'
|
||||
|
||||
export const useUsernameColumn = defineColumn((config?: FlexibleColumnConfig) => ({
|
||||
renderHead: () => renderHeadCell(config?.headerLabel),
|
||||
renderBody: (content: string, link?: Pick<LinkOptions, 'to' | 'href'>) =>
|
||||
h(VtsUsernameCell, { content, ...link, flexible: config?.flexible }),
|
||||
}))
|
||||
@@ -1,20 +0,0 @@
|
||||
import { defineColumns } from '@core/packages/table/define-columns.ts'
|
||||
import { useActionColumn } from '@core/tables/column-definitions/action-column.ts'
|
||||
import { useCheckboxColumn } from '@core/tables/column-definitions/checkbox-column.ts'
|
||||
import { useLinkOrTextColumn } from '@core/tables/column-definitions/link-or-text-column.ts'
|
||||
import { useNumberColumn } from '@core/tables/column-definitions/number-column.ts'
|
||||
import { useTextColumn } from '@core/tables/column-definitions/text-column.ts'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
export const useGroupColumns = defineColumns(() => {
|
||||
const { t } = useI18n()
|
||||
|
||||
return {
|
||||
checkbox: useCheckboxColumn(),
|
||||
name: useLinkOrTextColumn({ headerLabel: () => t('name') }),
|
||||
provider: useTextColumn({ headerLabel: () => t('provider') }),
|
||||
users: useNumberColumn({ headerLabel: () => t('users') }),
|
||||
roles: useNumberColumn({ headerLabel: () => t('roles') }),
|
||||
actions: useActionColumn({}),
|
||||
}
|
||||
})
|
||||
@@ -1,24 +0,0 @@
|
||||
import { defineColumns } from '@core/packages/table/define-columns.ts'
|
||||
import { useButtonIconColumn } from '@core/tables/column-definitions/button-icon-column.ts'
|
||||
import { useLinkColumn } from '@core/tables/column-definitions/link-column.ts'
|
||||
import { useNumberColumn } from '@core/tables/column-definitions/number-column.ts'
|
||||
import { useSelectItemColumn } from '@core/tables/column-definitions/select-item-column.ts'
|
||||
import { useTagColumn } from '@core/tables/column-definitions/tag-column.ts'
|
||||
import { useTextColumn } from '@core/tables/column-definitions/text-column.ts'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
export const usePrivilegeColumns = defineColumns(() => {
|
||||
const { t } = useI18n()
|
||||
|
||||
return {
|
||||
index: useLinkColumn(),
|
||||
resource: useTextColumn({ headerLabel: () => t('privilege:resource') }),
|
||||
scope: useTextColumn({ headerLabel: () => t('privilege:scope') }),
|
||||
appliedTo: useNumberColumn({ headerLabel: () => t('privilege:applied-to') }),
|
||||
action: useTextColumn({ headerLabel: () => t('privilege:action') }),
|
||||
effect: useTagColumn({ headerLabel: () => t('privilege:effect') }),
|
||||
edit: useButtonIconColumn({ buttonIcon: 'fa:pencil' }),
|
||||
remove: useButtonIconColumn({ buttonIcon: 'fa:trash', buttonAccent: 'danger' }),
|
||||
selectItem: useSelectItemColumn(),
|
||||
}
|
||||
})
|
||||
@@ -1,13 +0,0 @@
|
||||
import { defineColumns } from '@core/packages/table/define-columns.ts'
|
||||
import { useCheckboxColumn } from '@core/tables/column-definitions/checkbox-column.ts'
|
||||
import { useLinkColumn } from '@core/tables/column-definitions/link-column.ts'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
export const usePrivilegeScopeObjectColumns = defineColumns(() => {
|
||||
const { t } = useI18n()
|
||||
|
||||
return {
|
||||
checkbox: useCheckboxColumn(),
|
||||
object: useLinkColumn({ headerLabel: () => t('name') }),
|
||||
}
|
||||
})
|
||||
@@ -1,22 +0,0 @@
|
||||
import { defineColumns } from '@core/packages/table/define-columns.ts'
|
||||
import { useActionColumn } from '@core/tables/column-definitions/action-column.ts'
|
||||
import { useCheckboxColumn } from '@core/tables/column-definitions/checkbox-column.ts'
|
||||
import { useLinkOrTextColumn } from '@core/tables/column-definitions/link-or-text-column.ts'
|
||||
import { useNumberColumn } from '@core/tables/column-definitions/number-column.ts'
|
||||
import { useTextColumn } from '@core/tables/column-definitions/text-column.ts'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
export const useRoleColumns = defineColumns(() => {
|
||||
const { t } = useI18n()
|
||||
|
||||
return {
|
||||
checkbox: useCheckboxColumn(),
|
||||
name: useLinkOrTextColumn({ headerLabel: () => t('name') }),
|
||||
group: useLinkOrTextColumn({ headerLabel: () => t('group') }),
|
||||
description: useTextColumn({ headerLabel: () => t('description') }),
|
||||
users: useNumberColumn({ headerLabel: () => t('users') }),
|
||||
groups: useNumberColumn({ headerLabel: () => t('groups') }),
|
||||
privileges: useNumberColumn({ headerLabel: () => t('privileges') }),
|
||||
actions: useActionColumn({}),
|
||||
}
|
||||
})
|
||||
@@ -1,18 +0,0 @@
|
||||
import { defineColumns } from '@core/packages/table/define-columns.ts'
|
||||
import { useButtonColumn } from '@core/tables/column-definitions/button-column.ts'
|
||||
import { useNumberColumn } from '@core/tables/column-definitions/number-column.ts'
|
||||
import { useSelectItemColumn } from '@core/tables/column-definitions/select-item-column.ts'
|
||||
import { useTextColumn } from '@core/tables/column-definitions/text-column.ts'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
export const useRoleTemplateColumns = defineColumns(() => {
|
||||
const { t } = useI18n()
|
||||
|
||||
return {
|
||||
name: useTextColumn({ headerLabel: () => t('name') }),
|
||||
description: useTextColumn({ headerLabel: () => t('description') }),
|
||||
privileges: useNumberColumn({ headerLabel: () => t('privileges') }),
|
||||
select: useButtonColumn({ buttonVariant: 'secondary', buttonSize: 'small' }),
|
||||
selectItem: useSelectItemColumn(),
|
||||
}
|
||||
})
|
||||
@@ -1,21 +1,16 @@
|
||||
import { defineColumns } from '@core/packages/table/define-columns.ts'
|
||||
import { useActionColumn } from '@core/tables/column-definitions/action-column.ts'
|
||||
import { useCheckboxColumn } from '@core/tables/column-definitions/checkbox-column.ts'
|
||||
import { useTextColumn } from '@core/tables/column-definitions/text-column.ts'
|
||||
import { useSelectItemColumn } from '@core/tables/column-definitions/select-item-column.ts'
|
||||
import { useTruncatedTextColumn } from '@core/tables/column-definitions/truncated-text-column.ts'
|
||||
import { useUsernameColumn } from '@core/tables/column-definitions/username-column.ts'
|
||||
import { useUserNameColumn } from '@core/tables/column-definitions/user-name-column.ts'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
export const useUserColumns = defineColumns(() => {
|
||||
const { t } = useI18n()
|
||||
|
||||
return {
|
||||
checkbox: useCheckboxColumn(),
|
||||
username: useUsernameColumn({ headerLabel: () => t('username'), flexible: true }),
|
||||
firstName: useTextColumn({ headerLabel: () => t('first-name') }),
|
||||
lastName: useTextColumn({ headerLabel: () => t('last-name') }),
|
||||
username: useUserNameColumn({ headerLabel: () => t('username'), flexible: true }),
|
||||
email: useTruncatedTextColumn({ headerLabel: () => t('email') }),
|
||||
providers: useTruncatedTextColumn({ headerLabel: () => t('providers') }),
|
||||
actions: useActionColumn({}),
|
||||
selectItem: useSelectItemColumn(),
|
||||
}
|
||||
})
|
||||
|
||||
10
@xen-orchestra/web-core/test/can-focus-input.ts
Normal file
10
@xen-orchestra/web-core/test/can-focus-input.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { VueWrapper } from '@vue/test-utils'
|
||||
|
||||
// Whether the first input of a wrapper attached to the document takes the focus, which an `inert` ancestor prevents
|
||||
export function canFocusInput(wrapper: Pick<VueWrapper, 'get'>) {
|
||||
const input = wrapper.get('input').element
|
||||
|
||||
input.focus()
|
||||
|
||||
return document.activeElement === input
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import { useTooltipStore } from '@core/stores/tooltip.store.ts'
|
||||
|
||||
export function findTooltipContents() {
|
||||
return useTooltipStore().tooltips.map(tooltip => tooltip.options.content)
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export function hover(target: Element) {
|
||||
target.dispatchEvent(new MouseEvent('mouseenter'))
|
||||
}
|
||||
@@ -35,7 +35,6 @@
|
||||
"@vueuse/integrations": "^14.0.0",
|
||||
"@vueuse/math": "^14.0.0",
|
||||
"@vueuse/shared": "^14.0.0",
|
||||
"@xen-orchestra/acl": "^1.8.0",
|
||||
"@xen-orchestra/backups": "^1.0.1",
|
||||
"@xen-orchestra/cron": "^1.0.7",
|
||||
"@xen-orchestra/web-core": "^0.67.0",
|
||||
|
||||
9
@xen-orchestra/web/src/hide-permanently.d.ts
vendored
9
@xen-orchestra/web/src/hide-permanently.d.ts
vendored
@@ -1,9 +0,0 @@
|
||||
declare module '@xen-orchestra/web-core/packages/hide-permanently/types.ts' {
|
||||
interface PermanentlyHideableItems {
|
||||
'what-is-a-group': true
|
||||
'what-is-a-privilege': true
|
||||
'what-is-a-role': true
|
||||
}
|
||||
}
|
||||
|
||||
export {}
|
||||
@@ -65,9 +65,9 @@ const sections = computed<AdminMenuSection[]>(() => [
|
||||
{
|
||||
title: t('user-management'),
|
||||
items: [
|
||||
{ label: t('users'), href: undefined, to: { name: '/admin/user-management/users' } },
|
||||
{ label: t('groups'), href: undefined, to: { name: '/admin/user-management/groups' } },
|
||||
{ label: t('roles'), href: undefined, to: { name: '/admin/user-management/roles' } },
|
||||
{ label: t('users'), href: undefined, to: { name: '/admin/user-management' } },
|
||||
{ label: t('groups'), href: buildXo5Route('/settings/groups'), to: undefined },
|
||||
{ label: t('roles'), href: buildXo5Route('/settings/acls'), to: undefined },
|
||||
{
|
||||
label: t('ldap-auth-providers'),
|
||||
href: undefined,
|
||||
|
||||
@@ -8,16 +8,6 @@
|
||||
{{ t('users') }}
|
||||
</UiTabItem>
|
||||
</RouterLink>
|
||||
<RouterLink v-slot="{ isExactActive, href }" :to="{ name: '/admin/user-management/groups' }" custom>
|
||||
<UiTabItem :active="isExactActive" :href tag="a">
|
||||
{{ t('groups') }}
|
||||
</UiTabItem>
|
||||
</RouterLink>
|
||||
<RouterLink v-slot="{ isExactActive, href }" :to="{ name: '/admin/user-management/roles' }" custom>
|
||||
<UiTabItem :active="isExactActive" :href tag="a">
|
||||
{{ t('roles') }}
|
||||
</UiTabItem>
|
||||
</RouterLink>
|
||||
</TabList>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
<template>
|
||||
<UiAlert v-if="isInfoVisible" accent="info" close @close="hideInfo">
|
||||
<span class="typo-body-bold">{{ t('group:what-is-a-group?') }}</span>
|
||||
<template #description>
|
||||
<span class="typo-body-regular">{{ t('group:what-is-a-group-description') }}</span>
|
||||
</template>
|
||||
</UiAlert>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import UiAlert from '@core/components/ui/alert/UiAlert.vue'
|
||||
import { useHidePermanently } from '@core/packages/hide-permanently/use-hide-permanently.ts'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const [isInfoVisible, hideInfo] = useHidePermanently('what-is-a-group')
|
||||
</script>
|
||||
@@ -1,56 +0,0 @@
|
||||
<template>
|
||||
<DetailPageLayout>
|
||||
<template #alert>
|
||||
<GroupInfoAlert />
|
||||
</template>
|
||||
<template #menu="{ size }">
|
||||
<UiMenuItem
|
||||
:size
|
||||
:to="{ name: '/admin/group/[id]/general', params: { id: group.id } }"
|
||||
:selected="route.name === '/admin/group/[id]/general'"
|
||||
>
|
||||
{{ t('general') }}
|
||||
</UiMenuItem>
|
||||
<UiMenuItem
|
||||
:size
|
||||
:to="{ name: '/admin/group/[id]/roles', params: { id: group.id } }"
|
||||
:selected="route.name === '/admin/group/[id]/roles'"
|
||||
>
|
||||
{{ t('roles') }}
|
||||
</UiMenuItem>
|
||||
<UiMenuItem
|
||||
:size
|
||||
:to="{ name: '/admin/group/[id]/users', params: { id: group.id } }"
|
||||
:selected="route.name === '/admin/group/[id]/users'"
|
||||
>
|
||||
{{ t('users') }}
|
||||
</UiMenuItem>
|
||||
</template>
|
||||
<slot />
|
||||
<template v-if="slots.panel" #panel>
|
||||
<slot name="panel" />
|
||||
</template>
|
||||
</DetailPageLayout>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import GroupInfoAlert from '@/modules/group/components/GroupInfoAlert.vue'
|
||||
import type { FrontXoGroup } from '@/modules/group/remote-resources/use-xo-group-collection.ts'
|
||||
import DetailPageLayout from '@/shared/components/DetailPageLayout.vue'
|
||||
import UiMenuItem from '@core/components/ui/menu-item/UiMenuItem.vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useRoute } from 'vue-router'
|
||||
|
||||
defineProps<{
|
||||
group: FrontXoGroup
|
||||
}>()
|
||||
|
||||
const slots = defineSlots<{
|
||||
default(): any
|
||||
panel?(): any
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const route = useRoute()
|
||||
</script>
|
||||
@@ -1,27 +0,0 @@
|
||||
<template>
|
||||
<UiCard>
|
||||
<UiTitle>
|
||||
{{ t('group-details') }}
|
||||
</UiTitle>
|
||||
<VtsTabularKeyValueList>
|
||||
<VtsTabularKeyValueRow :label="t('name')" :value="group.name" />
|
||||
<VtsTabularKeyValueRow :label="t('uuid')" :value="group.id" />
|
||||
<VtsTabularKeyValueRow :label="t('provider')" :value="group.provider" />
|
||||
</VtsTabularKeyValueList>
|
||||
</UiCard>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { FrontXoGroup } from '@/modules/group/remote-resources/use-xo-group-collection.ts'
|
||||
import VtsTabularKeyValueList from '@core/components/tabular-key-value-list/VtsTabularKeyValueList.vue'
|
||||
import VtsTabularKeyValueRow from '@core/components/tabular-key-value-row/VtsTabularKeyValueRow.vue'
|
||||
import UiCard from '@core/components/ui/card/UiCard.vue'
|
||||
import UiTitle from '@core/components/ui/title/UiTitle.vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
defineProps<{
|
||||
group: FrontXoGroup
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
</script>
|
||||
@@ -1,58 +0,0 @@
|
||||
<template>
|
||||
<div class="group-header">
|
||||
<UiBreadcrumb :size>
|
||||
<span class="name">
|
||||
<VtsIcon name="object:organization" size="current" />
|
||||
{{ t('user-management') }}
|
||||
</span>
|
||||
<UiLink :size :to="{ name: '/admin/user-management/groups' }">
|
||||
{{ t('groups') }}
|
||||
</UiLink>
|
||||
<span class="name">
|
||||
<VtsIcon name="table:group" size="current" />
|
||||
{{ group.name }}
|
||||
</span>
|
||||
</UiBreadcrumb>
|
||||
</div>
|
||||
<UiHeadBar icon="table:group">
|
||||
{{ group.name }}
|
||||
</UiHeadBar>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { FrontXoGroup } from '@/modules/group/remote-resources/use-xo-group-collection.ts'
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import UiBreadcrumb from '@core/components/ui/breadcrumb/UiBreadcrumb.vue'
|
||||
import UiHeadBar from '@core/components/ui/head-bar/UiHeadBar.vue'
|
||||
import UiLink from '@core/components/ui/link/UiLink.vue'
|
||||
import { useUiStore } from '@core/stores/ui.store.ts'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
defineProps<{
|
||||
group: FrontXoGroup
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const uiStore = useUiStore()
|
||||
|
||||
const size = computed(() => (uiStore.isSmall ? 'small' : 'medium'))
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
.group-header {
|
||||
min-height: 5.6rem;
|
||||
padding: 1.2rem 1.6rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border-block-end: 0.1rem solid var(--color-neutral-border);
|
||||
background-color: var(--color-neutral-background-primary);
|
||||
|
||||
.name {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,136 +0,0 @@
|
||||
<template>
|
||||
<AssignmentsTableLayout
|
||||
:title="t('roles')"
|
||||
:can-add="canAddRoles"
|
||||
:is-adding="isAddingRoles"
|
||||
:can-detach="canDetachSelectedRoles"
|
||||
:is-detaching="isDetachingSelectedRoles"
|
||||
:detach-error-message="detachSelectedRolesErrorMessage"
|
||||
@add="addRolesUnselected()"
|
||||
@detach="detachSelectedRoles({ detached: true, onSuccess: selectionBindings.onClearSelection })"
|
||||
>
|
||||
<template #filter>
|
||||
<VtsQueryBuilder v-bind="searchBindings" :schema />
|
||||
</template>
|
||||
<VtsTable :state :pagination-bindings :selection-bindings sticky="right">
|
||||
<thead>
|
||||
<tr>
|
||||
<HeadCells />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<VtsRow v-for="role of paginatedRoles" :key="role.id" :selected="selectedRoleId === role.id">
|
||||
<BodyCells :item="role" />
|
||||
</VtsRow>
|
||||
</tbody>
|
||||
</VtsTable>
|
||||
</AssignmentsTableLayout>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useGroupRolesAdd } from '@/modules/group/composables/use-group-roles-add.composable.ts'
|
||||
import type { FrontXoGroup } from '@/modules/group/remote-resources/use-xo-group-collection.ts'
|
||||
import {
|
||||
type FilterableRole,
|
||||
useRoleQueryBuilder,
|
||||
} from '@/modules/role/composables/use-role-query-builder.composable.ts'
|
||||
import { useXoRoleGroupsRemoveJob } from '@/modules/role/jobs/xo-role-groups-remove.job.ts'
|
||||
import type { FrontXoRole } from '@/modules/role/remote-resources/use-xo-role-collection.ts'
|
||||
import AssignmentsTableLayout from '@/shared/components/AssignmentsTableLayout.vue'
|
||||
import VtsQueryBuilder from '@core/components/query-builder/VtsQueryBuilder.vue'
|
||||
import VtsRow from '@core/components/table/VtsRow.vue'
|
||||
import VtsTable from '@core/components/table/VtsTable.vue'
|
||||
import { usePagination } from '@core/composables/pagination.composable.ts'
|
||||
import { useRouteQuery } from '@core/composables/route-query.composable.ts'
|
||||
import { useTableSelection } from '@core/composables/table-selection.composable.ts'
|
||||
import { useTableState } from '@core/composables/table-state.composable.ts'
|
||||
import { useRoleColumns } from '@core/tables/column-sets/role-columns.ts'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { group, roles, busy, error } = defineProps<{
|
||||
group: FrontXoGroup
|
||||
roles: FrontXoRole[]
|
||||
busy?: boolean
|
||||
error?: boolean
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const selectedRoleId = useRouteQuery('id')
|
||||
|
||||
const { addRoles, canAddRoles, isAddingRoles } = useGroupRolesAdd(() => group)
|
||||
|
||||
const { items: filteredRoles, searchBindings, schema } = useRoleQueryBuilder('group-roles', () => roles)
|
||||
|
||||
const { pageRecords: paginatedRoles, paginationBindings } = usePagination('group-roles', filteredRoles)
|
||||
|
||||
const state = useTableState({
|
||||
busy: () => busy,
|
||||
error: () => error,
|
||||
empty: () =>
|
||||
roles.length === 0 ? t('no-role-applied') : filteredRoles.value.length === 0 ? { type: 'no-result' } : false,
|
||||
})
|
||||
|
||||
const { selectedIds, pageSelectionModel, isSelected, toggleSelection, selectionBindings } = useTableSelection({
|
||||
items: () => roles,
|
||||
filteredItems: filteredRoles,
|
||||
pageItems: paginatedRoles,
|
||||
getItemId: role => role.id,
|
||||
})
|
||||
|
||||
async function addRolesUnselected() {
|
||||
const addedRoles = await addRoles()
|
||||
|
||||
addedRoles.forEach(role => toggleSelection(role.id, false))
|
||||
}
|
||||
|
||||
const selectedRoles = computed(() => roles.filter(role => selectedIds.value.includes(role.id)))
|
||||
|
||||
const {
|
||||
run: detachSelectedRoles,
|
||||
canRun: canDetachSelectedRoles,
|
||||
isRunning: isDetachingSelectedRoles,
|
||||
errorMessage: detachSelectedRolesErrorMessage,
|
||||
} = useXoRoleGroupsRemoveJob(selectedRoles, () => [group])
|
||||
|
||||
const { HeadCells, BodyCells } = useRoleColumns({
|
||||
exclude: ['group', 'users', 'groups'],
|
||||
head: () => ({
|
||||
checkbox: r => r(pageSelectionModel),
|
||||
}),
|
||||
body: (role: FilterableRole) => {
|
||||
const {
|
||||
run: detachRole,
|
||||
canRun: canDetachRole,
|
||||
isRunning: isDetachingRole,
|
||||
errorMessage: detachRoleErrorMessage,
|
||||
} = useXoRoleGroupsRemoveJob(
|
||||
() => [role],
|
||||
() => [group]
|
||||
)
|
||||
|
||||
return {
|
||||
checkbox: r => r({ selected: isSelected(role.id), onToggle: () => toggleSelection(role.id) }),
|
||||
name: r =>
|
||||
r({ label: role.name, icon: 'fa:key', to: { name: '/admin/role/[id]/general', params: { id: role.id } } }),
|
||||
description: r => r(role.description),
|
||||
privileges: r => r(role.privilegesCount),
|
||||
actions: r =>
|
||||
r({
|
||||
onClick: () => (selectedRoleId.value = role.id),
|
||||
actions: [
|
||||
{
|
||||
label: t('action:detach'),
|
||||
icon: 'action:detach',
|
||||
onClick: () => detachRole({ detached: true, onSuccess: () => toggleSelection(role.id, false) }),
|
||||
disabled: !canDetachRole.value,
|
||||
busy: isDetachingRole.value,
|
||||
hint: detachRoleErrorMessage.value,
|
||||
},
|
||||
],
|
||||
}),
|
||||
}
|
||||
},
|
||||
})
|
||||
</script>
|
||||
@@ -1,137 +0,0 @@
|
||||
<template>
|
||||
<AssignmentsTableLayout
|
||||
:title="t('users')"
|
||||
:can-add="canAddUsers"
|
||||
:is-adding="isAddingUsers"
|
||||
:can-detach="canDetachSelectedUsers"
|
||||
:is-detaching="isDetachingSelectedUsers"
|
||||
:detach-error-message="detachSelectedUsersErrorMessage"
|
||||
@add="addUsersUnselected()"
|
||||
@detach="detachSelectedUsers({ detached: true, onSuccess: selectionBindings.onClearSelection })"
|
||||
>
|
||||
<template #filter>
|
||||
<VtsQueryBuilder v-bind="searchBindings" :schema />
|
||||
</template>
|
||||
<VtsTable :state :pagination-bindings :selection-bindings sticky="right">
|
||||
<thead>
|
||||
<tr>
|
||||
<HeadCells />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<VtsRow v-for="user of paginatedUsers" :key="user.id" :selected="selectedUserId === user.id">
|
||||
<BodyCells :item="user" />
|
||||
</VtsRow>
|
||||
</tbody>
|
||||
</VtsTable>
|
||||
</AssignmentsTableLayout>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useGroupUsersAdd } from '@/modules/group/composables/use-group-users-add.composable.ts'
|
||||
import { useXoGroupUsersRemoveJob } from '@/modules/group/jobs/xo-group-users-remove.job.ts'
|
||||
import type { FrontXoGroup } from '@/modules/group/remote-resources/use-xo-group-collection.ts'
|
||||
import {
|
||||
type FilterableUser,
|
||||
useUserQueryBuilder,
|
||||
} from '@/modules/user/composables/use-user-query-builder.composable.ts'
|
||||
import type { FrontXoUser } from '@/modules/user/remote-resources/use-xo-user-collection.ts'
|
||||
import { getUserDisplayName } from '@/modules/user/utils/xo-user.util.ts'
|
||||
import AssignmentsTableLayout from '@/shared/components/AssignmentsTableLayout.vue'
|
||||
import VtsQueryBuilder from '@core/components/query-builder/VtsQueryBuilder.vue'
|
||||
import VtsRow from '@core/components/table/VtsRow.vue'
|
||||
import VtsTable from '@core/components/table/VtsTable.vue'
|
||||
import { usePagination } from '@core/composables/pagination.composable.ts'
|
||||
import { useRouteQuery } from '@core/composables/route-query.composable.ts'
|
||||
import { useTableSelection } from '@core/composables/table-selection.composable.ts'
|
||||
import { useTableState } from '@core/composables/table-state.composable.ts'
|
||||
import { useUserColumns } from '@core/tables/column-sets/user-columns.ts'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { group, users, busy, error } = defineProps<{
|
||||
group: FrontXoGroup
|
||||
users: FrontXoUser[]
|
||||
busy?: boolean
|
||||
error?: boolean
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const selectedUserId = useRouteQuery('id')
|
||||
|
||||
const { addUsers, canAddUsers, isAddingUsers } = useGroupUsersAdd(() => group)
|
||||
|
||||
const { items: filteredUsers, searchBindings, schema } = useUserQueryBuilder('group-users', () => users)
|
||||
|
||||
const { pageRecords: paginatedUsers, paginationBindings } = usePagination('group-users', filteredUsers)
|
||||
|
||||
const state = useTableState({
|
||||
busy: () => busy,
|
||||
error: () => error,
|
||||
empty: () =>
|
||||
users.length === 0 ? t('no-user-attached') : filteredUsers.value.length === 0 ? { type: 'no-result' } : false,
|
||||
})
|
||||
|
||||
const { selectedIds, pageSelectionModel, isSelected, toggleSelection, selectionBindings } = useTableSelection({
|
||||
items: () => users,
|
||||
filteredItems: filteredUsers,
|
||||
pageItems: paginatedUsers,
|
||||
getItemId: user => user.id,
|
||||
})
|
||||
|
||||
async function addUsersUnselected() {
|
||||
const addedUsers = await addUsers()
|
||||
|
||||
addedUsers.forEach(user => toggleSelection(user.id, false))
|
||||
}
|
||||
|
||||
const selectedUsers = computed(() => users.filter(user => selectedIds.value.includes(user.id)))
|
||||
|
||||
const {
|
||||
run: detachSelectedUsers,
|
||||
canRun: canDetachSelectedUsers,
|
||||
isRunning: isDetachingSelectedUsers,
|
||||
errorMessage: detachSelectedUsersErrorMessage,
|
||||
} = useXoGroupUsersRemoveJob(() => [group], selectedUsers)
|
||||
|
||||
const { HeadCells, BodyCells } = useUserColumns({
|
||||
exclude: ['providers'],
|
||||
head: () => ({
|
||||
checkbox: r => r(pageSelectionModel),
|
||||
}),
|
||||
body: (user: FilterableUser) => {
|
||||
const {
|
||||
run: detachUser,
|
||||
canRun: canDetachUser,
|
||||
isRunning: isDetachingUser,
|
||||
errorMessage: detachUserErrorMessage,
|
||||
} = useXoGroupUsersRemoveJob(
|
||||
() => [group],
|
||||
() => [user]
|
||||
)
|
||||
|
||||
return {
|
||||
checkbox: r => r({ selected: isSelected(user.id), onToggle: () => toggleSelection(user.id) }),
|
||||
username: r => r(getUserDisplayName(user), { to: { name: '/admin/user/[id]/general', params: { id: user.id } } }),
|
||||
firstName: r => r(user.firstname),
|
||||
lastName: r => r(user.lastname),
|
||||
email: r => r(user.email),
|
||||
actions: r =>
|
||||
r({
|
||||
onClick: () => (selectedUserId.value = user.id),
|
||||
actions: [
|
||||
{
|
||||
label: t('action:detach'),
|
||||
icon: 'action:detach',
|
||||
onClick: () => detachUser({ detached: true, onSuccess: () => toggleSelection(user.id, false) }),
|
||||
disabled: !canDetachUser.value,
|
||||
busy: isDetachingUser.value,
|
||||
hint: detachUserErrorMessage.value,
|
||||
},
|
||||
],
|
||||
}),
|
||||
}
|
||||
},
|
||||
})
|
||||
</script>
|
||||
@@ -1,96 +0,0 @@
|
||||
<template>
|
||||
<div class="groups-selection-table">
|
||||
<VtsQueryBuilder v-bind="searchBindings" :schema />
|
||||
<VtsTable :state :pagination-bindings :selection-bindings>
|
||||
<thead>
|
||||
<tr>
|
||||
<HeadCells />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<VtsRow v-for="group of paginatedGroups" :key="group.id">
|
||||
<BodyCells :item="group" />
|
||||
</VtsRow>
|
||||
</tbody>
|
||||
</VtsTable>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import {
|
||||
type FilterableGroup,
|
||||
useGroupQueryBuilder,
|
||||
} from '@/modules/group/composables/use-group-query-builder.composable.ts'
|
||||
import type { FrontXoGroup } from '@/modules/group/remote-resources/use-xo-group-collection.ts'
|
||||
import VtsQueryBuilder from '@core/components/query-builder/VtsQueryBuilder.vue'
|
||||
import VtsRow from '@core/components/table/VtsRow.vue'
|
||||
import VtsTable from '@core/components/table/VtsTable.vue'
|
||||
import { usePagination } from '@core/composables/pagination.composable.ts'
|
||||
import { useTableSelection } from '@core/composables/table-selection.composable.ts'
|
||||
import { useTableState } from '@core/composables/table-state.composable.ts'
|
||||
import { useGroupColumns } from '@core/tables/column-sets/group-columns.ts'
|
||||
import { watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { groups, busy, error } = defineProps<{
|
||||
groups: FrontXoGroup[]
|
||||
busy?: boolean
|
||||
error?: boolean
|
||||
}>()
|
||||
|
||||
const selectedGroupIds = defineModel<FrontXoGroup['id'][]>('selectedGroupIds', { required: true })
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const {
|
||||
items: filteredGroups,
|
||||
searchBindings,
|
||||
schema,
|
||||
} = useGroupQueryBuilder('groups-selection', () => groups, {
|
||||
ignoreRoute: true,
|
||||
})
|
||||
|
||||
const { pageRecords: paginatedGroups, paginationBindings } = usePagination('groups-selection', filteredGroups, {
|
||||
ignoreRoute: true,
|
||||
})
|
||||
|
||||
const state = useTableState({
|
||||
busy: () => busy,
|
||||
error: () => error,
|
||||
empty: () =>
|
||||
groups.length === 0 ? t('no-group-detected') : filteredGroups.value.length === 0 ? { type: 'no-result' } : false,
|
||||
})
|
||||
|
||||
const { selectedIds, pageSelectionModel, isSelected, toggleSelection, selectionBindings } = useTableSelection({
|
||||
items: () => groups,
|
||||
filteredItems: filteredGroups,
|
||||
pageItems: paginatedGroups,
|
||||
getItemId: group => group.id,
|
||||
})
|
||||
|
||||
watch(selectedIds, ids => {
|
||||
selectedGroupIds.value = groups.filter(group => ids.includes(group.id)).map(group => group.id)
|
||||
})
|
||||
|
||||
const { HeadCells, BodyCells } = useGroupColumns({
|
||||
exclude: ['actions'],
|
||||
head: () => ({
|
||||
checkbox: r => r(pageSelectionModel),
|
||||
}),
|
||||
body: (group: FilterableGroup) => ({
|
||||
checkbox: r => r({ selected: isSelected(group.id), onToggle: () => toggleSelection(group.id) }),
|
||||
name: r => r({ label: group.name, icon: 'table:group' }),
|
||||
provider: r => r(group.provider ?? ''),
|
||||
users: r => r(group.usersCount),
|
||||
roles: r => r(group.rolesCount),
|
||||
}),
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
.groups-selection-table {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
</style>
|
||||
@@ -1,73 +0,0 @@
|
||||
<template>
|
||||
<UiDrawer @confirm="confirm()" @dismiss="emit('cancel')">
|
||||
<template #title>
|
||||
{{ title }}
|
||||
</template>
|
||||
|
||||
<template #content>
|
||||
<div class="content">
|
||||
<GroupsSelectionTable v-model:selected-group-ids="selectedGroupIds" :groups />
|
||||
<UiInfo v-if="isSelectionErrorVisible" accent="danger">
|
||||
{{ t('select-at-least-one-group.') }}
|
||||
</UiInfo>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #buttons>
|
||||
<VtsOverlayCancelButton @click="emit('cancel')" />
|
||||
<VtsOverlayConfirmButton>
|
||||
{{ t('action:add') }}
|
||||
</VtsOverlayConfirmButton>
|
||||
</template>
|
||||
</UiDrawer>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import GroupsSelectionTable from '@/modules/group/components/drawer/GroupsSelectionTable.vue'
|
||||
import type { FrontXoGroup } from '@/modules/group/remote-resources/use-xo-group-collection.ts'
|
||||
import VtsOverlayCancelButton from '@core/components/overlay/VtsOverlayCancelButton.vue'
|
||||
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
|
||||
import UiDrawer from '@core/components/ui/drawer/UiDrawer.vue'
|
||||
import UiInfo from '@core/components/ui/info/UiInfo.vue'
|
||||
import { computed, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { groups } = defineProps<{
|
||||
groups: FrontXoGroup[]
|
||||
title: string
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
confirm: [groups: FrontXoGroup[]]
|
||||
cancel: []
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const selectedGroupIds = ref<FrontXoGroup['id'][]>([])
|
||||
|
||||
const hasTriedToConfirm = ref(false)
|
||||
|
||||
const isSelectionErrorVisible = computed(() => hasTriedToConfirm.value && selectedGroupIds.value.length === 0)
|
||||
|
||||
function confirm() {
|
||||
hasTriedToConfirm.value = true
|
||||
|
||||
if (selectedGroupIds.value.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
emit(
|
||||
'confirm',
|
||||
groups.filter(group => selectedGroupIds.value.includes(group.id))
|
||||
)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
.content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
</style>
|
||||
@@ -1,148 +0,0 @@
|
||||
<template>
|
||||
<div class="groups-table">
|
||||
<UiTitle>
|
||||
{{ t('groups') }}
|
||||
</UiTitle>
|
||||
<VtsQueryBuilder v-bind="searchBindings" :schema />
|
||||
<div class="container">
|
||||
<VtsTableBulkActions :actions="bulkActions" />
|
||||
<VtsTable :state :pagination-bindings :selection-bindings sticky="right">
|
||||
<thead>
|
||||
<tr>
|
||||
<HeadCells />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<VtsRow v-for="group of paginatedGroups" :key="group.id" :selected="selectedGroupId === group.id">
|
||||
<BodyCells :item="group" />
|
||||
</VtsRow>
|
||||
</tbody>
|
||||
</VtsTable>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useGroupDelete } from '@/modules/group/composables/use-group-delete.composable.ts'
|
||||
import {
|
||||
type FilterableGroup,
|
||||
useGroupQueryBuilder,
|
||||
} from '@/modules/group/composables/use-group-query-builder.composable.ts'
|
||||
import type { FrontXoGroup } from '@/modules/group/remote-resources/use-xo-group-collection.ts'
|
||||
import type { ActionItem } from '@core/components/menu/VtsActionsMenu.vue'
|
||||
import VtsQueryBuilder from '@core/components/query-builder/VtsQueryBuilder.vue'
|
||||
import VtsRow from '@core/components/table/VtsRow.vue'
|
||||
import VtsTable from '@core/components/table/VtsTable.vue'
|
||||
import VtsTableBulkActions from '@core/components/table/VtsTableBulkActions.vue'
|
||||
import UiTitle from '@core/components/ui/title/UiTitle.vue'
|
||||
import { usePagination } from '@core/composables/pagination.composable.ts'
|
||||
import { useRouteQuery } from '@core/composables/route-query.composable.ts'
|
||||
import { useTableSelection } from '@core/composables/table-selection.composable.ts'
|
||||
import { useTableState } from '@core/composables/table-state.composable.ts'
|
||||
import { useGroupColumns } from '@core/tables/column-sets/group-columns.ts'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const {
|
||||
groups: rawGroups,
|
||||
busy,
|
||||
error,
|
||||
} = defineProps<{
|
||||
groups: FrontXoGroup[]
|
||||
busy?: boolean
|
||||
error?: boolean
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const selectedGroupId = useRouteQuery('id')
|
||||
|
||||
const { items: filteredGroups, searchBindings, schema } = useGroupQueryBuilder('groups', () => rawGroups)
|
||||
|
||||
const state = useTableState({
|
||||
busy: () => busy,
|
||||
error: () => error,
|
||||
empty: () =>
|
||||
rawGroups.length === 0 ? t('no-group-detected') : filteredGroups.value.length === 0 ? { type: 'no-result' } : false,
|
||||
})
|
||||
|
||||
const { pageRecords: paginatedGroups, paginationBindings } = usePagination('groups', filteredGroups)
|
||||
|
||||
const { selectedIds, pageSelectionModel, isSelected, toggleSelection, selectionBindings } = useTableSelection({
|
||||
items: () => rawGroups,
|
||||
filteredItems: filteredGroups,
|
||||
pageItems: paginatedGroups,
|
||||
getItemId: group => group.id,
|
||||
})
|
||||
|
||||
const selectedGroups = computed(() => rawGroups.filter(group => selectedIds.value.includes(group.id)))
|
||||
|
||||
const {
|
||||
deleteGroups: deleteSelectedGroups,
|
||||
canDeleteGroups: canDeleteSelectedGroups,
|
||||
isDeletingGroups: isDeletingSelectedGroups,
|
||||
deleteGroupsErrorMessage: deleteSelectedGroupsErrorMessage,
|
||||
} = useGroupDelete(selectedGroups)
|
||||
|
||||
const bulkActions = computed<ActionItem[]>(() => [
|
||||
{
|
||||
label: t('action:delete'),
|
||||
icon: 'action:delete',
|
||||
accent: 'danger',
|
||||
onClick: () => deleteSelectedGroups(),
|
||||
disabled: !canDeleteSelectedGroups.value,
|
||||
busy: isDeletingSelectedGroups.value,
|
||||
hint: deleteSelectedGroupsErrorMessage.value,
|
||||
},
|
||||
])
|
||||
|
||||
const { HeadCells, BodyCells } = useGroupColumns({
|
||||
head: () => ({
|
||||
checkbox: r => r(pageSelectionModel),
|
||||
}),
|
||||
body: (group: FilterableGroup) => {
|
||||
const { deleteGroups, canDeleteGroups, isDeletingGroups, deleteGroupsErrorMessage } = useGroupDelete(() => [group])
|
||||
|
||||
return {
|
||||
checkbox: r => r({ selected: isSelected(group.id), onToggle: () => toggleSelection(group.id) }),
|
||||
name: r =>
|
||||
r({
|
||||
label: group.name,
|
||||
icon: 'table:group',
|
||||
to: { name: '/admin/group/[id]/general', params: { id: group.id } },
|
||||
}),
|
||||
provider: r => r(group.provider ?? ''),
|
||||
users: r => r(group.usersCount),
|
||||
roles: r => r(group.rolesCount),
|
||||
actions: r =>
|
||||
r({
|
||||
onClick: () => (selectedGroupId.value = group.id),
|
||||
actions: [
|
||||
{
|
||||
label: t('action:delete'),
|
||||
icon: 'action:delete',
|
||||
accent: 'danger',
|
||||
onClick: () => deleteGroups(),
|
||||
disabled: !canDeleteGroups.value,
|
||||
busy: isDeletingGroups.value,
|
||||
hint: deleteGroupsErrorMessage.value,
|
||||
},
|
||||
],
|
||||
}),
|
||||
}
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="postcss">
|
||||
.groups-table,
|
||||
.container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2.4rem;
|
||||
}
|
||||
|
||||
.container {
|
||||
gap: 0.8rem;
|
||||
}
|
||||
</style>
|
||||
@@ -1,45 +0,0 @@
|
||||
<template>
|
||||
<VtsSidePanel :has-selection="group !== undefined" @close="emit('close')">
|
||||
<template v-if="group" #actions>
|
||||
<slot name="actions">
|
||||
<VtsDeleteButton
|
||||
:disabled="!canDeleteGroups"
|
||||
:busy="isDeletingGroups"
|
||||
:tooltip="deleteGroupsErrorMessage ?? false"
|
||||
@click="deleteGroups()"
|
||||
/>
|
||||
</slot>
|
||||
</template>
|
||||
<template v-if="group" #default>
|
||||
<GroupInfosCard :group />
|
||||
<GroupUsersCard :group />
|
||||
<GroupRolesCard :group />
|
||||
</template>
|
||||
</VtsSidePanel>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import GroupInfosCard from '@/modules/group/components/list/panel/cards/GroupInfosCard.vue'
|
||||
import GroupRolesCard from '@/modules/group/components/list/panel/cards/GroupRolesCard.vue'
|
||||
import GroupUsersCard from '@/modules/group/components/list/panel/cards/GroupUsersCard.vue'
|
||||
import { useGroupDelete } from '@/modules/group/composables/use-group-delete.composable.ts'
|
||||
import type { FrontXoGroup } from '@/modules/group/remote-resources/use-xo-group-collection.ts'
|
||||
import VtsDeleteButton from '@core/components/delete-button/VtsDeleteButton.vue'
|
||||
import VtsSidePanel from '@core/components/panel/VtsSidePanel.vue'
|
||||
|
||||
const { group } = defineProps<{
|
||||
group?: FrontXoGroup
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
close: []
|
||||
}>()
|
||||
|
||||
defineSlots<{
|
||||
actions?(): any
|
||||
}>()
|
||||
|
||||
const { deleteGroups, canDeleteGroups, isDeletingGroups, deleteGroupsErrorMessage } = useGroupDelete(() =>
|
||||
group !== undefined ? [group] : []
|
||||
)
|
||||
</script>
|
||||
@@ -1,45 +0,0 @@
|
||||
<template>
|
||||
<UiPanelCard class="group-infos-card">
|
||||
<UiPanelCardTitle
|
||||
:id="group.id"
|
||||
size="medium"
|
||||
:label="group.name"
|
||||
icon="table:group"
|
||||
:to="{ name: '/admin/group/[id]/general', params: { id: group.id } }"
|
||||
/>
|
||||
<div class="content">
|
||||
<VtsCardRowKeyValue truncate align-top>
|
||||
<template #key>{{ t('provider') }}</template>
|
||||
<template #value>{{ group.provider }}</template>
|
||||
<template v-if="group.provider" #addons>
|
||||
<VtsCopyButton :value="group.provider" />
|
||||
</template>
|
||||
</VtsCardRowKeyValue>
|
||||
</div>
|
||||
</UiPanelCard>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { FrontXoGroup } from '@/modules/group/remote-resources/use-xo-group-collection.ts'
|
||||
import VtsCardRowKeyValue from '@core/components/card/VtsCardRowKeyValue.vue'
|
||||
import VtsCopyButton from '@core/components/copy-button/VtsCopyButton.vue'
|
||||
import UiPanelCard from '@core/components/ui/panel-card/UiPanelCard.vue'
|
||||
import UiPanelCardTitle from '@core/components/ui/panel-card-title/UiPanelCardTitle.vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
defineProps<{
|
||||
group: FrontXoGroup
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
</script>
|
||||
|
||||
<style scoped lang="postcss">
|
||||
.group-infos-card {
|
||||
.content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,58 +0,0 @@
|
||||
<template>
|
||||
<UiPanelCard>
|
||||
<UiPanelCardTitle
|
||||
size="medium"
|
||||
:label="t('roles-applied')"
|
||||
:counter="areRolesReady ? groupRoles.length : undefined"
|
||||
/>
|
||||
|
||||
<VtsStateHero v-if="hasRoleFetchError" type="error" format="card" horizontal size="extra-small">
|
||||
{{ t('error-no-data') }}
|
||||
</VtsStateHero>
|
||||
|
||||
<VtsStateHero v-else-if="!areRolesReady" type="busy" format="card" horizontal size="extra-small" />
|
||||
|
||||
<UiLinkList
|
||||
v-else-if="groupRoles.length > 0"
|
||||
variant="vertical"
|
||||
:visible-items="5"
|
||||
:total-items="groupRoles.length"
|
||||
>
|
||||
<UiLink
|
||||
v-for="role of groupRoles"
|
||||
:key="role.id"
|
||||
icon="fa:key"
|
||||
size="small"
|
||||
:to="{ name: '/admin/user-management/roles', query: { id: role.id } }"
|
||||
>
|
||||
{{ role.name }}
|
||||
</UiLink>
|
||||
</UiLinkList>
|
||||
|
||||
<VtsStateHero v-else type="no-data" format="card" horizontal size="extra-small">
|
||||
{{ t('no-role-applied') }}
|
||||
</VtsStateHero>
|
||||
</UiPanelCard>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { FrontXoGroup } from '@/modules/group/remote-resources/use-xo-group-collection.ts'
|
||||
import { useXoRoleCollection } from '@/modules/role/remote-resources/use-xo-role-collection.ts'
|
||||
import VtsStateHero from '@core/components/state-hero/VtsStateHero.vue'
|
||||
import UiLink from '@core/components/ui/link/UiLink.vue'
|
||||
import UiLinkList from '@core/components/ui/link-list/UiLinkList.vue'
|
||||
import UiPanelCard from '@core/components/ui/panel-card/UiPanelCard.vue'
|
||||
import UiPanelCardTitle from '@core/components/ui/panel-card-title/UiPanelCardTitle.vue'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { group } = defineProps<{
|
||||
group: FrontXoGroup
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const { roles, areRolesReady, hasRoleFetchError } = useXoRoleCollection()
|
||||
|
||||
const groupRoles = computed(() => roles.value.filter(role => role.groupIds.includes(group.id)))
|
||||
</script>
|
||||
@@ -1,44 +0,0 @@
|
||||
<template>
|
||||
<UiPanelCard class="group-users-card">
|
||||
<UiPanelCardTitle size="medium" :label="t('users')" :counter="groupUsers.length" />
|
||||
|
||||
<UiLinkList v-if="groupUsers.length > 0" variant="vertical">
|
||||
<UiLink
|
||||
v-for="user in groupUsers"
|
||||
:key="user.id"
|
||||
icon="fa:circle-user"
|
||||
size="small"
|
||||
:to="{ name: '/admin/user-management/users', query: { id: user.id } }"
|
||||
>
|
||||
{{ getUserDisplayName(user) }}
|
||||
</UiLink>
|
||||
</UiLinkList>
|
||||
|
||||
<VtsStateHero v-else type="no-data" format="card" horizontal size="extra-small">
|
||||
{{ t('no-user-attached') }}
|
||||
</VtsStateHero>
|
||||
</UiPanelCard>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { FrontXoGroup } from '@/modules/group/remote-resources/use-xo-group-collection.ts'
|
||||
import { useXoUserCollection } from '@/modules/user/remote-resources/use-xo-user-collection.ts'
|
||||
import { getUserDisplayName } from '@/modules/user/utils/xo-user.util.ts'
|
||||
import VtsStateHero from '@core/components/state-hero/VtsStateHero.vue'
|
||||
import UiLink from '@core/components/ui/link/UiLink.vue'
|
||||
import UiLinkList from '@core/components/ui/link-list/UiLinkList.vue'
|
||||
import UiPanelCard from '@core/components/ui/panel-card/UiPanelCard.vue'
|
||||
import UiPanelCardTitle from '@core/components/ui/panel-card-title/UiPanelCardTitle.vue'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { group } = defineProps<{
|
||||
group: FrontXoGroup
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const { getUsersByIds } = useXoUserCollection()
|
||||
|
||||
const groupUsers = computed(() => getUsersByIds(group.users))
|
||||
</script>
|
||||
@@ -1,59 +0,0 @@
|
||||
import { useXoGroupDeleteJob } from '@/modules/group/jobs/xo-group-delete.job.ts'
|
||||
import type { FrontXoGroup } from '@/modules/group/remote-resources/use-xo-group-collection.ts'
|
||||
import { useDeleteModal } from '@core/composables/modals/use-delete-modal.ts'
|
||||
import { useRouteQuery } from '@core/composables/route-query.composable.ts'
|
||||
import { toComputed } from '@core/utils/to-computed.util.ts'
|
||||
import type { MaybeRefOrGetter } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
export function useGroupDelete(rawGroups: MaybeRefOrGetter<FrontXoGroup[]>) {
|
||||
const groups = toComputed(rawGroups)
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const selectedGroupId = useRouteQuery('id')
|
||||
|
||||
const {
|
||||
run,
|
||||
canRun: canDeleteGroups,
|
||||
isRunning: isDeletingGroups,
|
||||
errorMessage: deleteGroupsErrorMessage,
|
||||
} = useXoGroupDeleteJob(groups)
|
||||
|
||||
const { open } = useDeleteModal()
|
||||
|
||||
function confirmDelete() {
|
||||
const groupIds = groups.value.map(group => group.id)
|
||||
|
||||
run({
|
||||
detached: true,
|
||||
onSuccess: results => {
|
||||
const isSelectedGroupDeleted = results.some(
|
||||
(result, index) => result.status === 'fulfilled' && groupIds[index] === selectedGroupId.value
|
||||
)
|
||||
|
||||
if (isSelectedGroupDeleted) {
|
||||
selectedGroupId.value = ''
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function deleteGroups() {
|
||||
const count = groups.value.length
|
||||
|
||||
return open({
|
||||
events: {
|
||||
onConfirm: confirmDelete,
|
||||
},
|
||||
props: {
|
||||
subject: t('n-groups', { n: count }),
|
||||
description: t('group:delete-warning', { n: count }),
|
||||
confirmLabel: t('action:delete-n-groups', { n: count }),
|
||||
accent: 'danger',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return { deleteGroups, canDeleteGroups, isDeletingGroups, deleteGroupsErrorMessage }
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
import type { FrontXoGroup } from '@/modules/group/remote-resources/use-xo-group-collection.ts'
|
||||
import { useQueryBuilderSchema } from '@core/packages/query-builder/schema/use-query-builder-schema.ts'
|
||||
import { useQueryBuilderFilter } from '@core/packages/query-builder/use-query-builder-filter.ts'
|
||||
import { useNumberSchema } from '@core/utils/query-builder/use-number-schema.ts'
|
||||
import { useStringSchema } from '@core/utils/query-builder/use-string-schema.ts'
|
||||
import { computed, type MaybeRefOrGetter, toValue } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
export type FilterableGroup = FrontXoGroup & { usersCount: number; rolesCount: number }
|
||||
|
||||
function toFilterableGroup(group: FrontXoGroup): FilterableGroup {
|
||||
return {
|
||||
...group,
|
||||
usersCount: group.users.length,
|
||||
rolesCount: group.aclRoleIds.length,
|
||||
}
|
||||
}
|
||||
|
||||
export function useGroupQueryBuilder(
|
||||
id: string,
|
||||
groups: MaybeRefOrGetter<FrontXoGroup[]>,
|
||||
options?: Parameters<typeof useQueryBuilderFilter>[2]
|
||||
) {
|
||||
const { t } = useI18n()
|
||||
|
||||
const filterableGroups = computed(() => toValue(groups).map(group => toFilterableGroup(group)))
|
||||
|
||||
const { items, searchBindings } = useQueryBuilderFilter(id, filterableGroups, options)
|
||||
|
||||
const schema = useQueryBuilderSchema<FilterableGroup>({
|
||||
'': useStringSchema(t('any-property')),
|
||||
name: useStringSchema(t('name')),
|
||||
provider: useStringSchema(t('provider')),
|
||||
usersCount: useNumberSchema(t('users')),
|
||||
rolesCount: useNumberSchema(t('roles')),
|
||||
})
|
||||
|
||||
return { items, searchBindings, schema }
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
import type { FrontXoGroup } from '@/modules/group/remote-resources/use-xo-group-collection.ts'
|
||||
import { useXoRoleGroupsAddJob } from '@/modules/role/jobs/xo-role-groups-add.job.ts'
|
||||
import { type FrontXoRole, useXoRoleCollection } from '@/modules/role/remote-resources/use-xo-role-collection.ts'
|
||||
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
|
||||
import { toComputed } from '@core/utils/to-computed.util.ts'
|
||||
import { computed, type MaybeRefOrGetter, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
export function useGroupRolesAdd(rawGroup: MaybeRefOrGetter<FrontXoGroup>) {
|
||||
const group = toComputed(rawGroup)
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const { roles } = useXoRoleCollection()
|
||||
|
||||
const selectableRoles = computed(() => roles.value.filter(role => !role.groupIds.includes(group.value.id)))
|
||||
|
||||
const rolesToAdd = ref<FrontXoRole[]>([])
|
||||
|
||||
const { run, isRunning: isAddingRoles } = useXoRoleGroupsAddJob(rolesToAdd, () => [group.value])
|
||||
|
||||
const canAddRoles = computed(() => selectableRoles.value.length > 0)
|
||||
|
||||
const { open } = useOverlay({
|
||||
component: () => import('@/modules/role/components/drawer/SelectRolesDrawer.vue'),
|
||||
events: {
|
||||
onConfirm: (selectedRoles: FrontXoRole[]) => selectedRoles,
|
||||
onCancel: true,
|
||||
},
|
||||
})
|
||||
|
||||
async function addRoles(): Promise<FrontXoRole[]> {
|
||||
const response = await open({ props: { roles: selectableRoles.value, title: t('action:add-roles') } })
|
||||
|
||||
if (response.event !== 'onConfirm') {
|
||||
return []
|
||||
}
|
||||
|
||||
rolesToAdd.value = response.payload
|
||||
|
||||
run({ detached: true })
|
||||
|
||||
return response.payload
|
||||
}
|
||||
|
||||
return { addRoles, canAddRoles, isAddingRoles }
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
import { useXoGroupUsersAddJob } from '@/modules/group/jobs/xo-group-users-add.job.ts'
|
||||
import type { FrontXoGroup } from '@/modules/group/remote-resources/use-xo-group-collection.ts'
|
||||
import { type FrontXoUser, useXoUserCollection } from '@/modules/user/remote-resources/use-xo-user-collection.ts'
|
||||
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
|
||||
import { toComputed } from '@core/utils/to-computed.util.ts'
|
||||
import { computed, type MaybeRefOrGetter, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
export function useGroupUsersAdd(rawGroup: MaybeRefOrGetter<FrontXoGroup>) {
|
||||
const group = toComputed(rawGroup)
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const { users } = useXoUserCollection()
|
||||
|
||||
const selectableUsers = computed(() => users.value.filter(user => !group.value.users.includes(user.id)))
|
||||
|
||||
const usersToAdd = ref<FrontXoUser[]>([])
|
||||
|
||||
const { run, isRunning: isAddingUsers } = useXoGroupUsersAddJob(() => [group.value], usersToAdd)
|
||||
|
||||
const canAddUsers = computed(() => group.value.provider === undefined && selectableUsers.value.length > 0)
|
||||
|
||||
const { open } = useOverlay({
|
||||
component: () => import('@/modules/user/components/drawer/SelectUsersDrawer.vue'),
|
||||
events: {
|
||||
onConfirm: (selectedUsers: FrontXoUser[]) => selectedUsers,
|
||||
onCancel: true,
|
||||
},
|
||||
})
|
||||
|
||||
async function addUsers(): Promise<FrontXoUser[]> {
|
||||
const response = await open({ props: { users: selectableUsers.value, title: t('action:add-users') } })
|
||||
|
||||
if (response.event !== 'onConfirm') {
|
||||
return []
|
||||
}
|
||||
|
||||
usersToAdd.value = response.payload
|
||||
|
||||
run({ detached: true })
|
||||
|
||||
return response.payload
|
||||
}
|
||||
|
||||
return { addUsers, canAddUsers, isAddingUsers }
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import type { FrontXoGroup } from '@/modules/group/remote-resources/use-xo-group-collection.ts'
|
||||
import { defineJobArg } from '@core/packages/job'
|
||||
|
||||
export const xoGroupsArg = defineJobArg({
|
||||
identify: (group: FrontXoGroup) => group.id,
|
||||
toArray: true,
|
||||
})
|
||||
@@ -1,45 +0,0 @@
|
||||
import { xoGroupsArg } from '@/modules/group/jobs/xo-group-args.ts'
|
||||
import { type FrontXoGroup, useXoGroupCollection } from '@/modules/group/remote-resources/use-xo-group-collection.ts'
|
||||
import { useXoUserCollection } from '@/modules/user/remote-resources/use-xo-user-collection.ts'
|
||||
import { fetchDelete } from '@/shared/utils/fetch.util.ts'
|
||||
import { defineJob, JobError, JobRunningError } from '@core/packages/job'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
export const useXoGroupDeleteJob = defineJob('group.delete', [xoGroupsArg], () => {
|
||||
const { t } = useI18n()
|
||||
|
||||
const { $context: groupContext } = useXoGroupCollection()
|
||||
|
||||
const { $context: userContext } = useXoUserCollection()
|
||||
|
||||
return {
|
||||
async run(groups: FrontXoGroup[]) {
|
||||
const results = await Promise.allSettled(groups.map(group => fetchDelete(`groups/${group.id}`)))
|
||||
|
||||
results.forEach((result, index) => {
|
||||
if (result.status === 'rejected') {
|
||||
console.error(`Failed to delete group ${groups[index].id}:`, result.reason)
|
||||
}
|
||||
})
|
||||
|
||||
groupContext.forceReload()
|
||||
userContext.forceReload()
|
||||
|
||||
return results
|
||||
},
|
||||
|
||||
validate: (isRunning, groups: FrontXoGroup[]) => {
|
||||
if (groups.length === 0) {
|
||||
throw new JobError(t('job:group-delete:missing-group'))
|
||||
}
|
||||
|
||||
if (isRunning) {
|
||||
throw new JobRunningError(t('job:delete:in-progress'))
|
||||
}
|
||||
|
||||
if (groups.some(group => group.provider !== undefined)) {
|
||||
throw new JobError(t('job:group-delete:synchronized-group'))
|
||||
}
|
||||
},
|
||||
}
|
||||
})
|
||||
@@ -1,51 +0,0 @@
|
||||
import { xoGroupsArg } from '@/modules/group/jobs/xo-group-args.ts'
|
||||
import { type FrontXoGroup, useXoGroupCollection } from '@/modules/group/remote-resources/use-xo-group-collection.ts'
|
||||
import { xoUsersArg } from '@/modules/user/jobs/xo-user-args.ts'
|
||||
import { type FrontXoUser, useXoUserCollection } from '@/modules/user/remote-resources/use-xo-user-collection.ts'
|
||||
import { fetchPut } from '@/shared/utils/fetch.util.ts'
|
||||
import { settleSequentially } from '@/shared/utils/promise.util.ts'
|
||||
import { defineJob, JobError, JobRunningError } from '@core/packages/job'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
export const useXoGroupUsersAddJob = defineJob('group.users.add', [xoGroupsArg, xoUsersArg], () => {
|
||||
const { t } = useI18n()
|
||||
|
||||
const { $context: groupContext } = useXoGroupCollection()
|
||||
|
||||
const { $context: userContext } = useXoUserCollection()
|
||||
|
||||
return {
|
||||
async run(groups: FrontXoGroup[], users: FrontXoUser[]) {
|
||||
const results = await settleSequentially(
|
||||
groups.flatMap(group => users.map(user => () => fetchPut(`groups/${group.id}/users/${user.id}`)))
|
||||
)
|
||||
|
||||
results
|
||||
.filter(result => result.status === 'rejected')
|
||||
.forEach(result => console.error('Failed to add a user to a group:', result.reason))
|
||||
|
||||
groupContext.forceReload()
|
||||
userContext.forceReload()
|
||||
|
||||
return results
|
||||
},
|
||||
|
||||
validate: (isRunning, groups: FrontXoGroup[], users: FrontXoUser[]) => {
|
||||
if (groups.length === 0) {
|
||||
throw new JobError(t('job:group-users:missing-group'))
|
||||
}
|
||||
|
||||
if (users.length === 0) {
|
||||
throw new JobError(t('job:group-users:missing-user'))
|
||||
}
|
||||
|
||||
if (isRunning) {
|
||||
throw new JobRunningError(t('job:add:in-progress'))
|
||||
}
|
||||
|
||||
if (groups.some(group => group.provider !== undefined)) {
|
||||
throw new JobError(t('job:group-users:synchronized-group'))
|
||||
}
|
||||
},
|
||||
}
|
||||
})
|
||||
@@ -1,51 +0,0 @@
|
||||
import { xoGroupsArg } from '@/modules/group/jobs/xo-group-args.ts'
|
||||
import { type FrontXoGroup, useXoGroupCollection } from '@/modules/group/remote-resources/use-xo-group-collection.ts'
|
||||
import { xoUsersArg } from '@/modules/user/jobs/xo-user-args.ts'
|
||||
import { type FrontXoUser, useXoUserCollection } from '@/modules/user/remote-resources/use-xo-user-collection.ts'
|
||||
import { fetchDelete } from '@/shared/utils/fetch.util.ts'
|
||||
import { settleSequentially } from '@/shared/utils/promise.util.ts'
|
||||
import { defineJob, JobError, JobRunningError } from '@core/packages/job'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
export const useXoGroupUsersRemoveJob = defineJob('group.users.remove', [xoGroupsArg, xoUsersArg], () => {
|
||||
const { t } = useI18n()
|
||||
|
||||
const { $context: groupContext } = useXoGroupCollection()
|
||||
|
||||
const { $context: userContext } = useXoUserCollection()
|
||||
|
||||
return {
|
||||
async run(groups: FrontXoGroup[], users: FrontXoUser[]) {
|
||||
const results = await settleSequentially(
|
||||
groups.flatMap(group => users.map(user => () => fetchDelete(`groups/${group.id}/users/${user.id}`)))
|
||||
)
|
||||
|
||||
results
|
||||
.filter(result => result.status === 'rejected')
|
||||
.forEach(result => console.error('Failed to remove a user from a group:', result.reason))
|
||||
|
||||
groupContext.forceReload()
|
||||
userContext.forceReload()
|
||||
|
||||
return results
|
||||
},
|
||||
|
||||
validate: (isRunning, groups: FrontXoGroup[], users: FrontXoUser[]) => {
|
||||
if (groups.length === 0) {
|
||||
throw new JobError(t('job:group-users:missing-group'))
|
||||
}
|
||||
|
||||
if (users.length === 0) {
|
||||
throw new JobError(t('job:group-users:missing-user'))
|
||||
}
|
||||
|
||||
if (isRunning) {
|
||||
throw new JobRunningError(t('job:detach:in-progress'))
|
||||
}
|
||||
|
||||
if (groups.some(group => group.provider !== undefined)) {
|
||||
throw new JobError(t('job:group-users:synchronized-group'))
|
||||
}
|
||||
},
|
||||
}
|
||||
})
|
||||
@@ -6,7 +6,7 @@ import type { XoGroup } from '@vates/types'
|
||||
|
||||
export type FrontXoGroup = Pick<XoGroup, (typeof groupFields)[number]>
|
||||
|
||||
const groupFields = ['id', 'name', 'provider', 'users', 'aclRoleIds'] as const satisfies readonly (keyof XoGroup)[]
|
||||
const groupFields = ['id', 'name'] as const satisfies readonly (keyof XoGroup)[]
|
||||
|
||||
export const useXoGroupCollection = defineRemoteResource({
|
||||
url: `${BASE_URL}/groups?fields=${groupFields.join(',')}&ndjson=true`,
|
||||
@@ -1,17 +1,14 @@
|
||||
<template>
|
||||
<VtsErrorModal :title="t('unable-to-delete-network')" @close="emit('close')">
|
||||
<template #content>
|
||||
{{ error ?? t('error') }}
|
||||
<template v-if="showConnectedVifsMessage">
|
||||
<br />
|
||||
<I18nT keypath="disconnect-vifs-in-xo-5-to-delete-network" scope="global">
|
||||
<template #xo-5>
|
||||
<UiLink :href="xo5Link" size="medium">
|
||||
{{ t('xo-5') }}
|
||||
</UiLink>
|
||||
</template>
|
||||
</I18nT>
|
||||
</template>
|
||||
<p>{{ error ?? t('error') }}</p>
|
||||
<I18nT v-if="showConnectedVifsMessage" keypath="disconnect-vifs-in-xo-5-to-delete-network" scope="global" tag="p">
|
||||
<template #xo-5>
|
||||
<UiLink :href="xo5Link" size="medium">
|
||||
{{ t('xo-5') }}
|
||||
</UiLink>
|
||||
</template>
|
||||
</I18nT>
|
||||
</template>
|
||||
</VtsErrorModal>
|
||||
</template>
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
<template>
|
||||
<UiAlert v-if="isInfoVisible" accent="info" close @close="hideInfo">
|
||||
<span class="typo-body-bold">{{ t('role:what-is-a-role?') }}</span>
|
||||
<template #description>
|
||||
<span class="typo-body-regular">{{ t('role:what-is-a-role-description') }}</span>
|
||||
</template>
|
||||
</UiAlert>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import UiAlert from '@core/components/ui/alert/UiAlert.vue'
|
||||
import { useHidePermanently } from '@core/packages/hide-permanently/use-hide-permanently.ts'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const [isInfoVisible, hideInfo] = useHidePermanently('what-is-a-role')
|
||||
</script>
|
||||
@@ -1,63 +0,0 @@
|
||||
<template>
|
||||
<DetailPageLayout>
|
||||
<template #alert>
|
||||
<RoleInfoAlert />
|
||||
</template>
|
||||
<template #menu="{ size }">
|
||||
<UiMenuItem
|
||||
:size
|
||||
:to="{ name: '/admin/role/[id]/general', params: { id: role.id } }"
|
||||
:selected="route.name === '/admin/role/[id]/general'"
|
||||
>
|
||||
{{ t('general') }}
|
||||
</UiMenuItem>
|
||||
<UiMenuItem
|
||||
:size
|
||||
:to="{ name: '/admin/role/[id]/users', params: { id: role.id } }"
|
||||
:selected="route.name === '/admin/role/[id]/users'"
|
||||
>
|
||||
{{ t('users') }}
|
||||
</UiMenuItem>
|
||||
<UiMenuItem
|
||||
:size
|
||||
:to="{ name: '/admin/role/[id]/groups', params: { id: role.id } }"
|
||||
:selected="route.name === '/admin/role/[id]/groups'"
|
||||
>
|
||||
{{ t('groups') }}
|
||||
</UiMenuItem>
|
||||
<UiMenuItem
|
||||
:size
|
||||
:to="{ name: '/admin/role/[id]/privileges', params: { id: role.id } }"
|
||||
:selected="route.name === '/admin/role/[id]/privileges'"
|
||||
>
|
||||
{{ t('privileges') }}
|
||||
</UiMenuItem>
|
||||
</template>
|
||||
<slot />
|
||||
<template v-if="slots.panel" #panel>
|
||||
<slot name="panel" />
|
||||
</template>
|
||||
</DetailPageLayout>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import RoleInfoAlert from '@/modules/role/components/RoleInfoAlert.vue'
|
||||
import type { FrontXoRole } from '@/modules/role/remote-resources/use-xo-role-collection.ts'
|
||||
import DetailPageLayout from '@/shared/components/DetailPageLayout.vue'
|
||||
import UiMenuItem from '@core/components/ui/menu-item/UiMenuItem.vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useRoute } from 'vue-router'
|
||||
|
||||
defineProps<{
|
||||
role: FrontXoRole
|
||||
}>()
|
||||
|
||||
const slots = defineSlots<{
|
||||
default(): any
|
||||
panel?(): any
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const route = useRoute()
|
||||
</script>
|
||||
@@ -1,27 +0,0 @@
|
||||
<template>
|
||||
<UiCard>
|
||||
<UiTitle>
|
||||
{{ t('role:details') }}
|
||||
</UiTitle>
|
||||
<VtsTabularKeyValueList>
|
||||
<VtsTabularKeyValueRow :label="t('name')" :value="role.name" />
|
||||
<VtsTabularKeyValueRow :label="t('uuid')" :value="role.id" />
|
||||
<VtsTabularKeyValueRow :label="t('description')" :value="role.description" />
|
||||
</VtsTabularKeyValueList>
|
||||
</UiCard>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { FrontXoRole } from '@/modules/role/remote-resources/use-xo-role-collection.ts'
|
||||
import VtsTabularKeyValueList from '@core/components/tabular-key-value-list/VtsTabularKeyValueList.vue'
|
||||
import VtsTabularKeyValueRow from '@core/components/tabular-key-value-row/VtsTabularKeyValueRow.vue'
|
||||
import UiCard from '@core/components/ui/card/UiCard.vue'
|
||||
import UiTitle from '@core/components/ui/title/UiTitle.vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
defineProps<{
|
||||
role: FrontXoRole
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
</script>
|
||||
@@ -1,58 +0,0 @@
|
||||
<template>
|
||||
<div class="role-header">
|
||||
<UiBreadcrumb :size>
|
||||
<span class="name">
|
||||
<VtsIcon name="object:organization" size="current" />
|
||||
{{ t('user-management') }}
|
||||
</span>
|
||||
<UiLink :size :to="{ name: '/admin/user-management/roles' }">
|
||||
{{ t('roles') }}
|
||||
</UiLink>
|
||||
<span class="name">
|
||||
<VtsIcon name="fa:key" size="current" />
|
||||
{{ role.name }}
|
||||
</span>
|
||||
</UiBreadcrumb>
|
||||
</div>
|
||||
<UiHeadBar icon="fa:key">
|
||||
{{ role.name }}
|
||||
</UiHeadBar>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { FrontXoRole } from '@/modules/role/remote-resources/use-xo-role-collection.ts'
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import UiBreadcrumb from '@core/components/ui/breadcrumb/UiBreadcrumb.vue'
|
||||
import UiHeadBar from '@core/components/ui/head-bar/UiHeadBar.vue'
|
||||
import UiLink from '@core/components/ui/link/UiLink.vue'
|
||||
import { useUiStore } from '@core/stores/ui.store.ts'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
defineProps<{
|
||||
role: FrontXoRole
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const uiStore = useUiStore()
|
||||
|
||||
const size = computed(() => (uiStore.isSmall ? 'small' : 'medium'))
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
.role-header {
|
||||
min-height: 5.6rem;
|
||||
padding: 1.2rem 1.6rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border-block-end: 0.1rem solid var(--color-neutral-border);
|
||||
background-color: var(--color-neutral-background-primary);
|
||||
|
||||
.name {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,140 +0,0 @@
|
||||
<template>
|
||||
<AssignmentsTableLayout
|
||||
:title="t('groups')"
|
||||
:can-add="canAddGroups"
|
||||
:is-adding="isAddingGroups"
|
||||
:can-detach="canDetachSelectedGroups"
|
||||
:is-detaching="isDetachingSelectedGroups"
|
||||
:detach-error-message="detachSelectedGroupsErrorMessage"
|
||||
@add="addGroupsUnselected()"
|
||||
@detach="detachSelectedGroups({ detached: true, onSuccess: selectionBindings.onClearSelection })"
|
||||
>
|
||||
<template #filter>
|
||||
<VtsQueryBuilder v-bind="searchBindings" :schema />
|
||||
</template>
|
||||
<VtsTable :state :pagination-bindings :selection-bindings sticky="right">
|
||||
<thead>
|
||||
<tr>
|
||||
<HeadCells />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<VtsRow v-for="group of paginatedGroups" :key="group.id" :selected="selectedGroupId === group.id">
|
||||
<BodyCells :item="group" />
|
||||
</VtsRow>
|
||||
</tbody>
|
||||
</VtsTable>
|
||||
</AssignmentsTableLayout>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import {
|
||||
type FilterableGroup,
|
||||
useGroupQueryBuilder,
|
||||
} from '@/modules/group/composables/use-group-query-builder.composable.ts'
|
||||
import type { FrontXoGroup } from '@/modules/group/remote-resources/use-xo-group-collection.ts'
|
||||
import { useRoleGroupsAdd } from '@/modules/role/composables/use-role-groups-add.composable.ts'
|
||||
import { useXoRoleGroupsRemoveJob } from '@/modules/role/jobs/xo-role-groups-remove.job.ts'
|
||||
import type { FrontXoRole } from '@/modules/role/remote-resources/use-xo-role-collection.ts'
|
||||
import AssignmentsTableLayout from '@/shared/components/AssignmentsTableLayout.vue'
|
||||
import VtsQueryBuilder from '@core/components/query-builder/VtsQueryBuilder.vue'
|
||||
import VtsRow from '@core/components/table/VtsRow.vue'
|
||||
import VtsTable from '@core/components/table/VtsTable.vue'
|
||||
import { usePagination } from '@core/composables/pagination.composable.ts'
|
||||
import { useRouteQuery } from '@core/composables/route-query.composable.ts'
|
||||
import { useTableSelection } from '@core/composables/table-selection.composable.ts'
|
||||
import { useTableState } from '@core/composables/table-state.composable.ts'
|
||||
import { useGroupColumns } from '@core/tables/column-sets/group-columns.ts'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { role, groups, busy, error } = defineProps<{
|
||||
role: FrontXoRole
|
||||
groups: FrontXoGroup[]
|
||||
busy?: boolean
|
||||
error?: boolean
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const selectedGroupId = useRouteQuery('id')
|
||||
|
||||
const { addGroups, canAddGroups, isAddingGroups } = useRoleGroupsAdd(() => role)
|
||||
|
||||
const { items: filteredGroups, searchBindings, schema } = useGroupQueryBuilder('role-groups', () => groups)
|
||||
|
||||
const { pageRecords: paginatedGroups, paginationBindings } = usePagination('role-groups', filteredGroups)
|
||||
|
||||
const state = useTableState({
|
||||
busy: () => busy,
|
||||
error: () => error,
|
||||
empty: () =>
|
||||
groups.length === 0 ? t('no-group-attached') : filteredGroups.value.length === 0 ? { type: 'no-result' } : false,
|
||||
})
|
||||
|
||||
const { selectedIds, pageSelectionModel, isSelected, toggleSelection, selectionBindings } = useTableSelection({
|
||||
items: () => groups,
|
||||
filteredItems: filteredGroups,
|
||||
pageItems: paginatedGroups,
|
||||
getItemId: group => group.id,
|
||||
})
|
||||
|
||||
async function addGroupsUnselected() {
|
||||
const addedGroups = await addGroups()
|
||||
|
||||
addedGroups.forEach(group => toggleSelection(group.id, false))
|
||||
}
|
||||
|
||||
const selectedGroups = computed(() => groups.filter(group => selectedIds.value.includes(group.id)))
|
||||
|
||||
const {
|
||||
run: detachSelectedGroups,
|
||||
canRun: canDetachSelectedGroups,
|
||||
isRunning: isDetachingSelectedGroups,
|
||||
errorMessage: detachSelectedGroupsErrorMessage,
|
||||
} = useXoRoleGroupsRemoveJob(() => [role], selectedGroups)
|
||||
|
||||
const { HeadCells, BodyCells } = useGroupColumns({
|
||||
head: () => ({
|
||||
checkbox: r => r(pageSelectionModel),
|
||||
}),
|
||||
body: (group: FilterableGroup) => {
|
||||
const {
|
||||
run: detachGroup,
|
||||
canRun: canDetachGroup,
|
||||
isRunning: isDetachingGroup,
|
||||
errorMessage: detachGroupErrorMessage,
|
||||
} = useXoRoleGroupsRemoveJob(
|
||||
() => [role],
|
||||
() => [group]
|
||||
)
|
||||
|
||||
return {
|
||||
checkbox: r => r({ selected: isSelected(group.id), onToggle: () => toggleSelection(group.id) }),
|
||||
name: r =>
|
||||
r({
|
||||
label: group.name,
|
||||
icon: 'table:group',
|
||||
to: { name: '/admin/group/[id]/general', params: { id: group.id } },
|
||||
}),
|
||||
provider: r => r(group.provider ?? ''),
|
||||
users: r => r(group.usersCount),
|
||||
roles: r => r(group.rolesCount),
|
||||
actions: r =>
|
||||
r({
|
||||
onClick: () => (selectedGroupId.value = group.id),
|
||||
actions: [
|
||||
{
|
||||
label: t('action:detach'),
|
||||
icon: 'action:detach',
|
||||
onClick: () => detachGroup({ detached: true, onSuccess: () => toggleSelection(group.id, false) }),
|
||||
disabled: !canDetachGroup.value,
|
||||
busy: isDetachingGroup.value,
|
||||
hint: detachGroupErrorMessage.value,
|
||||
},
|
||||
],
|
||||
}),
|
||||
}
|
||||
},
|
||||
})
|
||||
</script>
|
||||
@@ -1,107 +0,0 @@
|
||||
<template>
|
||||
<div class="role-privileges-table">
|
||||
<UiTitle>
|
||||
{{ t('privileges') }}
|
||||
</UiTitle>
|
||||
<VtsQueryBuilder v-bind="searchBindings" :schema />
|
||||
<VtsTable :state :pagination-bindings sticky="right">
|
||||
<thead>
|
||||
<tr>
|
||||
<HeadCells />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<VtsRow
|
||||
v-for="privilege of paginatedPrivileges"
|
||||
:key="privilege.id"
|
||||
:selected="selectedPrivilegeId === privilege.id"
|
||||
>
|
||||
<BodyCells :item="privilege" />
|
||||
</VtsRow>
|
||||
</tbody>
|
||||
</VtsTable>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { usePrivilegeAppliedToCount } from '@/modules/role/composables/use-privilege-applied-to-count.composable.ts'
|
||||
import { usePrivilegeQueryBuilder } from '@/modules/role/composables/use-privilege-query-builder.composable.ts'
|
||||
import { usePrivilegeScopeTypeLabels } from '@/modules/role/composables/use-privilege-scope-type-labels.composable.ts'
|
||||
import type { FrontXoPrivilege } from '@/modules/role/remote-resources/use-xo-role-privileges-collection.ts'
|
||||
import { getPrivilegeScopeType } from '@/modules/role/utils/privilege-scope.util.ts'
|
||||
import { EFFECT_ACCENTS } from '@/modules/role/utils/xo-privilege.util.ts'
|
||||
import VtsQueryBuilder from '@core/components/query-builder/VtsQueryBuilder.vue'
|
||||
import VtsRow from '@core/components/table/VtsRow.vue'
|
||||
import VtsTable from '@core/components/table/VtsTable.vue'
|
||||
import UiTitle from '@core/components/ui/title/UiTitle.vue'
|
||||
import { usePagination } from '@core/composables/pagination.composable.ts'
|
||||
import { useRouteQuery } from '@core/composables/route-query.composable.ts'
|
||||
import { useTableState } from '@core/composables/table-state.composable.ts'
|
||||
import { usePrivilegeColumns } from '@core/tables/column-sets/privilege-columns.ts'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { privileges, busy, error } = defineProps<{
|
||||
privileges: FrontXoPrivilege[]
|
||||
busy?: boolean
|
||||
error?: boolean
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const selectedPrivilegeId = useRouteQuery('id')
|
||||
|
||||
const {
|
||||
items: filteredPrivileges,
|
||||
searchBindings,
|
||||
schema,
|
||||
} = usePrivilegeQueryBuilder('role-privileges', () => privileges)
|
||||
|
||||
const state = useTableState({
|
||||
busy: () => busy,
|
||||
error: () => error,
|
||||
empty: () =>
|
||||
privileges.length === 0
|
||||
? t('no-privilege-attached')
|
||||
: filteredPrivileges.value.length === 0
|
||||
? { type: 'no-result' }
|
||||
: false,
|
||||
})
|
||||
|
||||
const { pageRecords: paginatedPrivileges, paginationBindings } = usePagination('role-privileges', filteredPrivileges)
|
||||
|
||||
const scopeTypeLabels = usePrivilegeScopeTypeLabels()
|
||||
|
||||
const privilegeNumberById = computed(
|
||||
() => new Map(privileges.map((privilege, index) => [privilege.id, String(index + 1)]))
|
||||
)
|
||||
|
||||
const { HeadCells, BodyCells } = usePrivilegeColumns({
|
||||
exclude: ['edit', 'remove'],
|
||||
body: (privilege: FrontXoPrivilege) => {
|
||||
const appliedToCount = usePrivilegeAppliedToCount(privilege)
|
||||
|
||||
return {
|
||||
index: r =>
|
||||
r({
|
||||
label: privilegeNumberById.value.get(privilege.id) ?? '',
|
||||
to: { name: '/admin/privilege/[id]/general', params: { id: privilege.id } },
|
||||
}),
|
||||
resource: r => r(privilege.resource),
|
||||
scope: r => r(scopeTypeLabels[getPrivilegeScopeType(privilege.resource, privilege.selector)]),
|
||||
appliedTo: r => r(appliedToCount.value),
|
||||
action: r => r(privilege.action),
|
||||
effect: r => r(t(privilege.effect), EFFECT_ACCENTS[privilege.effect]),
|
||||
selectItem: r => r(() => (selectedPrivilegeId.value = privilege.id)),
|
||||
}
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
.role-privileges-table {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2.4rem;
|
||||
}
|
||||
</style>
|
||||
@@ -1,140 +0,0 @@
|
||||
<template>
|
||||
<AssignmentsTableLayout
|
||||
:title="t('users')"
|
||||
:can-add="canAddUsers"
|
||||
:is-adding="isAddingUsers"
|
||||
:can-detach="canDetachSelectedUsers"
|
||||
:is-detaching="isDetachingSelectedUsers"
|
||||
:detach-error-message="detachSelectedUsersErrorMessage"
|
||||
@add="addUsersUnselected()"
|
||||
@detach="detachSelectedUsers({ detached: true, onSuccess: selectionBindings.onClearSelection })"
|
||||
>
|
||||
<template #filter>
|
||||
<VtsQueryBuilder v-bind="searchBindings" :schema />
|
||||
</template>
|
||||
<VtsTable :state :pagination-bindings :selection-bindings sticky="right">
|
||||
<thead>
|
||||
<tr>
|
||||
<HeadCells />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<VtsRow v-for="user of paginatedUsers" :key="user.id" :selected="selectedUserId === user.id">
|
||||
<BodyCells :item="user" />
|
||||
</VtsRow>
|
||||
</tbody>
|
||||
</VtsTable>
|
||||
</AssignmentsTableLayout>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useRoleUsersAdd } from '@/modules/role/composables/use-role-users-add.composable.ts'
|
||||
import type { RoleUser } from '@/modules/role/composables/use-xo-role-users.composable.ts'
|
||||
import { useXoRoleUsersRemoveJob } from '@/modules/role/jobs/xo-role-users-remove.job.ts'
|
||||
import type { FrontXoRole } from '@/modules/role/remote-resources/use-xo-role-collection.ts'
|
||||
import {
|
||||
type FilterableUser,
|
||||
useUserQueryBuilder,
|
||||
} from '@/modules/user/composables/use-user-query-builder.composable.ts'
|
||||
import { getUserDisplayName } from '@/modules/user/utils/xo-user.util.ts'
|
||||
import AssignmentsTableLayout from '@/shared/components/AssignmentsTableLayout.vue'
|
||||
import VtsQueryBuilder from '@core/components/query-builder/VtsQueryBuilder.vue'
|
||||
import VtsRow from '@core/components/table/VtsRow.vue'
|
||||
import VtsTable from '@core/components/table/VtsTable.vue'
|
||||
import { usePagination } from '@core/composables/pagination.composable.ts'
|
||||
import { useRouteQuery } from '@core/composables/route-query.composable.ts'
|
||||
import { useTableSelection } from '@core/composables/table-selection.composable.ts'
|
||||
import { useTableState } from '@core/composables/table-state.composable.ts'
|
||||
import { useUserColumns } from '@core/tables/column-sets/user-columns.ts'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { role, users, busy, error } = defineProps<{
|
||||
role: FrontXoRole
|
||||
users: RoleUser[]
|
||||
busy?: boolean
|
||||
error?: boolean
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const selectedUserId = useRouteQuery('id')
|
||||
|
||||
const { addUsers, canAddUsers, isAddingUsers } = useRoleUsersAdd(() => role)
|
||||
|
||||
const { items: filteredUsers, searchBindings, schema } = useUserQueryBuilder('role-users', () => users)
|
||||
|
||||
const { pageRecords: paginatedUsers, paginationBindings } = usePagination('role-users', filteredUsers)
|
||||
|
||||
const state = useTableState({
|
||||
busy: () => busy,
|
||||
error: () => error,
|
||||
empty: () =>
|
||||
users.length === 0 ? t('no-user-attached') : filteredUsers.value.length === 0 ? { type: 'no-result' } : false,
|
||||
})
|
||||
|
||||
const { selectedIds, pageSelectionModel, isSelected, toggleSelection, selectionBindings } = useTableSelection({
|
||||
items: () => users.filter(user => user.isDirect),
|
||||
filteredItems: () => filteredUsers.value.filter(user => user.isDirect),
|
||||
pageItems: () => paginatedUsers.value.filter(user => user.isDirect),
|
||||
getItemId: user => user.id,
|
||||
})
|
||||
|
||||
async function addUsersUnselected() {
|
||||
const addedUsers = await addUsers()
|
||||
|
||||
addedUsers.forEach(user => toggleSelection(user.id, false))
|
||||
}
|
||||
|
||||
const hasNoDirectUserOnPage = computed(() => paginatedUsers.value.every(user => !user.isDirect))
|
||||
|
||||
const selectedUsers = computed(() => users.filter(user => selectedIds.value.includes(user.id)))
|
||||
|
||||
const {
|
||||
run: detachSelectedUsers,
|
||||
canRun: canDetachSelectedUsers,
|
||||
isRunning: isDetachingSelectedUsers,
|
||||
errorMessage: detachSelectedUsersErrorMessage,
|
||||
} = useXoRoleUsersRemoveJob(() => [role], selectedUsers)
|
||||
|
||||
const { HeadCells, BodyCells } = useUserColumns({
|
||||
exclude: ['providers'],
|
||||
head: () => ({
|
||||
checkbox: r => r(pageSelectionModel, { disabled: hasNoDirectUserOnPage.value }),
|
||||
}),
|
||||
body: (user: FilterableUser<RoleUser>) => {
|
||||
const {
|
||||
run: detachUser,
|
||||
canRun: canDetachUser,
|
||||
isRunning: isDetachingUser,
|
||||
errorMessage: detachUserErrorMessage,
|
||||
} = useXoRoleUsersRemoveJob(
|
||||
() => [role],
|
||||
() => [user]
|
||||
)
|
||||
|
||||
return {
|
||||
checkbox: r =>
|
||||
user.isDirect ? r({ selected: isSelected(user.id), onToggle: () => toggleSelection(user.id) }) : r(),
|
||||
username: r => r(getUserDisplayName(user), { to: { name: '/admin/user/[id]/general', params: { id: user.id } } }),
|
||||
firstName: r => r(user.firstname),
|
||||
lastName: r => r(user.lastname),
|
||||
email: r => r(user.email),
|
||||
actions: r =>
|
||||
r({
|
||||
onClick: () => (selectedUserId.value = user.id),
|
||||
actions: [
|
||||
{
|
||||
label: t('action:detach'),
|
||||
icon: 'action:detach',
|
||||
onClick: () => detachUser({ detached: true, onSuccess: () => toggleSelection(user.id, false) }),
|
||||
disabled: !canDetachUser.value,
|
||||
busy: isDetachingUser.value,
|
||||
hint: detachUserErrorMessage.value,
|
||||
},
|
||||
],
|
||||
}),
|
||||
}
|
||||
},
|
||||
})
|
||||
</script>
|
||||
@@ -1,304 +0,0 @@
|
||||
<template>
|
||||
<UiDrawer @confirm="onSubmit()" @dismiss="emit('cancel')">
|
||||
<template #title>
|
||||
{{ privilegeToEdit === undefined ? t('privilege:create-new') : t('privilege:edit') }}
|
||||
</template>
|
||||
|
||||
<template #content>
|
||||
<UiStepper :steps :current-step="currentStepIndex">
|
||||
<div v-if="currentStep === 'details'" class="fields">
|
||||
<RoleFormSelect v-bind="resourceSelectBindings" />
|
||||
<RoleFormSelect v-bind="actionsSelectBindings" />
|
||||
<RoleFormSelect v-bind="effectSelectBindings" />
|
||||
</div>
|
||||
|
||||
<div v-else-if="currentStep === 'scope'" class="scope">
|
||||
<UiRadioButtonGroup accent="brand" gap="wide" :label="t('privilege:scope-type')">
|
||||
<UiRadioButton
|
||||
v-for="scopeType of PRIVILEGE_SCOPE_TYPES"
|
||||
:key="scopeType"
|
||||
v-model="formData.scope.scopeType"
|
||||
accent="brand"
|
||||
:value="scopeType"
|
||||
:disabled="!availableScopeTypes.includes(scopeType)"
|
||||
>
|
||||
{{ scopeTypeLabels[scopeType] }}
|
||||
</UiRadioButton>
|
||||
</UiRadioButtonGroup>
|
||||
|
||||
<div
|
||||
v-if="formData.scope.scopeType === 'manual-selection' && selectableResource !== undefined"
|
||||
class="selector"
|
||||
>
|
||||
<PrivilegeScopeResourceTable
|
||||
v-model:selected-ids="formData.scope.selectedIds"
|
||||
:resource="selectableResource"
|
||||
/>
|
||||
<UiInfo v-if="selectedIdsError !== undefined" accent="danger" wrap>
|
||||
{{ selectedIdsError }}
|
||||
</UiInfo>
|
||||
</div>
|
||||
|
||||
<template v-else-if="formData.scope.scopeType === 'dynamic-selection'">
|
||||
<div class="selector">
|
||||
<VtsQueryBuilder v-bind="selectorSearchBindings" :schema="selectorSchema" />
|
||||
<UiInfo :accent="selectorMessage.accent" wrap>
|
||||
{{ selectorMessage.content }}
|
||||
</UiInfo>
|
||||
</div>
|
||||
<PrivilegeScopePreviewTable
|
||||
v-if="isSelectorPreviewEnabled && selectableResource !== undefined"
|
||||
:resource="selectableResource"
|
||||
:matches="selectorMatches"
|
||||
:is-ready="areSelectorMatchesReady"
|
||||
:has-error="hasSelectorMatchesError"
|
||||
/>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div v-else class="review">
|
||||
<UiTitle>
|
||||
{{ t('privilege:details') }}
|
||||
<template #action>
|
||||
<UiButton left-icon="fa:edit" variant="tertiary" accent="brand" size="medium" @click="backTo('details')">
|
||||
{{ t('action:edit') }}
|
||||
</UiButton>
|
||||
</template>
|
||||
</UiTitle>
|
||||
|
||||
<dl class="review-fields">
|
||||
<dt>{{ t('privilege:resource') }}</dt>
|
||||
<dd>{{ formData.details.resource }}</dd>
|
||||
|
||||
<dt>{{ t('privilege:action') }}</dt>
|
||||
<dd>{{ formData.details.actions.join(', ') }}</dd>
|
||||
|
||||
<dt>{{ t('privilege:effect') }}</dt>
|
||||
<dd>
|
||||
<UiTagsList>
|
||||
<UiTag :accent="EFFECT_ACCENTS[formData.details.effect]" variant="secondary">
|
||||
{{ t(formData.details.effect) }}
|
||||
</UiTag>
|
||||
</UiTagsList>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<UiTitle class="scope-title">
|
||||
{{ t('privilege:scope') }}
|
||||
<template #action>
|
||||
<UiButton left-icon="fa:edit" variant="tertiary" accent="brand" size="medium" @click="backTo('scope')">
|
||||
{{ t('action:edit') }}
|
||||
</UiButton>
|
||||
</template>
|
||||
</UiTitle>
|
||||
|
||||
<dl class="review-fields">
|
||||
<dt>{{ t('privilege:scope-type') }}</dt>
|
||||
<dd>{{ scopeTypeLabels[formData.scope.scopeType] }}</dd>
|
||||
|
||||
<template v-if="formData.scope.scopeType === 'manual-selection' && selectableResource !== undefined">
|
||||
<dt class="top-aligned">{{ t('privilege:scope') }}</dt>
|
||||
<dd>
|
||||
<PrivilegeScopeObjectsList :resource="selectableResource" :ids="formData.scope.selectedIds" />
|
||||
</dd>
|
||||
</template>
|
||||
|
||||
<template v-if="formData.scope.scopeType === 'dynamic-selection' && selectableResource !== undefined">
|
||||
<dt class="top-aligned">{{ t('privilege:selector') }}</dt>
|
||||
<dd>
|
||||
<UiLogEntryViewer :content="formData.scope.selector" size="medium" accent="info" />
|
||||
</dd>
|
||||
|
||||
<dt class="top-aligned">{{ t('privilege:scope-preview') }}</dt>
|
||||
<dd class="scope-preview">
|
||||
<PrivilegeScopeObjectsList :resource="selectableResource" :ids="selectorMatchIds" />
|
||||
</dd>
|
||||
</template>
|
||||
</dl>
|
||||
</div>
|
||||
</UiStepper>
|
||||
</template>
|
||||
|
||||
<template #buttons>
|
||||
<VtsOverlayCancelButton v-if="currentStep === 'details'" @click="emit('cancel')" />
|
||||
<VtsOverlayButton v-else variant="secondary" @click="back()">
|
||||
{{ t('action:go-back') }}
|
||||
</VtsOverlayButton>
|
||||
<VtsOverlayConfirmButton>
|
||||
{{ confirmLabel }}
|
||||
</VtsOverlayConfirmButton>
|
||||
</template>
|
||||
</UiDrawer>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import PrivilegeScopeObjectsList from '@/modules/role/components/drawer/scope/PrivilegeScopeObjectsList.vue'
|
||||
import PrivilegeScopePreviewTable from '@/modules/role/components/drawer/scope/PrivilegeScopePreviewTable.vue'
|
||||
import PrivilegeScopeResourceTable from '@/modules/role/components/drawer/scope/PrivilegeScopeResourceTable.vue'
|
||||
import RoleFormSelect from '@/modules/role/components/form/inputs/RoleFormSelect.vue'
|
||||
import { usePrivilegeScopeTypeLabels } from '@/modules/role/composables/use-privilege-scope-type-labels.composable.ts'
|
||||
import { useNewPrivilegeForm } from '@/modules/role/form/new-privilege/use-new-privilege-form.ts'
|
||||
import type { NewPrivilegePayload } from '@/modules/role/types.ts'
|
||||
import { PRIVILEGE_SCOPE_TYPES } from '@/modules/role/utils/privilege-scope.util.ts'
|
||||
import { EFFECT_ACCENTS } from '@/modules/role/utils/xo-privilege.util.ts'
|
||||
import type { InfoAccent } from '@core/components/ui/info/UiInfo.vue'
|
||||
import type { StepDefinition } from '@core/components/ui/stepper/UiStepper.vue'
|
||||
import VtsOverlayButton from '@core/components/overlay/VtsOverlayButton.vue'
|
||||
import VtsOverlayCancelButton from '@core/components/overlay/VtsOverlayCancelButton.vue'
|
||||
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
|
||||
import VtsQueryBuilder from '@core/components/query-builder/VtsQueryBuilder.vue'
|
||||
import UiButton from '@core/components/ui/button/UiButton.vue'
|
||||
import UiDrawer from '@core/components/ui/drawer/UiDrawer.vue'
|
||||
import UiInfo from '@core/components/ui/info/UiInfo.vue'
|
||||
import UiLogEntryViewer from '@core/components/ui/log-entry-viewer/UiLogEntryViewer.vue'
|
||||
import UiRadioButton from '@core/components/ui/radio-button/UiRadioButton.vue'
|
||||
import UiRadioButtonGroup from '@core/components/ui/radio-button-group/UiRadioButtonGroup.vue'
|
||||
import UiStepper from '@core/components/ui/stepper/UiStepper.vue'
|
||||
import UiTag from '@core/components/ui/tag/UiTag.vue'
|
||||
import UiTagsList from '@core/components/ui/tag/UiTagsList.vue'
|
||||
import UiTitle from '@core/components/ui/title/UiTitle.vue'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { privilegeToEdit } = defineProps<{
|
||||
privilegeToEdit?: NewPrivilegePayload
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
confirm: [privileges: NewPrivilegePayload[]]
|
||||
cancel: []
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const scopeTypeLabels = usePrivilegeScopeTypeLabels()
|
||||
|
||||
const {
|
||||
formData,
|
||||
currentStep,
|
||||
next,
|
||||
back,
|
||||
backTo,
|
||||
resourceSelectBindings,
|
||||
actionsSelectBindings,
|
||||
effectSelectBindings,
|
||||
selectableResource,
|
||||
availableScopeTypes,
|
||||
selectorSchema,
|
||||
selectorError,
|
||||
selectorSearchBindings,
|
||||
selectedIdsError,
|
||||
isSelectorPreviewEnabled,
|
||||
selectorMatches,
|
||||
areSelectorMatchesReady,
|
||||
hasSelectorMatchesError,
|
||||
validateAndBuildPayloads,
|
||||
} = useNewPrivilegeForm(privilegeToEdit)
|
||||
|
||||
const selectorMatchIds = computed(() => selectorMatches.value.map(match => match.id))
|
||||
|
||||
const steps = computed<StepDefinition[]>(() => [
|
||||
{ label: t('privilege:details') },
|
||||
{ label: t('privilege:select-scope') },
|
||||
{ label: t('privilege:review-and-confirm') },
|
||||
])
|
||||
|
||||
const selectorMessage = computed<{ content: string; accent: InfoAccent }>(() => {
|
||||
if (selectorError.value !== undefined) {
|
||||
return { content: selectorError.value, accent: 'danger' }
|
||||
}
|
||||
|
||||
return { content: t('privilege:dynamic-selection-info'), accent: 'info' }
|
||||
})
|
||||
|
||||
const confirmLabel = computed(() => {
|
||||
if (currentStep.value !== 'review') {
|
||||
return t('action:continue')
|
||||
}
|
||||
|
||||
return privilegeToEdit === undefined ? t('action:create') : t('action:save')
|
||||
})
|
||||
|
||||
const stepNames = ['details', 'scope', 'review'] as const
|
||||
|
||||
const currentStepIndex = computed(() => stepNames.indexOf(currentStep.value))
|
||||
|
||||
async function onSubmit() {
|
||||
if (currentStep.value !== 'review') {
|
||||
await next()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const privileges = await validateAndBuildPayloads()
|
||||
|
||||
if (privileges !== undefined) {
|
||||
emit('confirm', privileges)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
.fields {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2.4rem;
|
||||
|
||||
@media (--medium-or-large) {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
align-items: start;
|
||||
}
|
||||
}
|
||||
|
||||
.scope {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2.4rem;
|
||||
|
||||
.selector {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
}
|
||||
|
||||
.review {
|
||||
display: grid;
|
||||
grid-template-columns: auto 1fr;
|
||||
gap: 1.6rem 6.4rem;
|
||||
|
||||
> * {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
.scope-title {
|
||||
margin-block-start: 1.6rem;
|
||||
}
|
||||
|
||||
.review-fields {
|
||||
display: grid;
|
||||
grid-template-columns: subgrid;
|
||||
align-items: center;
|
||||
row-gap: 0.8rem;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
dt {
|
||||
color: var(--color-neutral-txt-secondary);
|
||||
|
||||
&.top-aligned {
|
||||
align-self: start;
|
||||
}
|
||||
}
|
||||
|
||||
dd {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.scope-preview {
|
||||
max-height: 24rem;
|
||||
overflow: auto;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,112 +0,0 @@
|
||||
<template>
|
||||
<div class="roles-selection-table">
|
||||
<VtsQueryBuilder v-bind="searchBindings" :schema />
|
||||
<VtsTable :state :pagination-bindings :selection-bindings>
|
||||
<thead>
|
||||
<tr>
|
||||
<HeadCells />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<VtsRow v-for="role of paginatedRoles" :key="role.id">
|
||||
<BodyCells :item="role" />
|
||||
</VtsRow>
|
||||
</tbody>
|
||||
</VtsTable>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import {
|
||||
type FilterableRole,
|
||||
useRoleQueryBuilder,
|
||||
} from '@/modules/role/composables/use-role-query-builder.composable.ts'
|
||||
import type { FrontXoRole } from '@/modules/role/remote-resources/use-xo-role-collection.ts'
|
||||
import VtsQueryBuilder from '@core/components/query-builder/VtsQueryBuilder.vue'
|
||||
import VtsRow from '@core/components/table/VtsRow.vue'
|
||||
import VtsTable from '@core/components/table/VtsTable.vue'
|
||||
import { usePagination } from '@core/composables/pagination.composable.ts'
|
||||
import { useTableSelection } from '@core/composables/table-selection.composable.ts'
|
||||
import { useTableState } from '@core/composables/table-state.composable.ts'
|
||||
import { useRoleColumns } from '@core/tables/column-sets/role-columns.ts'
|
||||
import { computed, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const {
|
||||
roles,
|
||||
inheritedRoleIds = [],
|
||||
busy,
|
||||
error,
|
||||
} = defineProps<{
|
||||
roles: FrontXoRole[]
|
||||
inheritedRoleIds?: FrontXoRole['id'][]
|
||||
busy?: boolean
|
||||
error?: boolean
|
||||
}>()
|
||||
|
||||
const selectedRoleIds = defineModel<FrontXoRole['id'][]>('selectedRoleIds', { required: true })
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const {
|
||||
items: filteredRoles,
|
||||
searchBindings,
|
||||
schema,
|
||||
} = useRoleQueryBuilder('roles-selection', () => roles, {
|
||||
ignoreRoute: true,
|
||||
})
|
||||
|
||||
const { pageRecords: paginatedRoles, paginationBindings } = usePagination('roles-selection', filteredRoles, {
|
||||
ignoreRoute: true,
|
||||
})
|
||||
|
||||
const state = useTableState({
|
||||
busy: () => busy,
|
||||
error: () => error,
|
||||
empty: () =>
|
||||
roles.length === 0 ? t('no-role-detected') : filteredRoles.value.length === 0 ? { type: 'no-result' } : false,
|
||||
})
|
||||
|
||||
const selectableRoles = computed(() => roles.filter(role => !inheritedRoleIds.includes(role.id)))
|
||||
|
||||
const { selectedIds, pageSelectionModel, isSelected, toggleSelection, selectionBindings } = useTableSelection({
|
||||
items: selectableRoles,
|
||||
filteredItems: filteredRoles,
|
||||
pageItems: paginatedRoles,
|
||||
getItemId: role => role.id,
|
||||
})
|
||||
|
||||
const hasNoSelectableRoleOnPage = computed(() => paginatedRoles.value.every(role => inheritedRoleIds.includes(role.id)))
|
||||
|
||||
watch(selectedIds, ids => {
|
||||
selectedRoleIds.value = selectableRoles.value.filter(role => ids.includes(role.id)).map(role => role.id)
|
||||
})
|
||||
|
||||
const { HeadCells, BodyCells } = useRoleColumns({
|
||||
exclude: ['group', 'actions'],
|
||||
head: () => ({
|
||||
checkbox: r => r(pageSelectionModel, { disabled: hasNoSelectableRoleOnPage.value }),
|
||||
}),
|
||||
body: (role: FilterableRole) => ({
|
||||
checkbox: r =>
|
||||
r({
|
||||
selected: inheritedRoleIds.includes(role.id) || isSelected(role.id),
|
||||
disabled: inheritedRoleIds.includes(role.id),
|
||||
onToggle: () => toggleSelection(role.id),
|
||||
}),
|
||||
name: r => r({ label: role.name, icon: 'fa:key' }),
|
||||
description: r => r(role.description),
|
||||
users: r => r(role.usersCount),
|
||||
groups: r => r(role.groupsCount),
|
||||
privileges: r => r(role.privilegesCount),
|
||||
}),
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
.roles-selection-table {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
</style>
|
||||
@@ -1,73 +0,0 @@
|
||||
<template>
|
||||
<UiDrawer @confirm="confirm()" @dismiss="emit('cancel')">
|
||||
<template #title>
|
||||
{{ title }}
|
||||
</template>
|
||||
|
||||
<template #content>
|
||||
<div class="content">
|
||||
<RolesSelectionTable v-model:selected-role-ids="selectedRoleIds" :roles />
|
||||
<UiInfo v-if="isSelectionErrorVisible" accent="danger">
|
||||
{{ t('select-at-least-one-role.') }}
|
||||
</UiInfo>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #buttons>
|
||||
<VtsOverlayCancelButton @click="emit('cancel')" />
|
||||
<VtsOverlayConfirmButton>
|
||||
{{ t('action:add') }}
|
||||
</VtsOverlayConfirmButton>
|
||||
</template>
|
||||
</UiDrawer>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import RolesSelectionTable from '@/modules/role/components/drawer/RolesSelectionTable.vue'
|
||||
import type { FrontXoRole } from '@/modules/role/remote-resources/use-xo-role-collection.ts'
|
||||
import VtsOverlayCancelButton from '@core/components/overlay/VtsOverlayCancelButton.vue'
|
||||
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
|
||||
import UiDrawer from '@core/components/ui/drawer/UiDrawer.vue'
|
||||
import UiInfo from '@core/components/ui/info/UiInfo.vue'
|
||||
import { computed, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { roles } = defineProps<{
|
||||
roles: FrontXoRole[]
|
||||
title: string
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
confirm: [roles: FrontXoRole[]]
|
||||
cancel: []
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const selectedRoleIds = ref<FrontXoRole['id'][]>([])
|
||||
|
||||
const hasTriedToConfirm = ref(false)
|
||||
|
||||
const isSelectionErrorVisible = computed(() => hasTriedToConfirm.value && selectedRoleIds.value.length === 0)
|
||||
|
||||
function confirm() {
|
||||
hasTriedToConfirm.value = true
|
||||
|
||||
if (selectedRoleIds.value.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
emit(
|
||||
'confirm',
|
||||
roles.filter(role => selectedRoleIds.value.includes(role.id))
|
||||
)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
.content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
</style>
|
||||
@@ -1,131 +0,0 @@
|
||||
<template>
|
||||
<div class="privilege-scope-hosts-table">
|
||||
<VtsQueryBuilder v-bind="searchBindings" :schema />
|
||||
<VtsTable :state :pagination-bindings :selection-bindings="readonly ? undefined : selectionBindings">
|
||||
<thead>
|
||||
<tr>
|
||||
<HeadCells />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<VtsRow v-for="host of paginatedHosts" :key="host.id">
|
||||
<BodyCells :item="host" />
|
||||
</VtsRow>
|
||||
</tbody>
|
||||
</VtsTable>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useHostQueryBuilder } from '@/modules/host/composables/use-host-query-builder.composable.ts'
|
||||
import { type FrontXoHost, useXoHostCollection } from '@/modules/host/remote-resources/use-xo-host-collection.ts'
|
||||
import { getHostIcon } from '@/modules/host/utils/xo-host.util.ts'
|
||||
import { useXoPifCollection } from '@/modules/pif/remote-resources/use-xo-pif-collection.ts'
|
||||
import { getHostIpAddresses } from '@/modules/pif/utils/xo-pif.util.ts'
|
||||
import VtsQueryBuilder from '@core/components/query-builder/VtsQueryBuilder.vue'
|
||||
import VtsRow from '@core/components/table/VtsRow.vue'
|
||||
import VtsTable from '@core/components/table/VtsTable.vue'
|
||||
import { usePagination } from '@core/composables/pagination.composable.ts'
|
||||
import { useTableSelection } from '@core/composables/table-selection.composable.ts'
|
||||
import { useTableState } from '@core/composables/table-state.composable.ts'
|
||||
import { icon } from '@core/icons'
|
||||
import { useHostColumns } from '@core/tables/column-sets/host-columns.ts'
|
||||
import { logicAnd, logicNot, logicOr } from '@vueuse/math'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { visibleIds, readonly = false } = defineProps<{
|
||||
visibleIds?: string[]
|
||||
readonly?: boolean
|
||||
}>()
|
||||
|
||||
const selectedIds = defineModel<string[]>('selectedIds', { default: () => [] })
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const { hosts, areHostsReady, hasHostFetchError, isMasterHost } = useXoHostCollection()
|
||||
|
||||
const visibleHosts = computed(() =>
|
||||
visibleIds === undefined ? hosts.value : hosts.value.filter(host => visibleIds.includes(host.id))
|
||||
)
|
||||
|
||||
const { pifsByHost, arePifsReady, hasPifFetchError } = useXoPifCollection()
|
||||
|
||||
const isReady = logicAnd(areHostsReady, arePifsReady)
|
||||
|
||||
const {
|
||||
items: filteredHosts,
|
||||
searchBindings,
|
||||
schema,
|
||||
} = useHostQueryBuilder('privilege-scope-hosts', visibleHosts, {
|
||||
ignoreRoute: true,
|
||||
})
|
||||
|
||||
const state = useTableState({
|
||||
busy: logicNot(isReady),
|
||||
error: logicOr(hasHostFetchError, hasPifFetchError),
|
||||
empty: () =>
|
||||
visibleHosts.value.length === 0
|
||||
? t('no-host-detected')
|
||||
: filteredHosts.value.length === 0
|
||||
? { type: 'no-result' }
|
||||
: false,
|
||||
})
|
||||
|
||||
const { pageRecords: paginatedHosts, paginationBindings } = usePagination('privilege-scope-hosts', filteredHosts, {
|
||||
ignoreRoute: true,
|
||||
})
|
||||
|
||||
const { pageSelectionModel, isSelected, toggleSelection, selectionBindings } = useTableSelection({
|
||||
items: visibleHosts,
|
||||
filteredItems: filteredHosts,
|
||||
pageItems: paginatedHosts,
|
||||
getItemId: (host): string => host.id,
|
||||
selectedIds,
|
||||
})
|
||||
|
||||
function getMasterIcon(host: FrontXoHost) {
|
||||
if (!isMasterHost(host.id)) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return {
|
||||
icon: icon('status:primary-circle'),
|
||||
tooltip: t('master'),
|
||||
}
|
||||
}
|
||||
|
||||
const { HeadCells, BodyCells } = useHostColumns({
|
||||
exclude: ['srStatus', 'selectItem', 'actions'],
|
||||
head: () => ({
|
||||
checkbox: r => (readonly ? r() : r(pageSelectionModel)),
|
||||
}),
|
||||
body: (host: FrontXoHost) => {
|
||||
const ipAddresses = computed(() => getHostIpAddresses(host.address, pifsByHost.value.get(host.id)))
|
||||
const hostIcon = computed(() => getHostIcon(host))
|
||||
const rightIcon = computed(() => getMasterIcon(host))
|
||||
|
||||
return {
|
||||
checkbox: r => (readonly ? r() : r({ selected: isSelected(host.id), onToggle: () => toggleSelection(host.id) })),
|
||||
host: r =>
|
||||
r({
|
||||
label: host.name_label,
|
||||
to: { name: '/host/[id]/dashboard', params: { id: host.id } },
|
||||
icon: hostIcon.value,
|
||||
rightIcon: rightIcon.value,
|
||||
}),
|
||||
description: r => r(host.name_description),
|
||||
ipAddresses: r => r(ipAddresses.value),
|
||||
tags: r => r(host.tags),
|
||||
}
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
.privilege-scope-hosts-table {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
</style>
|
||||
@@ -1,34 +0,0 @@
|
||||
<template>
|
||||
<ul class="privilege-scope-objects-list">
|
||||
<li v-for="object of selectedObjects" :key="object.id">
|
||||
<UiLink size="medium" :to="object.to" :icon="object.icon">{{ object.label }}</UiLink>
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { usePrivilegeScopeObjectsByIds } from '@/modules/role/composables/use-privilege-scope-objects-by-ids.composable.ts'
|
||||
import type { SelectablePrivilegeResource } from '@/modules/role/utils/privilege-catalogue.util.ts'
|
||||
import UiLink from '@core/components/ui/link/UiLink.vue'
|
||||
|
||||
const { resource, ids } = defineProps<{
|
||||
resource: SelectablePrivilegeResource
|
||||
ids: string[]
|
||||
}>()
|
||||
|
||||
const { objects: selectedObjects } = usePrivilegeScopeObjectsByIds(
|
||||
() => resource,
|
||||
() => ids
|
||||
)
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
.privilege-scope-objects-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
</style>
|
||||
@@ -1,97 +0,0 @@
|
||||
<template>
|
||||
<div class="privilege-scope-objects-table">
|
||||
<VtsQueryBuilder v-bind="searchBindings" :schema />
|
||||
<VtsTable :state :pagination-bindings :selection-bindings="readonly ? undefined : selectionBindings">
|
||||
<thead>
|
||||
<tr>
|
||||
<HeadCells />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<VtsRow v-for="object of paginatedObjects" :key="object.id">
|
||||
<BodyCells :item="object" />
|
||||
</VtsRow>
|
||||
</tbody>
|
||||
</VtsTable>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { PrivilegeScopeObject } from '@/modules/role/types.ts'
|
||||
import VtsQueryBuilder from '@core/components/query-builder/VtsQueryBuilder.vue'
|
||||
import VtsRow from '@core/components/table/VtsRow.vue'
|
||||
import VtsTable from '@core/components/table/VtsTable.vue'
|
||||
import { usePagination } from '@core/composables/pagination.composable.ts'
|
||||
import { useTableSelection } from '@core/composables/table-selection.composable.ts'
|
||||
import { useTableState } from '@core/composables/table-state.composable.ts'
|
||||
import { useQueryBuilderSchema } from '@core/packages/query-builder/schema/use-query-builder-schema.ts'
|
||||
import { useQueryBuilderFilter } from '@core/packages/query-builder/use-query-builder-filter.ts'
|
||||
import { usePrivilegeScopeObjectColumns } from '@core/tables/column-sets/privilege-scope-object-columns.ts'
|
||||
import { useStringSchema } from '@core/utils/query-builder/use-string-schema.ts'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const {
|
||||
tableId,
|
||||
objects,
|
||||
isReady,
|
||||
hasError,
|
||||
emptyMessage,
|
||||
readonly = false,
|
||||
} = defineProps<{
|
||||
tableId: string
|
||||
objects: PrivilegeScopeObject[]
|
||||
isReady: boolean
|
||||
hasError: boolean
|
||||
emptyMessage: string
|
||||
readonly?: boolean
|
||||
}>()
|
||||
|
||||
const selectedIds = defineModel<string[]>('selectedIds', { default: () => [] })
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const { items: filteredObjects, searchBindings } = useQueryBuilderFilter(tableId, () => objects, { ignoreRoute: true })
|
||||
|
||||
const schema = useQueryBuilderSchema<PrivilegeScopeObject>({
|
||||
'': useStringSchema(t('any-property')),
|
||||
label: useStringSchema(t('name')),
|
||||
})
|
||||
|
||||
const state = useTableState({
|
||||
busy: () => !isReady,
|
||||
error: () => hasError,
|
||||
empty: () =>
|
||||
objects.length === 0 ? emptyMessage : filteredObjects.value.length === 0 ? { type: 'no-result' } : false,
|
||||
})
|
||||
|
||||
const { pageRecords: paginatedObjects, paginationBindings } = usePagination(tableId, filteredObjects, {
|
||||
ignoreRoute: true,
|
||||
})
|
||||
|
||||
const { pageSelectionModel, isSelected, toggleSelection, selectionBindings } = useTableSelection({
|
||||
items: () => objects,
|
||||
filteredItems: filteredObjects,
|
||||
pageItems: paginatedObjects,
|
||||
getItemId: object => object.id,
|
||||
selectedIds,
|
||||
})
|
||||
|
||||
const { HeadCells, BodyCells } = usePrivilegeScopeObjectColumns({
|
||||
head: () => ({
|
||||
checkbox: r => (readonly ? r() : r(pageSelectionModel)),
|
||||
}),
|
||||
body: (object: PrivilegeScopeObject) => ({
|
||||
checkbox: r =>
|
||||
readonly ? r() : r({ selected: isSelected(object.id), onToggle: () => toggleSelection(object.id) }),
|
||||
object: r => r({ label: object.label, to: object.to, icon: object.icon }),
|
||||
}),
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
.privilege-scope-objects-table {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
</style>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user