Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Edgar G.
$request.isUserInRole("Administrator") returns false when user is an Admin
15 febbraio 2012 9.21
Risposta

Edgar G.

Punteggio: New Member

Messaggi: 23

Data di Iscrizione: 24 ottobre 2011

Messaggi recenti

Hey guys,

In Liferay 6.0 I have $request.isUserInRole("Administrator") in my theme and it returns false even when the user is an Admin. I also tried $request.isUserInRole("administrator").

What am I missing?

Thanks!
Henrique Simoes de Andrade
RE: $request.isUserInRole("Administrator") returns false when user is an Ad
15 febbraio 2012 11.05
Risposta

Henrique Simoes de Andrade

Punteggio: Regular Member

Messaggi: 165

Data di Iscrizione: 30 aprile 2010

Messaggi recenti

Hi,
Try (power adminsitrator):
1$permissionChecker.isOmniadmin()

Or Community Admin:
1$permissionChecker.isCommunityAdmin($scopeGroupId)


HTH
Edgar G.
RE: $request.isUserInRole("Administrator") returns false when user is an Ad
15 febbraio 2012 11.39
Risposta

Edgar G.

Punteggio: New Member

Messaggi: 23

Data di Iscrizione: 24 ottobre 2011

Messaggi recenti

Thanks for your reply, Henrique! That does work and it checks the permission directly which is fine.

However, I went about it this way:

1
2#* Get the roles and put them in an arraylist *#
3#set ($roles = $serviceLocator.findService("com.liferay.portal.service.RoleService").getUserRoles($user_id))
4#set ($roleNameArray = [])
5#foreach( $role in $roles )
6     $roleNameArray.add($role.getName())
7#end


Then later in the code I can check whether or not a certain role is contained in the $roleNameArray.

1
2#if( ($roleNameArray.contains("Administrator") )
3#* this user is an administrator *#
4#end


I can also check if the current user is in a custom role too.

1
2$roleNameArray.contains("myCustomRole")
Tanaji Londhe
RE: $request.isUserInRole("Administrator") returns false when user is an Ad
9 luglio 2012 5.39
Risposta

Tanaji Londhe

Punteggio: Regular Member

Messaggi: 196

Data di Iscrizione: 25 aprile 2012

Messaggi recenti

Hi,
I use following code in my portal_normal.vm file. It work propetrly but print some extra true true value on my page

<div..............> ................

#set ($roles = $serviceLocator.findService("com.liferay.portal.service.RoleService").getUserRoles($user_id))
#set ($roleNameArray = [])
#foreach( $role in $roles )
$roleNameArray.add($role.getName())
#end

$user_name = $roleName

</div>

OutPut :
true true
[Administrator, User]


So plz how to remove this error.

Thanks,
Tanaji Londhe.
Tanaji Londhe
RE: $request.isUserInRole("Administrator") returns false when user is an Ad
9 luglio 2012 6.44
Risposta

Tanaji Londhe

Punteggio: Regular Member

Messaggi: 196

Data di Iscrizione: 25 aprile 2012

Messaggi recenti

Tanaji M. Londhe:
Hi,
I use following code in my portal_normal.vm file. It work propetrly but print some extra true true value on my page

<div..............> ................

#set ($roles = $serviceLocator.findService("com.liferay.portal.service.RoleService").getUserRoles($user_id))
#set ($roleNameArray = [])
#foreach( $role in $roles )
$roleNameArray.add($role.getName())
#end

$user_name = $roleName

</div>

OutPut :
true true
[Administrator, User]


So plz how to remove this error.

Thanks,
Tanaji Londhe.



I think value true is present after this line $roleNameArray.add($role.getName())
David H Nebinger
RE: $request.isUserInRole("Administrator") returns false when user is an Ad
9 luglio 2012 8.01
Risposta

David H Nebinger

Community Moderator

Punteggio: Liferay Legend

Messaggi: 12524

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

I think the error is in your velocity code. You can find resources to help learn correct velocity syntax via a simple google search...
Tanaji Londhe
RE: $request.isUserInRole("Administrator") returns false when user is an Ad
9 luglio 2012 22.31
Risposta

Tanaji Londhe

Punteggio: Regular Member

Messaggi: 196

Data di Iscrizione: 25 aprile 2012

Messaggi recenti

Hi,

I resovle that error just adding one varialbe $temp = $roleNameArray.add($role.getName())
Because "$roleNameArray.add($role.getName())" it returns me "true" value when successful adding in array.
Thanks David.

Thanks,
Tanaji Londhe.
Alex alex
RE: $request.isUserInRole("Administrator") returns false when user is an Ad
31 dicembre 2012 1.57
Risposta

Alex alex

Punteggio: New Member

Messaggi: 13

Data di Iscrizione: 16 ottobre 2012

Messaggi recenti

Hi,
I'm trying to modify the portal-normal.vm in order to make a logo clickable or not according to the current user role.
I found that the code for getting the Current User role is like the follow:
#set ($rService = $serviceLocator.findService("com.liferay.portal.service.RoleService"))
#set ($usrRoles = $rService.getUserRoles( $user_id ))
#foreach( $usrRole in $usrRoles )
#If ($usrRole.getName() == "MyRole")
do something
#end
#end

The issues i'm facing is this:
1) When i enter the portal as Administrator the $usrRoles is full with the Administrator's roles
2) When i enter the portal as normal (PowerUser, User) the $usrRoles variable is wholly EMPTY.

In this way i cannot check if a normal user1 has the role1 (so he can click on the logo) and if a normal user2 has the role2 (and he cannot click on the logo).
Why this works just for Administrator role?
Is there anything i missed with code? I'm working with liferay 6.1 ga2
Thanks a lot
Tanaji Londhe
RE: $request.isUserInRole("Administrator") returns false when user is an Ad
1 gennaio 2013 23.34
Risposta

Tanaji Londhe

Punteggio: Regular Member

Messaggi: 196

Data di Iscrizione: 25 aprile 2012

Messaggi recenti

Hi Alex,

Can u tell me "MyRole" is define for Administrator or all user from below code.
If it is for only Administrator the specify another "if" condition for other normal users along with its role.

#If ($usrRole.getName() == "MyRole")
do something
#end
Alex alex
RE: $request.isUserInRole("Administrator") returns false when user is an Ad
2 gennaio 2013 1.32
Risposta

Alex alex

Punteggio: New Member

Messaggi: 13

Data di Iscrizione: 16 ottobre 2012

Messaggi recenti

Hi Tanaji,
no "My Role" is a normal role defined for all user.
The strange thing is that using the "foreach (.......)" code i should fill the $usrRoles variable with all user role... i tried to print them too.
But this work just for administrator. If i'm Administrato the code prints: Administrator, user, power user...etc
If i'm logged as a normal user... the code doesn't print anything....
how is it possible?
i'm working with liferay 6.1 ga2 version
thanks
Alex alex
RE: $request.isUserInRole("Administrator") returns false when user is an Ad
2 gennaio 2013 3.07
Risposta

Alex alex

Punteggio: New Member

Messaggi: 13

Data di Iscrizione: 16 ottobre 2012

Messaggi recenti

maybe it's solved:

#set ($usrRoles = $user.getRoles())
#foreach( $usrRole in $usrRoles )
#If ($usrRole.getName() == "MyRole")
do something
#end
#end
Tanaji Londhe
RE: $request.isUserInRole("Administrator") returns false when user is an Ad
2 gennaio 2013 3.39
Risposta

Tanaji Londhe

Punteggio: Regular Member

Messaggi: 196

Data di Iscrizione: 25 aprile 2012

Messaggi recenti

Did you get solution or not?