Add error on image upload by anonymous user

This commit is contained in:
Pavel Mineev
2020-03-12 15:44:31 -05:00
committed by Umputun
parent c9485fab3f
commit 779839aeb4
@@ -88,6 +88,10 @@ const messages = defineMessages({
id: 'commentForm.unexpected-error',
defaultMessage: 'Something went wrong. Please try again a bit later.',
},
anonymousUploadingDisabled: {
id: 'commentForm.unexpected-error',
defaultMessage: 'Image uploading is disabled for unauthorized users. You should login before uploading.',
},
});
export class CommentForm extends Component<Props, State> {
@@ -248,6 +252,7 @@ export class CommentForm extends Component<Props, State> {
}
onDragOver(e: DragEvent) {
if (!this.props.user) e.preventDefault();
if (!this.props.uploadImage) return;
if (StaticStore.config.max_image_size === 0) return;
if (!this.textAreaRef) return;
@@ -259,6 +264,14 @@ export class CommentForm extends Component<Props, State> {
}
onDrop(e: DragEvent) {
if (!this.props.user) {
this.setState({
isErrorShown: true,
errorMessage: this.props.intl.formatMessage(messages.anonymousUploadingDisabled),
});
e.preventDefault();
return;
}
if (!this.props.uploadImage) return;
if (StaticStore.config.max_image_size === 0) return;
if (!e.dataTransfer) return;