SessionAsSigner - database object conflicts

柔情痞子 提交于 2019-12-08 09:31:08

问题


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:

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:

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...

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.


回答1:


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.




回答2:


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())



来源:https://stackoverflow.com/questions/25845795/sessionassigner-database-object-conflicts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!