(user_id)
return [{
        'id': row[0],
        'max_inactivity': row[1].total_seconds(),
        'message': row[2],
        'contacts': [{
            'id': row[3][n],
            'username': row[4][n],
            'full_name': row[5][n],
            'email': row[6][n],
        } for n in range(len(row[3]))]
    } for row in cursor.fetchall()]
Return all inactivity groups of which a user is member and where they
    exceed the maximum inactivity period. For those groups, a list of contact
    users is included as well (if any).
Return all inactivity groups of which a user is member and where they
    exceed the maximum inactivity period. For those groups, a list of contact
    users is included as well (if any).
Return all inactivity groups of which a user is member and where they exceed the maximum inactivity period . For those groups a list of contact users is included as well ( if any ) .
def get_exceeded_inactivity_periods(user_id) -> List[Dict[str, Any]]:
    """Return all inactivity groups of which a user is member and where they
    exceed the maximum inactivity period. For those groups, a list of contact
    users is included as well (if any).
    """
    cursor = connection.cursor()
    cursor.execute("""
        SELECT g.id, g.max_inactivity, g.message, c.user_ids, c.user_logins,
            c.user_names, c.user_emails
        FROM (
            SELECT cgi.id, cgi.max_inactivity, cgi.message
            FROM catmaid_group_inactivity_period cgi
            JOIN auth_user_groups aug
                ON aug.group_id = cgi.group_id
            JOIN auth_user au
                ON au.id = aug.user_id
            WHERE cgi.max_inactivity < (now() - au.last_login)
                AND aug.user_id = %(user_id)s
            ORDER BY cgi.max_inactivity ASC
        ) g
        JOIN LATERAL (
            SELECT array_agg(igc.user_id) AS user_ids,
                array_agg(u.username) AS user_logins,
                array_agg(u.first_name || ' ' || u.last_name) AS user_names,
                array_agg(u.email) as user_emails
            FROM catmaid_group_inactivity_period_contact igc
            JOIN auth_user u
                ON u.id = igc.user_id
            WHERE igc.inactivity_period_id = g.id
        ) c
        ON TRUE
    """, {
        'user_id': user_id
    })

    return [{
        'id': row[0],
        'max_inactivity': row[1].total_seconds(),
        'message': row[2],
        'contacts': [{
            'id': row[3][n],
            'username': row[4][n],
            'full_name': row[5][n],
            'email': row[6][n],
        } for n in range(len(row[3]))]
    } for row in cursor.fetchall()]
def get_exceeded_inactivity_periods ( user_id ) -> List [ Dict [ str , Any ] ] : cursor = connection . cursor ( ) cursor . execute ( """
        SELECT g.id, g.max_inactivity, g.message, c.user_ids, c.user_logins,
            c.user_names, c.user_emails
        FROM (
            SELECT cgi.id, cgi.max_inactivity, cgi.message
            FROM catmaid_group_inactivity_period cgi
            JOIN auth_user_groups aug
                ON aug.group_id = cgi.group_id
            JOIN auth_user au
                ON au.id = aug.user_id
            WHERE cgi.max_inactivity < (now() - au.last_login)
                AND aug.user_id = %(user_id)s
            ORDER BY cgi.max_inactivity ASC
        ) g
        JOIN LATERAL (
            SELECT array_agg(igc.user_id) AS user_ids,
                array_agg(u.username) AS user_logins,
                array_agg(u.first_name || ' ' || u.last_name) AS user_names,
                array_agg(u.email) as user_emails
            FROM catmaid_group_inactivity_period_contact igc
            JOIN auth_user u
                ON u.id = igc.user_id
            WHERE igc.inactivity_period_id = g.id
        ) c
        ON TRUE
    """ , { 'user_id' : user_id } ) return [ { 'id' : row [ 0 ] , 'max_inactivity' : row [ 1 ] . total_seconds ( ) , 'message' : row [ 2 ] , 'contacts' : [ { 'id' : row [ 3 ] [ n ] , 'username' : row [ 4 ] [ n ] , 'full_name' : row [ 5 ] [ n ] , 'email' : row [ 6 ] [ n ] , } for n in range ( len ( row [ 3 ] ) ) ] } for row in cursor . fetchall ( ) ]