Skip to content

Commit e162ca1

Browse files
committed
feat(policy): ask create scope through prompt dialog
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent a797862 commit e162ca1

1 file changed

Lines changed: 77 additions & 33 deletions

File tree

src/views/Settings/PolicyWorkbench/RealPolicyWorkbench.vue

Lines changed: 77 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,7 @@
200200
</label>
201201
</div>
202202
<div v-if="state.viewMode === 'system-admin'" class="policy-workbench__crud-create">
203-
<label class="policy-workbench__create-inline">
204-
<span>{{ t('libresign', 'Create in') }}</span>
205-
<select class="policy-workbench__create-select" :value="newRuleScope" @change="setNewRuleScope(($event.target as HTMLSelectElement).value as 'system' | 'group' | 'user', true)">
206-
<option value="system">{{ t('libresign', 'Instance') }}</option>
207-
<option value="group">{{ t('libresign', 'Group') }}</option>
208-
<option value="user">{{ t('libresign', 'User') }}</option>
209-
</select>
210-
</label>
211-
<NcButton variant="primary" size="small" :disabled="isCreateRuleDisabled" :title="createRuleDisabledReason || undefined" @click="startCreateRule()">
203+
<NcButton variant="primary" size="small" :disabled="!hasCreatableScope" :title="createRuleDisabledReason || undefined" @click="requestCreateRule()">
212204
{{ t('libresign', 'Create rule') }}
213205
</NcButton>
214206
<p v-if="createRuleDisabledReason" class="policy-workbench__table-note policy-workbench__table-note--align-right">
@@ -341,6 +333,32 @@
341333
</div>
342334
</NcDialog>
343335

336+
<NcDialog
337+
v-if="showCreateScopeDialog"
338+
:name="t('libresign', 'What do you want to create?')"
339+
size="normal"
340+
:can-close="true"
341+
@closing="cancelCreateScopeDialog">
342+
<div class="policy-workbench__create-scope-dialog">
343+
<p>{{ t('libresign', 'Choose the level where the new rule should be created.') }}</p>
344+
<div class="policy-workbench__create-scope-actions">
345+
<NcButton variant="secondary" :disabled="scopeCreateDisabledReason('system').length > 0" @click="startCreateRuleForScope('system')">
346+
{{ t('libresign', 'Instance') }}
347+
</NcButton>
348+
<NcButton variant="secondary" :disabled="scopeCreateDisabledReason('group').length > 0" @click="startCreateRuleForScope('group')">
349+
{{ t('libresign', 'Group') }}
350+
</NcButton>
351+
<NcButton variant="secondary" :disabled="scopeCreateDisabledReason('user').length > 0" @click="startCreateRuleForScope('user')">
352+
{{ t('libresign', 'User') }}
353+
</NcButton>
354+
</div>
355+
<ul class="policy-workbench__create-scope-notes">
356+
<li v-if="scopeCreateDisabledReason('group')">{{ t('libresign', 'Group') }}: {{ scopeCreateDisabledReason('group') }}</li>
357+
<li v-if="scopeCreateDisabledReason('user')">{{ t('libresign', 'User') }}: {{ scopeCreateDisabledReason('user') }}</li>
358+
</ul>
359+
</div>
360+
</NcDialog>
361+
344362
<NcDialog
345363
v-if="pendingDiscardAction"
346364
:name="t('libresign', 'Discard unsaved changes?')"
@@ -399,14 +417,14 @@ const saveStatus = ref<'idle' | 'saving' | 'saved'>('idle')
399417
const saveFeedbackTimeout = ref<number | null>(null)
400418
const pendingRemoval = ref<{ ruleId: string, scope: 'system' | 'group' | 'user', targetLabel: string, help: string } | null>(null)
401419
const pendingDiscardAction = ref<'cancel-editor' | 'close-setting' | null>(null)
420+
const showCreateScopeDialog = ref(false)
402421
const isRemovingRule = ref(false)
403422
const removalFeedback = ref<string | null>(null)
404423
const removalFeedbackTimeout = ref<number | null>(null)
405424
const lastPress = ref<{ surface: 'cards' | 'list', key: string, x: number, y: number } | null>(null)
406425
const recentSelectionGesture = ref<{ surface: 'cards' | 'list', key: string, at: number } | null>(null)
407426
const crudSearch = ref('')
408427
const crudScopeFilter = ref<'all' | 'system' | 'group' | 'user'>('all')
409-
const newRuleScope = ref<'system' | 'group' | 'user'>('group')
410428
const crudPage = ref(1)
411429
const CRUD_PAGE_SIZE = 20
412430
@@ -549,19 +567,30 @@ const editorHelp = computed(() => {
549567
return t('libresign', 'A user override is the most specific layer and takes priority over inherited defaults.')
550568
})
551569
552-
const createRuleDisabledReason = computed(() => {
553-
if (newRuleScope.value === 'group') {
570+
function scopeCreateDisabledReason(scope: 'system' | 'group' | 'user') {
571+
if (scope === 'group') {
554572
return state.createGroupOverrideDisabledReason || ''
555573
}
556574
557-
if (newRuleScope.value === 'user') {
575+
if (scope === 'user') {
558576
return state.createUserOverrideDisabledReason || ''
559577
}
560578
561579
return ''
580+
}
581+
582+
const hasCreatableScope = computed(() => {
583+
return ['system', 'group', 'user']
584+
.some((scope) => scopeCreateDisabledReason(scope as 'system' | 'group' | 'user').length === 0)
562585
})
563586
564-
const isCreateRuleDisabled = computed(() => createRuleDisabledReason.value.length > 0)
587+
const createRuleDisabledReason = computed(() => {
588+
if (!hasCreatableScope.value) {
589+
return t('libresign', 'A higher-level rule is blocking new exceptions in all scopes.')
590+
}
591+
592+
return ''
593+
})
565594
566595
const pendingRemovalMessage = computed(() => {
567596
if (!pendingRemoval.value) {
@@ -651,20 +680,25 @@ function setCrudScopeFilter(value: 'all' | 'system' | 'group' | 'user', selected
651680
crudPage.value = 1
652681
}
653682
654-
function setNewRuleScope(value: 'system' | 'group' | 'user', selected: boolean) {
655-
if (!selected) {
683+
function requestCreateRule() {
684+
if (!hasCreatableScope.value) {
656685
return
657686
}
658687
659-
newRuleScope.value = value
688+
showCreateScopeDialog.value = true
689+
}
690+
691+
function cancelCreateScopeDialog() {
692+
showCreateScopeDialog.value = false
660693
}
661694
662-
function startCreateRule() {
663-
if (isCreateRuleDisabled.value) {
695+
function startCreateRuleForScope(scope: 'system' | 'group' | 'user') {
696+
if (scopeCreateDisabledReason(scope).length > 0) {
664697
return
665698
}
666699
667-
state.startEditor({ scope: newRuleScope.value })
700+
showCreateScopeDialog.value = false
701+
state.startEditor({ scope })
668702
}
669703
670704
function onSettingsFilterChange(value: string | number) {
@@ -932,6 +966,7 @@ onBeforeUnmount(() => {
932966
}
933967
934968
pendingDiscardAction.value = null
969+
showCreateScopeDialog.value = false
935970
})
936971
</script>
937972

@@ -1900,22 +1935,31 @@ onBeforeUnmount(() => {
19001935
}
19011936
}
19021937
1903-
&__create-inline {
1904-
display: inline-flex;
1905-
align-items: center;
1906-
gap: 0.45rem;
1938+
&__create-scope-dialog {
1939+
display: flex;
1940+
flex-direction: column;
1941+
gap: 0.75rem;
1942+
1943+
p {
1944+
margin: 0;
1945+
}
1946+
}
1947+
1948+
&__create-scope-actions {
1949+
display: flex;
1950+
gap: 0.5rem;
1951+
flex-wrap: wrap;
1952+
}
1953+
1954+
&__create-scope-notes {
1955+
margin: 0;
1956+
padding-inline-start: 1.1rem;
19071957
font-size: 0.84rem;
19081958
color: var(--color-text-maxcontrast);
1909-
}
19101959
1911-
&__create-select {
1912-
height: 2rem;
1913-
min-width: 8.5rem;
1914-
padding: 0 0.5rem;
1915-
border: 1px solid color-mix(in srgb, var(--color-border-maxcontrast) 68%, transparent);
1916-
border-radius: 8px;
1917-
background: var(--color-main-background);
1918-
color: var(--color-main-text);
1960+
li {
1961+
margin: 0;
1962+
}
19191963
}
19201964
19211965
&__table-empty-state {

0 commit comments

Comments
 (0)