Projet

Général

Profil

Révision 140af436

Ajouté par Julien Enselme il y a plus de 10 ans

fix-cas.py: posait problème si on voulait modifier tout les
utilisateurs authentifié.

Voir les différences:

other-scripts/fix-cas.py
23 23
            tables[key] = elt.format(prefix)
24 24

  
25 25
        # We take into account the roles to modify
26
        for role in roles:
27
            i = roles.index(role)
28
            roles[i] = "'" + role + "'"
29
        format_dict = {'roles_to_modify': ', '.join(roles)}
30

  
31
        # We are ready to format queries
32
        format_dict.update(tables)
33

  
34
        select = """SELECT {users}.name, {users}.uid FROM {users}
35
        JOIN {users_roles} ON {users_roles}.uid = {users}.uid
36
        JOIN {role} ON {role}.rid = {users_roles}.rid
37
        WHERE {role}.name IN ({roles_to_modify}) AND {users}.uid NOT IN
38
        (SELECT uid FROM {cas_user})
39
        """.format(**format_dict)
26
        # If 'authenticated user' is among them, then we modify all users
27
        if 'authenticated user' not in roles:
28
            for role in roles:
29
                i = roles.index(role)
30
                roles[i] = "'" + role + "'"
31
            format_dict = {'roles_to_modify': ', '.join(roles)}
32

  
33
            # We are ready to format queries
34
            format_dict.update(tables)
35

  
36
            select = """SELECT {users}.name, {users}.uid FROM {users}
37
            JOIN {users_roles} ON {users_roles}.uid = {users}.uid
38
            JOIN {role} ON {role}.rid = {users_roles}.rid
39
            WHERE {role}.name IN ({roles_to_modify}) AND {users}.uid NOT IN
40
            (SELECT uid FROM {cas_user})
41
            """.format(**format_dict)
42
        else:
43
            select = """SELECT {users}.name, {users}.uid FROM {users}
44
            WHERE {users}.uid NOT IN (SELECT uid FROM {cas_user})""".format(**tables)
40 45

  
41 46
        insert = """INSERT INTO {cas_user} (uid, cas_name)
42 47
        VALUES (%s, %s)
43
        """.format(**format_dict)
48
        """.format(**tables)
44 49

  
45 50
        cur.execute(select)
46 51
        rows = cur.fetchall()

Formats disponibles : Unified diff