#NEWLINE# def hasAccess( self , doc , user = None , level = AccessType . READ ) : #NEWLINE# #INDENT# '\n        This overrides the default AccessControlledModel behavior for checking\n        access to perform an optimized subset of the access control behavior.\n\n        :param doc: The group to check permission on.\n        :type doc: dict\n        :param user: The user to check against.\n        :type user: dict\n        :param level: The access level.\n        :type level: AccessType\n        :returns: Whether the access is granted.\n        ' #NEWLINE# if ( user is None ) : #NEWLINE# #INDENT# return ( ( doc == AccessType . READ ) and ( doc . get ( 'public' , False ) is True ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( user . get ( 'admin' , False ) is True ) : #NEWLINE# #INDENT# return True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( level == AccessType . READ ) : #NEWLINE# #INDENT# return ( ( doc . get ( 'public' , False ) is True ) or ( doc [ '_id' ] in user . get ( 'groups' , [ ] ) ) or ( doc [ '_id' ] in [ i [ 'groupId' ] for i in user . get ( 'groupInvites' , [ ] ) ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return self . _hasUserAccess ( doc . get ( 'access' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) . get ( 'users' , [ ] ) , user [ '_id' ] , level )