Developer Forum »
Querying for a set of nodes belonging to a particular user group
42 posts

How would I go about this?

For instance, I am a member of user group "foo", which is a subgroup of "bar". I want to query for all nodes of some type that have a limited read access to "foo" thus excluding documents that have read access set to "bar", eventhough I am elligible to access those nodes.

Naturally I would also be returned with documents that may have a read access set to some subgroup of "foo", if I (the session) have access.

Are there some internal relations that I could use? :)

Thanks!

 

-Emil

120 posts

These are the internals of Aql.IsMember() :

 

        public static AqlExpressionBoolean MemberOf(AqlExpressionInteger groupId, UserAccess access) {
            // Restricting result to content user has read access to
            switch (access.UserType) {
                case SystemUserType.Administrator:
                case SystemUserType.System:
                    return null; // no restriction
                case SystemUserType.Anonymous:
                    return groupId == (int)SystemUserGroupType.Anonymous;
                case SystemUserType.User:
                    UniqueList<int> groups = new UniqueList<int>();
                    groups.Add((int)SystemUserGroupType.Anonymous);
                    groups.Add((int)SystemUserGroupType.AllUsers);
                    foreach (int id in access.Memberships) groups.Add(id);
                    return Aql.In(groupId, groups);
                default:
                    throw new Exception("Internal error. Unknown user type. ");
            }
        }
        public static AqlExpressionBoolean MemberOf(AqlExpressionInteger groupId, int userId) {
            SystemUserType type;
            UniqueList<int> memberships = new UniqueList<int>();
            switch (userId) {
                case (int)SystemUserType.System: type = SystemUserType.System; break;
                default:
                    if (userId < -10) {
                        type = SystemUserType.Anonymous;
                    } else {
                        var users = WAFRuntime.SystemSession.GetContents<SystemUser>(AqlContent.NodeId == userId);
                        if (users.Count > 0) {
                            var user = users.First();
                            type = user.IsAdmin ? SystemUserType.Administrator : SystemUserType.User;
                            if (type == SystemUserType.User) memberships = user.GetAllMembershipsById();
                        } else {
                            type = SystemUserType.Anonymous;
                        }
                    }
                    break;
            }
            return MemberOf(groupId, new UserAccess(type, memberships));
        }
120 posts

Does this help?

 

Can you not just query the user group directly?

 

query.Where( alias.ReadGroupId = 10 );

1