Edgewall Software

Ticket #4245: groupprovider_fix.diff_against_prev_impl.patch

File groupprovider_fix.diff_against_prev_impl.patch, 1.4 KB (added by ants.aasma@…, 5 years ago)

Diff against the previous implementation to highlight the changes.

  • trac/perm.py

     
    155155        cursor = db.cursor() 
    156156        groups = permissions 
    157157        users = set([u[0] for u in self.env.get_known_users()]) 
     158         
     159        # Collect the implicit groups and their members. This too could use a 
     160        # more efficient API 
     161        implicit_groups = {} 
     162        for provider in self.group_providers: 
     163            for username in users: 
     164                for groupname in provider.get_permission_groups(username): 
     165                    try: 
     166                        implicit_groups[groupname].add(username) 
     167                    except KeyError: 
     168                        implicit_groups[groupname] = set(username) 
     169             
    158170        result = set() 
    159171 
    160172        # First iteration finds all users and groups that have any of the 
     
    168180                           % (', '.join(['%s'] * len(groups))), groups) 
    169181            groups = [] 
    170182            for username, nummembers in cursor: 
     183                if username in implicit_groups: 
     184                    # A group with members provided by group_providers has 
     185                    # the necessary permissions set so add all its members. 
     186                    result.update(implicit_groups[username]) 
    171187                if username in users: 
    172188                    result.add(username) 
    173189                elif nummembers: