Try our conversational search powered by Generative AI!

Get users with certain group names sync problem

Vote:
 

I have a query where I search for members in a specified range of group names. Works great but... If a user's roles change inside the "real" provider, the query doesn't seem to return the correct results until the user has logged in once more. Is there a job or something that exist that can force changes to be visible inside the data store that the query engine uses?

var cg1 = new CriteriaGroup();

membersQuery.Groups = new GroupCollectionCriterion();
membersQuery.Groups.Containing = new GroupCriterion();
membersQuery.Groups.Containing.Name = new StringCriterion();
membersQuery.Groups.Containing.Name.Includes = new StringInCriterion();
membersQuery.Groups.Containing.Name.Includes.Values.AddRange(groupNames);
cg1.AddCriterion(membersQuery.Groups);
..
UserCollection members = QueryHandler.Instance.GetQueryResult<IUser, UserCollection>(membersQuery, ..

    

#57117
Feb 27, 2012 14:19
Vote:
 

Have you tried to throw away cached results and then re-query once more?

 

QueryHandler.Instance.RemoveQueryResultCache(membersQuery);
#57528
Mar 19, 2012 15:00
Vote:
 

I can't think that the roles synch will be involved when removing the cached result for any query? When I'm back working in that project I will give it a quick test run though... Thanks!

#57584
Mar 22, 2012 9:24
Vote:
 

Hi Johan,
I had a similar problem once where I needed to update forum rights for a user, when the roles had changed inside the "real provider". I fixed it with the following code :

        /// <summary>
        /// Synchronize user roles/groups and invalidate cached entityitems for the user
        /// </summary>
        /// <param name="user">Cloned user object</param>
        /// <returns></returns>
        public static IUser SynchronizeUser(IUser user)
        {
           string[] rolesForUser = Roles.GetRolesForUser(user.UserName);
            List<string> list1 = new List<string>(Enumerable.Where<string>((IEnumerable<string>)rolesForUser, (Func<string, bool>)(roleName => Integrator.ShouldTransferRole(roleName))));
            List<IGroup> list2 = new List<IGroup>();
            foreach (IGroup group in (CacheableCollectionBase<IGroup, GroupCollection>)user.Groups)
            {
                if (!list1.Contains(group.Name) && Integrator.ShouldTransferRole(group.Name))
                    list2.Add(group);
                else
                    list1.Remove(group.Name);
            }
            foreach (IGroup group in list2)
                user.Groups.Remove(group);
            foreach (string roleName in list1)
                user.Groups.Add(Integrator.SynchronizeRole(roleName));
            CommunitySystem.CurrentContext.DefaultSecurity.UpdateUser(user);
            return user;
        }

    
 I hope this helps 

#57726
Mar 26, 2012 10:05
Vote:
 

I'd hoped something was built in but I can work with something like that! Thanks!

#57804
Mar 28, 2012 12:39
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.