From 779839aeb44fc0aa4f0d4945a66fcec539369dea Mon Sep 17 00:00:00 2001 From: Pavel Mineev Date: Thu, 12 Mar 2020 20:49:36 +0300 Subject: [PATCH] Add error on image upload by anonymous user --- .../app/components/comment-form/comment-form.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/frontend/app/components/comment-form/comment-form.tsx b/frontend/app/components/comment-form/comment-form.tsx index 4c095cbd..a3738e41 100644 --- a/frontend/app/components/comment-form/comment-form.tsx +++ b/frontend/app/components/comment-form/comment-form.tsx @@ -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 { @@ -248,6 +252,7 @@ export class CommentForm extends Component { } 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 { } 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;