I have a subdirectory under app-files. I want any logged in user to be able to create files in that dir. When a file is created, I use an afterSaveFileFromByteArray event handler to set the permissions on the file to give full access to the user that created the file, and to any user with an app-created Role called ‘Administrator’. I explicitly turn off all access for AuthenticatedUser and NotAuthenticatedUser, then explicitly grant it for the user, and for the Administrator role. Here is the current handler:
Backendless.ServerCode.File.afterSaveFileFromByteArray('app-files', async function(req, res) {
await Backendless.Files.Permissions.READ.denyForRole("AuthenticatedUser", req.context.eventContext)
await Backendless.Files.Permissions.DELETE.denyForRole("AuthenticatedUser", req.context.eventContext)
await Backendless.Files.Permissions.READ.denyForRole("NotAuthenticatedUser", req.context.eventContext)
await Backendless.Files.Permissions.DELETE.denyForRole("NotAuthenticatedUser", req.context.eventContext)
await Backendless.Files.Permissions.READ.grantForUser(req.context.userId, req.context.eventContext)
await Backendless.Files.Permissions.DELETE.grantForUser(req.context.userId, req.context.eventContext)
await Backendless.Files.Permissions.READ.grantForRole("Administrator", req.context.eventContext)
await Backendless.Files.Permissions.DELETE.grantForRole("Administrator", req.context.eventContext)
});
When I try to access these files from a user account that has the Administrator role, GETS fail with Bad Request unless I turn on access for AuthenticatedUser. But then ANY logged in user can read the files, which trashes the entire plan. I won’t bore you with all the various combinations I have tried to implement this scheme. I think it would save time if someone would please just tell me exactly what permissions to set on the directory and on each file in it to achieve the simple goal described above (anyone logged in can create, only user who created file or anyone who has Admin role assigned can read or delete).
Also, is there any point at all to allowing or denying write permission to a File, as opposed to a directory?
Thank you,
Kelly
app id 8149FCCE-07DA-F988-FFBB-6154872C9500