VladislavLysov
VladislavLysov

Reputation: 651

Alfresco Prohibit all users to delete a content

I have next task - prohibit all users(except admin) to delete a content in Alfresco. I'm use a permission service for that, but it doesn't work:

private void setReadOnly(ScriptNode node) {
        permissionService.deletePermissions(node.getNodeRef());
        permissionService.setPermission(node.getNodeRef(),
PermissionService.ALL_AUTHORITIES, PermissionService.CONSUMER, true);
}

But if i'm add my user if other group(for example - Template designer) and than add new permission for blocking content from Alfresco Share(for example group-"TEMPLATE_DESIGNER" role-"COORDINATOR") - after that my user must delete content, add new content(if it folder) and other... Another way to solve my problem -

private void setReadOnly(ScriptNode node) {
        permissionService.deletePermissions(node.getNodeRef());
        permissionService.setInheritParentPermissions(node.getNodeRef(), false);
}

but it is not suitable for some reason. Please, answer - how to prohibit delete a content for all users(except admin)? Thank you.

Upvotes: 5

Views: 2271

Answers (2)

Tahir Malik
Tahir Malik

Reputation: 6643

OK Second Answer:

Create a behavior which implements NodeServicePolicies.BeforeDeleteNodePolicy.

This behavior will get triggered every time before a user tries to delete an item. So Then you'll have a NodeRef, from there you can check which node it is and if you want to make it deletable or not.

The best way to do this is to:

  • Ad a custom aspect and evaluate it with the behavior
  • Or define a custom node type, which has a custom metadata boolean or something which is set by a javascript or a rule which triggers the javascript. And make that field hidden, so no user can check/uncheck it

Btw check this PDF by Jeff Pots on creating behaviors :)

Upvotes: 2

Tahir Malik
Tahir Malik

Reputation: 6643

Can't you just change the permissionDefinitions.xml and remove the delete permission for every role?

There is a separate role for admin, just leave that as it is.

UPDATE: If you just want to do it for just one folder, then you can set the permissions manually. Un-check inherit permission and set the the groups & user to editor rights. Only coordinator has delete rights, see page Docs

In case you want to remove the permission of the owner, which still has delete rights. just create a Javascript which removes the owner.

Upvotes: 2

Related Questions