Skip to content

Commit

Permalink
fix(schema): only load schema when user has rights on produce screen (#…
Browse files Browse the repository at this point in the history
…1600)

close #1597
  • Loading branch information
AlexisSouquiere committed Nov 19, 2023
1 parent 4d031f9 commit dd374c9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class App extends React.Component {
window.location = uriLogin();
}

return error;
return Promise.reject(error);
} catch (e) {
// Propagate cancel
if (axios.isCancel(error)) {
Expand Down
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 dd374c9

Please sign in to comment.