留言板

Document Library folder Subscribe permission

Youssef A. AlMuhaidib,修改在8 年前。

Document Library folder Subscribe permission

New Member 帖子: 19 加入日期: 13-1-28 最近的帖子
I'm trying to get if a user has SUBSCRIBE permission to a folder, I'm using:


List<folder> folders = DLAppServiceUtil.getFolders(themeDisplay.getScopeGroupId(), folderId);
for(Folder f : folders){
			logger.info("folder name: {}, has subscribe: {}, support subscribe: {}", f.getName(), f.containsPermission(themeDisplay.getPermissionChecker(), ActionKeys.SUBSCRIBE), f.isSupportsSubscribing());
			boolean hasPer = themeDisplay.getPermissionChecker().hasPermission(themeDisplay.getScopeGroupId(), "com.liferay.portlet.documentlibrary", themeDisplay.getScopeGroupId(), ActionKeys.SUBSCRIBE);
			logger.info("has subscribe: {}", hasPer);
		}
</folder>


the "f.containsPermission(themeDisplay.getPermissionChecker(), ActionKeys.SUBSCRIBE)" always false, even with admin user..
on the other hand, "themeDisplay.getPermissionChecker().hasPermission" is returning true..

I checked DL implementation on how to check for subscribe permission "view_entries.jsp" and it's working


<c:if test="<%= DLPermission.contains(permissionChecker, scopeGroupId, ActionKeys.SUBSCRIBE) &amp;&amp; ((folder == null) || folder.isSupportsSubscribing()) &amp;&amp; (DLUtil.getEmailFileEntryAddedEnabled(portletPreferences) || DLUtil.getEmailFileEntryUpdatedEnabled(portletPreferences)) %>">
</c:if>


is this an issue? what is folder.containsPermission method used for? and how to achieve what I need?
note: I'm using a custom portlet
thumbnail
Andrew Jardine,修改在8 年前。

RE: Document Library folder Subscribe permission

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
Hi Youssef,

Have you tried used the DLUtil class? There are a few isSubscribed* methods in there -- specifically one for:


public static boolean isSubscribedToFolder(long companyId, long groupId, long userId, long folderId)


Can you let me know if that one works for you?
Youssef A. AlMuhaidib,修改在8 年前。

RE: Document Library folder Subscribe permission

New Member 帖子: 19 加入日期: 13-1-28 最近的帖子
hey Andrew,
Didn't try that .. Will try and let you know..

But what I'm trying to achieve is to check if the user has the permission.. if so will check if he is subscribed or not
If not will not show the subscribe link at all ..
thumbnail
Andrew Jardine,修改在8 年前。

RE: Document Library folder Subscribe permission

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
Oh I see -- you're one level back from what I am suggesting. I'll keep digging through the source and tell you is I find anything else that might help. The behaviour you are descriving though does sound suspicious. As far as I know, the permissionChecker that is available in the jsp is the one that comes from the ThemeDisplay -- so strange that it is not yielding the correct result.

What about this method (on the permission checker)


public boolean hasPermission(long groupId, String name, long primKey, String actionId);


where the primKey is not the groupId but rather the folder id?
Youssef A. AlMuhaidib,修改在8 年前。

RE: Document Library folder Subscribe permission

New Member 帖子: 19 加入日期: 13-1-28 最近的帖子
Hey,
here is my loging code

List<folder> folders  = DLAppServiceUtil.getFolders(themeDisplay.getScopeGroupId(), folderId);
for(Folder f : folders){
	logger.info("folder name: {}, has subscribe: {}, support subscribe: {}", f.getName(), f.containsPermission(themeDisplay.getPermissionChecker(), ActionKeys.SUBSCRIBE), f.isSupportsSubscribing());
	boolean hasPermission = themeDisplay.getPermissionChecker().hasPermission(themeDisplay.getScopeGroupId(), "com.liferay.portlet.documentlibrary", themeDisplay.getScopeGroupId(), ActionKeys.SUBSCRIBE);
	logger.info("PermissionChecker().hasPermission: {}", hasPermission);
}		
</folder>


the results using normal user "site memeber"

INFO  [http-bio-8080-exec-31][CdrController:145] folder name: Operator CDR, has subscribe: false, support subscribe: true
INFO  [http-bio-8080-exec-31][CdrController:134] PermissionChecker().hasPermission: false
INFO  [http-bio-8080-exec-31][CdrController:145] folder name: Company CDR, has subscribe: false, support subscribe: true
INFO  [http-bio-8080-exec-31][CdrController:134] PermissionChecker().hasPermission: false

as you see both (folder.containsPermission and permissionChecker().hasPermission) are returning false.
also the strange thing is: site member do not have subscribe permission at all even in liferay's D&M portlet!
only admin role got that permission
this is the log result from a user with admin role:

INFO  [http-bio-8080-exec-18][CdrController:145] folder name: Operator CDR, has subscribe: false, support subscribe: true
INFO  [http-bio-8080-exec-18][CdrController:134] PermissionChecker().hasPermission: true
INFO  [http-bio-8080-exec-18][CdrController:145] folder name: Company CDR, has subscribe: false, support subscribe: true
INFO  [http-bio-8080-exec-18][CdrController:134] PermissionChecker().hasPermission: true
Youssef A. AlMuhaidib,修改在8 年前。

RE: Document Library folder Subscribe permission

New Member 帖子: 19 加入日期: 13-1-28 最近的帖子
after I went to Site Member role and added the following permission
Documents and Media Display > Documents: Subscribe


now normal user permissions:


INFO  [http-bio-8080-exec-59][CdrController:145] folder name: Operator CDR, has subscribe: false, support subscribe: true
INFO  [http-bio-8080-exec-59][CdrController:134] PermissionChecker().hasPermission: true
INFO  [http-bio-8080-exec-59][CdrController:145] folder name: Company CDR, has subscribe: false, support subscribe: true
INFO  [http-bio-8080-exec-59][CdrController:134] PermissionChecker().hasPermission: true

the odd thing, Documents Folder resource doesn't have Subscribe permission
I think that's why folder.containsPermission is returning false