Skip to content

Commit

Permalink
Only load schema with user has rights
Browse files Browse the repository at this point in the history
Fix produce issue with no schema
  • Loading branch information
AlexisSouquiere committed Oct 23, 2023
1 parent 8214a11 commit cd01adb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions client/src/containers/Topic/TopicProduce/TopicProduce.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class TopicProduce extends Form {
topicsSearchValue: '',
multiMessage: false,
tombstone: false,
valuePlaceholder: '{"param": "value"}'
valuePlaceholder: '{"param": "value"}',
roles: JSON.parse(sessionStorage.getItem('roles'))
};

schema = {
Expand All @@ -62,6 +63,7 @@ class TopicProduce extends Form {

async componentDidMount() {
const { clusterId, topicId } = this.props.match.params;
const { roles } = this.state;

let response = await this.getApi(uriTopicsPartitions(clusterId, topicId));
let partitions = response.data.map(item => {
Expand All @@ -78,7 +80,10 @@ class TopicProduce extends Form {
}
});

await this.getPreferredSchemaForTopic();
if (roles.SCHEMA && roles.SCHEMA.includes('READ')) {
await this.getPreferredSchemaForTopic();
}

const topicEventData = popProduceToTopicValues();
if (Object.keys(topicEventData).length) {
await this.initByTopicEvent(topicEventData);
Expand Down Expand Up @@ -353,6 +358,8 @@ class TopicProduce extends Form {
}

renderResults = (results, searchValue, selectedValue, tag) => {
const { roles } = this.state;

return (
<div style={{ maxHeight: '678px', overflowY: 'auto', minHeight: '89px' }}>
<ul
Expand Down Expand Up @@ -391,7 +398,9 @@ class TopicProduce extends Form {
} else if (tag === 'topicId') {
if (selectedValue !== key) {
this.setState({ topicId: key });
this.getPreferredSchemaForTopic();
if (roles.SCHEMA && roles.SCHEMA.includes('READ')) {
this.getPreferredSchemaForTopic();
}
}
}
}}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/akhq/repositories/RecordRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ public RecordMetadata produce(
}
}

if (value.isPresent() && valueSchema.isPresent()) {
if (value.isPresent() && valueSchema.isPresent() && StringUtils.isNotEmpty(valueSchema.get())) {
Schema schema = schemaRegistryRepository.getLatestVersion(clusterId, valueSchema.get());
SchemaSerializer valueSerializer = serializerFactory.createSerializer(clusterId, schema.getId());
valueAsBytes = valueSerializer.serialize(value.get());
Expand Down

0 comments on commit cd01adb

Please sign in to comment.