Skip to content

Commit

Permalink
Make filtered message receiver always returning a message
Browse files Browse the repository at this point in the history
  • Loading branch information
szczygiel-m committed Aug 21, 2024
1 parent d863e8f commit 1a6b9ed
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 14 deletions.
3 changes: 2 additions & 1 deletion hermes-console/src/composables/topic/use-form-topic/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export interface FormValidators {
ownerSource: FieldValidator<string>[];
owner: FieldValidator<any>[];
contentType: FieldValidator<string>[];
retentionTimeDuration: FieldValidator<number>[];
retentionTimeDurationHours: FieldValidator<number>[];
retentionTimeDurationDays: FieldValidator<number>[];
maxMessageSize: FieldValidator<number>[];
offlineRetentionTime: FieldValidator<number>[];
ack: FieldValidator<string>[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ function formValidators(): FormValidators {
ownerSource: [required()],
owner: [required()],
contentType: [required()],
retentionTimeDuration: [required(), min(0), max(7)],
retentionTimeDurationDays: [required(), min(1), max(7)],
retentionTimeDurationHours: [required(), min(1), max(24)],
maxMessageSize: [required(), min(0)],
offlineRetentionTime: [required(), min(0)],
offlineRetentionTime: [required(), min(1)],
ack: [required()],
};
}
Expand Down
3 changes: 2 additions & 1 deletion hermes-console/src/dummy/topic-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export const dummyTopicFormValidator = {
ownerSource: [required()],
owner: [required()],
contentType: [required()],
retentionTimeDuration: [required(), min(0), max(7)],
retentionTimeDurationDays: [required(), min(0), max(7)],
retentionTimeDurationHours: [required(), min(0), max(7)],
maxMessageSize: [required(), min(0)],
offlineRetentionTime: [required(), min(0)],
ack: [required()],
Expand Down
4 changes: 4 additions & 0 deletions hermes-console/src/i18n/en-US/subscription-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ const messages = {
title: 'Warning: Tracking all messages enabled',
text: 'Please chose this option only when necessary. Mainly this is for debugging problems with subscription. Remember to disable this mode after the problem is solved.',
},
adminForm: {
title: 'Warning: Admin form enabled.',
text: 'New fields in the form have been revealed (they are highlighted). The form will be submitted regardless of the validation of the fields.',
},
},
actions: {
create: 'Create subscription',
Expand Down
4 changes: 4 additions & 0 deletions hermes-console/src/i18n/en-US/topic-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ const messages = {
title: 'Warning: Tracking all messages enabled',
text: 'Please chose this option only when necessary. Mainly this is for debugging problems with subscription. Remember to disable this mode after the problem is solved.',
},
adminForm: {
title: 'Warning: Admin form enabled.',
text: 'New fields in the form have been revealed (they are highlighted). The form will be submitted regardless of the validation of the fields.',
},
},
info: {
avro: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<script setup lang="ts">
import { computed, ref } from 'vue';
import { isAdmin } from '@/utils/roles-util';
import { useAppConfigStore } from '@/store/app-config/useAppConfigStore';
import { useCreateSubscription } from '@/composables/subscription/use-create-subscription/useCreateSubscription';
import { useEditSubscription } from '@/composables/subscription/use-edit-subscription/useEditSubscription';
import { useGlobalI18n } from '@/i18n';
import { useImportSubscription } from '@/composables/subscription/use-import-subscription/useImportSubscription';
import { useNotificationsStore } from '@/store/app-notifications/useAppNotifications';
import { useRoles } from '@/composables/roles/use-roles/useRoles';
import ConsoleAlert from '@/components/console-alert/ConsoleAlert.vue';
import SelectField from '@/components/select-field/SelectField.vue';
import SubscriptionHeaderFilters from '@/views/subscription/subscription-form/subscription-header-filters/SubscriptionHeaderFilters.vue';
Expand Down Expand Up @@ -39,6 +41,7 @@
? useCreateSubscription(props.topic)
: useEditSubscription(props.topic, props.subscription!!);
const { importFormData } = useImportSubscription();
const roles = useRoles(null, null)?.roles;
const showHighRequestTimeoutAlert = computed(
() =>
form.value.subscriptionPolicy.requestTimeout >=
Expand Down Expand Up @@ -69,7 +72,7 @@
}
async function submit() {
if (isFormValid.value) {
if (isFormValid.value || isAdmin(roles?.value)) {
const isOperationSucceeded = await createOrUpdateSubscription();
if (isOperationSucceeded) {
emit('created', form.value.name);
Expand All @@ -85,6 +88,13 @@
</script>

<template>
<console-alert
v-if="isAdmin(roles)"
:title="$t('subscriptionForm.warnings.adminForm.title')"
:text="$t('subscriptionForm.warnings.adminForm.text')"
type="warning"
class="mb-4"
/>
<v-file-input
v-if="operation === 'add'"
:label="$t('subscriptionForm.actions.import')"
Expand Down
42 changes: 37 additions & 5 deletions hermes-console/src/views/topic/topic-form/TopicForm.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<script setup lang="ts">
import { computed, ref } from 'vue';
import { isAdmin } from '@/utils/roles-util';
import { useAppConfigStore } from '@/store/app-config/useAppConfigStore';
import { useCreateTopic } from '@/composables/topic/use-create-topic/useCreateTopic';
import { useEditTopic } from '@/composables/topic/use-edit-topic/useEditTopic';
import { useGlobalI18n } from '@/i18n';
import { useImportTopic } from '@/composables/topic/use-import-topic/useImportTopic';
import { useNotificationsStore } from '@/store/app-notifications/useAppNotifications';
import { useRoles } from '@/composables/roles/use-roles/useRoles';
import AceEditor from '@/components/ace-editor/AceEditor.vue';
import ConsoleAlert from '@/components/console-alert/ConsoleAlert.vue';
import SelectField from '@/components/select-field/SelectField.vue';
import TextField from '@/components/text-field/TextField.vue';
import type { TopicWithSchema } from '@/api/Topic';
import type { SelectFieldOption } from '@/components/select-field/types';
import type { TopicWithSchema } from '@/api/topic';
const props = defineProps<{
topic: TopicWithSchema | null;
Expand All @@ -37,6 +40,19 @@
: useEditTopic(props.topic!!);
const { importFormData } = useImportTopic();
const adminContentTypes: SelectFieldOption[] = [
{
title: 'AVRO',
value: 'AVRO',
},
{
title: 'JSON',
value: 'JSON',
},
];
const roles = useRoles(null, null)?.roles;
const ownerSelectorPlaceholder = computed(
() =>
configStore.loadedConfig.owner.sources.find(
Expand All @@ -54,6 +70,16 @@
const isAuthorizationSelected = computed(() => form.value.auth.enabled);
const durationValidator = computed(() =>
form.value.retentionTime.retentionUnit === 'DAYS'
? validators.retentionTimeDurationDays
: validators.retentionTimeDurationHours,
);
const allowedContentTypes = computed(() =>
isAdmin(roles?.value) ? adminContentTypes : dataSources.contentTypes,
);
const isAvroContentTypeSelected = computed(
() => form.value.contentType === 'AVRO',
);
Expand All @@ -71,7 +97,7 @@
const showAvroAlert = computed(() => form.value.contentType === 'AVRO');
async function submit() {
if (isFormValid.value) {
if (isFormValid.value || isAdmin(roles?.value)) {
const isOperationSucceeded = await createOrUpdateTopic();
if (isOperationSucceeded) {
emit('created', form.value.name);
Expand All @@ -87,6 +113,13 @@
</script>

<template>
<console-alert
v-if="isAdmin(roles)"
:title="$t('topicForm.warnings.adminForm.title')"
:text="$t('topicForm.warnings.adminForm.text')"
type="warning"
class="mb-4"
/>
<v-file-input
v-if="operation === 'add'"
:label="$t('topicForm.actions.import')"
Expand Down Expand Up @@ -213,7 +246,7 @@

<text-field
v-model.number="form.retentionTime.duration"
:rules="validators.retentionTimeDuration"
:rules="durationValidator"
type="number"
:label="$t('topicForm.fields.retentionTime.duration')"
/>
Expand All @@ -238,7 +271,7 @@
<select-field
v-model="form.contentType"
:label="$t('topicForm.fields.contentType')"
:items="dataSources.contentTypes"
:items="allowedContentTypes"
/>

<text-field
Expand Down Expand Up @@ -280,7 +313,6 @@
/>

<v-divider />

<!-- text not in i18n because of a problem with escaping characters-->
<console-alert
style="white-space: pre"
Expand Down
8 changes: 4 additions & 4 deletions hermes-management/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'java-library'
id 'application'
id "com.github.node-gradle.node" version "2.2.4"
id "com.github.node-gradle.node" version "7.0.2"
}

mainClassName = 'pl.allegro.tech.hermes.management.HermesManagement'
Expand Down Expand Up @@ -51,9 +51,9 @@ node {
version = '20.4.0'
distBaseUrl = 'https://nodejs.org/dist'
download = true
workDir = file("${project.buildDir}/nodejs")
npmWorkDir = file("${project.buildDir}/npm")
nodeModulesDir = file("${project.rootDir}/hermes-console")
workDir.set(file("${project.buildDir}/nodejs"))
npmWorkDir.set(file("${project.buildDir}/npm"))
nodeProjectDir.set(file("${project.rootDir}/hermes-console"))
}

yarnSetup.dependsOn(nodeSetup)
Expand Down

0 comments on commit 1a6b9ed

Please sign in to comment.