RE: LF 7.0 - Override default permissions defined inside of documentlibrary

Seth Burden, modified 7 Years ago. New Member Posts: 4 Join Date: 5/13/15 Recent Posts

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!

Jamie Sammons, modified 7 Years ago. New Member Posts: 4 Join Date: 5/13/15 Recent Posts

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

  1. Start a new Liferay Module Project Fragment
  2. Select 'com.liferay.document.library.web-1.4.2.jar' as the Host OSGi Bundle
  3. Click the 'liferay +' icon to select from the list of available files to override
  4. Select 'resource-actions/default.xml'
  5. 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

https://github.com/liferay/liferay-portal/blob/master/portal-impl/src/resource-actions/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.

thumbnail
Amos Fong, modified 7 Years ago. Liferay Legend Posts: 2047 Join Date: 10/7/08 Recent Posts

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);
    }