Fórum

Check if user has permission for viewing journalArticle

Luca Lupo, modificado 11 Anos atrás.

Check if user has permission for viewing journalArticle

Regular Member Postagens: 106 Data de Entrada: 01/10/12 Postagens Recentes
Hi Guys,

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

Thanks,

Luca
thumbnail
Bart Simpson, modificado 11 Anos atrás.

RE: Check if user has permission for viewing journalArticle

Liferay Master Postagens: 522 Data de Entrada: 29/08/11 Postagens Recentes
User
 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
ActionKeys.VIEW 


Hope it helps
Luca Lupo, modificado 11 Anos atrás.

RE: Check if user has permission for viewing journalArticle

Regular Member Postagens: 106 Data de Entrada: 01/10/12 Postagens Recentes
Hi Bart....my version of life ray (6.1.1) doesn't have this class

com.liferay.portlet.journal.service.permission

emoticon
thumbnail
Harish Kumar, modificado 11 Anos atrás.

RE: Check if user has permission for viewing journalArticle

Expert Postagens: 483 Data de Entrada: 31/07/10 Postagens Recentes
com.liferay.portlet.journal.service.permission.JournalArticlePermission class is there in LR 6.1.10 GA1
Luca Lupo, modificado 11 Anos atrás.

RE: Check if user has permission for viewing journalArticle

Regular Member Postagens: 106 Data de Entrada: 01/10/12 Postagens Recentes
Thanks Harish,

I have this version liferay-portal-6.1.1-ce-ga2 and I cannot find the class emoticon
Oliver Bayer, modificado 11 Anos atrás.

RE: Check if user has permission for viewing journalArticle

Liferay Master Postagens: 894 Data de Entrada: 18/02/09 Postagens Recentes
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
thumbnail
Bart Simpson, modificado 11 Anos atrás.

RE: Check if user has permission for viewing journalArticle (Resposta)

Liferay Master Postagens: 522 Data de Entrada: 29/08/11 Postagens Recentes
https://github.com/liferay/liferay-portal/blob/6.1.1-ga2/portal-impl/src/com/liferay/portlet/journal/service/permission/JournalArticlePermission.java
Luca Lupo, modificado 11 Anos atrás.

RE: Check if user has permission for viewing journalArticle

Regular Member Postagens: 106 Data de Entrada: 01/10/12 Postagens Recentes
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, modificado 11 Anos atrás.

RE: Check if user has permission for viewing journalArticle

Regular Member Postagens: 106 Data de Entrada: 01/10/12 Postagens Recentes
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
thumbnail
Vitaliy Koshelenko, modificado 11 Anos atrás.

RE: Check if user has permission for viewing journalArticle (Resposta)

Expert Postagens: 319 Data de Entrada: 25/03/11 Postagens Recentes
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:

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


Vitaliy
thumbnail
Bart Simpson, modificado 11 Anos atrás.

RE: Check if user has permission for viewing journalArticle

Liferay Master Postagens: 522 Data de Entrada: 29/08/11 Postagens Recentes
Thanks Vitaliy, for this very good insight.
Luca Lupo, modificado 11 Anos atrás.

RE: Check if user has permission for viewing journalArticle

Regular Member Postagens: 106 Data de Entrada: 01/10/12 Postagens Recentes
Thanks Guys...it worked perfectly....I have to say the community is really great here emoticon