The Raven
The Raven

Reputation: 527

SessionAsSigner - database object conflicts

Hello Domino programmers!

I work on a Xpages application and i ran into a following problem:

I have to use sessionAsSigner object to get number of all documents in a view. I use single computed field to display: user visible document count / all documents count value and another computed field to display current (not sessionAsSigner) user name.

Page looks as follows:

Page design

Under UserName Computed field code i entered following code:

session.createName(session.getEffectiveUserName()).getCommon()

Under DocCount Computed field code i entered following code:

var viewAsUser = database.getView("AllByHID");
var docCountUser = viewAsUser.getAllEntries().getCount();

var dbAsSigner = sessionAsSigner.getCurrentDatabase();
var viewAsSigner = dbAsSigner.getView("AllByHID");
var docCountSigner = viewAsSigner.getAllEntries().getCount();

return docCountUser.toString() + "/" + docCountSigner.toString();

I received following result:

enter image description here

This is correct number of documents a current user can see, but it seems like sessionAsSigner usage was completely ignored. (?)

After some "tinkering" I swapped some lines of code to get:

var dbAsSigner = sessionAsSigner.getCurrentDatabase();
var viewAsSigner = dbAsSigner.getView("AllByHID");
var docCountSigner = viewAsSigner.getAllEntries().getCount();

var viewAsUser = database.getView("AllByHID");
var docCountUser = viewAsUser.getAllEntries().getCount();

return docCountUser.toString() + "/" + docCountSigner.toString();

and in result...

enter image description here

Both values are correct, but i wonder why can't i get them in a single call? Am I missing something here?

Any help will be appreciated.

Upvotes: 0

Views: 346

Answers (2)

Sven Hasselbach
Sven Hasselbach

Reputation: 10485

The problem is that Domino knows about the existing reference of the view and uses this instead of creating two instances (with different access rights).

You have to recycle the view first:

var dbAsSigner = sessionAsSigner.getCurrentDatabase();
var viewAsSigner = dbAsSigner.getView("AllByHID");
var docCountSigner = viewAsSigner.getAllEntries().getCount();
viewAsSigner.recycle();

var viewAsUser = database.getView("AllByHID");
var docCountUser = viewAsUser.getAllEntries().getCount();

return docCountUser.toString() + "/" + docCountSigner.toString();

This should work.

Upvotes: 4

Paul Stephen Withers
Paul Stephen Withers

Reputation: 15739

getCurrentDatabase() should not be used with sessionAsSigner. It will retrieve the same Database object retrieved for the current user. Instead use sessionAsSigner.getDatabase(database.getServerName(), database.getFilePath())

Upvotes: 0

Related Questions