Issue
- I want to show only certain file types to some users.
- For example: they should see .doc and .pdf only but not .xls
- Is it possible to hide/show documents based on extensions?
Environment
- Liferay DXP 7.4
Resolution
While it is not possible to hide or show documents based on their extensions, there are a couple of ways to achieve this requirement.
Using the role-based permission system
- Liferay DXP has a role-based permissions system. Administrators can let users collaborate on files by assigning the appropriate file permissions to a Role, and then assigning users to that Role. Consider the following steps:
- Navigate to Control Panel > Users > Roles
- Create a new Regular Role (for example "PDF access")
- Go to Define Permissions and add View permissions to Documents and Media
- Assign this role to a user who is also a Site Member
- Navigate to Content & Data > Documents and Media
- Create a new folder (eg: "PDFs")
- Upload the required files in this folder
- Edit the Permissions of the Folder
- Remove all Permissions for Guests and Site Members
- Add view permission for the role "PDF access" only
- To verify the results:
- Place a Documents & Media widget on the Home Page
- Sign in with a user who has the "PDF access" role and see that you have access to "PDFs" folder
- Sign in with any other user and the folder will not appear
- The permissions can be added/revoked for individual files only, but if you use a separate folder you will not have to edit the permissions for each file.
Using Content Page Personalization
- Create Experiences based on User Segments which will dynamically control what users can see.
- Navigate to Control Panel > Configuration > Custom Fields.
- Select the User entity and create a custom field of type drop-down.
- Name it "File Type" and provide 2 options for it:
pdf
doc - Open the Permissions for the custom field and add View permission to User role.
- Create userA, where you set this field to "pdf".
- Create userB, where you set this field to "doc".
- Add both users to the Liferay site.
- Navigate to Site Administration for Liferay DXP > Categorization > Categories.
- Create a Vocabulary with the same name as the custom field: "File Type" (make sure that it is exactly the same).
- Add 2 categories to it, with the names corresponding to the 2 custom field values respectively: pdf and doc.
- Navigate to Content & Data > Documents and Media
- Upload 2 documents, one with each category.
- Navigate to People > Segments
- Create 2 segments (pdf segment, doc segment), a segment for each user: drag'n'drop the "File Type" property and one has to be equal with pdf and other with doc.
- Under Site Builder > Collections create a new Dynamic Collection and click on the blue Add Personalized Variation button.
- Add the 2 created segments and position them above Anyone, so they will be prioritized.
- Set the item types to Documents and Media/Basic Document and under filter, pdf should contain pdf category etc.
- Add an Asset Publisher widget to the home page, and configure it to show the created collection.
- Edit the home page and click on the Experience menu in the upper left corner.
- Create 2 new experiences: "pdf experience" with Audience set to "pdf segment", and "doc experience" with Audience set to "doc segment".
- Login with the userA and userB and check the results.
- One caveat of this approach is that you have to use the categories every time you upload a document. Another way to implement this experience personalization of documents could be to create separate Document Types for the different file types and use those when you upload documents (instead of the Basic Document type). That way, you would not have to manually add categories when uploading the document, just have to make sure that you select the right document type when uploading a file.