How to set permissions?

Hi support,

I'm trying to implement the new access control and permissions feature in FileManagerController.

Unfortunately the description is missing some parts and the demo is somehow incomplete.

How do I set the current role in the file manager?

The description tells, that there is a method setRole() but I can't find it in the API.

Also there are several AccessRules defined but where are they attached to the file manager?

Please help.

Regards,

Stephan


5 Replies

JA Jafar Ali Shahulhameed Syncfusion Team February 12, 2024 08:36 AM UTC

Hi Stephan,


Based on the shared details we can understand that you are trying to utilize Syncfusion File Manager component.  We would like to inform you that we use Role property in the service provider to set the role of the File Manager. We have prepared the sample aligning with your requirements. Kindly refer the code changes below,


[FileManagerAccessController.cs]

 

List<AccessRule> Rules = new List<AccessRule> {

    //Deny writing for particular folder

    new AccessRule { Path = "/Documents", Role = "Document Manager", Read = Permission.Allow, Write = Permission.Deny, Copy = Permission.Allow, WriteContents = Permission.Deny, Upload = Permission.Deny, Download = Permission.Deny, IsFile = false },

    // Deny writing for particular file

    new AccessRule { Path = "/Pictures/Employees/Adam.png", Role = "Document Manager", Read = Permission.Allow, Write = Permission.Deny, Copy = Permission.Deny, Download = Permission.Deny, IsFile = true },

    // Folder Rule

    new AccessRule { Path = "/", Role = "Document Manager", Read = Permission.Allow, Write = Permission.Deny, Copy = Permission.Deny, WriteContents = Permission.Deny, Upload = Permission.Deny, Download = Permission.Deny, IsFile = false },

};

For further references check out the below documentation link:


Access Control: https://ej2.syncfusion.com/documentation/file-manager/access-control


We have attached the sample for your reference,


Stack-blitz sample: https://stackblitz.com/edit/6mhmnz?file=index.js


Kindly check out the shared details and get back to us if you need further assistance.


Regards,

Jafar


Attachment: service_b0040ff2.zip


SS Stephan Schrade February 12, 2024 09:20 AM UTC

Hi support,

many thanks for your answer, but this didn't not scope my questions.

As I can see in the docs and api I can set the access rule with "new AccessRule". But what happens after that? How do I  tell the file manager to use these rules?

Also in your stackblitz I can't see any code where the access rules are set and glued to the filemanager.

Also I can't see any code where the role is set at the filemanager.

There is no setRole() and setRules() Method or something similar of the filemanager component in the docs and the api.

Please give me examples in pure js.

Regards,

Stephan



PM Prasanth Madhaiyan Syncfusion Team February 13, 2024 09:07 AM UTC

Hi Stephan,


Based on the shared details, we understand that your requirement is to learn how to use access control in the JavaScript FileManager component. However, we would like to inform you that we have implemented access control support on the server side. The FileManagerAccessController enables you to define security permissions for folders and files using a set of folder or file access rules. To set up access rules for folders and individual files, utilize the SetRules() method in the controller.


Refer to the below code snippets.


namespace EJ2APIServices.Controllers

{

 

    [Route("api/[controller]")]

    [EnableCors("AllowAllOrigins")]

    public class FileManagerAccessController : Controller

    {

       

        [Route("FileOperations")]

        public object FileOperations([FromBody] FileManagerDirectoryContent args)

        {

            this.operation.SetRules(GetRules());

           

        }

 

       

 

        public AccessDetails GetRules()

        {

            AccessDetails accessDetails = new AccessDetails();

            List<AccessRule> Rules = new List<AccessRule> {

                //Deny writing for particular folder

                new AccessRule { Path = "/Documents", Role = "Document Manager", Read = Permission.Allow, Write = Permission.Deny, Copy = Permission.Allow, WriteContents = Permission.Deny, Upload = Permission.Deny, Download = Permission.Deny, IsFile = false },

                // Deny writing for particular file

                new AccessRule { Path = "/Pictures/Employees/Adam.png", Role = "Document Manager", Read = Permission.Allow, Write = Permission.Deny, Copy = Permission.Deny, Download = Permission.Deny, IsFile = true },

                // Folder Rule

                new AccessRule { Path = "/", Role = "Document Manager", Read = Permission.Allow, Write = Permission.Deny, Copy = Permission.Deny, WriteContents = Permission.Deny, Upload = Permission.Deny, Download = Permission.Deny, IsFile = false },

            };

            accessDetails.AccessRules = Rules;

            accessDetails.Role = "Document Manager";

            return accessDetails;

        }

    }

 

}


For your reference, we have attached the sample and Physical service provider.


Sample: https://stackblitz.com/edit/6mhmnz-i5wmac?file=index.js


Physical provider: https://github.com/SyncfusionExamples/ej2-aspcore-file-provider


To learn more about Access Control in the FileManager component, please refer to the documentation and demo below.


Documentation: https://ej2.syncfusion.com/documentation/file-manager/access-control


Demo: https://ej2.syncfusion.com/demos/#/material3/file-manager/access-control.html


Check out the shared details and let us know if you need any further assistance.


Regards,

Prasanth Madhaiyan.



SS Stephan Schrade February 13, 2024 09:40 AM UTC

Hi support,

many thanks!

Now I do understand your concept.

I was not aware that this is a backend thing.

Your info now helps me to add this to my own FileManager backend written in php.

Regards,

Stephan



SS Shereen Shajahan Syncfusion Team February 14, 2024 05:18 AM UTC

Hi Stephan,

Thank you for the update. Please get back to us for assistance in the future.

Regards,

Shereen


Loader.
Up arrow icon