Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MediaSaving event messages always assumed as errors #11094

Closed
matthewcare opened this issue Sep 14, 2021 · 2 comments
Closed

MediaSaving event messages always assumed as errors #11094

matthewcare opened this issue Sep 14, 2021 · 2 comments
Labels
status/stale Marked as stale due to inactivity type/bug

Comments

@matthewcare
Copy link
Contributor

matthewcare commented Sep 14, 2021

Which exact Umbraco version are you using? For example: 8.13.1 - don't just write v8

8.16+

Bug summary

If you have a MediaSaving event / notification handler, and want to add an event message, it is always interpreted as an error when uploading new media items regardless of if you set EventMessageType to Success, or any other non-error option.
This is an issue when uploading new media, as you then have to reload in order to view what you have just uploaded.

The issue appears to stem from umbfiledropzone.directive.js whereby when a file is uploaded this is checked

.success(function(data, status, headers, config) {
    if (data.notifications && data.notifications.length > 0) {
        // set error status on file
        file.uploadStatus = "error";
        // Throw message back to user with the cause of the error
        file.serverErrorMessage = data.notifications[0].message;
        // Put the file in the rejected pool
        scope.rejected.push(file);

The status should only be set to error if the EventMessageType is Error.
It also appears that you cannot have multiple messages here either, as the first item in the array is always chosen for the display message

Specifics

No response

Steps to reproduce

Create a MediaSaving event / notification handler, and add a message - Umbraco 9 example:

public class IssueExampleComponent : INotificationHandler<MediaSavingNotification>
{
	public void Handle(MediaSavingNotification notification)
	{
		foreach (var entity in notification.SavedEntities)
		{
			notification.Messages.Add(new EventMessage("Event message",
			"An event message to show",
			EventMessageType.Info));
		}
	}
}

Upload a new media item, and the media will appear to have errored, and will show a red error message. You will then have to refresh to see the media you've just uploaded.
Note: This is for new media items, as saving an existing media item will show a notification as expected.

Expected result / actual result

Expected result - A notification added during a media saving event / notification, should not be treated as an error unless EventMessageType.Error is used.
Actual result - All notifications are treated as errors, even if EventMessageType.Success is used.

@matthewcare
Copy link
Contributor Author

Whilst writing a fix for this for Umbraco 9, I found that the PostAddFile endpoint isn't correctly returning response data.
Issue: #11278
Which I have opened a PR to fix
#11279

@umbrabot
Copy link

Hiya @matthewcare,

Just wanted to let you know that we noticed that this issue got a bit stale and might not be relevant any more.

We will close this issue for now but we're happy to open it up again if you think it's still relevant (for example: it's a feature request that's not yet implemented, or it's a bug that's not yet been fixed).

To open it this issue up again, you can write @umbrabot still relevant in a new comment as the first line. It would be super helpful for us if on the next line you could let us know why you think it's still relevant.

For example:

@umbrabot still relevant
This bug can still be reproduced in version x.y.z

This will reopen the issue in the next few hours.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

@umbrabot umbrabot added the status/stale Marked as stale due to inactivity label Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/stale Marked as stale due to inactivity type/bug
Projects
None yet
Development

No branches or pull requests

2 participants