Jun 24, 2016 4:08 AM
6 Posts

Hide-whens on XPage doesn't work for users listed within groups in server directory.

  • Category: Application Development
  • Platform: Windows
  • Release: 9.0.1
  • Role: Developer
  • Tags:
  • Replies: 7

Hello,

I have two divs on a Xpage, with 2 different hide-whens as below...

1. var acl:NotesACL = database.getACL();
var entry:NotesACLEntry = acl.getEntry(@UserName());
//return @IsMember("[Panel]", entry.getRoles()).toString();
if(entry.getRoles().contains("[Admin]")||entry.getRoles().contains("[Hiring_Team]")){
return true;
}

And

2. var acl:NotesACL = database.getACL();
var entry:NotesACLEntry = acl.getEntry(@UserName());
//return @IsMember("[Panel]", entry.getRoles()).toString();
if((entry.getRoles().contains("[Panel]") || entry.getRoles().contains("[]") || entry.getRoles().contains("")) && !(entry.getRoles().contains("[Admin]") || entry.getRoles().contains("[Hiring_Team]")))
{
return true;
}

These works perfectly for users having explicit entries on ACL, but doesn't for same users while their explicit entries are removed from ACL and their names are listed within a group in server directory with same access level and Roles enabled. It shows below error after opening on browsers...

Error while executing JavaScript computed expression
Script interpreter error, line=4, col=11: 'entry' is null

And points to this line...

if((entry.getRoles().contains("[Panel]") || entry.getRoles().contains("[]") || entry.getRoles().contains("")) && !(entry.getRoles().contains("[Admin]") || entry.getRoles().contains("[Hiring_Team]")))

 

Could anyone please help why this doesn't work on browsers?

Thanks in anticipation.

Regards,

Abhishek SenGupta.

Jun 24, 2016 5:22 AM
98 Posts
Working as designed
NotesACL.getEntry(String) can only find direct entries; see usage notes in Designer Help:
"If a person is not listed explicitly in the ACL, but is a member of a group listed in the ACL, getEntry does not find that person's name."


A possible workaround is to use NotesSession.evaluate(@UserNamesList), which should return a complete list of the current user's names, roles and groups the user is a member of.
Jun 24, 2016 9:54 AM
98 Posts
More info
First of all, there's a little (but important) flaw in my suggested workaround in that the quotes are missing around @UserNamesList.
Second, it might be necessary to provide a formula context to the evaluate method; i.e., pass a NotesDocument object as second argument.


Here's a corrected version:


var session:NotesSession = database.getParent();

var doc:NotesDocument = <your code here>;
var userNamesList = session.evaluate("@UserNamesList", doc)
;
Jun 24, 2016 7:12 AM
6 Posts
Looking for workaround code

Hello Jochen,

Thank you very much for your input. I'm very new to Xpages. Could you please provide me part of code that could work with NotesSession.evaluate(@UserNamesList)?

Regards,

Abhishek SenGupta.

Jun 24, 2016 7:40 AM
98 Posts
I don't have a complete code example at my fingertips, but...
...it should be fairly easy to figure out by reading the relevant pages in Domino Designer Help. I'd start with the Help page about the @UserNamesList formula language function, which can be found under "IBM Domino Designer Basic User Guide and Reference", and then proceed with the Help page(s) about the NotesSession class, to be found under "IBM Domino Designer XPages Reference".
Jun 27, 2016 1:31 AM
36 Posts
Then again Designer Help is sometimes off. Luckily not all bad.
For instance, the help for @UserRoles states that roles for users in groups are not returned.  Thankfully, this is untrue and those roles ARE returned.  Also, because @UserRoles returns only a subset of @UserNamesList, evaluating formulas using @UserRoles is a lot faster than @UserNamesList.
Jun 28, 2016 4:46 AM
98 Posts
You are right, @UserRoles is sufficient if only roles, no groups, matter
...which is what the OP's first post indicates indeed, if one takes a closer look at the code.

FWIW, the resulting code looks very similar:

var session:NotesSession = database.getParent();
var doc:NotesDocument = <your code here>;
var userNamesList = session.evaluate("@UserRoles", doc)
;
Jun 24, 2016 6:34 PM
6 Posts
Thank you.

Thank you very much, Jochen, for all your time and help.

I've figured it out and implemented successfully, as you suggested.