Reputation: 5
I have a view in which I want to hide documents (you’ll see later that it’s not really the documents that cause my problem but the categorized view) accessible only by a certain role.
I’ll try to be as specific as possible so don’t hesitate to ask me questions if something isn’t clear.
Please note that English is not my first language ;-)
I have 4 different types of documents, 3 (TypeA, TypeB and TypeC) are visible to everyone and 1 (TypeD) need a certain role (ex. [RoleD]).
The view is categorized by document type and there are security fields on each document that prevent them to be seen if you don’t have the proper role. So when you look at the view while not being a member of [RoleD] you get this result:
TypeA
Doc1
Doc2
Doc3
TypeB
Doc4
Doc5
TypeC
Doc6
Doc7
TypeD
{Empty}
My problem is that even though all the documents of TypeD are hidden, I wish to also hide the “category”.
I’ve tried some condition in the view selection to select the TypeD documents only when the user is a member of the role [RoleD] but without any success using @If, @IsMember (and @IsNotMember) and @UserRoles. The result is weird, even if I’m a member of the role, the category and documents are hidden (?!?!?).
Here’s what I’ve tried so far:
Try #1
@If(@IsNotMember("[RoleD]";@UserRoles) ; DocTypeField != "TypeD" ; 1=1)
Try #2
@IsNotMember("[RoleD]";@UserRoles) & DocTypeField != "TypeD"
|
@IsMember("[RoleD]";@UserRoles) & 1=1
I hope it's not too confusing.
Thanks for your much needed help.
Upvotes: 0
Views: 6074
Reputation: 14628
Ken's answer is correct. However I want to point out two things.
First, 'do not show empty categories' can cause slower performance for users. This is particularly true in cases where there are lots of documents (many tens of thousands) and individual users only have access to a very small percentage of them.
Second, the reason you can't use @UserRoles reliably in a view is that for regular views the view index is not built by the client. It is the indexer task on the server that applies the selection formula, so @UserRoles will return the roles that apply to the server id. If you use a private view that is indexed by the client, then @UserRoles will return what you expect. There are more details than this to consider, but the rule of thumb is that view selection formulas should normally not use functions that return different results for different users or different results at different date/times.
Upvotes: 1
Reputation: 22266
There is a view property called "do not show empty categories". Is that set on your view?
Upvotes: 2