Skip to content

Commit 766d128

Browse files
committed
OTel quicksetup: Disable option to create passwords without permissions
CMK-34207 Change-Id: Ib49f5eb8634b0310aeeb180cf5cc3a453fabd072 (cherry picked from commit b215f1a)
1 parent f231e3a commit 766d128

4 files changed

Lines changed: 54 additions & 4 deletions

File tree

packages/cmk-frontend-vue/src/mode-otel/ModeCreateOTelConfApp.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const props = defineProps<{
5151
event_console_allowed: boolean
5252
collector_activation_allowed: boolean
5353
metric_backend_allowed: boolean
54+
may_create_password: boolean
5455
overview_url: string
5556
cloud_grpc_receiver_endpoint?: string | null
5657
cloud_http_receiver_endpoint?: string | null
@@ -390,6 +391,7 @@ async function onSaveClick(): Promise<void> {
390391
:endpoint-config-allowed="endpoint_config_allowed"
391392
:encryption-allowed="encryption_allowed"
392393
:event-console-allowed="event_console_allowed"
394+
:may-create-password="may_create_password"
393395
:grpc-default-port="GRPC_DEFAULT_PORT"
394396
:http-default-port="HTTP_DEFAULT_PORT"
395397
/>

packages/cmk-frontend-vue/src/mode-otel/otel-configuration-steps/CollectorAuthConfig.vue

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import usei18n from '@/lib/i18n'
1010
import useId from '@/lib/useId'
1111
1212
import CmkDropdown from '@/components/CmkDropdown/CmkDropdown.vue'
13+
import CmkHelpText from '@/components/CmkHelpText.vue'
1314
import CmkLabel from '@/components/CmkLabel.vue'
1415
import type { Suggestion } from '@/components/CmkSuggestions'
1516
import CmkInlineButton from '@/components/user-input/CmkInlineButton.vue'
@@ -30,6 +31,7 @@ const props = defineProps<{
3031
noAuthAllowed: boolean
3132
availablePasswords: Suggestion[]
3233
showErrors: boolean
34+
mayCreatePassword: boolean
3335
}>()
3436
3537
const emit = defineEmits<{ createPassword: [] }>()
@@ -128,7 +130,25 @@ const passwordErrors = computed<string[]>(() => {
128130
:form-validation="passwordErrors.length > 0"
129131
:no-elements-text="_t('No passwords available')"
130132
/>
131-
<CmkInlineButton @click="emit('createPassword')">{{ _t('Create') }}</CmkInlineButton>
133+
<CmkInlineButton :disabled="!mayCreatePassword" @click="emit('createPassword')">{{
134+
_t('Create')
135+
}}</CmkInlineButton>
136+
<CmkHelpText
137+
v-if="!mayCreatePassword"
138+
:aria-label="_t('Why is creating a password unavailable?')"
139+
:help="
140+
_t(
141+
'Creating a new password is not available for your account. ' +
142+
'All of the following are required:' +
143+
'<ul>' +
144+
'<li>The permission \'Make changes, perform actions\'.</li>' +
145+
'<li>The permission \'Password management\'.</li>' +
146+
'<li>Either the permission \'Write access to all passwords\', ' +
147+
'or membership in a contact group that could own the new password.</li>' +
148+
'</ul>'
149+
)
150+
"
151+
/>
132152
</div>
133153
<CmkInlineValidation v-if="passwordErrors.length" :validation="passwordErrors" />
134154
</div>

packages/cmk-frontend-vue/src/mode-otel/otel-configuration-steps/ConfigureCollector.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const props = defineProps<{
3333
endpointConfigAllowed: boolean
3434
encryptionAllowed: boolean
3535
eventConsoleAllowed: boolean
36+
mayCreatePassword: boolean
3637
grpcDefaultPort: number
3738
httpDefaultPort: number
3839
}>()
@@ -279,6 +280,7 @@ defineExpose({ validate, onPasswordCreated })
279280
:no-auth-allowed="noAuthAllowed"
280281
:available-passwords="availablePasswords"
281282
:show-errors="displayErrors"
283+
:may-create-password="mayCreatePassword"
282284
@create-password="openPasswordSlideIn('grpc')"
283285
/>
284286
<CollectorConnectionOptions
@@ -318,6 +320,7 @@ defineExpose({ validate, onPasswordCreated })
318320
:no-auth-allowed="noAuthAllowed"
319321
:available-passwords="availablePasswords"
320322
:show-errors="displayErrors"
323+
:may-create-password="mayCreatePassword"
321324
@create-password="openPasswordSlideIn('http')"
322325
/>
323326
<CollectorConnectionOptions

packages/cmk-frontend-vue/tests/mode-otel/ConfigureCollector.test.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ function renderComponent(
3737
grpcDefaultPort = 4317,
3838
httpDefaultPort = 4318,
3939
initialGrpcEnabled = true,
40-
initialHttpEnabled = false
40+
initialHttpEnabled = false,
41+
mayCreatePassword = true
4142
) {
4243
const grpcEnabled = ref<boolean>(initialGrpcEnabled)
4344
const httpEnabled = ref<boolean>(initialHttpEnabled)
@@ -89,9 +90,10 @@ function renderComponent(
8990
encryptionAllowed,
9091
eventConsoleAllowed,
9192
grpcDefaultPort,
92-
httpDefaultPort
93+
httpDefaultPort,
94+
mayCreatePassword
9395
}),
94-
template: `<ConfigureCollector ref="compRef" :no-auth-allowed="noAuthAllowed" :endpoint-config-allowed="endpointConfigAllowed" :encryption-allowed="encryptionAllowed" :event-console-allowed="eventConsoleAllowed" :grpc-default-port="grpcDefaultPort" :http-default-port="httpDefaultPort" v-model:grpc-enabled="grpcEnabled" v-model:http-enabled="httpEnabled" v-model:grpc-auth="grpcAuth" v-model:http-auth="httpAuth" v-model:grpc-endpoint="grpcEndpoint" v-model:http-endpoint="httpEndpoint" v-model:grpc-encryption="grpcEncryption" v-model:http-encryption="httpEncryption" v-model:grpc-event-console="grpcEventConsole" v-model:http-event-console="httpEventConsole" v-model:pending-passwords="pendingPasswords" v-model:available-passwords="availablePasswords" />`
96+
template: `<ConfigureCollector ref="compRef" :no-auth-allowed="noAuthAllowed" :endpoint-config-allowed="endpointConfigAllowed" :encryption-allowed="encryptionAllowed" :event-console-allowed="eventConsoleAllowed" :may-create-password="mayCreatePassword" :grpc-default-port="grpcDefaultPort" :http-default-port="httpDefaultPort" v-model:grpc-enabled="grpcEnabled" v-model:http-enabled="httpEnabled" v-model:grpc-auth="grpcAuth" v-model:http-auth="httpAuth" v-model:grpc-endpoint="grpcEndpoint" v-model:http-endpoint="httpEndpoint" v-model:grpc-encryption="grpcEncryption" v-model:http-encryption="httpEncryption" v-model:grpc-event-console="grpcEventConsole" v-model:http-event-console="httpEventConsole" v-model:pending-passwords="pendingPasswords" v-model:available-passwords="availablePasswords" />`
9597
})
9698
)
9799

@@ -766,6 +768,29 @@ describe('ConfigureCollector', () => {
766768
})
767769
})
768770

771+
describe('password creation permission', () => {
772+
test('Create button is enabled and no hint is shown when password creation is allowed', async () => {
773+
mockPasswordsResponse()
774+
// noAuthAllowed=false makes basicauth the default, so the Create button is rendered
775+
renderComponent(false, true, true, true, 4317, 4318, true, false, true)
776+
777+
const createButton = await screen.findByRole('button', { name: 'Create' })
778+
expect(createButton).toBeEnabled()
779+
expect(
780+
screen.queryByLabelText('Why is creating a password unavailable?')
781+
).not.toBeInTheDocument()
782+
})
783+
784+
test('Create button is disabled and a hint is shown when password creation is not allowed', async () => {
785+
mockPasswordsResponse()
786+
renderComponent(false, true, true, true, 4317, 4318, true, false, false)
787+
788+
const createButton = await screen.findByRole('button', { name: 'Create' })
789+
expect(createButton).toBeDisabled()
790+
expect(screen.getByLabelText('Why is creating a password unavailable?')).toBeInTheDocument()
791+
})
792+
})
793+
769794
describe('enabled/disabled tab behaviour', () => {
770795
test('validate() returns false when both tabs are disabled', async () => {
771796
mockPasswordsResponse()

0 commit comments

Comments
 (0)