SenseNet / sensenet

Open Source Content Services Platform written in .NET
https://sensenet.com
GNU General Public License v2.0
173 stars 112 forks source link

[BUG] Error moving items to the Trash #849

Closed herflis closed 4 years ago

herflis commented 4 years ago

If a user tries to delete a content with moving it into the Trash the following error message is shown There was an error deleting content '<テストファイル>.xlsx': Error moving item to the trash

Steps to reproduce:

  1. Login with businesscat at admin.sensenet.com
  2. Open a doclib and go to a folder
  3. Open the context menu on one of the documents and choose 'Delete'
  4. On the confirmation window leave the 'Permanently' checkbox empty
  5. Click on the Delete button

image.png

Solution

  1. if the user does not have Delete permission to the content, we should provide a more informative error message. Catch SenseNetSecurityException here and look into the Data property for the missing permission. https://github.com/SenseNet/sensenet/blob/8cbb5bd9ddb8eeee387144b3c519d7b70ca1b599/src/ContentRepository/TrashBag.cs#L234

  2. add the AddNew permission for the user to the trashbag when creating it, so that the code can move the content into it later. https://github.com/SenseNet/sensenet/blob/8cbb5bd9ddb8eeee387144b3c519d7b70ca1b599/src/ContentRepository/TrashBag.cs#L225

enikonemeth commented 4 years ago

The businesscat user hasn't got the required permission (Delete) on the related content(s). I think the problem is the "not userfriendly" error message from the backend. As the comment says: We should handle permission related error messages on a different way:

https://github.com/SenseNet/sensenet/blob/70f55bff9086eeb7b2ac132ef350ae817a65f911/src/Services/ApplicationModel/DeleteBatchAction.cs row 108-130

 catch (Exception e)
                {
                    //TODO: we should log only relevant exceptions here and skip
                    // business logic-related errors, e.g. lack of permissions or
                    // existing target content path.
                    SnLog.WriteException(e);

                    errors.Add(new ErrorContent
                    {
                        Content = new {node?.Id, node?.Path},
                        Error = new Error
                        {
                            Code = "NotSpecified",
                            ExceptionType = e.GetType().FullName,
                            InnerError = new StackInfo {Trace = e.StackTrace},
                            Message = new ErrorMessage
                            {
                                Lang = System.Globalization.CultureInfo.CurrentUICulture.Name.ToLower(),
                                Value = e.Message
                            }
                        }
                    });
                }