Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Luca Lupo
Check if user has permission for viewing journalArticle
October 15, 2012 3:34 AM
Answer

Luca Lupo

Rank: Regular Member

Posts: 106

Join Date: October 1, 2012

Recent Posts

Hi Guys,

Do you know how can i check (programmatically) whereas a user has permission for viewing journalArticle?

Thanks,

Luca
Bart Simpson
RE: Check if user has permission for viewing journalArticle
October 10, 2012 11:00 PM
Answer

Bart Simpson

Rank: Liferay Master

Posts: 524

Join Date: August 29, 2011

Recent Posts

User
1 void com.liferay.portlet.journal.service.permission.JournalArticlePermission.check(PermissionChecker permissionChecker, JournalArticle article, String actionId) throws PortalException


pass the current permission checker from jsp or in velocity and actionId as
1ActionKeys.VIEW


Hope it helps
Luca Lupo
RE: Check if user has permission for viewing journalArticle
October 11, 2012 12:09 AM
Answer

Luca Lupo

Rank: Regular Member

Posts: 106

Join Date: October 1, 2012

Recent Posts

Hi Bart....my version of life ray (6.1.1) doesn't have this class

com.liferay.portlet.journal.service.permission

emoticon
Harish Kumar
RE: Check if user has permission for viewing journalArticle
October 11, 2012 12:17 AM
Answer

Harish Kumar

Rank: Expert

Posts: 351

Join Date: July 31, 2010

Recent Posts

com.liferay.portlet.journal.service.permission.JournalArticlePermission class is there in LR 6.1.10 GA1
Luca Lupo
RE: Check if user has permission for viewing journalArticle
October 11, 2012 12:52 AM
Answer

Luca Lupo

Rank: Regular Member

Posts: 106

Join Date: October 1, 2012

Recent Posts

Thanks Harish,

I have this version liferay-portal-6.1.1-ce-ga2 and I cannot find the class emoticon
Oliver Bayer
RE: Check if user has permission for viewing journalArticle
October 11, 2012 1:20 AM
Answer

Oliver Bayer

Rank: Liferay Master

Posts: 881

Join Date: February 18, 2009

Recent Posts

Hi Luca,

the class is definetely there emoticon. It's located in the portal-impl.jar file. If you need the sources e.g. for debugging you should download and extract the sources zip file available in the downloads section.

HTH Oli
Bart Simpson
RE: Check if user has permission for viewing journalArticle
October 11, 2012 1:44 AM
Answer

Bart Simpson

Rank: Liferay Master

Posts: 524

Join Date: August 29, 2011

Recent Posts

https://github.com/liferay/liferay-portal/blob/6.1.1-ga2/portal-impl/src/com/liferay/portlet/journal/service/permission/JournalArticlePermission.java
Luca Lupo
RE: Check if user has permission for viewing journalArticle
October 11, 2012 5:19 AM
Answer

Luca Lupo

Rank: Regular Member

Posts: 106

Join Date: October 1, 2012

Recent Posts

Hi Bart...I finally managed to find the class by importing the .jar.

However, I have some troubles understanding "pass the current permission checker from jsp". Where should I take the permissionchecker?

Thanks
Luca Lupo
RE: Check if user has permission for viewing journalArticle
October 11, 2012 5:29 AM
Answer

Luca Lupo

Rank: Regular Member

Posts: 106

Join Date: October 1, 2012

Recent Posts

Okay, I found out that I can take that from themeDisplay.

However, the function returns void, so how can i understand if the user has permission or not?

I found out that there is also this function I can use:

PermissionLocalServiceUtil.hasUserPermissions(user.getUserId(), groupId, actionId, resourceIds, bag)

But I don't understand what bag is.

Helppp
Vitaliy Koshelenko
RE: Check if user has permission for viewing journalArticle
October 11, 2012 9:46 AM
Answer

Vitaliy Koshelenko

Rank: Regular Member

Posts: 240

Join Date: March 25, 2011

Recent Posts

Hi, Luca.

Although function JournalArticlePermission#check(PermissionChecker permissionChecker, JournalArticle article, String actionId) returns void, it also throws PrincipalException if user has no permissions to perform specified action on article (for example to view the article if actionId=ActionKeys.VIEW). So, you can just handle this exception:

1try {
2     JournalArticlePermission.check(permissionChecker, article, String ActionKeys.VIEW)
3} catch(PrincipalException e) {
4//user has no permissions - handle exception in this case
5}


Vitaliy
Bart Simpson
RE: Check if user has permission for viewing journalArticle
October 11, 2012 9:21 PM
Answer

Bart Simpson

Rank: Liferay Master

Posts: 524

Join Date: August 29, 2011

Recent Posts

Thanks Vitaliy, for this very good insight.
Luca Lupo
RE: Check if user has permission for viewing journalArticle
October 12, 2012 1:39 AM
Answer

Luca Lupo

Rank: Regular Member

Posts: 106

Join Date: October 1, 2012

Recent Posts

Thanks Guys...it worked perfectly....I have to say the community is really great here emoticon