Today I’ll talk about a CAML query attribute, the “membership” attribute. This attribute allows especially to query the groups the current user!
If we look at the msdn documentation, we see that there are 5 different settings possible. However, this documentation is not very detailed. The purpose of this article is to detail the different possibilities.
We will see these possibilities through tests.
Here are the parameters used for the tests:
Site structure :
RootSite based on « TeamSite »
Susbsite based on « TeamSite »
Groups and users :
The tests were performed on the subsite. The site was created by inheriting from the parent security, then security has been broken and a new group “subtestgroup” was created.
- Groups :
- Test Owners
- Test Members
- Users :
- User 1 :
- Current user
- Member of “Test Owners” and “subtestgroup”
- User 1 :
- User 2
- rights granted directly on the subtestsite.
The 0 is replaced by different parameters.
List and tasks targeted:
Standard task list. The following tasks were created.
- T1 assigned to user1
- T2 assigned to test owners
- T3 assigned to subtestgroup
- T4 assigned to user2
- T5 assigned to test members
Here the parameters, up to the test!
1) SPWeb.AllUsers :
This value is used to identify the tasks assigned to users (not groups)
Test result: T1 and T4
2 ) SPGroup :
Using this parameter, you must add an ID parameter with the ID of the desired group. This parameter will return the list of tasks assigned to members of this group.
The test will be performed using the ID of groups “members tests “(ID 7, empty group) and “test owners’”(ID 5, containing User 1)
If we change the query used by this one
<Membership Type=””SPGroup”” ID=”7”>
Test result : no tasks
Test with ID 5
Test result : T1
3 ) SPWeb.Groups :
The tasks assigned to the group site collection appear but not the tasks assigned to specific groups site
Test result : T2 and T5
4 ) CurrentUserGroups :
The tasks assigned to the current user groups will appear but not tasks assigned directly to the user.
Test result : T2 et T3
5 ) SPWeb.Users :
Tasks assigned to users who have received rights to the site directly (not through a group).
Test result : T4
Hope this helps!