Avoid Assets Download

Hi! I would like to create a permission in order to avoid “assets” download to certain users
I got this
https://pimcore.com/docs/5.x/Development_Documentation/Best_Practice/Modifying_Permissions_based_on_Object_Data.html
from previous posts.

Do u think I can use it for set permissions on Assets? where can I check which permission I can set (exactly I would like to avoid download to a certain group of users).
Thanks in adv
M

Hi @mircocervi

There is no permission for asset download in pimcore.If you have permission to view , you can download the asset.

In your case you can create a new permission either by adding entry into the table users_permission_definitions or if you are creating a pimcore bundle you can add the following code in the installer.It will create a new permission.

    $permissionDefinition = new \Pimcore\Model\User\Permission\Definition();
    $permissionDefinition->setKey("plugin_translations");
    $permissionDefinition->save();

And then you can override asset toolbar and asset folder toolbar to hide/show that download button based on user permissions.

1 Like

Thanks for the tip @neha. After that do u know how can I “override asset toolbar to hide the download buttom”? or can me address to a place where I read about it? I guess I need to work on ExtJs …or may I am wrong?
M

Hi @mircocervi,
You can do this with the help of the below code sample.
E.g.
write code in startup js or your custom js

preOpenAsset:function (asset, type){
let toolbar = asset.toolbar;
let user = pimcore.globalmanager.get(“user”);
if (user.admin || user.isAllowed(“your_plugin_name”)) {
// toolbar.items.items[5].hide();
// manipulate code according to your permissions and need
}
}
OR
postOpenAsset:function (asset, type){
let toolbar = asset.toolbar;
let user = pimcore.globalmanager.get(“user”);
if (user.admin || user.isAllowed(“your_plugin_name”)) {
console.log(toolbar.items.items);
// toolbar.items.items[5].hide();
// manipulate code according to your permissions and need
}
}

1 Like

awsome!! today I work on it :slight_smile:

Hi @rahulshrivastava the download button will not be at 5th position always.For a user who have only view and list permission in that case download button will be the first one.

1 Like

Hi @neha This is a sample code based on assumption, 5th positions can be either upload/download button or something else. And here I have also written a comment to modify it as needed.

1 Like