Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 | 70x 20x 2x 2x 2x 2x 2x 140x 2x 520x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 6x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 1170x 45x 450x 450x 2x 45x 2x 2x 45x 4x 1x 45x 1x 1x 1x 1x 8x 8x 7x 7x 5x 5x 8x 8x 2x 2x 2x 2x 1x 1x 45x 53x 53x 17x 17x 17x 17x 11x 45x 59x 59x 97x 59x 3x 1x 1x 1x 1x 1x 1x 1x 45x 33x 53x | <template>
<BaseFormSidebar
:is-open="isOpen"
:dirty="dirty"
storage-key="role-form-sidebar"
:title="mode === 'create' ? t('role.createNew') : t('role.editRole')"
panel-width="1400px"
:loading="loading"
:submit-disabled="!isValid"
:submit-label="mode === 'create' ? 'Create Role' : 'Update Role'"
:submit-icon="mode === 'create' ? 'fa-solid fa-plus' : 'fa-solid fa-save'"
submit-button-class="btn-success"
@close="handleClose"
@submit="handleSubmit"
>
<!-- Language Selector -->
<EditingLanguageSelector
:model-value="currentLanguage"
:languages="enabledLanguages"
class="mb-3"
@update:model-value="$emit('update:currentLanguage', $event)"
/>
<form @submit.prevent="handleSubmit">
<div class="mb-3">
<MultilingualInput
:model-value="formData.name"
label="Name"
:placeholder="t('role.placeholderName')"
:default-language="defaultLanguage"
:enabled-languages="enabledLanguages"
:current-language="currentLanguage"
:show-language-selector="false"
required
@update:model-value="$emit('update:formData', { ...formData, name: $event })"
/>
</div>
<div class="mb-3">
<MultilingualTextarea
:model-value="formData.description"
label="Description"
:placeholder="t('role.placeholderDescription')"
:default-language="defaultLanguage"
:enabled-languages="enabledLanguages"
:current-language="currentLanguage"
:show-language-selector="false"
:rows="2"
@update:model-value="$emit('update:formData', { ...formData, description: $event })"
/>
</div>
<div class="mb-3">
<label class="form-label fw-bold">Permissions <span class="text-danger">*</span></label>
<div class="border rounded p-3 permissions-container permissions-card">
<div class="row">
<div
v-for="category in permissionCategories"
:key="category.nameKey"
class="col-12 mb-2"
>
<h6 class="text-primary mb-1 small">{{ t(category.nameKey) }}</h6>
<div
v-for="perm in category.permissions"
:key="perm.value"
class="form-check form-check-sm mb-2"
>
<input
:id="`perm-${mode}-${perm.value}`"
:checked="formData.permissions.includes(perm.value)"
type="checkbox"
:value="perm.value"
class="form-check-input"
@change="
togglePermission(perm.value, ($event.target as HTMLInputElement).checked)
"
/>
<label class="form-check-label small" :for="`perm-${mode}-${perm.value}`">
{{ t(perm.descriptionKey) }}
</label>
</div>
</div>
</div>
<div class="mt-2 pt-2 border-top">
<div class="d-flex justify-content-between align-items-center mb-2">
<label class="form-label small mb-0 fw-bold">{{
t('role.entitySpecificPermission')
}}</label>
<button
type="button"
class="btn btn-sm btn-outline-primary"
@click="toggleCustomBuilder"
>
<font-awesome-icon icon="fa-solid fa-plus" class="me-1" />
{{ t('role.addPermission') }}
</button>
</div>
<div v-if="showCustomBuilder" class="border rounded p-2 custom-builder-card">
<div class="row g-2 align-items-end">
<div class="col-12 col-md-5">
<label class="form-label small mb-1 d-block">{{ t('role.entity') }}</label>
<select
v-model="customEntityId"
class="form-select form-select-sm"
name="custom-entity"
>
<option value="" disabled>{{ t('common.select') }}</option>
<option
v-for="entity in entitiesStore.entities"
:key="entity.id"
:value="entity.id"
>
{{ getTranslation(entity.name) }}
</option>
</select>
</div>
<div class="col-12 col-md-5">
<label class="form-label small mb-1 d-block">{{ t('role.action') }}</label>
<select
v-model="customOptionValue"
class="form-select form-select-sm"
name="custom-option"
>
<optgroup :label="t('role.scopeEntity')">
<option v-for="opt in ENTITY_OPTIONS" :key="opt.value" :value="opt.value">
{{ t(opt.labelKey) }}
</option>
</optgroup>
<optgroup :label="t('role.scopeItems')">
<option v-for="opt in ITEMS_OPTIONS" :key="opt.value" :value="opt.value">
{{ t(opt.labelKey) }}
</option>
</optgroup>
<optgroup
v-if="transitionOptions.length > 0"
:label="t('role.scopeTransitions')"
>
<option v-for="opt in transitionOptions" :key="opt.value" :value="opt.value">
{{ opt.label }}
</option>
</optgroup>
</select>
</div>
<div class="col-12 col-md-2">
<label class="form-label small mb-1 d-block invisible"> </label>
<button
type="button"
class="btn btn-sm btn-success w-100"
:disabled="!customEntityId"
@click="addCustomEntityPermission"
>
<font-awesome-icon icon="fa-solid fa-check" class="me-1" />
{{ t('role.confirmAddPermission') }}
</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div v-if="formData.permissions.length > 0" class="mb-3">
<label class="form-label fw-bold"
>Selected Permissions ({{ formData.permissions.length }})</label
>
<div class="border rounded p-2 selected-permissions-card">
<span v-for="perm in formData.permissions" :key="perm" class="badge bg-primary me-1 mb-1">
{{ describePermission(perm) }}
<button
type="button"
class="btn-close btn-close-white ms-1"
style="font-size: 0.6rem"
@click="removePermission(perm)"
/>
</span>
</div>
</div>
<div v-if="error" class="alert alert-danger">
{{ error }}
</div>
</form>
</BaseFormSidebar>
</template>
<script setup lang="ts">
// @implements UC-I18N-003.1, UC-I18N-010.1, UC-WORKFLOW-005.1
import { useUnsavedChanges } from '@/composables/useUnsavedChanges'
import BaseFormSidebar from '@/components/BaseFormSidebar.vue'
import MultilingualInput from '@/components/MultilingualInput.vue'
import MultilingualTextarea from '@/components/MultilingualTextarea.vue'
import { useUILanguage } from '@/composables/useUILanguage'
import { useLanguage } from '@/composables/useLanguage'
import { useEntitiesStore } from '@/stores/entities'
import EditingLanguageSelector from './EditingLanguageSelector.vue'
import { isValidPermissionFormat } from '@/utils/permissionFormat'
import {
describeTransition,
listProtectedTransitions,
parseTransitionPermission,
transitionPermission
} from '@/utils/workflowTransitionPermission'
import { ref, computed, watch } from 'vue'
const { t } = useUILanguage()
const { getTranslation } = useLanguage()
const entitiesStore = useEntitiesStore()
const props = defineProps<{
isOpen: boolean
mode: 'create' | 'edit'
formData: {
name: string | Record<string, string>
description: string | Record<string, string>
permissions: string[]
}
defaultLanguage: string
enabledLanguages: string[]
currentLanguage: string
loading: boolean
error: string
}>()
const emit = defineEmits<{
'update:formData': [value: any]
'update:currentLanguage': [value: string]
close: []
submit: []
}>()
const showCustomBuilder = ref(false)
const customEntityId = ref('')
const customOptionValue = ref('entity:read')
const permissionCategories = [
{
nameKey: 'role.categoryEntities',
permissions: [
{ value: 'entities:create', descriptionKey: 'role.permDescEntitiesCreate' },
{ value: 'entities:list', descriptionKey: 'role.permDescEntitiesList' },
{ value: 'entities-*:read', descriptionKey: 'role.permDescEntitiesRead' },
{ value: 'entities-*:update', descriptionKey: 'role.permDescEntitiesUpdate' },
{ value: 'entities-*:delete', descriptionKey: 'role.permDescEntitiesDelete' },
{ value: 'entities-*:*', descriptionKey: 'role.permDescEntitiesAll' }
]
},
{
nameKey: 'role.categoryItems',
permissions: [
{ value: 'entities-*:items:create', descriptionKey: 'role.permDescItemsCreate' },
{ value: 'entities-*:items:list', descriptionKey: 'role.permDescItemsList' },
{ value: 'entities-*:items:read', descriptionKey: 'role.permDescItemsRead' },
{ value: 'entities-*:items:update', descriptionKey: 'role.permDescItemsUpdate' },
{ value: 'entities-*:items:delete', descriptionKey: 'role.permDescItemsDelete' },
{ value: 'entities-*:items:*', descriptionKey: 'role.permDescItemsAll' }
]
},
{
nameKey: 'role.categoryMembers',
permissions: [
{ value: 'members:invite', descriptionKey: 'role.permDescMembersInvite' },
{ value: 'members:list', descriptionKey: 'role.permDescMembersList' },
{ value: 'members:remove', descriptionKey: 'role.permDescMembersRemove' },
{ value: 'members:approve', descriptionKey: 'role.permDescMembersApprove' }
]
},
{
nameKey: 'role.categoryRoles',
permissions: [
{ value: 'roles:create', descriptionKey: 'role.permDescRolesCreate' },
{ value: 'roles:list', descriptionKey: 'role.permDescRolesList' },
{ value: 'roles:update', descriptionKey: 'role.permDescRolesUpdate' },
{ value: 'roles:delete', descriptionKey: 'role.permDescRolesDelete' },
{ value: 'roles:assign', descriptionKey: 'role.permDescRolesAssign' }
]
},
{
nameKey: 'role.categoryFlows',
permissions: [
{ value: 'flows:update', descriptionKey: 'role.permDescFlowsUpdate' },
{ value: 'flows:delete', descriptionKey: 'role.permDescFlowsDelete' },
{ value: 'pages:update', descriptionKey: 'role.permDescPagesUpdate' }
]
},
{
nameKey: 'role.categoryStore',
permissions: [{ value: 'packs:publish', descriptionKey: 'role.permDescPacksPublish' }]
},
{
nameKey: 'role.categoryAdmin',
permissions: [{ value: '*:*', descriptionKey: 'role.permDescAdminAll' }]
}
]
const PERMISSION_DESCRIPTION_LOOKUP: Record<string, string> = Object.fromEntries(
permissionCategories.flatMap((category) =>
category.permissions.map((perm) => [perm.value, perm.descriptionKey])
)
)
// Options for the entity-specific permission builder, grouped by whether they
// apply to the entity itself or to its items — mirrors the two forms
// documented in rbac.req.md's "Permission string format": `entities-{id}:{verb}`
// and `entities-{id}:items:{verb}`.
const CUSTOM_PERMISSION_OPTIONS: Array<{
value: string
scope: 'entity' | 'items'
action: string
labelKey: string
}> = [
{ value: 'entity:read', scope: 'entity', action: 'read', labelKey: 'role.optionEntityRead' },
{
value: 'entity:update',
scope: 'entity',
action: 'update',
labelKey: 'role.optionEntityUpdate'
},
{
value: 'entity:delete',
scope: 'entity',
action: 'delete',
labelKey: 'role.optionEntityDelete'
},
{ value: 'entity:*', scope: 'entity', action: '*', labelKey: 'role.optionEntityAll' },
{ value: 'items:create', scope: 'items', action: 'create', labelKey: 'role.optionItemsCreate' },
{ value: 'items:list', scope: 'items', action: 'list', labelKey: 'role.optionItemsList' },
{ value: 'items:read', scope: 'items', action: 'read', labelKey: 'role.optionItemsRead' },
{ value: 'items:update', scope: 'items', action: 'update', labelKey: 'role.optionItemsUpdate' },
{ value: 'items:delete', scope: 'items', action: 'delete', labelKey: 'role.optionItemsDelete' },
{ value: 'items:*', scope: 'items', action: '*', labelKey: 'role.optionItemsAll' }
]
const ENTITY_OPTIONS = CUSTOM_PERMISSION_OPTIONS.filter((opt) => opt.scope === 'entity')
const ITEMS_OPTIONS = CUSTOM_PERMISSION_OPTIONS.filter((opt) => opt.scope === 'items')
// Prefix of the builder's option values for protected workflow transitions
const TRANSITION_OPTION_PREFIX = 'transition:'
/** Protected workflow transitions of the entity picked in the builder. */
const transitionOptions = computed(() => {
const entity = entitiesStore.entities.find((e) => e.id === customEntityId.value)
return listProtectedTransitions(entity?.fields).map((entry) => ({
value: `${TRANSITION_OPTION_PREFIX}${entry.fieldId}:${entry.from}:${entry.to}`,
label: describeTransition(entry, getTranslation)
}))
})
// A transition only exists for the entity it was picked from.
watch(customEntityId, () => {
if (customOptionValue.value.startsWith(TRANSITION_OPTION_PREFIX)) {
customOptionValue.value = 'entity:read'
}
})
const customPermission = computed(() => {
Iif (!customEntityId.value) return ''
Eif (customOptionValue.value.startsWith(TRANSITION_OPTION_PREFIX)) {
const [fieldId, from, to] = customOptionValue.value
.slice(TRANSITION_OPTION_PREFIX.length)
.split(':')
return transitionPermission(customEntityId.value, fieldId!, from!, to!)
}
const option = CUSTOM_PERMISSION_OPTIONS.find((opt) => opt.value === customOptionValue.value)
if (!option) return ''
return option.scope === 'items'
? `entities-${customEntityId.value}:items:${option.action}`
: `entities-${customEntityId.value}:${option.action}`
})
/** Human-readable label for a permission string, for the "Selected Permissions" list. */
function describePermission(perm: string): string {
const descriptionKey = PERMISSION_DESCRIPTION_LOOKUP[perm]
if (descriptionKey) return t(descriptionKey)
const transition = parseTransitionPermission(perm)
if (transition) return describeTransitionPermission(transition)
const itemsMatch = /^entities-([^:]+):items:(.+)$/.exec(perm)
const entityMatch = itemsMatch ? null : /^entities-([^:]+):(.+)$/.exec(perm)
const match = itemsMatch ?? entityMatch
if (!match) return perm
const [, entityId, action] = match
const option = CUSTOM_PERMISSION_OPTIONS.find(
(opt) => opt.scope === (itemsMatch ? 'items' : 'entity') && opt.action === action
)
if (!option) return perm
const entity = entitiesStore.entities.find((e) => e.id === entityId)
return `${t(option.labelKey)} — ${entity ? getTranslation(entity.name) : entityId}`
}
/**
* "Trigger transition Status: Draft → Published — Articles". Falls back to the
* raw string when the entity, field or transition no longer exists.
*/
function describeTransitionPermission(
parsed: NonNullable<ReturnType<typeof parseTransitionPermission>>
): string {
const entity = entitiesStore.entities.find((e) => e.id === parsed.entityId)
const entry = listProtectedTransitions(entity?.fields).find(
(candidate) =>
candidate.fieldId === parsed.fieldId &&
candidate.from === parsed.from &&
candidate.to === parsed.to
)
if (!entity || !entry)
return transitionPermission(parsed.entityId, parsed.fieldId, parsed.from, parsed.to)
return `${t('role.optionTransition').replace('{transition}', describeTransition(entry, getTranslation))} — ${getTranslation(entity.name)}`
}
// The sidebar is toggled via `isOpen`, not unmounted, so its own local state
// (the custom-permission builder in particular) would otherwise leak from one
// create/edit session into the next. Reset it, and lazily fetch entities for
// the entity dropdown, every time it transitions from closed to open.
watch(
() => props.isOpen,
(open) => {
if (!open) return
showCustomBuilder.value = false
customEntityId.value = ''
customOptionValue.value = 'entity:read'
if (entitiesStore.entities.length === 0 && !entitiesStore.loading) {
// A failed fetch just leaves the entity dropdown empty — not worth
// surfacing here, but fetchEntities() rethrows, so this must be caught.
entitiesStore.fetchEntities().catch(() => {})
}
},
{ immediate: true }
)
const isValid = computed(() => {
const name = props.formData.name
const hasName =
typeof name === 'string'
? name.trim().length > 0
: Object.values(name).some((val) => val && val.trim().length > 0)
return hasName && props.formData.permissions.length > 0
})
function handleClose() {
emit('close')
}
function handleSubmit() {
emit('submit')
}
function togglePermission(permission: string, checked: boolean) {
const permissions = [...props.formData.permissions]
if (checked && !permissions.includes(permission)) {
permissions.push(permission)
} else if (!checked) {
const index = permissions.indexOf(permission)
if (index > -1) permissions.splice(index, 1)
}
emit('update:formData', { ...props.formData, permissions })
}
function removePermission(perm: string) {
const permissions = props.formData.permissions.filter((p) => p !== perm)
emit('update:formData', { ...props.formData, permissions })
}
function toggleCustomBuilder() {
showCustomBuilder.value = !showCustomBuilder.value
}
function addCustomEntityPermission() {
const permission = customPermission.value
Iif (!permission || !isValidPermissionFormat(permission)) return
const permissions = [...props.formData.permissions]
Eif (!permissions.includes(permission)) {
permissions.push(permission)
}
emit('update:formData', { ...props.formData, permissions })
}
// Closing, or leaving the page, asks before dropping the changes (BaseFormSidebar)
const { dirty } = useUnsavedChanges(
() => props.formData,
() => props.isOpen
)
</script>
<style scoped>
.permissions-container {
max-height: 400px;
overflow-y: auto;
}
.permissions-card {
background-color: var(--bw-surface-muted);
border-color: var(--bw-border) !important;
}
.selected-permissions-card {
background-color: var(--bw-surface);
border-color: var(--bw-border) !important;
}
.custom-builder-card {
background-color: var(--bw-surface);
border-color: var(--bw-border) !important;
}
.form-check-sm {
font-size: 0.875rem;
}
.form-check-sm .form-check-input {
margin-top: 0.15rem;
}
</style>
|