Foros de discusión

Check if user has permission for viewing journalArticle

Luca Lupo, modificado hace 11 años.

Check if user has permission for viewing journalArticle

Regular Member Mensajes: 106 Fecha de incorporación: 1/10/12 Mensajes recientes
Hi Guys,

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

Thanks,

Luca
thumbnail
Bart Simpson, modificado hace 11 años.

RE: Check if user has permission for viewing journalArticle

Liferay Master Mensajes: 522 Fecha de incorporación: 29/08/11 Mensajes recientes
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 hace 11 años.

RE: Check if user has permission for viewing journalArticle

Regular Member Mensajes: 106 Fecha de incorporación: 1/10/12 Mensajes recientes
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 hace 11 años.

RE: Check if user has permission for viewing journalArticle

Expert Mensajes: 483 Fecha de incorporación: 31/07/10 Mensajes recientes
com.liferay.portlet.journal.service.permission.JournalArticlePermission class is there in LR 6.1.10 GA1
Luca Lupo, modificado hace 11 años.

RE: Check if user has permission for viewing journalArticle

Regular Member Mensajes: 106 Fecha de incorporación: 1/10/12 Mensajes recientes
Thanks Harish,

I have this version liferay-portal-6.1.1-ce-ga2 and I cannot find the class emoticon
Oliver Bayer, modificado hace 11 años.

RE: Check if user has permission for viewing journalArticle

Liferay Master Mensajes: 894 Fecha de incorporación: 18/02/09 Mensajes recientes
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 hace 11 años.

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

Liferay Master Mensajes: 522 Fecha de incorporación: 29/08/11 Mensajes recientes
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 hace 11 años.

RE: Check if user has permission for viewing journalArticle

Regular Member Mensajes: 106 Fecha de incorporación: 1/10/12 Mensajes recientes
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 hace 11 años.

RE: Check if user has permission for viewing journalArticle

Regular Member Mensajes: 106 Fecha de incorporación: 1/10/12 Mensajes recientes
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 hace 11 años.

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

Expert Mensajes: 319 Fecha de incorporación: 25/03/11 Mensajes recientes
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 hace 11 años.

RE: Check if user has permission for viewing journalArticle

Liferay Master Mensajes: 522 Fecha de incorporación: 29/08/11 Mensajes recientes
Thanks Vitaliy, for this very good insight.
Luca Lupo, modificado hace 11 años.

RE: Check if user has permission for viewing journalArticle

Regular Member Mensajes: 106 Fecha de incorporación: 1/10/12 Mensajes recientes
Thanks Guys...it worked perfectly....I have to say the community is really great here emoticon