Provision for custom messages

Hi Team,

We want to show certain custom messages to the user as per our requirements.

For eg: if the user is denied access to a particular folder or any functionality like upload, download, the buttons should be disabled and a popup should appear stating that you do not have sufficient access.

Is there a provision to do the same?

12 Replies 1 reply marked as answer

IL Indhumathy Loganathan Syncfusion Team May 28, 2021 10:41 AM UTC

Hi Rohit, 
 
Greetings from Syncfusion support. 
 
We have validated your requirement in File Manager component. We have provided access control support for File Manager component similar to your requirement where you can set the permission based on the user. When restricted users try to access the denied folders, it will show the access denied error popup. Please, refer the below link for access control support in File Manager component. 
 
 
You need to send the user id through beforeSend event. By setting attributes as deny, you can prevent required file operations in File Manager component. Refer to the below code snippet. 
 
beforeSend(args) { 
  var data = JSON.parse(args.ajaxSettings.data); 
  if (args.action == 'read') { 
    // Allow custom data for upload operations 
    data['User_name'] = 'User1'; 
  } 
  // Add custom parameter in ajax settings 
  args.ajaxSettings.data = JSON.stringify(data); 
} 
 
Controller.cs 
 
[Route("FileOperations")] 
public object FileOperations([FromBody] FileManagerDirectoryContent1 args) 
{ 
    // Set rules for the user 
    this.operation.SetRules(GetRules(args.User_name)); 
... 
... 
public AccessDetails GetRules(string user_value) 
{ 
    AccessDetails accessDetails = new AccessDetails(); 
 
    List<AccessRule> accessRules = new List<AccessRule> {   
        // Access Rules for folder available in root folder     
            new AccessRule { Path = "/*.*", Role = "Adminstrator", Read = Permission.Deny, Write = Permission.Deny, Copy = Permission.Deny, WriteContents = Permission.Deny, Upload = Permission.Deny, Download = Permission.Deny}, 
            //Access Rules for files available in root folder 
            new AccessRule { Path = "/*.*", Role = "Adminstrator", Read = Permission.Allow, Write = Permission.Deny, Copy = Permission.Deny, WriteContents = Permission.Deny, Upload = Permission.Deny, Download = Permission.Deny, IsFile=true}, 
    }; 
    accessDetails.AccessRules = accessRules; 
    if (user_value == "User1") 
    { 
        // Here, you need to set the role for File Manager component. 
        accessDetails.Role = "Adminstrator"; 
    } 
    else 
    { 
        accessDetails.Role = "Document Manager"; 
    } 
    return accessDetails; 
} 
 
You can find the sample from below link. 
 
 
 
Please let us know if you need any further assistance. 
 
Regards, 
Indhumathy L 



RS Rohit Swarup July 6, 2021 11:35 AM UTC

Hi,


We are using the permission object for restricting the file operations in FileManager control.

1)For Delete  an error popup is coming up with null message. Is this message from the 'message' property of permission object in the file data or it is returned from somewhere else.

(Want to know how the Access Denied popup comes up for all operations and from where the message is fetched.)

2)Also for Copy,Cut operation, it's allowing to make the API call for copy action.(I have mage args.cancel=true for the default error popup  and showing error message in another custom dialog)

How Can I get proper error mesaage for access denied (which approach)

3) If we are returning the Access denied error message from the API calls ( copy, cut) then how can we get those error messages. In the Failure event args We get some generalized error message which is shown in a dialog

  1. action: "copy"
  2. error:
    1. code: "404"
    2. fileExists: null
    3. message: "NetworkError: Failed to send on XMLHTTPRequest: Failed to load http://xx.xx.xx.xx:xxxx/api/fileOperations"
  3. name: "failure"


By what way we can get the error messages provided by the REST APIs to show in the error notification on failure event.



Thanks



IL Indhumathy Loganathan Syncfusion Team July 7, 2021 02:40 PM UTC

Hi Rohit, 
 
We have validated your requirement in File Manager component. Please find the answer for your queries. 
 
Query 1: Want to know how the Access Denied popup comes up for all operations and from where the message is fetched 
 
We have in-build support for access control in File Manager component. Based on the access rules permissions the error messages are displayed in the dialog. Access denied error will be shown based on the access rules set for files and folders. Refer to the below details. 
 
S.No 
Action 
Code 
Error Message 
1.       
Read 
 
 
 
 
 
 
 
2.       
Download 
 
 
 
 
 
 
 
3.       
Upload 
 
 
 
 
 
 
4.       
Delete 
 
 
 
 
 
5.       
Copy 
 
 
Query 2: How Can I get proper error message for access denied 
 
You can Deny the Copy action by setting the access rule in controller. Check the below code snippet. 
 
// FileRules For Administrator 
new AccessRule { Path = "/*.*", Role = "Administrator", Read = Permission.Allow, Write = Permission.Allow, Copy = Permission.Deny, Download = Permission.Allow, IsFile = true }, 
 
When you copy the permission denied file and tried to paste it in someplace, you will get the above showed copy action access denied error. 
 
Query 3: By what way we can get the error messages provided by the REST APIs 
 
You can use the beforePopupOpen event to get the access denied error messages while performing operations. Check the below code snippet. 
 
  beforePopupOpen(args) { 
    //Prints the error message in console 
    console.log( 
      args.popupModule.element.querySelector('.e-fe-errorcontent').innerText 
    ); 
  } 
 
 
 
Please check the shared details and get back to us if you need any further assistance. 
 
Regards, 
Indhumathy L


RS Rohit Swarup July 8, 2021 11:32 AM UTC

Hi,


By what way we can get the error messages provided by the REST APIs
 
You can use the
beforePopupOpen
event to get the access denied error messages while performing operations. Check the below code snippet.
 
  beforePopupOpen(args) { 
    //Prints the error message in console 
    console.log( 
      args.popupModule.element.querySelector('.e-fe-errorcontent').innerText 
    ); 
  } 

In our implementation the APIs give custom error response for no file permission scenario.

1)The above mentioned   error can be seen in our implemented dialogs but we can see the network error and not the API response error. For clearer notifications , we particularly want to show the error (in dialog /notification toast) which comes as response from the API controller when the API gives 400 or 401 or 500 errors with custom error response. As shown below for Copy operation (with false permission)

{

"errorCode" : "ER927",

"errorMessage" : "You do not have privileges to view or delete documents."

}

Can we fetch these errors from the control's failure event.


2) In the control I am using for Cut,Copy operations, the Control doesn't show any dialog for access denied , it directly make API calls for copy and cut operations. Hence we have thrown errors from API controller.

Contrarily for Delete operation if I don't have permission, I get a Access denied popup with message provided in permission object.

Could you please explain more about this.



Thanks.



IL Indhumathy Loganathan Syncfusion Team July 9, 2021 02:23 PM UTC

Hi Rohit, 
 
We have validated your reported query in File Manager component. Please find the answer for your queries. 
 
Query 1: Can we fetch these errors from the control's failure event 
 
We understood that you have denied the copy operation and need to show the denied error message inside your custom dialog using the failure event. We suspect that the access denied rule is not proper in your end because we are able to get the error message in the failure event. Please check the below video footage. 
 
 
Check the below code snippet. 
 
beforeSend(args) { 
  var data = JSON.parse(args.ajaxSettings.data); 
  // Allow custom data for all file operations 
  data['User_name'] = 'User1'; 
  // Add custom parameter in ajax settings 
  args.ajaxSettings.data = JSON.stringify(data); 
} 
failure(args) { 
//Print the error message in console 
  console.log(args.error.message); 
} 
 
We suggest you to check the rules and whether you have denied permission for the correct user role. If you still face any difficulties, kindly share the below details to serve you better. 
 
1.      Share your access rules related codes. 
2.      Whether you are writing any custom error messages in service provider. If yes, share the code snippets for the same. 
3.      Client side access role declaration related code snippet in beforeSend event. 
4.      If possible, replicate the issue in the shared sample. 
 
Query 2: Control doesn't show any dialog for access denied , it directly make API calls for copy and cut operations 
 
We have validated your reported query but unable to replicate the reported issue. If the permission to perform cut and copy operation is denied, then the API call does not trigger while performing those operations. Please check the below code snippet. 
 
//Rules for the files inside specific folder 
new AccessRule { Path = "/Downloads/*.*", Role = "Adminstrator", Read = Permission.Allow, Write = Permission.Deny, Copy = Permission.Deny, WriteContents = Permission.Allow, Upload = Permission.Allow, Download = Permission.Deny, IsFile = true }, 
//Rules for the folders inside specific folder 
new AccessRule { Path = "/Downloads/*", Role = "Adminstrator", Read = Permission.Allow, Write = Permission.Deny, Copy = Permission.Deny, WriteContents = Permission.Allow, Upload = Permission.Allow, Download = Permission.Deny, IsFile = false }, 
 
In the above code, we have denied both the cut and copy operations by setting Write and Copy operations as Deny in access rules. We have denied these permissions only inside the Downloads folder in the directory of folders. We write access rules for both files and folders inside the Downloads folders. 
 
When either cut or copy is performed on permission denied files/folders, the API call doesn’t trigger, it only triggers when you paste them in any place and this will show the access denied error. Please check the sample demonstrating this in the below link. 
 
 
 
Please check the shared details and get back to us with the requested details if you face any difficulties to assist you promptly. 
 
Regards, 
Indhumathy L 



RS Rohit Swarup July 14, 2021 07:56 AM UTC

Hi  Indhumathy ,

Our requirement for customization of error messages is not limited to Access Permission. Whenever the API fails, we need to show error message which comes from API and not a generic message like 404. 


For eg: File Operation API for Search is written such that,  it will give results only when user types more than 3 character. If user types 2 chars and click on search, API fails with response below:

{

  1. errorCode: "ER002"
  2. errorMessage: "Search term should be at least 3 characters"

}

We want to show this message to the user, instead of a generic message which comes built in like "404- -NetworkError: Failed to send on XMLHTTPRequest: ..."


We wanted to know how we can extract this message from API response. It would be really helpful.



IL Indhumathy Loganathan Syncfusion Team July 15, 2021 01:27 PM UTC

Hi Rohit, 
 
We have validated your requirement in File Manager component. We have handled the general errors in server side and return the response with error code and error message. You can retrieve those error messages in the failure event. For you reference, we modified our service provider to throw error message for search string with length less than 3. 
 
Refer to the below code snippet. 
 
public virtual FileManagerResponse Search(string path, string searchString, bool showHiddenItems = false, bool caseSensitive = false, params FileManagerDirectoryContent[] data) 
 
  … 
  … 
  if(searchString.Length < 5) 
  { 
    ErrorDetails er = new ErrorDetails(); 
    er.Code = "ER002"; 
    er.Message = "Search term should be at least 3 characters."; 
    searchResponse.Error = er;                    
  } 
  else 
  { 
    searchResponse.Files = (IEnumerable<FileManagerDirectoryContent>)foundedFiles; 
  } 
  return searchResponse; 
} 
 
You can find the sample from below link. 
 
 
 
In the above sample, when you perform search with less than 3 characters, error dialog popup with “Search term should be at least 3 characters” error message. You can retrieve these message in File Manager failure event. You can also customize your own dialog with the retrieved error message by preventing our default dialog. 
 
Please check the sample and get back to us if you need any further assistance. 
 
Regards, 
Indhumathy L 



RS Rohit Swarup replied to Indhumathy Loganathan July 18, 2021 03:30 PM UTC

Hi,

We are already using the failure event to retrieve the errors for all operations, But In the failure event, we are not able to get the Custom messages provides by the REST service APIs. Instead, we get the generic error as below:

"404- -NetworkError: Failed to send on XMLHTTPRequest: ..."


In our implementation , the REST service is throwing error response as below:

{

"errorCode" : "ER927",

"errorMessage" : "You do not have privileges to view or delete documents."

}

Please provide assistance to fetch these errors from the Code as we don't get any details about the API request made in the events.


Thanks



RS Rohit Swarup replied to Indhumathy Loganathan July 18, 2021 04:41 PM UTC

Hi,

We are using the ejs-uploader component as well and get the error response in failure event of upload operation as below:



With File manager the behavior is not the same , we get error details as:



We want error details in File manager's all operations similar to uploader component's failure event. 

Could you please provide the solution as soon as possible.



IL Indhumathy Loganathan Syncfusion Team July 19, 2021 12:09 PM UTC

Hi Rohit, 
 
We have validated your reported query in File Manager component. By default, the upload failure event response of File Manager will be similar to the Uploader component failure response. Check the below screenshot for file upload failure error. 
 
 
 
Also you can get the status code and failure messages under the error context for all file operations of File Manager. These are generic error messages. You can use our failure event to customize the default code and messages.  
 
For your reference, we have modified the default read operation failure error. Refer to the below code snippet. 
 
  failure(args) { 
    if (args.error.code == '404') { 
      //Modify the error message 
      args.error.message = 'Failed to send request to an invalid Url'; 
    } 
    console.log(args); 
    //Append the modified error message in dialog 
    document.querySelector('.e-fe-errorcontent').innerText = args.error.message; 
  } 
 
 
 
 
Similar to the above way you can customize your own custom error messages in File Manager component. 
 
Please check the shared details and let us know if you need any further assistance. 
 
Regards, 
Indhumathy L 


Marked as answer

RS Rohit Swarup July 20, 2021 10:30 AM UTC

Hi Indumathy,


We are looking for custom error handling for all the operations like READ,CUT,COPY,DELETE,DOWNLOAD.

It will be really helpful If we can have a quick discussion on call to get clear understanding of the issue.


Thanks.



KR Keerthana Rajendran Syncfusion Team July 21, 2021 01:50 PM UTC

Hi Rohit, 
 
We checked your query. As mentioned in our earlier update, you can return the required error code and message from server side for required operations(Copy, delete etc.,). You can retrieve this error message through failure event and process further based on your scenario.  
 
For reference, we have prevented the delete action for folders and returned an error message from server. Refer to the following code. 
 
  public virtual FileManagerResponse Delete(string path, string[] names, params FileManagerDirectoryContent[] data) 
        { 
            FileManagerResponse DeleteResponse = new FileManagerResponse(); 
              .   .    . 
                for (int i = 0; i < names.Length; i++) 
                { 
                    bool IsFile = !IsDirectory(physicalPath, names[i]); 
                    if(!IsFile) 
                    { 
                        ErrorDetails er = new ErrorDetails(); 
                        er.Message = "Folders cannot be deleted"; 
                        er.Code = "402"; 
                        DeleteResponse.Error = er; 
                        return DeleteResponse; 
                    } 
 
 failure(args) { 
    if (args.error.code == '404') { 
      args.error.message = 'Failed to send request to an invalid Url'; 
    } 
    if (args.action == 'delete') { 
      console.log(args.error.message); 
    } 
    console.log(args); 
    document.querySelector('.e-fe-errorcontent').innerText = args.error.message; 
  } 
 
 
Similar to the above code, you can return the error response in required operations and retrieve this through failure event in client side.  
 
 
 
Please let us know if you need further assistance. 
 
Regards, 
Keerthana R. 


Loader.
Up arrow icon