Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: LF 7.0 - Override default permissions defined inside of documentlibrary
In Liferay 7.0, how do I override default permissions defined inside of documentlibrary.xml? I want some of the automatically checked permissions on the User role to be removed when folders are created and the Access permission to be automatically checked. In 6.2, we were able to override by modifying documentlibrary.xml, placing it in a folder named resource-actions and then placing the resources-actions folder at \liferay-portal-6.2-ee-sp11\tomcat-7.0.42\webapps\ROOT\WEB-INF\classes
What the new way to accomplish this within Liferay 7.0? Thank you in advance for anyone who can help on this!
I have found a working solution and wanted to share in-case anyone else is running into a similar issue. Hopefully there aren’t any hidden/unforeseen pitfalls but it seems to be working fine in my local environment so far.
If using the Eclipse Liferay IDE
- Start a new Liferay Module Project Fragment
- Select 'com.liferay.document.library.web-1.4.2.jar' as the Host OSGi Bundle
- Click the 'liferay +' icon to select from the list of available files to override
- Select 'resource-actions/default.xml'
- Click Finish
After project creation, open default-ext.xml
Note: Only a couple of ‘portlet-resource’ elements are defined. It does not include any ‘model-resource’ elements which I added manually as described below.
See the source for documentlibrary.xml
...there is a model-resource element for 'com.liferay.document.library.kernel.model.DLFolder' within documentlibrary.xml
Copy the model-resource element into default-ext.xml and remove/add any default permissions. I have attached a copy of my default-ext.xml.
Build/Deploy the module. Go to documents and media and click to create a new folder. You should see the default permissions checked or not checked based on what you defined in default-ext.xml.
Warning – this may impact any existing folders already existing in your documents and media libraries. I had a small library set up locally and could not access the parent folder contents anymore. New folders and contents once the module is deployed are fine. I’m not sure if something I tried before I implemented this solution messed up the existing parent folder of my library or what. This is just a fair warning in-case you have anything important setup locally for something else. The error I was seeing is – ‘…Someone may be trying to circumvent the permission checker’. However, I created the entire library as admin and was logged in as the admin when clicking on it (which is when the error occurs on the console) so I’m not sure what happened to corrupt my folder.
Attachments:
Looks like you already figure out a solution, but just wanted to post an alternative in case someone needs more logic like I did.
I created a JournalArticleLocalServiceWrapper and overrided the addArticle method and based on a condition, changed the permissions:
protected Map<Long, String[]> getRoleIdsToActionIds(JournalArticle journalArticle) { Map<Long, String[]> roleIdsToActionIds = new HashMap<>(); roleIdsToActionIds.put(ROLE_GUEST_ID, new String[0]); roleIdsToActionIds.put(ROLE_EMPLOYEE_ID, new String[] {ActionKeys.VIEW}); roleIdsToActionIds.put(ROLE_SITE_MEMBER_ID, new String[0]); /* if (structureFieldValue == x) { add more permissions here }*/ return roleIdsToActionIds; } protected void updateResourcePermissions(JournalArticle journalArticle) throws PortalException { Map<Long, String[]> roleIdsToActionIds = getRoleIdsToActionIds(journalArticle); _resourcePermissionLocalService.setResourcePermissions( journalArticle.getCompanyId(), JournalArticle.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(journalArticle.getResourcePrimKey()), roleIdsToActionIds); }
Powered by Liferay™