'If an entity ID is provided, the dict will be the users
with roles assigned to that entity. The key will be the user IDs.
If a user ID is provided, the dict will be the entities the
user has roles for. The key will be the entity pe_ids.
If both an entity and user ID is provided, the dict will be
the roles assigned to that user for that entity. The key will be
the user ID.
@type entity_id: int
@param entity_id: the pe_id of the entity
@type user_id: int
@param user_id: id of the user account
@return: dict
1: [
"staff_reader",
"project_reader",
2: ['

def get_assigned_roles(self, entity_id=None, user_id=None):

    if ((not entity_id) and (not user_id)):
        raise RuntimeError('Not    enough    arguments')
    mtable = current.auth.settings.table_membership
    gtable = current.auth.settings.table_group
    utable = current.auth.settings.table_user
    query = (((((mtable.deleted != True) & (gtable.deleted != True)) & (gtable.id == mtable.group_id)) & (utable.deleted != True)) & (utable.id == mtable.user_id))
    if user_id:
        field = mtable.pe_id
        query &= ((mtable.user_id == user_id) & (mtable.pe_id != None))
    if entity_id:
        field = utable.id
        query &= (mtable.pe_id == entity_id)
    rows = current.db(query).select(utable.id, gtable.uuid, mtable.pe_id)
    assigned_roles = OrderedDict()
    roles = self.roles
    for row in rows:
        object_id = row[field]
        role_uid = row[gtable.uuid]
        if (role_uid in roles):
            if (object_id not in assigned_roles):
                assigned_roles[object_id] = []
            assigned_roles[object_id].append(role_uid)
    return assigned_roles
