#NEWLINE# def getAccessLevel( self , doc , user ) : #NEWLINE# #INDENT# '\n        Return the maximum access level for a given user on the group.\n\n        :param doc: The group to check access on.\n        :param user: The user to get the access level for.\n        :returns: The max AccessType available for the user on the object.\n        ' #NEWLINE# if ( user is None ) : #NEWLINE# #INDENT# if doc . get ( 'public' , False ) : #NEWLINE# #INDENT# return AccessType . READ #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return AccessType . NONE #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if user . get ( 'admin' , False ) : #NEWLINE# #INDENT# return AccessType . ADMIN #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# access = doc . get ( 'access' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# level = AccessType . NONE #NEWLINE# if ( doc [ '_id' ] in user . get ( 'groups' , [ ] ) ) : #NEWLINE# #INDENT# level = AccessType . READ #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( doc [ '_id' ] in [ i [ 'groupId' ] for i in user . get ( 'groupInvites' , [ ] ) ] ) : #NEWLINE# #INDENT# return AccessType . READ #NEWLINE# #UNINDENT# #UNINDENT# for userAccess in access . get ( 'users' , [ ] ) : #NEWLINE# #INDENT# if ( userAccess [ 'id' ] == user [ '_id' ] ) : #NEWLINE# #INDENT# level = max ( level , userAccess [ 'level' ] ) #NEWLINE# if ( level == AccessType . ADMIN ) : #NEWLINE# #INDENT# return level #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return level